Commit 3af23546451e33ed3407f558add8546e011c377b
1 parent
b27d1dd1
Exists in
master
and in
4 other branches
Now ingest status history for Irap
Showing
1 changed file
with
15 additions
and
7 deletions
Show diff stats
app/commands/commands.py
... | ... | @@ -304,7 +304,7 @@ def feed_from_irap(csv_file_name): |
304 | 304 | db.session.add(n_ap) |
305 | 305 | db.session.commit() |
306 | 306 | |
307 | - # Now feed the charges. | |
307 | + # Now feed both charges and status history | |
308 | 308 | # |
309 | 309 | # At least one for each csv row |
310 | 310 | # At most one for each year |
... | ... | @@ -317,22 +317,30 @@ def feed_from_irap(csv_file_name): |
317 | 317 | # TODO: period names should come from db request |
318 | 318 | for period_name in range(2011, 2030): |
319 | 319 | t = Period.query.filter(Period.name == period_name).one() |
320 | - charge = r[f"{period_name}"] | |
320 | + charge_value = r[f"{period_name}"] | |
321 | 321 | # Charge are stored as percent in db, but as fraction of ETP in irap csv |
322 | 322 | # we make the conversion here. |
323 | 323 | try: |
324 | - charge = int(100 * float(charge)) | |
324 | + charge_value = int(100 * float(charge_value)) | |
325 | 325 | except ValueError: |
326 | - charge = 0 | |
327 | - if charge == 0: | |
326 | + charge_value = 0 | |
327 | + if charge_value == 0: | |
328 | 328 | continue |
329 | 329 | n_c = Charge(agent_id=a.id, |
330 | 330 | project_id=p.id, |
331 | 331 | service_id=s.id, |
332 | 332 | capacity_id=c.id, |
333 | 333 | period_id=t.id, |
334 | - charge_rate=charge) | |
335 | - db.session.add(n_c) | |
334 | + charge_rate=charge_value) | |
335 | + status_value = r[status_key].strip().upper() | |
336 | + if not status_value: | |
337 | + continue | |
338 | + st = AgentStatus.query.filter(AgentStatus.name == status_value).one_or_none() | |
339 | + if st is None: | |
340 | + continue | |
341 | + print(f"Adding history p: {t.name}, a: {a.firstname}, s: {st.name}") | |
342 | + n_ap = AgentHistory(period_id=t.id, agent_id=a.id, status_id=st.id) | |
343 | + db.session.add_all([n_c, n_ap]) | |
336 | 344 | db.session.commit() |
337 | 345 | |
338 | 346 | ... | ... |