-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add API EndPoint for BAN Address scoring #323
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,129 @@ async function computeFilteredStats(codesCommune) { | |
return {total, ban, bal} | ||
} | ||
|
||
module.exports = {computeStats, computeFilteredStats} | ||
async function computeScoringStats() { | ||
const toPercent = (value, total) => Math.round((value / total) * 100) | ||
|
||
async function getStatistics() { | ||
const guichetAddr = 'ign-api-gestion-ign' | ||
const adresseCollection = mongo.db.collection('numeros') | ||
|
||
// Total des documents 'adresse' | ||
const totalDocuments = await adresseCollection.countDocuments() | ||
|
||
// Nb-bal: Nombre de documents 'Adresse' avec source 'bal' | ||
const nbBal = await adresseCollection.countDocuments({sources: 'bal'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sur l'adresse, le champ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalement, quand on test sur une unique valeur, il me semble que cette syntaxe est OK ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est bien de l'avoir en tète. Mais pas un souci sur une condition égalité /in simple (et pour les sources bal normalement il est seul) |
||
|
||
// Score-5: Nombre de documents 'Adresse' avec source 'bal', certificationCommune à true, parcelles non vides et banId non null | ||
const score5 = await adresseCollection.countDocuments({ | ||
sources: 'bal', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
certificationCommune: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Le champ |
||
parcelles: {$not: {$size: 0}}, | ||
banId: {$ne: null}, | ||
}) | ||
|
||
// Score-4: Nombre de documents 'Adresse' avec source 'bal', certificationCommune à true ou parcelles non vides et banId non null (mais pas les deux à la fois) | ||
const score4 = await adresseCollection.countDocuments({ | ||
sources: 'bal', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
$or: [ | ||
{certificationCommune: true}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
{parcelles: {$not: {$size: 0}}, banId: {$ne: null}}, | ||
], | ||
$nor: [ | ||
{certificationCommune: true, parcelles: {$not: {$size: 0}}, banId: {$ne: null}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
] | ||
}) | ||
|
||
// Score-3: Nombre de documents 'Adresse' avec source 'bal', certificationCommune à false, parcelles vides et banId non null | ||
const score3 = await adresseCollection.countDocuments({ | ||
sources: 'bal', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
certificationCommune: {$ne: true}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
parcelles: {$size: 0}, | ||
banId: {$ne: null}, | ||
}) | ||
|
||
// Score-3-Legacy: Nombre de documents 'Adresse' avec source 'bal', certificationCommune à true ou parcelles non vides et banId à null (mais pas les deux à la fois) | ||
const score3Legacy = await adresseCollection.countDocuments({ | ||
sources: 'bal', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
$or: [ | ||
{certificationCommune: true}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
{parcelles: {$not: {$size: 0}}, banId: null} | ||
], | ||
$nor: [ | ||
{certificationCommune: true, parcelles: {$not: {$size: 0}}, banId: null} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
] | ||
}) | ||
|
||
// Score-2: Nombre de documents 'Adresse' avec source 'bal', certificationCommune à false, parcelles vides et banId à null | ||
const score2 = await adresseCollection.countDocuments({ | ||
sources: 'bal', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
certificationCommune: {$ne: true}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour |
||
parcelles: {$size: 0}, | ||
banId: null, | ||
}) | ||
|
||
// Score-1: Nombre de documents 'Adresse' avec source 'Guichet Adresse' et 'certifie' à true | ||
const score1 = await adresseCollection.countDocuments({sources: guichetAddr, certifie: true}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem pour le champ |
||
|
||
const score0 = totalDocuments - score1 - score2 - score3 - score4 - score5 | ||
const score0Legacy = totalDocuments - score1 - score2 - score3Legacy - score4 - score5 | ||
|
||
const nbBalPercent = toPercent(nbBal, totalDocuments) | ||
const score5Percent = toPercent(score5, totalDocuments) | ||
const score4Percent = toPercent(score4, totalDocuments) | ||
const score3Percent = toPercent(score3, totalDocuments) | ||
const score3LegacyPercent = toPercent(score3Legacy, totalDocuments) | ||
const score2Percent = toPercent(score2, totalDocuments) | ||
const score1Percent = toPercent(score1, totalDocuments) | ||
const score0Percent = 100 - score1Percent - score2Percent - score3Percent - score4Percent - score5Percent | ||
const score0LegacyPercent = 100 - score1Percent - score2Percent - score3LegacyPercent - score4Percent - score5Percent | ||
|
||
return { | ||
'pre-score': { | ||
total: totalDocuments, | ||
'source-bal': nbBal, | ||
score0: score0Legacy, | ||
score1, | ||
score2, | ||
score3: score3Legacy, | ||
score4, | ||
score5, | ||
}, | ||
score: { | ||
total: totalDocuments, | ||
'source-bal': nbBal, | ||
score0, | ||
score1, | ||
score2, | ||
score3, | ||
score4, | ||
score5, | ||
}, | ||
'pre-score-percent': { | ||
total: totalDocuments, | ||
'source-bal': nbBalPercent, | ||
score0: score0LegacyPercent, | ||
score1: score1Percent, | ||
score2: score2Percent, | ||
score3: score3LegacyPercent, | ||
score4: score4Percent, | ||
score5: score5Percent, | ||
}, | ||
'score-percent': { | ||
total: totalDocuments, | ||
'source-bal': nbBalPercent, | ||
score0: score0Percent, | ||
score1: score1Percent, | ||
score2: score2Percent, | ||
score3: score3Percent, | ||
score4: score4Percent, | ||
score5: score5Percent, | ||
} | ||
|
||
} | ||
} | ||
|
||
return getStatistics() | ||
} | ||
|
||
module.exports = {computeStats, computeFilteredStats, computeScoringStats} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sur l'explorer le guichet adresse est sourcé avec