Spaces:
Paused
Paused
Commit
•
a4b0df8
1
Parent(s):
a216741
fixes for wweia categories
Browse files- algo.py +6 -2
- db/db_utils.py +29 -35
- run.py +3 -0
algo.py
CHANGED
@@ -142,7 +142,11 @@ class Algo:
|
|
142 |
'confidence_score': None,
|
143 |
'similar_words': None,
|
144 |
'is_food': False,
|
145 |
-
'food_nonfood_score': 1.0
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
break
|
148 |
|
@@ -358,7 +362,7 @@ class Algo:
|
|
358 |
results_batch.append(mapping)
|
359 |
|
360 |
# Store results in batches
|
361 |
-
if len(results_batch)
|
362 |
store_results_batch(self.db_cursor, self.db_conn, self.run_key, results_batch)
|
363 |
results_batch = []
|
364 |
|
|
|
142 |
'confidence_score': None,
|
143 |
'similar_words': None,
|
144 |
'is_food': False,
|
145 |
+
'food_nonfood_score': 1.0,
|
146 |
+
'wweia_category': 'Non-Food Item',
|
147 |
+
'water_content': None,
|
148 |
+
'dry_matter_content': None,
|
149 |
+
'leakage': None
|
150 |
}
|
151 |
break
|
152 |
|
|
|
362 |
results_batch.append(mapping)
|
363 |
|
364 |
# Store results in batches
|
365 |
+
if len(results_batch) == 1:
|
366 |
store_results_batch(self.db_cursor, self.db_conn, self.run_key, results_batch)
|
367 |
results_batch = []
|
368 |
|
db/db_utils.py
CHANGED
@@ -183,38 +183,32 @@ def store_result_to_db(cursor, conn, run_key, result):
|
|
183 |
return False
|
184 |
|
185 |
def store_results_batch(cursor, conn, run_key, results_batch):
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
conn.commit()
|
216 |
-
except Exception as e:
|
217 |
-
logging.info(f" - Error storing results to db: {e}")
|
218 |
-
conn.rollback()
|
219 |
-
return False
|
220 |
-
return True
|
|
|
183 |
return False
|
184 |
|
185 |
def store_results_batch(cursor, conn, run_key, results_batch):
|
186 |
+
cursor.executemany('''
|
187 |
+
INSERT INTO results (run_key, run_row, date, input_word, dictionary_word, is_food, wweia_category, dry_matter_content, leakage, weight, weight_metric_tonnes, donor, similarity_score, food_nonfood_score, distance, ef, mt_lb_mile, baseline_emissions, leakage_emissions, project_emissions, total_emissions_reduction)
|
188 |
+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
189 |
+
''', [
|
190 |
+
(
|
191 |
+
run_key,
|
192 |
+
result['run_row'],
|
193 |
+
result['date'],
|
194 |
+
result['input_word'],
|
195 |
+
result['dictionary_word'],
|
196 |
+
result['is_food'],
|
197 |
+
result['wweia_category'],
|
198 |
+
result['dry_matter_content'],
|
199 |
+
result['leakage'],
|
200 |
+
result['weight'],
|
201 |
+
result['weight_metric_tonnes'],
|
202 |
+
result['donor'],
|
203 |
+
result['similarity_score'],
|
204 |
+
result['food_nonfood_score'],
|
205 |
+
result['distance'],
|
206 |
+
result['ef'],
|
207 |
+
result['mt_lb_mile'],
|
208 |
+
result['baseline_emissions'],
|
209 |
+
result['leakage_emissions'],
|
210 |
+
result['project_emissions'],
|
211 |
+
result['total_emissions_reduction']
|
212 |
+
) for result in results_batch
|
213 |
+
])
|
214 |
+
conn.commit()
|
|
|
|
|
|
|
|
|
|
|
|
run.py
CHANGED
@@ -40,6 +40,9 @@ if __name__ == "__main__":
|
|
40 |
|
41 |
input_data = input_data[last_row_num:]
|
42 |
|
|
|
|
|
|
|
43 |
# profiler = cProfile.Profile()
|
44 |
# profiler.enable()
|
45 |
|
|
|
40 |
|
41 |
input_data = input_data[last_row_num:]
|
42 |
|
43 |
+
# limit to 100 rows
|
44 |
+
# input_data = input_data[:100]
|
45 |
+
|
46 |
# profiler = cProfile.Profile()
|
47 |
# profiler.enable()
|
48 |
|