-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implementation uses a plpython udf that calls the scoring api of the data inclusion schema.
- Loading branch information
Showing
7 changed files
with
110 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% macro udf__score() %} | ||
|
||
DROP FUNCTION IF EXISTS processings.score; | ||
|
||
CREATE OR REPLACE FUNCTION processings.score(data JSONB) | ||
RETURNS | ||
TABLE( | ||
score_ligne FLOAT, | ||
nom_critere TEXT, | ||
score_critere FLOAT | ||
) | ||
AS $$ | ||
|
||
import json | ||
|
||
import pydantic | ||
|
||
from data_inclusion.schema import Service, score_qualite | ||
|
||
|
||
# TODO(vmttn): run score *after* pydantic validation then remove this try/except | ||
try: | ||
service = Service(**json.loads(data)) | ||
except pydantic.ValidationError as exc: | ||
return [] | ||
|
||
score, details = score_qualite.score(service) | ||
|
||
return [ | ||
{ | ||
"score_ligne": score, | ||
"nom_critere": nom_critere, | ||
"score_critere": score_critere, | ||
} | ||
for nom_critere, score_critere in details.items() | ||
] | ||
|
||
$$ LANGUAGE plpython3u; | ||
|
||
{% endmacro %} |
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
16 changes: 16 additions & 0 deletions
16
pipeline/dbt/models/intermediate/int__criteres_qualite.sql
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
WITH services AS ( | ||
SELECT * FROM {{ ref('int__union_services__enhanced') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
services._di_surrogate_id AS "service_id", | ||
scores.score_critere AS "score_critere", | ||
scores.nom_critere AS "nom_critere", | ||
scores.score_ligne AS "score_ligne" | ||
FROM | ||
services, | ||
LATERAL (SELECT * FROM processings.score(TO_JSONB(services))) AS scores | ||
) | ||
|
||
SELECT * FROM final |
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