Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
33a42e88
Commit
33a42e88
authored
2 years ago
by
Saket Agrahari
Browse files
Options
Downloads
Patches
Plain Diff
COMP-122 publisher 2022 for charging mech
parent
6b5580bd
No related branches found
No related tags found
1 merge request
!10
Charging structure changes
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compendium_v2/publishers/survey_publisher_2022.py
+68
-14
68 additions, 14 deletions
compendium_v2/publishers/survey_publisher_2022.py
test/test_organization.py
+1
-0
1 addition, 0 deletions
test/test_organization.py
test/test_survey_publisher_2022.py
+25
-6
25 additions, 6 deletions
test/test_survey_publisher_2022.py
with
94 additions
and
20 deletions
compendium_v2/publishers/survey_publisher_2022.py
+
68
−
14
View file @
33a42e88
...
@@ -5,6 +5,8 @@ import math
...
@@ -5,6 +5,8 @@ import math
from
sqlalchemy
import
text
from
sqlalchemy
import
text
from
collections
import
defaultdict
from
collections
import
defaultdict
from
compendium_v2.db.model
import
FeeType
from
compendium_v2.environment
import
setup_logging
from
compendium_v2.environment
import
setup_logging
from
compendium_v2.config
import
load
from
compendium_v2.config
import
load
from
compendium_v2
import
db
,
survey_db
from
compendium_v2
import
db
,
survey_db
...
@@ -92,6 +94,13 @@ class OrgQuestion(enum.Enum):
...
@@ -92,6 +94,13 @@ class OrgQuestion(enum.Enum):
sub_orgs_5_role
=
16439
sub_orgs_5_role
=
16439
class
ChargingStructure
(
enum
.
Enum
):
"""
Answers are strings
"""
charging_structure
=
16410
def
query_budget
():
def
query_budget
():
with
survey_db
.
session_scope
()
as
survey
:
with
survey_db
.
session_scope
()
as
survey
:
return
survey
.
execute
(
text
(
BUDGET_QUERY
))
return
survey
.
execute
(
text
(
BUDGET_QUERY
))
...
@@ -214,23 +223,28 @@ def transfer_staff_data():
...
@@ -214,23 +223,28 @@ def transfer_staff_data():
continue
continue
# initialize on first use, so we don't add data for nrens with no answers
# 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
():
for
nren_name
,
nren_info
in
data
.
items
():
if
sum
([
nren_info
[
question
]
for
question
in
StaffQuestion
])
==
0
:
if
sum
([
nren_info
[
question
]
for
question
in
StaffQuestion
])
==
0
:
logger
.
info
(
f
'
{
nren_name
}
has no staff data. Deleting if exists.
'
)
logger
.
info
(
f
'
{
nren_name
}
has no staff data. Deleting if exists.
'
)
session
.
query
(
model
.
NrenStaff
).
filter
(
session
.
query
(
model
.
NrenStaff
).
filter
(
model
.
NrenStaff
.
nren_id
==
nren_dict
[
nren_name
].
id
,
model
.
NrenStaff
.
nren_id
==
nren_dict
[
nren_name
].
id
,
model
.
NrenStaff
.
year
==
2022
,
model
.
NrenStaff
.
year
==
2022
,
).
delete
()
).
delete
()
continue
continue
employed
=
nren_info
[
StaffQuestion
.
permanent_fte
]
+
nren_info
[
StaffQuestion
.
subcontracted_fte
]
employed
=
nren_info
[
StaffQuestion
.
permanent_fte
]
+
nren_info
[
technical
=
nren_info
[
StaffQuestion
.
technical_fte
]
+
nren_info
[
StaffQuestion
.
non_technical_fte
]
StaffQuestion
.
subcontracted_fte
]
technical
=
nren_info
[
StaffQuestion
.
technical_fte
]
+
nren_info
[
StaffQuestion
.
non_technical_fte
]
if
not
math
.
isclose
(
if
not
math
.
isclose
(
employed
,
employed
,
technical
,
technical
,
abs_tol
=
0.01
,
abs_tol
=
0.01
,
):
):
logger
.
info
(
logger
.
info
(
f
'
{
nren_name
}
FTE do not equal across employed/technical categories.
'
f
'
{
nren_name
}
FTE do not equal across employed/technical categories.
'
...
@@ -249,7 +263,6 @@ def transfer_staff_data():
...
@@ -249,7 +263,6 @@ def transfer_staff_data():
def
transfer_nren_parent_org
():
def
transfer_nren_parent_org
():
# clean up the data a bit by removing some strings
# clean up the data a bit by removing some strings
strings_to_replace
=
[
strings_to_replace
=
[
'
We are affiliated to
'
'
We are affiliated to
'
...
@@ -280,13 +293,17 @@ def transfer_nren_parent_org():
...
@@ -280,13 +293,17 @@ def transfer_nren_parent_org():
def
transfer_nren_sub_org
():
def
transfer_nren_sub_org
():
suborg_questions
=
[
suborg_questions
=
[
(
OrgQuestion
.
sub_orgs_1_name
,
OrgQuestion
.
sub_orgs_1_choice
,
OrgQuestion
.
sub_orgs_1_role
),
(
OrgQuestion
.
sub_orgs_1_name
,
OrgQuestion
.
sub_orgs_1_choice
,
(
OrgQuestion
.
sub_orgs_2_name
,
OrgQuestion
.
sub_orgs_2_choice
,
OrgQuestion
.
sub_orgs_2_role
),
OrgQuestion
.
sub_orgs_1_role
),
(
OrgQuestion
.
sub_orgs_3_name
,
OrgQuestion
.
sub_orgs_3_choice
,
OrgQuestion
.
sub_orgs_3_role
),
(
OrgQuestion
.
sub_orgs_2_name
,
OrgQuestion
.
sub_orgs_2_choice
,
(
OrgQuestion
.
sub_orgs_4_name
,
OrgQuestion
.
sub_orgs_4_choice
,
OrgQuestion
.
sub_orgs_4_role
),
OrgQuestion
.
sub_orgs_2_role
),
(
OrgQuestion
.
sub_orgs_5_name
,
OrgQuestion
.
sub_orgs_5_choice
,
OrgQuestion
.
sub_orgs_5_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
:
with
db
.
session_scope
()
as
session
:
...
@@ -329,6 +346,42 @@ def transfer_nren_sub_org():
...
@@ -329,6 +346,42 @@ def transfer_nren_sub_org():
session
.
commit
()
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
'
f
'
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
_cli
(
config
):
def
_cli
(
config
):
helpers
.
init_db
(
config
)
helpers
.
init_db
(
config
)
transfer_budget
()
transfer_budget
()
...
@@ -336,6 +389,7 @@ def _cli(config):
...
@@ -336,6 +389,7 @@ def _cli(config):
transfer_staff_data
()
transfer_staff_data
()
transfer_nren_parent_org
()
transfer_nren_parent_org
()
transfer_nren_sub_org
()
transfer_nren_sub_org
()
transfer_charging_structure
()
@click.command
()
@click.command
()
...
...
This diff is collapsed.
Click to expand it.
test/test_organization.py
+
1
−
0
View file @
33a42e88
...
@@ -12,6 +12,7 @@ def test_parentorganization_response(client, test_organization_data):
...
@@ -12,6 +12,7 @@ def test_parentorganization_response(client, test_organization_data):
jsonschema
.
validate
(
result
,
ORGANIZATION_RESPONSE_SCHEMA
)
jsonschema
.
validate
(
result
,
ORGANIZATION_RESPONSE_SCHEMA
)
assert
result
assert
result
def
test_suborganization_response
(
client
,
test_organization_data
):
def
test_suborganization_response
(
client
,
test_organization_data
):
rv
=
client
.
get
(
rv
=
client
.
get
(
'
/api/organization/sub
'
,
'
/api/organization/sub
'
,
...
...
This diff is collapsed.
Click to expand it.
test/test_survey_publisher_2022.py
+
25
−
6
View file @
33a42e88
from
compendium_v2
import
db
from
compendium_v2
import
db
from
compendium_v2.db
import
model
from
compendium_v2.db
import
model
from
compendium_v2.publishers.survey_publisher_2022
import
_cli
,
FundingSource
,
StaffQuestion
,
OrgQuestion
from
compendium_v2.publishers.survey_publisher_2022
import
_cli
,
FundingSource
,
\
StaffQuestion
,
OrgQuestion
,
ChargingStructure
def
org_data
(
question
):
def
org_data
(
question
):
...
@@ -105,7 +106,6 @@ def org_data(question):
...
@@ -105,7 +106,6 @@ def org_data(question):
def
test_publisher
(
client
,
mocker
,
dummy_config
):
def
test_publisher
(
client
,
mocker
,
dummy_config
):
global
org_data
global
org_data
def
get_rows_as_tuples
(
*
args
,
**
kwargs
):
def
get_rows_as_tuples
(
*
args
,
**
kwargs
):
...
@@ -164,14 +164,23 @@ def test_publisher(client, mocker, dummy_config):
...
@@ -164,14 +164,23 @@ def test_publisher(client, mocker, dummy_config):
if
question
in
OrgQuestion
:
if
question
in
OrgQuestion
:
return
org_data
(
question
)
return
org_data
(
question
)
if
question
==
ChargingStructure
.
charging_structure
:
return
[
(
'
nren1
'
,
'
We do not charge them directly
'
),
(
'
nren2
'
,
'
We charge a usage-based fee
'
),
(
'
nren3
'
,
'
Other
'
),
]
mocker
.
patch
(
'
compendium_v2.publishers.survey_publisher_2022.query_budget
'
,
mocker
.
patch
(
'
compendium_v2.publishers.survey_publisher_2022.query_budget
'
,
get_rows_as_tuples
)
get_rows_as_tuples
)
mocker
.
patch
(
'
compendium_v2.publishers.survey_publisher_2022.query_funding_sources
'
,
mocker
.
patch
(
funding_source_data
)
'
compendium_v2.publishers.survey_publisher_2022.query_funding_sources
'
,
funding_source_data
)
mocker
.
patch
(
'
compendium_v2.publishers.survey_publisher_2022.query_question
'
,
mocker
.
patch
(
question_data
)
'
compendium_v2.publishers.survey_publisher_2022.query_question
'
,
question_data
)
with
db
.
session_scope
()
as
session
:
with
db
.
session_scope
()
as
session
:
nren_names
=
[
nren_names
=
[
...
@@ -239,3 +248,13 @@ def test_publisher(client, mocker, dummy_config):
...
@@ -239,3 +248,13 @@ def test_publisher(client, mocker, dummy_config):
assert
org_data
[
1
].
nren
.
name
.
lower
()
==
'
nren3
'
assert
org_data
[
1
].
nren
.
name
.
lower
()
==
'
nren3
'
assert
org_data
[
1
].
organization
==
'
Org3
'
assert
org_data
[
1
].
organization
==
'
Org3
'
charging_structures
=
session
.
query
(
model
.
ChargingStructure
).
order_by
(
model
.
ChargingStructure
.
nren_id
.
asc
()).
all
()
assert
len
(
charging_structures
)
==
3
assert
charging_structures
[
0
].
nren
.
name
.
lower
()
==
'
nren1
'
assert
charging_structures
[
0
].
fee_type
==
'
no_charge
'
assert
charging_structures
[
1
].
nren
.
name
.
lower
()
==
'
nren2
'
assert
charging_structures
[
1
].
fee_type
==
'
usage_based_fee
'
assert
charging_structures
[
2
].
nren
.
name
.
lower
()
==
'
nren3
'
assert
charging_structures
[
2
].
fee_type
==
'
other
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment