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
f36b693c
Commit
f36b693c
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
update 2022 publisher
parent
592ac584
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/publishers/survey_publisher_2022.py
+52
-12
52 additions, 12 deletions
compendium_v2/publishers/survey_publisher_2022.py
test/test_survey_publisher_2022.py
+20
-5
20 additions, 5 deletions
test/test_survey_publisher_2022.py
with
72 additions
and
17 deletions
compendium_v2/publishers/survey_publisher_2022.py
+
52
−
12
View file @
f36b693c
...
@@ -40,7 +40,8 @@ JOIN sections s ON q.section_id = s.id
...
@@ -40,7 +40,8 @@ JOIN sections s ON q.section_id = s.id
JOIN compendia c ON s.compendium_id = c.id
JOIN compendia c ON s.compendium_id = c.id
WHERE
WHERE
a.question_id = {}
a.question_id = {}
AND c.year = 2022
AND c.year = 2022
AND a.value NOT IN (
'""'
,
'"
NA
"'
,
'"
N/A
"'
)
ORDER BY n.id, a.question_id, a.updated_at DESC
ORDER BY n.id, a.question_id, a.updated_at DESC
"""
"""
...
@@ -53,7 +54,7 @@ class FundingSource(enum.Enum):
...
@@ -53,7 +54,7 @@ class FundingSource(enum.Enum):
GOV_PUBLIC_BODIES
=
16409
GOV_PUBLIC_BODIES
=
16409
class
Question
(
enum
.
Enum
):
class
Staff
Question
(
enum
.
Enum
):
"""
"""
Answers are numbers expressed in FTEs (full time equivalents)
Answers are numbers expressed in FTEs (full time equivalents)
"""
"""
...
@@ -63,6 +64,13 @@ class Question(enum.Enum):
...
@@ -63,6 +64,13 @@ class Question(enum.Enum):
non_technical_fte
=
16417
non_technical_fte
=
16417
class
OrgQuestion
(
enum
.
Enum
):
"""
Answers are strings
"""
parent_org_name
=
16419
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
))
...
@@ -75,7 +83,7 @@ def query_funding_sources():
...
@@ -75,7 +83,7 @@ def query_funding_sources():
yield
source
,
survey
.
execute
(
text
(
query
))
yield
source
,
survey
.
execute
(
text
(
query
))
def
query_question
(
question
:
Question
):
def
query_question
(
question
:
enum
.
Enum
):
query
=
QUESTION_TEMPLATE_QUERY
.
format
(
question
.
value
)
query
=
QUESTION_TEMPLATE_QUERY
.
format
(
question
.
value
)
with
survey_db
.
session_scope
()
as
survey
:
with
survey_db
.
session_scope
()
as
survey
:
return
survey
.
execute
(
text
(
query
))
return
survey
.
execute
(
text
(
query
))
...
@@ -170,7 +178,7 @@ def transfer_staff_data():
...
@@ -170,7 +178,7 @@ def transfer_staff_data():
nren_dict
=
helpers
.
get_uppercase_nren_dict
(
session
)
nren_dict
=
helpers
.
get_uppercase_nren_dict
(
session
)
data
=
{}
data
=
{}
for
question
in
Question
:
for
question
in
Staff
Question
:
rows
=
query_question
(
question
)
rows
=
query_question
(
question
)
for
row
in
rows
:
for
row
in
rows
:
nren_name
=
row
[
0
].
upper
()
nren_name
=
row
[
0
].
upper
()
...
@@ -185,10 +193,10 @@ def transfer_staff_data():
...
@@ -185,10 +193,10 @@ 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
Question
})[
question
]
=
value
data
.
setdefault
(
nren_name
,
{
question
:
0
for
question
in
Staff
Question
})[
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
Question
])
==
0
:
if
sum
([
nren_info
[
question
]
for
question
in
Staff
Question
])
==
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
,
...
@@ -196,8 +204,8 @@ def transfer_staff_data():
...
@@ -196,8 +204,8 @@ def transfer_staff_data():
).
delete
()
).
delete
()
continue
continue
employed
=
nren_info
[
Question
.
permanent_fte
]
+
nren_info
[
Question
.
subcontracted_fte
]
employed
=
nren_info
[
Staff
Question
.
permanent_fte
]
+
nren_info
[
Staff
Question
.
subcontracted_fte
]
technical
=
nren_info
[
Question
.
technical_fte
]
+
nren_info
[
Question
.
non_technical_fte
]
technical
=
nren_info
[
Staff
Question
.
technical_fte
]
+
nren_info
[
Staff
Question
.
non_technical_fte
]
if
not
math
.
isclose
(
if
not
math
.
isclose
(
employed
,
employed
,
technical
,
technical
,
...
@@ -210,20 +218,52 @@ def transfer_staff_data():
...
@@ -210,20 +218,52 @@ def transfer_staff_data():
staff_data
=
model
.
NrenStaff
(
staff_data
=
model
.
NrenStaff
(
nren_id
=
nren_dict
[
nren_name
].
id
,
nren_id
=
nren_dict
[
nren_name
].
id
,
year
=
2022
,
year
=
2022
,
permanent_fte
=
nren_info
[
Question
.
permanent_fte
],
permanent_fte
=
nren_info
[
Staff
Question
.
permanent_fte
],
subcontracted_fte
=
nren_info
[
Question
.
subcontracted_fte
],
subcontracted_fte
=
nren_info
[
Staff
Question
.
subcontracted_fte
],
technical_fte
=
nren_info
[
Question
.
technical_fte
],
technical_fte
=
nren_info
[
Staff
Question
.
technical_fte
],
non_technical_fte
=
nren_info
[
Question
.
non_technical_fte
],
non_technical_fte
=
nren_info
[
Staff
Question
.
non_technical_fte
],
)
)
session
.
merge
(
staff_data
)
session
.
merge
(
staff_data
)
session
.
commit
()
session
.
commit
()
def
transfer_nren_parent_org
():
# clean up the data a bit by removing some strings
strings_to_replace
=
[
'
We are affiliated to
'
]
with
db
.
session_scope
()
as
session
:
nren_dict
=
helpers
.
get_uppercase_nren_dict
(
session
)
rows
=
query_question
(
OrgQuestion
.
parent_org_name
)
for
row
in
rows
:
nren_name
=
row
[
0
].
upper
()
value
=
str
(
row
[
1
]).
replace
(
'"'
,
''
)
for
string
in
strings_to_replace
:
value
=
value
.
replace
(
string
,
''
)
if
nren_name
not
in
nren_dict
:
logger
.
info
(
f
'
{
nren_name
}
unknown. Skipping.
'
)
continue
parent_org
=
model
.
ParentOrganization
(
nren_id
=
nren_dict
[
nren_name
].
id
,
year
=
2022
,
organization
=
value
,
)
session
.
merge
(
parent_org
)
session
.
commit
()
def
_cli
(
config
):
def
_cli
(
config
):
helpers
.
init_db
(
config
)
helpers
.
init_db
(
config
)
transfer_budget
()
transfer_budget
()
transfer_funding_sources
()
transfer_funding_sources
()
transfer_staff_data
()
transfer_staff_data
()
transfer_nren_parent_org
()
@click.command
()
@click.command
()
...
...
This diff is collapsed.
Click to expand it.
test/test_survey_publisher_2022.py
+
20
−
5
View file @
f36b693c
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
,
Question
from
compendium_v2.publishers.survey_publisher_2022
import
_cli
,
FundingSource
,
StaffQuestion
,
Org
Question
def
test_publisher
(
client
,
mocker
,
dummy_config
):
def
test_publisher
(
client
,
mocker
,
dummy_config
):
...
@@ -31,33 +31,38 @@ def test_publisher(client, mocker, dummy_config):
...
@@ -31,33 +31,38 @@ def test_publisher(client, mocker, dummy_config):
]
]
def
question_data
(
question
):
def
question_data
(
question
):
if
question
==
Question
.
non_technical_fte
:
if
question
==
Staff
Question
.
non_technical_fte
:
return
[
return
[
(
'
nren1
'
,
'
10
'
),
(
'
nren1
'
,
'
10
'
),
(
'
nren2
'
,
'
80
'
),
(
'
nren2
'
,
'
80
'
),
(
'
nren3
'
,
'
30
'
),
(
'
nren3
'
,
'
30
'
),
]
]
if
question
==
Question
.
technical_fte
:
if
question
==
Staff
Question
.
technical_fte
:
return
[
return
[
(
'
nren1
'
,
'
50
'
),
(
'
nren1
'
,
'
50
'
),
(
'
nren2
'
,
'
20
'
),
(
'
nren2
'
,
'
20
'
),
(
'
nren3
'
,
'
30
'
),
(
'
nren3
'
,
'
30
'
),
]
]
if
question
==
Question
.
permanent_fte
:
if
question
==
Staff
Question
.
permanent_fte
:
return
[
return
[
(
'
nren1
'
,
'
40
'
),
(
'
nren1
'
,
'
40
'
),
(
'
nren2
'
,
'
abc
'
),
(
'
nren2
'
,
'
abc
'
),
(
'
nren3
'
,
'
30
'
),
(
'
nren3
'
,
'
30
'
),
]
]
if
question
==
Question
.
subcontracted_fte
:
if
question
==
Staff
Question
.
subcontracted_fte
:
return
[
return
[
(
'
nren1
'
,
'
0
'
),
(
'
nren1
'
,
'
0
'
),
(
'
nren2
'
,
'
0
'
),
(
'
nren2
'
,
'
0
'
),
(
'
nren3
'
,
'
0
'
),
(
'
nren3
'
,
'
0
'
),
]
]
if
question
==
OrgQuestion
.
parent_org_name
:
return
[
(
'
nren1
'
,
'
Org1
'
),
(
'
nren3
'
,
'
Org3
'
),
]
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
)
...
@@ -124,3 +129,13 @@ def test_publisher(client, mocker, dummy_config):
...
@@ -124,3 +129,13 @@ def test_publisher(client, mocker, dummy_config):
assert
staff_data
[
2
].
technical_fte
==
30
assert
staff_data
[
2
].
technical_fte
==
30
assert
staff_data
[
2
].
permanent_fte
==
30
assert
staff_data
[
2
].
permanent_fte
==
30
assert
staff_data
[
2
].
subcontracted_fte
==
0
assert
staff_data
[
2
].
subcontracted_fte
==
0
org_data
=
session
.
query
(
model
.
ParentOrganization
).
order_by
(
model
.
ParentOrganization
.
nren_id
.
asc
()).
all
()
assert
len
(
org_data
)
==
2
assert
org_data
[
0
].
nren
.
name
.
lower
()
==
'
nren1
'
assert
org_data
[
0
].
organization
==
'
Org1
'
assert
org_data
[
1
].
nren
.
name
.
lower
()
==
'
nren3
'
assert
org_data
[
1
].
organization
==
'
Org3
'
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