-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get accessibilite from acces libre database (#87)
* feat: get accessibilite from acces libre database * fix: reduce size of database of acces libre
- Loading branch information
Showing
5 changed files
with
139 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 48 additions & 3 deletions
51
src/transformer/fields/accessibilite/accessibilite.field.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
import { Url } from '@gouvfr-anct/lieux-de-mediation-numerique'; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
import { Adresse, Url } from '@gouvfr-anct/lieux-de-mediation-numerique'; | ||
import { LieuxMediationNumeriqueMatching, DataSource, Colonne } from '../../input'; | ||
import { ratio } from 'fuzzball'; | ||
|
||
export type Erp = { | ||
name: string; | ||
siret: string; | ||
web_url: string; | ||
voie: string; | ||
numero: string; | ||
postal_code: string; | ||
}; | ||
|
||
const getAccessibiliteFromAccesLibre = ( | ||
source: DataSource, | ||
matching: LieuxMediationNumeriqueMatching, | ||
accesLibreData: Erp[], | ||
adresseProcessed: Adresse | ||
): Url | undefined => { | ||
const erpMatchWithScores: Erp[] = accesLibreData | ||
.filter((erp: Erp): boolean => erp.postal_code === adresseProcessed.code_postal) | ||
.filter( | ||
(erp: Erp): boolean => | ||
ratio(source[matching.nom.colonne] ?? '', erp.name) > 60 || | ||
ratio(adresseProcessed.voie, erp.numero.concat(' ', erp.voie)) > 60 | ||
); | ||
|
||
const accesLibreUrlByFuzzyMatch: string | undefined = | ||
erpMatchWithScores.length === 1 ? erpMatchWithScores[0]?.web_url : undefined; | ||
const currentPivot: string | undefined = | ||
matching.pivot?.colonne != null && source[matching.pivot.colonne] !== '' ? source[matching.pivot.colonne] : undefined; | ||
const accesLibreUrlBySiretMatch: string | undefined = | ||
erpMatchWithScores.find((erp: Erp): boolean => erp.siret === currentPivot)?.web_url ?? undefined; | ||
|
||
const accesLibreUrl: string | undefined = accesLibreUrlBySiretMatch ?? accesLibreUrlByFuzzyMatch ?? undefined; | ||
|
||
return accesLibreUrl == null ? undefined : Url(accesLibreUrl); | ||
}; | ||
|
||
const canProcessAccessibilite = (source: DataSource, accessibilite?: Colonne): accessibilite is Colonne => | ||
accessibilite?.colonne != null && source[accessibilite.colonne] != null && source[accessibilite.colonne] !== ''; | ||
|
||
export const processAccessibilite = (source: DataSource, matching: LieuxMediationNumeriqueMatching): Url | undefined => | ||
canProcessAccessibilite(source, matching.accessibilite) ? Url(source[matching.accessibilite.colonne] ?? '') : undefined; | ||
export const processAccessibilite = ( | ||
source: DataSource, | ||
matching: LieuxMediationNumeriqueMatching, | ||
accesLibreData: Erp[], | ||
adresseProcessed: Adresse | ||
): Url | undefined => | ||
canProcessAccessibilite(source, matching.accessibilite) | ||
? Url(source[matching.accessibilite.colonne] ?? '') | ||
: getAccessibiliteFromAccesLibre(source, matching, accesLibreData, adresseProcessed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters