From 4a4311e8297c138b5456823277429192fab447eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Arod?= Date: Tue, 17 Sep 2024 13:54:59 +0200 Subject: [PATCH] reafactor: deplace desc --- src/notion/publish/v2/publishStatsToPage.ts | 2 +- src/statistiques/v2/ELStatsV2.ts | 2 +- src/statistiques/v2/{ => desc}/StatsDesc.ts | 2 +- .../v2/generales/StatsGenerales.ts | 2 +- src/statistiques/v2/penales/StatsPenales.ts | 2 +- .../v2/penales/computeSankeyData.ts | 19 +++++++++++++++++++ src/statistiques/v2/sankey/SankeyData.ts | 8 ++++++++ .../v2/sankey/sankeyDataToMermaidDiagram.ts | 5 +++++ src/statistiques/v2/sociales/StatsSociales.ts | 2 +- 9 files changed, 38 insertions(+), 6 deletions(-) rename src/statistiques/v2/{ => desc}/StatsDesc.ts (91%) create mode 100644 src/statistiques/v2/penales/computeSankeyData.ts create mode 100644 src/statistiques/v2/sankey/SankeyData.ts create mode 100644 src/statistiques/v2/sankey/sankeyDataToMermaidDiagram.ts diff --git a/src/notion/publish/v2/publishStatsToPage.ts b/src/notion/publish/v2/publishStatsToPage.ts index 5ecbb82..8e3e2c3 100644 --- a/src/notion/publish/v2/publishStatsToPage.ts +++ b/src/notion/publish/v2/publishStatsToPage.ts @@ -6,7 +6,7 @@ import { StatDesc, StatGroupDesc, StatsType, -} from "../../../statistiques/v2/StatsDesc"; +} from "../../../statistiques/v2/desc/StatsDesc"; import { listAllChildrenBlocks } from "../../utils/listAllChildrenBlocks"; import { removeBlocks } from "../../utils/removeBlocks"; diff --git a/src/statistiques/v2/ELStatsV2.ts b/src/statistiques/v2/ELStatsV2.ts index f652e32..eea6347 100644 --- a/src/statistiques/v2/ELStatsV2.ts +++ b/src/statistiques/v2/ELStatsV2.ts @@ -1,5 +1,5 @@ import { statsPenalesDesc } from "./penales/StatsPenales"; -import { StatsType } from "./StatsDesc"; +import { StatsType } from "./desc/StatsDesc"; export const eLStatsV2Desc = { label: "Stats v2", diff --git a/src/statistiques/v2/StatsDesc.ts b/src/statistiques/v2/desc/StatsDesc.ts similarity index 91% rename from src/statistiques/v2/StatsDesc.ts rename to src/statistiques/v2/desc/StatsDesc.ts index 72da807..8629bdd 100644 --- a/src/statistiques/v2/StatsDesc.ts +++ b/src/statistiques/v2/desc/StatsDesc.ts @@ -1,4 +1,4 @@ -import { ValueFormatOptions } from "../../format/ValueFormatOptions"; +import { ValueFormatOptions } from "../../../format/ValueFormatOptions"; export type StatGroupDesc = { label: string; diff --git a/src/statistiques/v2/generales/StatsGenerales.ts b/src/statistiques/v2/generales/StatsGenerales.ts index cc5b58c..55b0871 100644 --- a/src/statistiques/v2/generales/StatsGenerales.ts +++ b/src/statistiques/v2/generales/StatsGenerales.ts @@ -1,4 +1,4 @@ -import { StatsType } from "../StatsDesc"; +import { StatsType } from "../desc/StatsDesc"; export const statsGeneralesDesc = { label: "Stats Générales", diff --git a/src/statistiques/v2/penales/StatsPenales.ts b/src/statistiques/v2/penales/StatsPenales.ts index e2a48d5..61b7b54 100644 --- a/src/statistiques/v2/penales/StatsPenales.ts +++ b/src/statistiques/v2/penales/StatsPenales.ts @@ -1,4 +1,4 @@ -import { StatsType } from "../StatsDesc"; +import { StatsType } from "../desc/StatsDesc"; export const statsPenalesDesc = { label: "Stats Pénales", diff --git a/src/statistiques/v2/penales/computeSankeyData.ts b/src/statistiques/v2/penales/computeSankeyData.ts new file mode 100644 index 0000000..a076cba --- /dev/null +++ b/src/statistiques/v2/penales/computeSankeyData.ts @@ -0,0 +1,19 @@ +import { Famille } from "../../../data/Famille"; +import { SankeyData } from "../sankey/SankeyData"; +export function computeSequencEvtPenalSankeyData(familles: Famille[]) { + const sankeyData: SankeyData = {}; + + familles.forEach((f) => { + // Compute all transitions, Events are already sorted + for (let index = 0; index < f.Evenements.length - 1; index++) { + const fromEvt = f.Evenements[index]; + const toEvt = f.Evenements[index + 1]; + const fromTransitions = sankeyData[fromEvt.Type] || {}; + sankeyData[fromEvt.Type] = { + ...fromTransitions, + [toEvt.Type]: (fromTransitions[toEvt.Type] || 0) + 1, + }; + } + }); + return sankeyData; +} diff --git a/src/statistiques/v2/sankey/SankeyData.ts b/src/statistiques/v2/sankey/SankeyData.ts new file mode 100644 index 0000000..9e31946 --- /dev/null +++ b/src/statistiques/v2/sankey/SankeyData.ts @@ -0,0 +1,8 @@ +/** + * Sankey diagram transitions + */ +export type SankeyData = { + [fromKey: string]: { + [toKey: string]: number; + }; +}; diff --git a/src/statistiques/v2/sankey/sankeyDataToMermaidDiagram.ts b/src/statistiques/v2/sankey/sankeyDataToMermaidDiagram.ts new file mode 100644 index 0000000..7a9fe08 --- /dev/null +++ b/src/statistiques/v2/sankey/sankeyDataToMermaidDiagram.ts @@ -0,0 +1,5 @@ +import { SankeyData } from "./SankeyData"; + +eport function sankeyDataToMermaidDiagram(sankeyData: SankeyData) { + +} \ No newline at end of file diff --git a/src/statistiques/v2/sociales/StatsSociales.ts b/src/statistiques/v2/sociales/StatsSociales.ts index 80cace8..04ed465 100644 --- a/src/statistiques/v2/sociales/StatsSociales.ts +++ b/src/statistiques/v2/sociales/StatsSociales.ts @@ -1,4 +1,4 @@ -import { StatsType } from "../StatsDesc"; +import { StatsType } from "../desc/StatsDesc"; export const statsSocialesDesc = { label: "Stats Sociales",