@@ -182,46 +182,50 @@ def _run_update_loop(self):
182
182
try :
183
183
self .logging .info ("run_update_loop()" )
184
184
while self .stats ["status" ] == "on" :
185
- products = self ._get_products ()
186
- self .logging .info (f"❤️ Found { len (products )} products to decorate" )
187
- for prod in products :
188
- self .stats ["seen" ] += 1
189
- self .logging .info (f"Looking at { self ._prod_desc (prod )} " )
190
- decoration = {}
191
- try :
192
- impact = self ._estimate_with_deadline (prod )
193
- self .logging .info (f"❤️ Computed { impact ['impacts_geom_means' ]} " )
194
- max_confidence_idx = np .argmax (impact ['confidence_score_distribution' ])
195
- decoration ["impact" ] = {
196
- "likeliest_recipe" : impact ['recipes' ][max_confidence_idx ],
197
- "likeliest_impacts" : {
198
- "Climate change" : impact ['impact_distributions' ]['Climate change' ][max_confidence_idx ],
199
- "EF single score" : impact ['impact_distributions' ]['EF single score' ][max_confidence_idx ],
200
- },
201
- "ef_single_score_log_stddev" : np .std (np .log (impact ['impact_distributions' ]['EF single score' ])),
202
- "mass_ratio_uncharacterized" : impact ['uncharacterized_ingredients_mass_proportion' ]['impact' ],
203
- "uncharacterized_ingredients" : impact ['uncharacterized_ingredients' ],
204
- "uncharacterized_ingredients_mass_proportion" : impact ['uncharacterized_ingredients_mass_proportion' ],
205
- "uncharacterized_ingredients_ratio" : impact ['uncharacterized_ingredients_ratio' ],
206
- "warnings" : impact ['warnings' ],
207
- }
208
- self .stats ["estimate_impacts_success" ] += 1
209
- except Exception as e :
210
- error_desc = f"{ e .__class__ .__name__ } : { e } "
211
- self .logging .info (f"💀 get_impact([{ self ._prod_desc (prod )} ]): { error_desc } " )
212
- decoration ["error" ] = error_desc
213
- self .stats ["estimate_impacts_failure" ] += 1
214
- self ._add_error (error_desc )
215
- try :
216
- self ._update_product (prod , decoration )
217
- self .logging .info (f"❤️ Stored decoration for { self ._prod_desc (prod )} " )
218
- self .stats ["update_extended_data_success" ] += 1
219
- except Exception as e :
220
- error_desc = f"{ e .__class__ .__name__ } : { e } "
221
- self .logging .info (f"💀 update_product(...): { error_desc } " )
222
- self .stats ["update_extended_data_failure" ] += 1
223
- self ._add_error (error_desc )
224
- time .sleep (30 )
185
+ try :
186
+ products = self ._get_products ()
187
+ self .logging .info (f"❤️ Found { len (products )} products to decorate" )
188
+ for prod in products :
189
+ self .stats ["seen" ] += 1
190
+ self .logging .info (f"Looking at { self ._prod_desc (prod )} " )
191
+ decoration = {}
192
+ try :
193
+ impact = self ._estimate_with_deadline (prod )
194
+ self .logging .info (f"❤️ Computed { impact ['impacts_geom_means' ]} " )
195
+ max_confidence_idx = np .argmax (impact ['confidence_score_distribution' ])
196
+ decoration ["impact" ] = {
197
+ "likeliest_recipe" : impact ['recipes' ][max_confidence_idx ],
198
+ "likeliest_impacts" : {
199
+ "Climate change" : impact ['impact_distributions' ]['Climate change' ][max_confidence_idx ],
200
+ "EF single score" : impact ['impact_distributions' ]['EF single score' ][max_confidence_idx ],
201
+ },
202
+ "ef_single_score_log_stddev" : np .std (np .log (impact ['impact_distributions' ]['EF single score' ])),
203
+ "mass_ratio_uncharacterized" : impact ['uncharacterized_ingredients_mass_proportion' ]['impact' ],
204
+ "uncharacterized_ingredients" : impact ['uncharacterized_ingredients' ],
205
+ "uncharacterized_ingredients_mass_proportion" : impact ['uncharacterized_ingredients_mass_proportion' ],
206
+ "uncharacterized_ingredients_ratio" : impact ['uncharacterized_ingredients_ratio' ],
207
+ "warnings" : impact ['warnings' ],
208
+ }
209
+ self .stats ["estimate_impacts_success" ] += 1
210
+ except Exception as e :
211
+ error_desc = f"{ e .__class__ .__name__ } : { e } "
212
+ self .logging .info (f"💀 get_impact([{ self ._prod_desc (prod )} ]): { error_desc } " )
213
+ decoration ["error" ] = error_desc
214
+ self .stats ["estimate_impacts_failure" ] += 1
215
+ self ._add_error (error_desc )
216
+ try :
217
+ self ._update_product (prod , decoration )
218
+ self .logging .info (f"❤️ Stored decoration for { self ._prod_desc (prod )} " )
219
+ self .stats ["update_extended_data_success" ] += 1
220
+ except Exception as e :
221
+ error_desc = f"{ e .__class__ .__name__ } : { e } "
222
+ self .logging .info (f"💀 update_product(...): { error_desc } " )
223
+ self .stats ["update_extended_data_failure" ] += 1
224
+ self ._add_error (error_desc )
225
+ time .sleep (30 )
226
+ except Exception as e :
227
+ self .logging .info (f"💀 update loop got error: { e } \n Sleeping a few minutes and retrying." )
228
+ time .sleep (600 )
225
229
except Exception as e :
226
230
self .logging .info (f"💀 update loop terminates: { e } " )
227
231
finally :
0 commit comments