Skip to content

Commit

Permalink
Get udis and tap water
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlesdoiron committed Mar 7, 2024
1 parent 583682d commit 2f741de
Show file tree
Hide file tree
Showing 7 changed files with 54,973 additions and 6,884 deletions.
7 changes: 3 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ libs
mail
node_modules

api-node/data/municipalities.json
api-node/data/municipalities-consolidated.json
api-node/data/epci.json
api-node/data/*

CHANGELOG.md
pyrightconfig.json
README.md
api-node/.yarn
api-node/.yarnrc.yml
api-node/.yarnrc.yml
**/*.json
26 changes: 21 additions & 5 deletions api-node/src/controllers/udi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod';
import { catchErrors } from '../middlewares/errors';
import { type CustomError } from '~/types/error';
import { UdiService } from '~/service/udi.js';
import { type TabWaterResponse } from '~/types/api/tap_water';

const router = express.Router();

Expand All @@ -29,17 +30,32 @@ router.post(
next(customError);
}
const { lat, lon } = req.body;
const currentUdi = await UdiService.getUdiByCoordinates(lat, lon);
if (!currentUdi) {
const currentUdi = UdiService.getUdiByCoordinates(lat, lon);
if (!currentUdi[0]) {
res.status(404).send({ error: 'No UDI found' });
return;
}

const result = await fetch(
`https://hubeau.eaufrance.fr/api/v1/qualite_eau_potable/resultats_dis?code_reseau=${currentUdi}&size=20`,
`https://hubeau.eaufrance.fr/api/v1/qualite_eau_potable/resultats_dis?code_reseau=${currentUdi[0]}&size=20`,
);
const data = await result.json();
res.status(200).send({ ok: true, data: { currentUdi, data } });
const data = (await result.json()) as TabWaterResponse;
const sub_indicators = data.data.map((d) => {
return {
label: d.libelle_parametre,
value: d.resultat_numerique,
unit: d.libelle_unite,
conformity_pc: d.conformite_references_pc_prelevement,
};
});
const indicator = {
conclusion: data.data[0].conclusion_conformite_prelevement,
confirmity: data.data[0].conformite_references_pc_prelevement,
date: data.data[0].date_prelevement,
// all: data.data,
};

res.status(200).send({ ok: true, indicator, sub_indicators });
},
),
);
Expand Down
4 changes: 2 additions & 2 deletions api-node/src/service/udi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import * as turf from '@turf/turf';
// 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]';
export namespace UdiService {
const udisData = udis as Udis;
export async function getUdiByCoordinates(
export function getUdiByCoordinates(
lat: number,
long: number,
): Promise<Array<string | null>> {
): Array<string | null> {
const currentCoordinates = turf.point([long, lat]);
return udisData.features
.map((feature) => {
Expand Down
49 changes: 49 additions & 0 deletions api-node/src/types/api/tap_water.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export interface TabWaterResponse {
count: number;
first: string;
last: string;
prev: any;
next: string;
api_version: string;
data: TabWaterData[];
}

export interface TabWaterData {
code_departement: string;
nom_departement: string;
code_prelevement: string;
code_parametre: string;
code_parametre_se: string;
code_parametre_cas?: string;
libelle_parametre: string;
libelle_parametre_maj: string;
libelle_parametre_web: any;
code_type_parametre: string;
code_lieu_analyse: string;
resultat_alphanumerique: string;
resultat_numerique: number;
libelle_unite: string;
code_unite: string;
limite_qualite_parametre?: string;
reference_qualite_parametre?: string;
code_commune: string;
nom_commune: string;
nom_uge: string;
nom_distributeur: string;
nom_moa: string;
date_prelevement: string;
conclusion_conformite_prelevement: string;
conformite_limites_bact_prelevement: string;
conformite_limites_pc_prelevement: string;
conformite_references_bact_prelevement: string;
conformite_references_pc_prelevement: string;
reference_analyse?: string;
code_installation_amont: any;
nom_installation_amont: any;
reseaux: Reseaux[];
}

export interface Reseaux {
code: string;
nom: string;
}
Loading

0 comments on commit 2f741de

Please sign in to comment.