Skip to content

Commit b214774

Browse files
Léonard Micheletleonarf
authored andcommitted
ajout de cas d'erreur dans les calculs d'indicateurs
1 parent 6642114 commit b214774

5 files changed

Lines changed: 127 additions & 26 deletions

File tree

enthic/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
INFO_TRAITEMENT,
2323
ONTOLOGY,
2424
SCORE_DESCRIPTION,
25+
SCORE_ERROR,
2526
)
2627
from enthic.scoring.main import compute_score, get_percentiles, save_score_in_database
2728
from enthic.utils.ape_utils import (
@@ -130,6 +131,17 @@ def scores():
130131
return OKJSONResponse(SCORE_DESCRIPTION)
131132

132133

134+
@application.route("/ontology/error_code", methods=["GET"], strict_slashes=False)
135+
@application.route("/ontology/error_codes", methods=["GET"], strict_slashes=False)
136+
def error_codes():
137+
"""
138+
Return description of all scores computed.
139+
140+
:return: HTTP Response as application/json. the ontology as JSON.
141+
"""
142+
return OKJSONResponse(SCORE_ERROR)
143+
144+
133145
@application.route("/ontology/metadata", methods=["GET"], strict_slashes=False)
134146
def metadata():
135147
"""

enthic/compute_indicators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def compute_companies_statistics(host, year, limit, offset):
1313
:param host: API address IP + port
1414
"""
1515
indicators_count = 0
16-
for i in range(offset, 2000000, limit):
16+
for i in range(offset, 2500000, limit):
1717
url = "http://" + host + "/compute/company/all/" + str(i) + "/" + str(limit)
1818
if year:
1919
url += "/" + str(year)

enthic/ontology.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,10 +3164,13 @@ def read_account():
31643164
-1100: "Montant des salaires non fournis",
31653165
-1200: "Montant des salaires à zéro",
31663166
-1300: "Montant des salaires négatif",
3167+
-1400: "Montant des salaires supérieurs aux charges",
31673168
-2000: "Montant des cotisations sociales incohérent",
31683169
-2100: "Montant des cotisations sociales non fournis",
31693170
-2200: "Montant des cotisations sociales à zéro",
31703171
-2300: "Montant des cotisations sociales négatif",
3172+
-2400: "Montant des cotisations sociales supérieurs aux salaires",
3173+
-2500: "Montant des cotisations sociales supérieurs aux charges",
31713174
-3100: "Montant des impôts sur les bénéfices non fournis",
31723175
-3200: "Montant des impôts sur les bénéfices négatif",
31733176
-4100: "Effectifs non fournis",
@@ -3177,4 +3180,11 @@ def read_account():
31773180
-6100: "Montant des charges d’exploitation non fournis",
31783181
-6200: "Montant des charges d’exploitation à zéro",
31793182
-6300: "Montant des charges d’exploitation négatif",
3183+
-6400: "Montant des charges d’exploitation incohérent",
3184+
-7100: "Montant du résultat d'exploitation non fournis",
3185+
-7200: "Montant du résultat d'exploitation négatif",
3186+
-8000: "Montant du résultat financier ou exceptionnel non négligeable",
3187+
-9000: "Montant des resultats négatif ou nul",
3188+
-10000: "Montant de la participation négatif",
3189+
-9999: "Numérateur ou dénominateur incohérent",
31803190
}

enthic/scoring/compute_stats.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,43 @@ def check_tree_data(tree_item):
119119
child_data["status"] = "computed"
120120
if "computedValue" in child_data:
121121
child_data["value"] = child_data["computedValue"]
122+
for child_child_name in tree_item["children"][child_name][
123+
"children"
124+
]:
125+
set_to_zero_computed(
126+
tree_item["children"][child_name]["children"][
127+
child_child_name
128+
]
129+
)
122130
else:
123131
child_data["value"] = 0
124132

125133
computed_sum = computed_sum_from_computed
134+
135+
# If official value match computed value * 1000, it mean value was multiplied by 1000 by mistake
136+
elif (
137+
abs((computed_sum * 1000 - value) / value) < relative_error
138+
or abs(computed_sum * 1000 - value) < absolute_error
139+
):
140+
tree_item["data"]["status"] = "scaled down"
141+
tree_item["data"]["value"] = computed_sum
142+
# Fix children values if needed
143+
if child_missing_count > 0:
144+
for child_name in tree_item["children"]:
145+
set_to_zero_computed(tree_item["children"][child_name])
146+
147+
# If official value match computed value / 1000, it mean value was divided by 1000 by mistake
148+
elif (
149+
abs((computed_sum - value * 1000) / value) < relative_error
150+
or abs(computed_sum - value * 1000) < absolute_error
151+
):
152+
tree_item["data"]["status"] = "scaled up"
153+
tree_item["data"]["value"] = computed_sum
154+
# Fix children values if needed
155+
if child_missing_count > 0:
156+
for child_name in tree_item["children"]:
157+
set_to_zero_computed(tree_item["children"][child_name])
158+
126159
# If there is only one value missing from children, set this child's value equal to the computed difference
127160
elif child_missing_count == 1:
128161
for child_name in tree_item["children"]:

