Commit e817ff5ea43f14fc57645d13db3efa6c7e7203e2
1 parent
fe74c223
Exists in
master
and in
4 other branches
Random Charge Agent only <100
Showing
3 changed files
with
12 additions
and
2 deletions
Show diff stats
README.md
app/commands/commands.py
1 | 1 | import sys |
2 | - | |
3 | 2 | import click |
4 | 3 | import random |
5 | 4 | |
5 | +from sqlalchemy.sql import func | |
6 | 6 | from sqlalchemy.ext.automap import automap_base |
7 | 7 | from sqlalchemy.orm import Session |
8 | 8 | from sqlalchemy import create_engine |
... | ... | @@ -58,7 +58,7 @@ def feed_from_lesia(): |
58 | 58 | |
59 | 59 | @bp.cli.command("feed_periods") |
60 | 60 | def feed_periods(): |
61 | - for y in ['2019', '2020', '2021']: | |
61 | + for y in range(2014, 2023): | |
62 | 62 | for s in ['S1', 'S2']: |
63 | 63 | period_name = "{}_{}".format(y, s) |
64 | 64 | p = Period(name=period_name) |
... | ... | @@ -79,6 +79,14 @@ def random_charges(agent): |
79 | 79 | capacity_id = random.choice([i for (i,) in db.session.query(Capacity.id).all()]) |
80 | 80 | period_id = random.choice([i for (i,) in db.session.query(Period.id).all()]) |
81 | 81 | percent = random.choice(range(10, 110, 10)) |
82 | + # check max agent charge for the period | |
83 | + total_charge = db.session.query(func.sum(Charge.charge_rate).label("total_charge")) \ | |
84 | + .filter(Charge.agent_id == agent_id, | |
85 | + Charge.period_id == period_id | |
86 | + ).scalar() | |
87 | + if total_charge is not None and (total_charge + percent)>= 100: | |
88 | + print("Skipping agent {} for period {}".format(agent_id, period_id)) | |
89 | + continue | |
82 | 90 | charge = Charge(agent_id=agent_id, |
83 | 91 | project_id=project_id, |
84 | 92 | service_id=service_id, | ... | ... |
requirements.txt