feat: stats générales v2
parent
a6c42aef80
commit
5e109539c0
23
src/index.ts
23
src/index.ts
|
@ -8,6 +8,8 @@ import { computeELStats } from "./statistiques/v1/computeELStats";
|
||||||
import { computeStatsParAnciennete } from "./statistiques/v1/computeEvenementsParAnciennete";
|
import { computeStatsParAnciennete } from "./statistiques/v1/computeEvenementsParAnciennete";
|
||||||
import { computeStatsPenales } from "./statistiques/v2/penales/computeStatsPenales";
|
import { computeStatsPenales } from "./statistiques/v2/penales/computeStatsPenales";
|
||||||
import { statsPenalesDesc } from "./statistiques/v2/penales/StatsPenales";
|
import { statsPenalesDesc } from "./statistiques/v2/penales/StatsPenales";
|
||||||
|
import { computeStatsGenerales } from "./statistiques/v2/generales/computeStatsGenerales";
|
||||||
|
import { statsGeneralesDesc } from "./statistiques/v2/generales/StatsGenerales";
|
||||||
|
|
||||||
type ProcessOptions = {
|
type ProcessOptions = {
|
||||||
dryRun: boolean;
|
dryRun: boolean;
|
||||||
|
@ -69,7 +71,8 @@ function buildProcessOptions(): ProcessOptions {
|
||||||
JSON.stringify(statsParAnciennete, null, " ")
|
JSON.stringify(statsParAnciennete, null, " ")
|
||||||
);
|
);
|
||||||
|
|
||||||
const statsV2 = computeStatsPenales(familles);
|
const statsPenales = computeStatsPenales(familles);
|
||||||
|
const statsGenerales = computeStatsGenerales(familles);
|
||||||
|
|
||||||
if (options.dryRun) {
|
if (options.dryRun) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -77,7 +80,14 @@ function buildProcessOptions(): ProcessOptions {
|
||||||
);
|
);
|
||||||
writeFileSync("./el-stats-v1.json", JSON.stringify(elStats, null, " "));
|
writeFileSync("./el-stats-v1.json", JSON.stringify(elStats, null, " "));
|
||||||
|
|
||||||
writeFileSync("./el-stats-v2.json", JSON.stringify(statsV2, null, " "));
|
writeFileSync(
|
||||||
|
"./el-stats-v2.json",
|
||||||
|
JSON.stringify(
|
||||||
|
{ generales: statsGenerales, penales: statsPenales },
|
||||||
|
null,
|
||||||
|
" "
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log("Publishing statistics...");
|
console.log("Publishing statistics...");
|
||||||
await publishStatisticsToNotion(elStats, currentDate, notionClient);
|
await publishStatisticsToNotion(elStats, currentDate, notionClient);
|
||||||
|
@ -87,7 +97,14 @@ function buildProcessOptions(): ProcessOptions {
|
||||||
"969eac5c-a4eb-49d4-b4ad-c341c9c4c785",
|
"969eac5c-a4eb-49d4-b4ad-c341c9c4c785",
|
||||||
|
|
||||||
statsPenalesDesc,
|
statsPenalesDesc,
|
||||||
statsV2
|
statsPenales
|
||||||
|
);
|
||||||
|
await publishStatsToPage(
|
||||||
|
notionClient,
|
||||||
|
"313751fb-daed-4b33-992f-c86d7ac2de37",
|
||||||
|
|
||||||
|
statsGeneralesDesc,
|
||||||
|
statsGenerales
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { StatsType } from "../StatsDesc";
|
||||||
|
|
||||||
|
export const statsGeneralesDesc = {
|
||||||
|
label: "Stats Générales",
|
||||||
|
stats: {
|
||||||
|
nbFamillesActuellementResistantes: {
|
||||||
|
label: "Nb Familles actuellement Résistantes",
|
||||||
|
},
|
||||||
|
nbFamillesResistantesDepuisLeDebut: {
|
||||||
|
label: "Nb Familles Résistantes depuis le début du mouvement",
|
||||||
|
},
|
||||||
|
|
||||||
|
dureeResistanceMoyenne: {
|
||||||
|
label: "Duree de résistantes moyenne",
|
||||||
|
unit: " jours",
|
||||||
|
},
|
||||||
|
|
||||||
|
dureeResistanceMedianne: {
|
||||||
|
label: "Duree de résistantes médiane",
|
||||||
|
unit: " jours",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type StatsGenerales = StatsType<typeof statsGeneralesDesc>;
|
|
@ -0,0 +1,26 @@
|
||||||
|
import {
|
||||||
|
dureeResistanceInDays,
|
||||||
|
Famille,
|
||||||
|
isExResistant,
|
||||||
|
isResistant,
|
||||||
|
} from "../../../data/Famille";
|
||||||
|
import { average } from "../../../utils/math/average";
|
||||||
|
import { median } from "../../../utils/math/median";
|
||||||
|
import { StatsGenerales } from "./StatsGenerales";
|
||||||
|
|
||||||
|
export function computeStatsGenerales(familles: Famille[]): StatsGenerales {
|
||||||
|
const famillesResistantesOrEx = familles.filter(
|
||||||
|
(f) => isResistant(f) || isExResistant(f)
|
||||||
|
);
|
||||||
|
const dureesResistances = famillesResistantesOrEx.map(
|
||||||
|
(f) => dureeResistanceInDays(f)!
|
||||||
|
);
|
||||||
|
const statsGenerales: StatsGenerales = {
|
||||||
|
nbFamillesActuellementResistantes: familles.filter((f) => isResistant(f))
|
||||||
|
.length,
|
||||||
|
nbFamillesResistantesDepuisLeDebut: famillesResistantesOrEx.length,
|
||||||
|
dureeResistanceMedianne: median(dureesResistances),
|
||||||
|
dureeResistanceMoyenne: average(dureesResistances),
|
||||||
|
};
|
||||||
|
return statsGenerales;
|
||||||
|
}
|
Loading…
Reference in New Issue