enthic/scoring/scoring_functions.py

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,44 @@ def compute_exploitation_share(data):
1212
participation = data["participation"]
1313
impot = data["impot"]
1414
resultat_exploitation = data["resultat_exploitation"]
15+
benefice_attribue = data["benefice_attribue"]
1516

1617
# If any values unknown, cannot compute score
1718
if isnan(impot):
1819
return -3100
1920
if impot < 0:
2021
return -3200
21-
if (
22-
any(isnan(value) for value in [resultat_exploitation])
23-
or resultat_exploitation < 0
24-
):
25-
return float("nan")
22+
if isnan(resultat_exploitation):
23+
return -7100
24+
if isnan(benefice_attribue):
25+
benefice_attribue = 0
26+
if resultat_exploitation + benefice_attribue <= 0:
27+
return -7200
2628

2729
if isnan(participation):
2830
participation = 0
2931
# Compute score if possible
3032
shared_part = participation + impot
31-
if resultat_exploitation > 0:
32-
return shared_part / resultat_exploitation
3333

34-
return float("nan")
34+
total_resultat = resultat_exploitation + benefice_attribue
35+
result = shared_part / total_resultat
36+
37+
if result < 0 and participation < 0:
38+
return -10000
39+
40+
if result > 10:
41+
resultat_exceptionnel = data["resultat_exceptionnel"]
42+
resultat_financier = data["resultat_financier"]
43+
if isnan(resultat_financier):
44+
resultat_financier = 0
45+
if isnan(resultat_exceptionnel):
46+
resultat_exceptionnel = 0
47+
if resultat_exceptionnel + resultat_financier > total_resultat:
48+
return -8000
49+
if result > 1000:
50+
return -9999
51+
52+
return result
3553

3654

3755
def compute_overall_wages_weight(data):
@@ -59,8 +77,22 @@ def compute_overall_wages_weight(data):
5977

6078
result = (salaires + cotisations_sociales) / charges
6179

62-
if result < 0 and charges < 0:
63-
return -6300
80+
if result < 0:
81+
if charges < 0:
82+
return -6300
83+
elif cotisations_sociales < 0:
84+
return -2300
85+
elif salaires < 0:
86+
return -1300
87+
88+
if result > 2:
89+
if cotisations_sociales > charges and salaires > charges:
90+
return -6400
91+
elif cotisations_sociales > charges:
92+
return -2500
93+
elif salaires > charges:
94+
return -1400
95+
return -9999
6496

6597
return result
6698

@@ -96,6 +128,8 @@ def compute_wage_quality(data):
96128
return -1300
97129
if cotisations_sociales < 0:
98130
return -2300
131+
if ratio > 2:
132+
return -2400
99133
return ratio
100134

101135

@@ -151,16 +185,25 @@ def compute_profit_sharing(data):
151185
):
152186
return float("nan")
153187

154-
somme_resultats = resultat_financier + resultat_exploitation + resultat_exceptionnel
155-
if somme_resultats == 0:
156-
return float("nan")
188+
if isnan(benefice_attribue):
189+
benefice_attribue = 0
190+
somme_resultats = (
191+
resultat_financier
192+
+ resultat_exploitation
193+
+ resultat_exceptionnel
194+
+ benefice_attribue
195+
)
196+
197+
if somme_resultats <= 0:
198+
return -9000
157199

158200
if isnan(participation):
159201
participation = 0
160202

161203
result = (participation + impot) / somme_resultats
162-
if result < 0 and not isnan(benefice_attribue) and benefice_attribue > 0:
163-
return -5100
204+
205+
if result < 0 and participation < 0:
206+
return -10000
164207

165208
return result
166209

@@ -196,17 +239,17 @@ def compute_exploitation_part(data):
196239
) == 0:
197240
return float("nan")
198241

199-
result = (data["produits_exploitation"] + data["charges_exploitation"]) / (
200-
data["produits_exploitation"]
201-
+ data["charges_exploitation"]
202-
+ data["produits_exceptionnel"]
203-
+ data["charges_exceptionnel"]
204-
+ data["produits_financier"]
205-
+ data["charges_financier"]
242+
result = (
243+
abs(data["produits_exploitation"]) + abs(data["charges_exploitation"])
244+
) / (
245+
abs(data["produits_exploitation"])
246+
+ abs(data["charges_exploitation"])
247+
+ abs(data["produits_exceptionnel"])
248+
+ abs(data["charges_exceptionnel"])
249+
+ abs(data["produits_financier"])
250+
+ abs(data["charges_financier"])
206251
)
207-
if result < 0:
208-
if data["charges_exploitation"] < 0:
209-
return -6300
252+
210253
return result
211254

212255

@@ -224,3 +267,6 @@ def compute_data_availability(data):
224267
data_available += 1
225268

226269
return data_available / len(data)
270+
271+
272+
# SELECT * FROM `annual_statistics` where stats_type != 4 and value not in (-4300, -6300, -6100, -6200, -5100, -1000, -1100, -1200, -1300, -2000, -2100, -2200, -2300, -2400, -2500, -3100, -3200, -4100, -4200, -4300, -1400, -6400, -7100, -7200, -8000, -9000, -9999, -10000) ORDER BY `annual_statistics`.`value` ASC;

0 commit comments

Comments
 (0)