Commit 0a8a3ec6a44727ce3dc7644858d2b3ac0a60501b
1 parent
796a5688
Exists in
master
and in
4 other branches
Convert charge from % to ETP after db request result
Showing
1 changed file
with
12 additions
and
3 deletions
Show diff stats
app/db_mgr.py
1 | from app.models import db, Period | 1 | from app.models import db, Period |
2 | 2 | ||
3 | +# TODO: make this configurable, and choose another place to use it, | ||
4 | +# in 'routes.py' maybe | ||
5 | +# Charge as stored on a 100% basis, percent of total worked time; | ||
6 | +# Here it is possible to convert to an ETP basis, dividing by 100 | ||
7 | +# or we set it to '1' if we want to keep the percent basis | ||
8 | +charge_unit = 100 | ||
9 | + | ||
3 | 10 | ||
4 | def projects(): | 11 | def projects(): |
5 | """ | 12 | """ |
@@ -86,6 +93,8 @@ def charges_by_project_stacked(project_id, category="service"): | @@ -86,6 +93,8 @@ def charges_by_project_stacked(project_id, category="service"): | ||
86 | . | 93 | . |
87 | . | 94 | . |
88 | per_n, value_n0, value_n1, ....., value_nn, | 95 | per_n, value_n0, value_n1, ....., value_nn, |
96 | + | ||
97 | + TODO: common with charges_by_agent_stacked(agent_id): code to extrat | ||
89 | """ | 98 | """ |
90 | if category == 'capacity': | 99 | if category == 'capacity': |
91 | category_table = 'capacity' | 100 | category_table = 'capacity' |
@@ -117,7 +126,7 @@ def charges_by_project_stacked(project_id, category="service"): | @@ -117,7 +126,7 @@ def charges_by_project_stacked(project_id, category="service"): | ||
117 | # build the charges line for the current period | 126 | # build the charges line for the current period |
118 | category_charges = [period_name] | 127 | category_charges = [period_name] |
119 | for (category_rate,) in db.session.execute(charge_by_categorie_req): | 128 | for (category_rate,) in db.session.execute(charge_by_categorie_req): |
120 | - category_rate = str(category_rate) if category_rate else '0' | 129 | + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0' |
121 | category_charges.append(category_rate) | 130 | category_charges.append(category_rate) |
122 | all_charges.append(category_charges) | 131 | all_charges.append(category_charges) |
123 | 132 | ||
@@ -127,6 +136,7 @@ def charges_by_project_stacked(project_id, category="service"): | @@ -127,6 +136,7 @@ def charges_by_project_stacked(project_id, category="service"): | ||
127 | def charges_by_agent_stacked(agent_id): | 136 | def charges_by_agent_stacked(agent_id): |
128 | """ | 137 | """ |
129 | Build the list of charges for all projects of one agent, period by period | 138 | Build the list of charges for all projects of one agent, period by period |
139 | + TODO: common with charges_by_project_stacked(project_id, ..) code to extrat | ||
130 | :param agent_id: | 140 | :param agent_id: |
131 | :return: | 141 | :return: |
132 | """ | 142 | """ |
@@ -143,10 +153,9 @@ def charges_by_agent_stacked(agent_id): | @@ -143,10 +153,9 @@ def charges_by_agent_stacked(agent_id): | ||
143 | group by p.id | 153 | group by p.id |
144 | order by p.id | 154 | order by p.id |
145 | """.format(agent_id, period_id) | 155 | """.format(agent_id, period_id) |
146 | - print(charge_by_project_req) | ||
147 | category_charges = [period_name] | 156 | category_charges = [period_name] |
148 | for (category_rate,) in db.session.execute(charge_by_project_req): | 157 | for (category_rate,) in db.session.execute(charge_by_project_req): |
149 | - category_rate = str(category_rate) if category_rate else '0' | 158 | + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0' |
150 | category_charges.append(category_rate) | 159 | category_charges.append(category_rate) |
151 | all_charges.append(category_charges) | 160 | all_charges.append(category_charges) |
152 | return all_charges | 161 | return all_charges |