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
047a070c
Commit
047a070c
authored
1 year ago
by
Remco Tukker
Browse files
Options
Downloads
Patches
Plain Diff
first version of v2 publisher
parent
caab071d
No related branches found
No related tags found
1 merge request
!77
Feature/comp 276 publisher v2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/publishers/survey_publisher_v2.py
+112
-0
112 additions, 0 deletions
compendium_v2/publishers/survey_publisher_v2.py
compendium_v2/routes/survey.py
+9
-2
9 additions, 2 deletions
compendium_v2/routes/survey.py
with
121 additions
and
2 deletions
compendium_v2/publishers/survey_publisher_v2.py
0 → 100644
+
112
−
0
View file @
047a070c
from
decimal
import
Decimal
from
sqlalchemy
import
delete
,
select
from
compendium_v2.db
import
db
from
compendium_v2.db.model
import
BudgetEntry
,
ChargingStructure
,
ECProject
,
FeeType
,
FundingSource
,
InstitutionURLs
,
\
NrenStaff
,
ParentOrganization
,
Policy
,
SubOrganization
,
TrafficVolume
from
compendium_v2.db.survey_model
import
ResponseStatus
,
SurveyResponse
def
map_2023
(
year
,
nren
,
answers
):
for
table_class
in
[
BudgetEntry
,
ChargingStructure
,
ECProject
,
FundingSource
,
InstitutionURLs
,
NrenStaff
,
ParentOrganization
,
Policy
,
SubOrganization
,
TrafficVolume
]:
db
.
session
.
execute
(
delete
(
table_class
).
where
(
table_class
.
year
==
2023
))
answers
=
answers
[
"
data
"
]
budget
=
answers
.
get
(
"
budget
"
)
if
budget
:
db
.
session
.
add
(
BudgetEntry
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
budget
=
Decimal
(
budget
)))
funding_source
=
answers
.
get
(
"
income_sources
"
)
if
funding_source
:
db
.
session
.
add
(
FundingSource
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
client_institutions
=
Decimal
(
funding_source
.
get
(
"
client_institutions
"
,
0
)),
european_funding
=
Decimal
(
funding_source
.
get
(
"
european_funding
"
,
0
)),
gov_public_bodies
=
Decimal
(
funding_source
.
get
(
"
gov_public_bodies
"
,
0
)),
commercial
=
Decimal
(
funding_source
.
get
(
"
commercial
"
,
0
)),
other
=
Decimal
(
funding_source
.
get
(
"
other
"
,
0
))
))
charging
=
answers
.
get
(
"
charging_mechanism
"
)
if
charging
:
db
.
session
.
add
(
ChargingStructure
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
fee_type
=
FeeType
[
charging
]))
staff_roles
=
answers
.
get
(
"
staff_roles
"
,
{})
staff_employment_type
=
answers
.
get
(
"
staff_employment_type
"
,
{})
if
staff_roles
or
staff_employment_type
:
db
.
session
.
add
(
NrenStaff
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
permanent_fte
=
Decimal
(
staff_employment_type
.
get
(
"
permanent_fte
"
,
0
)),
subcontracted_fte
=
Decimal
(
staff_employment_type
.
get
(
"
subcontracted_fte
"
,
0
)),
technical_fte
=
Decimal
(
staff_roles
.
get
(
"
technical_fte
"
,
0
)),
non_technical_fte
=
Decimal
(
staff_roles
.
get
(
"
nontechnical_fte
"
,
0
))
))
parent
=
answers
.
get
(
"
parent_organization_name
"
)
if
parent
:
db
.
session
.
add
(
ParentOrganization
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
organization
=
parent
))
subs
=
answers
.
get
(
"
suborganization_details
"
)
if
subs
:
for
sub
in
subs
:
db
.
session
.
add
(
SubOrganization
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
organization
=
sub
.
get
(
"
suborganization_name
"
),
role
=
sub
.
get
(
"
suborganization_role
"
)
# TODO handle 'other' option properly
))
ec_projects
=
answers
.
get
(
"
ec_project_names
"
)
if
ec_projects
:
for
ec_project
in
ec_projects
:
db
.
session
.
add
(
ECProject
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
project
=
ec_project
.
get
(
"
ec_project_name
"
)))
strategy
=
answers
.
get
(
"
corporate_strategy_url
"
,
""
)
policies
=
answers
.
get
(
"
policies
"
,
{})
if
strategy
or
policies
:
db
.
session
.
add
(
Policy
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
strategic_plan
=
strategy
,
environmental
=
policies
.
get
(
"
environmental_policy
"
,
{}).
get
(
"
url
"
,
""
),
equal_opportunity
=
policies
.
get
(
"
equal_opportunity_policy
"
,
{}).
get
(
"
url
"
,
""
),
connectivity
=
policies
.
get
(
"
connectivity_policy
"
,
{}).
get
(
"
url
"
,
""
),
acceptable_use
=
policies
.
get
(
"
acceptable_use_policy
"
,
{}).
get
(
"
url
"
,
""
),
privacy_notice
=
policies
.
get
(
"
privacy_notice
"
,
{}).
get
(
"
url
"
,
""
),
data_protection
=
policies
.
get
(
"
data_protection_contact
"
,
{}).
get
(
"
url
"
,
""
)
# TODO gender_equality_policy missing?
))
traffic_estimate
=
answers
.
get
(
"
traffic_estimate
"
)
if
traffic_estimate
:
db
.
session
.
add
(
TrafficVolume
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
strategic_plan
=
strategy
,
to_customers
=
Decimal
(
traffic_estimate
.
get
(
"
to_customers
"
)),
from_customers
=
Decimal
(
traffic_estimate
.
get
(
"
from_customers
"
)),
to_external
=
Decimal
(
traffic_estimate
.
get
(
"
to_external
"
)),
from_external
=
Decimal
(
traffic_estimate
.
get
(
"
from_external
"
)),
))
institution_urls
=
answers
.
get
(
"
connected_sites_lists
"
)
if
institution_urls
:
db
.
session
.
add
(
InstitutionURLs
(
nren_id
=
nren
.
id
,
nren
=
nren
,
year
=
year
,
urls
=
institution_urls
,
))
def
publish
(
year
):
responses
=
db
.
session
.
scalars
(
select
(
SurveyResponse
).
where
(
SurveyResponse
.
survey_year
==
year
)
.
where
(
SurveyResponse
.
status
==
ResponseStatus
.
completed
)
).
unique
()
question_mapping
=
{
2023
:
map_2023
}
mapping_function
=
question_mapping
[
year
]
for
response
in
responses
:
mapping_function
(
year
,
response
.
nren
,
response
.
answers
)
This diff is collapsed.
Click to expand it.
compendium_v2/routes/survey.py
+
9
−
2
View file @
047a070c
...
...
@@ -8,6 +8,7 @@ from sqlalchemy.orm import joinedload, load_only
from
compendium_v2.db
import
db
from
compendium_v2.db.model
import
NREN
,
PreviewYear
from
compendium_v2.db.survey_model
import
Survey
,
SurveyResponse
,
SurveyStatus
,
RESPONSE_NOT_STARTED
from
compendium_v2.publishers.survey_publisher_v2
import
publish
from
compendium_v2.routes
import
common
from
compendium_v2.auth.session_management
import
admin_required
...
...
@@ -195,7 +196,10 @@ def preview_survey(year) -> Any:
if
survey
.
status
not
in
[
SurveyStatus
.
closed
,
SurveyStatus
.
preview
]:
return
{
'
message
'
:
'
Survey is not closed or in preview and can therefore not be published for preview
'
},
400
# TODO call new survey_publisher with all completed responses and the year
if
year
<
2023
:
return
{
'
message
'
:
'
The 2023 survey is the first that can be published from this application
'
},
400
publish
(
year
)
preview
=
db
.
session
.
scalar
(
select
(
PreviewYear
).
where
(
PreviewYear
.
year
==
year
))
if
not
preview
:
...
...
@@ -223,7 +227,10 @@ def publish_survey(year) -> Any:
if
survey
.
status
not
in
[
SurveyStatus
.
preview
,
SurveyStatus
.
published
]:
return
{
'
message
'
:
'
Survey is not in preview or published and can therefore not be published
'
},
400
# TODO call new survey_publisher with all completed responses and the year
if
year
<
2023
:
return
{
'
message
'
:
'
The 2023 survey is the first that can be published from this application
'
},
400
publish
(
year
)
db
.
session
.
execute
(
delete
(
PreviewYear
).
where
(
PreviewYear
.
year
==
year
))
...
...
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