Skip to content

Commit

Permalink
Tableau json transformer en dictionnaire pour un parcours plus rapide…
Browse files Browse the repository at this point in the history
… et facile
  • Loading branch information
thomasduppi committed Jan 23, 2024
1 parent 96b9eb0 commit 50dc89c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions Code source/assets/js/locura4iot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const listNodeWithColor = [];
const listNodeWithColor = {};
// Le listNodeWithColor est de la forme
// [0:{node: "0xFD24", targets: ["0x35A1", "0x2EF4", "0x8C05", "0x907D", "0xBA89"], times: [23.0, 0.0, 0.0, 0.0, 0.0], couleur: "#FFFFFF"}]
// Nous voulons le passer à la forme
Expand Down Expand Up @@ -42,15 +42,15 @@ async function lirePortSerie() {
for (let i = 0; i < lines.length - 1; i++) {
try {
const jsonData = JSON.parse(lines[i]); // Convertit la ligne en objet JSON
const nodeExistante = listNodeWithColor.some(item => item.node === jsonData.node);

const nodeExistante = jsonData.node in listNodeWithColor ? true : false;

//SI C'EST UNE NOUVELLE EQUIPE
if (!nodeExistante) {
// Ajoute un attribut "couleur" avec une couleur générée
jsonData.couleur = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
//admin : createTableau(jsonData);
listNodeWithColor.push(jsonData);
listNodeWithColor[jsonData.node] = jsonData;
localStorage.setItem('listNodeWithColor', JSON.stringify(listNodeWithColor));
}
console.log(listNodeWithColor);
Expand All @@ -64,13 +64,6 @@ async function lirePortSerie() {

textStreamReader.releaseLock(); // Ferme les flux après la lecture
await readableStreamClosed;

// On effectue la conversion de listNodeWithColor en objet JSON
// const listNodeWithColorJSON = {};
// listNodeWithColor.forEach(item => {
// listNodeWithColorJSON[item.node] = item;
// });
// console.log(listNodeWithColorJSON);
}
catch (error) {
console.error('Erreur lors de la demande ou de l\'ouverture du port série :', error);
Expand Down

0 comments on commit 50dc89c

Please sign in to comment.