Updated statistics

This commit is contained in:
Damien Broqua 2024-02-02 09:38:35 +01:00
parent bf2e9be3b7
commit 061e72c459
4 changed files with 118 additions and 72 deletions

View file

@ -165,24 +165,17 @@ Publié automatiquement via #musictopus`;
constructor(req, viewname) {
super(req, viewname);
this.colors = {
nord0: "#2e3440",
nord1: "#3b4252",
nord2: "#434c5e",
nord3: "#4C566A",
nord4: "#d8dee9",
nord5: "#e5e9f0",
nord6: "#eceff4",
nord7: "#8fbcbb",
nord8: "#88c0d0",
nord9: "#81a1c1",
nord10: "#5e81ac",
nord11: "#d08770",
nord12: "#bf616a",
nord13: "#ebcb8b",
nord14: "#a3be8c",
nord15: "#b48ead",
};
this.colors = [
"#2e3440",
"#d8dee9",
"#8fbcbb",
"#5e81ac",
"#d08770",
"#bf616a",
"#ebcb8b",
"#a3be8c",
"#b48ead",
];
}
/**
@ -535,6 +528,10 @@ Publié automatiquement via #musictopus`;
const byStyles = {};
const byFormats = {};
const top10 = [];
let byStyles10 = [];
const max = this.colors.length - 1;
const colorsCount = this.colors.length;
const albums = await AlbumsModel.find({
User,
@ -565,7 +562,7 @@ Publié automatiquement via #musictopus`;
name,
count: 0,
color: this.colors[
`nord${Object.keys(byGenres).length % 15}`
Object.keys(byGenres).length % colorsCount
],
};
}
@ -581,7 +578,7 @@ Publié automatiquement via #musictopus`;
name,
count: 0,
color: this.colors[
`nord${Object.keys(byStyles).length % 15}`
Object.keys(byStyles).length % colorsCount
],
};
}
@ -599,7 +596,7 @@ Publié automatiquement via #musictopus`;
name,
count: 0,
color: this.colors[
`nord${Object.keys(byFormats).length % 15}`
Object.keys(byFormats).length % colorsCount
],
};
}
@ -615,13 +612,42 @@ Publié automatiquement via #musictopus`;
top10.push(top[index]);
});
// INFO: On ordonne par quantité pour on récupère le top 10
// INFO: On convertit les styles en tableau
Object.keys(byStyles).forEach((index) => {
byStyles10.push(byStyles[index]);
});
// INFO: On ordonne les artistes par quantité d'albums
top10.sort((a, b) => (a.count > b.count ? -1 : 1));
// INFO: On ordonne les styles par quantité
byStyles10.sort((a, b) => (a.count > b.count ? -1 : 1));
const tmp = [];
// INFO: On recupère le top N des styles et on mets le reste dans le label "autre"
for (let i = 0; i < byStyles10.length; i += 1) {
if (i < max) {
tmp.push({
...byStyles10[i],
color: this.colors[max - i],
});
} else if (i === max) {
tmp.push({
name: "Autre",
count: 0,
color: this.colors[0],
});
tmp[max].count += byStyles10[i].count;
} else {
tmp[max].count += byStyles10[i].count;
}
}
byStyles10 = tmp;
this.setPageTitle("Mes statistiques");
this.setPageContent("top10", top10.splice(0, 10));
this.setPageContent("byGenres", byGenres);
this.setPageContent("byStyles", byStyles);
this.setPageContent("byStyles", byStyles10);
this.setPageContent("byFormats", byFormats);
}