Skip to content
Snippets Groups Projects

merge feature/COMP-152-EC-PROJECTS-TABLE into develop

Merged Bjarke Madsen requested to merge feature/COMP-152-EC-PROJECTS-TABLE into develop
2 unresolved threads
8 files
+ 231
311
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -7,6 +7,8 @@ import html
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
@@ -98,6 +100,13 @@ class ECQuestion(enum.Enum):
EC_PROJECT = 16453
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))
@@ -178,9 +187,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.')
@@ -220,7 +227,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:
@@ -234,13 +242,12 @@ def transfer_staff_data():
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,
@@ -255,7 +262,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 '
@@ -286,7 +292,6 @@ 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),
@@ -335,6 +340,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:
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 transfer_ec_projects():
with db.session_scope() as session:
nren_dict = helpers.get_uppercase_nren_dict(session)
@@ -385,6 +425,7 @@ def _cli(config):
transfer_staff_data()
transfer_nren_parent_org()
transfer_nren_sub_org()
transfer_charging_structure()
transfer_ec_projects()
Loading