Skip to content

Commit

Permalink
fix(stats): handle null index and values (Fixes #1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsagetlethias committed Aug 30, 2023
1 parent 082310d commit 42a7e89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@ export class PostgresPublicStatsRepo implements IPublicStatsRepo {
year,
SUM(CASE WHEN year = ${CURRENT_YEAR} THEN 1 ELSE 0 END) AS count,
SUM(CASE
WHEN (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres')::float > 30 THEN 1
WHEN jsonb_typeof(data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres') = 'number'
AND (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres')::text::float > 30 THEN 1
ELSE 0
END) AS countWomen30percentExecutives_gt,
SUM(CASE
WHEN (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres')::float <= 30 THEN 1
WHEN jsonb_typeof(data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres') = 'number'
AND (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_cadres')::text::float <= 30 THEN 1
ELSE 0
END) AS countWomen30percentExecutives_lte,
SUM(CASE
WHEN (data->'indicateurs'->'représentation_équilibrée'->'motif_non_calculabilité_cadres') IS NOT NULL THEN 1
ELSE 0
END) AS countWomen30percentExecutives_nc,
SUM(CASE
WHEN (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres')::float > 30 THEN 1
WHEN jsonb_typeof(data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres') = 'number'
AND (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres')::text::float > 30 THEN 1
ELSE 0
END) AS countWomen30percentMembers_gt,
SUM(CASE
WHEN (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres')::float <= 30 THEN 1
WHEN jsonb_typeof(data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres') = 'number'
AND (data->'indicateurs'->'représentation_équilibrée'->'pourcentage_femmes_membres')::text::float <= 30 THEN 1
ELSE 0
END) AS countWomen30percentMembers_lte,
SUM(CASE
Expand All @@ -55,7 +59,10 @@ export class PostgresPublicStatsRepo implements IPublicStatsRepo {
year,
(data->'entreprise'->'effectif'->'tranche')::text AS workforce_range,
COUNT(*) AS count,
AVG((data->'déclaration'->'index')::numeric) AS average
AVG(CASE
WHEN jsonb_typeof(data->'déclaration'->'index') = 'number' THEN (data->'déclaration'->'index')::text::numeric
ELSE NULL
END) AS average
FROM
${this.declarationTable}
WHERE
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export type FeatureFlag = keyof typeof config.ff;

export const config = {
/** in seconds */
searchRevalidate: 60 * 5,
get searchRevalidate() {
return this.env === "dev" ? 1 : 60 * 5;
},
get nonce() {
return this.githubSha;
},
Expand Down

0 comments on commit 42a7e89

Please sign in to comment.