Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Création d'un schéma dédié aux statistiques publiques #2741

Merged
merged 13 commits into from
Feb 18, 2025
Merged
Binary file modified .database/potentiel-dev.dump
Binary file not shown.
16 changes: 16 additions & 0 deletions .github/workflows/shared-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ jobs:
cache: 'npm'
- run: npm ci
- run: npm run test:libraries

verify_statistics:
runs-on: ubuntu-latest
env:
EVENT_STORE_CONNECTION_STRING: postgres://potadmindb:localpwd@localhost:5432/potentiel

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm run up
- run: npm exec potentiel-cli stats extraire
4 changes: 4 additions & 0 deletions cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"command": "0 10 1 * * ./packages/applications/scheduled-tasks/notifier-gestionnaires-réseau.sh",
"size": "M"
},
{
"command": "0 6 * * * ./packages/applications/scheduled-tasks/extraire-données-statistiques-publiques.sh",
"size": "M"
},
{
"command": "0 2 * * * ./packages/applications/scheduler/scheduler.sh",
"size": "M"
Expand Down
29 changes: 28 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"./packages/libraries/*",
"./packages/domain/*",
"./packages/infrastructure/*",
"./packages/statistiques/*",
"./packages/applications/*",
"./packages/specifications"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/applications/cli/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DATABASE
EVENT_STORE_CONNECTION_STRING=postgres://potadmindb:localpwd@localhost:5432/potentiel
3 changes: 2 additions & 1 deletion packages/applications/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"@potentiel-libraries/keycloak-cjs": "*",
"@potentiel-domain/reseau": "*",
"@potentiel-applications/bootstrap": "*",
"@potentiel-infrastructure/domain-adapters": "*"
"@potentiel-infrastructure/domain-adapters": "*",
"@potentiel-statistiques/statistiques-publiques": "*"
},
"devDependencies": {
"@potentiel-config/tsconfig": "*",
Expand Down
39 changes: 39 additions & 0 deletions packages/applications/cli/src/commands/stats/extraire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Command } from '@oclif/core';
import { z } from 'zod';

import {
cleanStatistiquesPubliques,
computeStatistiquesPubliques,
} from '@potentiel-statistiques/statistiques-publiques';

const configSchema = z.object({
EVENT_STORE_CONNECTION_STRING: z.string(),
});

export default class ExtraireStats extends Command {
static override description =
'Extrait les données des statistiques publiques (permet de tester la tâche planifiée dédiée)';

static override args = {};

static override flags = {};

public async init() {
const { success } = configSchema.safeParse(process.env);
console.info(`Env variables defined : ${success}`);
}

public async run(): Promise<void> {
console.info('Lancement du script...');

console.info('Clean données statistiques publiques existantes');
await cleanStatistiquesPubliques();

console.info('Compute nouvelles données statistiques publiques');
await computeStatistiquesPubliques();

console.info('Fin du script ✨');

process.exit(0);
}
}
3 changes: 3 additions & 0 deletions packages/applications/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{ "path": "../../domain/réseau" },
{
"path": "../../infrastructure/domain-adapters"
},
{
"path": "../../statistiques/statistiques-publiques"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash -l


if [ -z $EVENT_STORE_CONNECTION_STRING ]
then
echo "Connection is missing!"
exit 1
fi

if [ -z $SENTRY_CRONS ]
then
echo "A monitoring variable is missing !"
fi

SENTRY_URL=$(echo "$SENTRY_CRONS" | sed 's|<monitor_slug>|extraire-donnees-statistiques-publiques|')

handle_error() {
local message="Error on 'extraire-donnees-statistiques-publiques' script line $1"
echo $message

local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
local hostname=$(hostname)

curl "${MONITORING_URL}&status=error"

exit 1
}

trap 'handle_error $LINENO' ERR

echo "Launching job [EXTRAIRE DONNÉES STATISTIQUES PUBLIQUES]"

npm run start:extraire-données-statistiques-publiques -w @potentiel-applications/scheduled-tasks

curl "${MONITORING_URL}&status=ok"

exit 0
4 changes: 3 additions & 1 deletion packages/applications/scheduled-tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"start:créer-backup": "node ./dist/backup/créer-backup",
"start:mettre-à-jour-gestionnaire-réseau": "node ./dist/gestionnaireRéseau",
"start:récupérer-fichier-gf-candidature-référentiel-dgec": "node ./dist/garanties-financières/récupérer-fichier-gf-candidature-référentiel-dgec",
"start:notifier-gestionnaires-réseau": "node ./dist/raccordement/notifier-gestionnaires-réseau"
"start:notifier-gestionnaires-réseau": "node ./dist/raccordement/notifier-gestionnaires-réseau",
"start:extraire-données-statistiques-publiques": "node ./dist/statistiques-publiques/extraire-données-statistiques-publiques"
},
"dependencies": {
"@potentiel-applications/routes": "*",
"@potentiel-statistiques/statistiques-publiques": "*",
"@potentiel-domain/common": "*",
"@potentiel-domain/elimine": "*",
"@potentiel-domain/laureat": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {
cleanStatistiquesPubliques,
computeStatistiquesPubliques,
} from '@potentiel-statistiques/statistiques-publiques';

(async () => {
await cleanStatistiquesPubliques();
await computeStatistiquesPubliques();
process.exit(0);
})();
3 changes: 3 additions & 0 deletions packages/applications/scheduled-tasks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
},
{
"path": "../routes"
},
{
"path": "../../statistiques/statistiques-publiques"
}
]
}
17 changes: 17 additions & 0 deletions packages/statistiques/statistiques-publiques/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@potentiel-statistiques/statistiques-publiques",
"version": "0.0.0",
"description": "Statistics referential for the Potentiel public dashboard",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"private": true,
"scripts": {
"build": "tsc"
},
"dependencies": {
"@potentiel-libraries/pg-helpers": "*"
},
"devDependencies": {
"@potentiel-config/tsconfig": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create table if not exists domain_public_statistic.scalar_statistic (
type varchar primary key not null,
value decimal not null
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create schema if not exists domain_public_statistic;
12 changes: 12 additions & 0 deletions packages/statistiques/statistiques-publiques/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
cleanNombreTotalProjet,
computeNombreTotalProjet,
} from './projet/nombreTotalProjet.statistic';

export const cleanStatistiquesPubliques = async () => {
await cleanNombreTotalProjet();
};

export const computeStatistiquesPubliques = async () => {
await computeNombreTotalProjet();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { executeQuery } from '@potentiel-libraries/pg-helpers';

export const cleanNombreTotalProjet = () =>
executeQuery(`
delete
from domain_public_statistic.scalar_statistic
where type = 'nombreTotalProjet'
`);

export const computeNombreTotalProjet = () =>
executeQuery(
`
insert
into domain_public_statistic.scalar_statistic
values('nombreTotalProjet', (
select
count(*)
from
domain_views.projection
where key like 'candidature|%'))
`,
);
12 changes: 12 additions & 0 deletions packages/statistiques/statistiques-publiques/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@potentiel-config/tsconfig/tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"references": [
{
"path": "../../libraries/pg-helpers"
}
]
}
Loading