forked from dbroqua/MusicTopus
Added current year and last year in statistics page
This commit is contained in:
parent
48287f2bae
commit
14f46ae112
3 changed files with 228 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
import { format as formatDate } from "date-fns";
|
||||
import { format as formatDate, startOfYear, subYears } from "date-fns";
|
||||
import fs from "fs";
|
||||
|
||||
import Mastodon from "mastodon";
|
||||
|
@ -525,6 +525,22 @@ Publié automatiquement via #musictopus`;
|
|||
const top10 = [];
|
||||
let byStyles10 = [];
|
||||
const max = this.colors.length - 1;
|
||||
const startYear = startOfYear(new Date());
|
||||
const lastStartYear = startOfYear(subYears(new Date(), 1));
|
||||
const currentYear = {
|
||||
year: formatDate(startYear, "yyyy"),
|
||||
total: 0,
|
||||
byGenres: {},
|
||||
byStyles: {},
|
||||
byFormats: {},
|
||||
};
|
||||
const lastYear = {
|
||||
year: formatDate(lastStartYear, "yyyy"),
|
||||
total: 0,
|
||||
byGenres: {},
|
||||
byStyles: {},
|
||||
byFormats: {},
|
||||
};
|
||||
|
||||
const colorsCount = this.colors.length;
|
||||
|
||||
|
@ -535,7 +551,14 @@ Publié automatiquement via #musictopus`;
|
|||
|
||||
for (let i = 0; i < albums.length; i += 1) {
|
||||
const currentFormats = [];
|
||||
const { artists, genres, styles, formats } = albums[i];
|
||||
const { artists, genres, styles, formats, createdAt } = albums[i];
|
||||
|
||||
// INFO: On s'occupe de la rétrospective
|
||||
if (createdAt > startYear) {
|
||||
currentYear.total += 1;
|
||||
} else if (createdAt > lastStartYear) {
|
||||
lastYear.total += 1;
|
||||
}
|
||||
|
||||
// INFO: On regroupe les artistes par nom pour en faire le top10
|
||||
for (let j = 0; j < artists.length; j += 1) {
|
||||
|
@ -563,6 +586,28 @@ Publié automatiquement via #musictopus`;
|
|||
}
|
||||
|
||||
byGenres[name].count += 1;
|
||||
|
||||
// INFO: On s'occupe de la rétrospective
|
||||
if (createdAt > startYear) {
|
||||
if (!currentYear.byGenres[name]) {
|
||||
currentYear.total += 1;
|
||||
currentYear.byGenres[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byGenres[name].color,
|
||||
};
|
||||
}
|
||||
currentYear.byGenres[name].count += 1;
|
||||
} else if (createdAt > lastStartYear) {
|
||||
if (!lastYear.byGenres[name]) {
|
||||
lastYear.byGenres[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byGenres[name].color,
|
||||
};
|
||||
}
|
||||
lastYear.byGenres[name].count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// INFO: On regroupe les styles
|
||||
|
@ -579,6 +624,28 @@ Publié automatiquement via #musictopus`;
|
|||
}
|
||||
|
||||
byStyles[name].count += 1;
|
||||
|
||||
// INFO: On s'occupe de la rétrospective
|
||||
if (createdAt > startYear) {
|
||||
if (!currentYear.byStyles[name]) {
|
||||
currentYear.total += 1;
|
||||
currentYear.byStyles[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byStyles[name].color,
|
||||
};
|
||||
}
|
||||
currentYear.byStyles[name].count += 1;
|
||||
} else if (createdAt > lastStartYear) {
|
||||
if (!lastYear.byStyles[name]) {
|
||||
lastYear.byStyles[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byStyles[name].color,
|
||||
};
|
||||
}
|
||||
lastYear.byStyles[name].count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// INFO: On regroupe les formats
|
||||
|
@ -598,6 +665,28 @@ Publié automatiquement via #musictopus`;
|
|||
|
||||
byFormats[name].count += 1;
|
||||
currentFormats.push(name);
|
||||
|
||||
// INFO: On s'occupe de la rétrospective
|
||||
if (createdAt > startYear) {
|
||||
if (!currentYear.byFormats[name]) {
|
||||
currentYear.total += 1;
|
||||
currentYear.byFormats[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byFormats[name].color,
|
||||
};
|
||||
}
|
||||
currentYear.byFormats[name].count += 1;
|
||||
} else if (createdAt > lastStartYear) {
|
||||
if (!lastYear.byFormats[name]) {
|
||||
lastYear.byFormats[name] = {
|
||||
name,
|
||||
count: 0,
|
||||
color: byFormats[name].color,
|
||||
};
|
||||
}
|
||||
lastYear.byFormats[name].count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -644,6 +733,8 @@ Publié automatiquement via #musictopus`;
|
|||
this.setPageContent("byGenres", byGenres);
|
||||
this.setPageContent("byStyles", byStyles10);
|
||||
this.setPageContent("byFormats", byFormats);
|
||||
this.setPageContent("currentYear", currentYear);
|
||||
this.setPageContent("lastYear", lastYear);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue