Skip to content
Snippets Groups Projects

Charging structure changes

Merged Bjarke Madsen requested to merge charging-structure-changes into develop
6 unresolved threads
9 files
+ 237
318
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -5,6 +5,8 @@ import math
from sqlalchemy import text
from collections import defaultdict
from compendium_v2.db.model import FeeType
from compendium_v2.environment import setup_logging
from compendium_v2.config import load
from compendium_v2 import db, survey_db
@@ -92,6 +94,13 @@ class OrgQuestion(enum.Enum):
sub_orgs_5_role = 16439
class ChargingStructure(enum.Enum):
"""
Answers are strings
"""
charging_structure = 16410
def query_budget():
with survey_db.session_scope() as survey:
return survey.execute(text(BUDGET_QUERY))
@@ -172,9 +181,7 @@ def transfer_funding_sources():
total = sum(nren_info.values())
if not math.isclose(total, 100, abs_tol=0.01):
logger.info(
f'{nren_name} funding sources do not sum to 100%.'
f' ({total})')
logger.info(f'{nren_name} funding sources do not sum to 100%. ({total})')
if nren_name not in nren_dict:
logger.info(f'{nren_name} unknown. Skipping.')
@@ -214,7 +221,8 @@ def transfer_staff_data():
continue
# initialize on first use, so we don't add data for nrens with no answers
data.setdefault(nren_name, {question: 0 for question in StaffQuestion})[question] = value
data.setdefault(nren_name, {question: 0 for question in StaffQuestion})[
question] = value
for nren_name, nren_info in data.items():
if sum([nren_info[question] for question in StaffQuestion]) == 0:
@@ -225,16 +233,17 @@ def transfer_staff_data():
).delete()
continue
employed = nren_info[StaffQuestion.permanent_fte] + nren_info[StaffQuestion.subcontracted_fte]
technical = nren_info[StaffQuestion.technical_fte] + nren_info[StaffQuestion.non_technical_fte]
employed = nren_info[StaffQuestion.permanent_fte] + nren_info[
StaffQuestion.subcontracted_fte]
technical = nren_info[StaffQuestion.technical_fte] + nren_info[
StaffQuestion.non_technical_fte]
if not math.isclose(
employed,
technical,
abs_tol=0.01,
employed,
technical,
abs_tol=0.01,
):
logger.info(
f'{nren_name} FTE do not equal across employed/technical categories.'
f' ({employed} != {technical})')
logger.info(f'{nren_name} FTE do not equal across employed/technical categories.'
f' ({employed} != {technical})')
staff_data = model.NrenStaff(
nren_id=nren_dict[nren_name].id,
@@ -249,7 +258,6 @@ def transfer_staff_data():
def transfer_nren_parent_org():
# clean up the data a bit by removing some strings
strings_to_replace = [
'We are affiliated to '
@@ -280,13 +288,17 @@ def transfer_nren_parent_org():
def transfer_nren_sub_org():
suborg_questions = [
(OrgQuestion.sub_orgs_1_name, OrgQuestion.sub_orgs_1_choice, OrgQuestion.sub_orgs_1_role),
(OrgQuestion.sub_orgs_2_name, OrgQuestion.sub_orgs_2_choice, OrgQuestion.sub_orgs_2_role),
(OrgQuestion.sub_orgs_3_name, OrgQuestion.sub_orgs_3_choice, OrgQuestion.sub_orgs_3_role),
(OrgQuestion.sub_orgs_4_name, OrgQuestion.sub_orgs_4_choice, OrgQuestion.sub_orgs_4_role),
(OrgQuestion.sub_orgs_5_name, OrgQuestion.sub_orgs_5_choice, OrgQuestion.sub_orgs_5_role)
(OrgQuestion.sub_orgs_1_name, OrgQuestion.sub_orgs_1_choice,
OrgQuestion.sub_orgs_1_role),
(OrgQuestion.sub_orgs_2_name, OrgQuestion.sub_orgs_2_choice,
OrgQuestion.sub_orgs_2_role),
(OrgQuestion.sub_orgs_3_name, OrgQuestion.sub_orgs_3_choice,
OrgQuestion.sub_orgs_3_role),
(OrgQuestion.sub_orgs_4_name, OrgQuestion.sub_orgs_4_choice,
OrgQuestion.sub_orgs_4_role),
(OrgQuestion.sub_orgs_5_name, OrgQuestion.sub_orgs_5_choice,
OrgQuestion.sub_orgs_5_role)
]
with db.session_scope() as session:
@@ -329,6 +341,41 @@ def transfer_nren_sub_org():
session.commit()
def transfer_charging_structure():
with db.session_scope() as session:
nren_dict = helpers.get_uppercase_nren_dict(session)
rows = query_question(ChargingStructure.charging_structure)
for row in rows:
nren_name = row[0].upper()
value = row[1].replace('"', '').strip()
if nren_name not in nren_dict:
logger.info(f'{nren_name} unknown. Skipping from charging structure.')
continue
if "do not charge" in value:
    • Author Maintainer

      minor thing, but why is this in rather than a direct comparison between the values? I think that would be clearer

Please register or sign in to reply
charging_structure = FeeType.no_charge.value
elif "combination" in value:
charging_structure = FeeType.combination.value
elif "flat" in value:
charging_structure = FeeType.flat_fee.value
elif "usage-based" in value:
charging_structure = FeeType.usage_based_fee.value
elif "Other" in value:
charging_structure = FeeType.other.value
else:
charging_structure = None
charging_structure = model.ChargingStructure(
nren_id=nren_dict[nren_name].id,
year=2022,
fee_type=charging_structure,
)
session.merge(charging_structure)
session.commit()
def _cli(config):
helpers.init_db(config)
transfer_budget()
@@ -336,6 +383,7 @@ def _cli(config):
transfer_staff_data()
transfer_nren_parent_org()
transfer_nren_sub_org()
transfer_charging_structure()
@click.command()
Loading