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
a75cf469
Commit
a75cf469
authored
2 years ago
by
Remco Tukker
Browse files
Options
Downloads
Patches
Plain Diff
start of the actual mapping code
parent
ef4e82ae
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!47
Feature/comp 218 migrating 2022 data
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium_v2/conversion/conversion.py
+48
-1
48 additions, 1 deletion
compendium_v2/conversion/conversion.py
compendium_v2/static/survey-bundle.js
+1
-1
1 addition, 1 deletion
compendium_v2/static/survey-bundle.js
with
49 additions
and
2 deletions
compendium_v2/conversion/conversion.py
+
48
−
1
View file @
a75cf469
...
...
@@ -9,6 +9,7 @@ it can be used to prefill the 2023 survey.
"""
import
logging
import
click
import
json
from
sqlalchemy
import
delete
,
text
,
select
...
...
@@ -20,6 +21,8 @@ from compendium_v2.survey_db import model as survey_model
from
compendium_v2.db.model
import
NREN
from
compendium_v2.db.survey_model
import
Survey
,
SurveyResponse
from
compendium_v2.conversion.mapping
import
id_to_name
setup_logging
()
logger
=
logging
.
getLogger
(
'
conversion
'
)
...
...
@@ -111,6 +114,49 @@ def query_nren(nren_id: int):
return
answers
def
convert_answers
(
answers
):
data
=
{}
for
id
,
question_name
in
id_to_name
.
items
():
if
not
id
in
answers
:
continue
if
'
{
'
in
question_name
:
continue
answer
=
answers
[
id
]
if
len
(
answer
)
>
1
and
answer
[
0
]
==
'"'
and
answer
[
-
1
]
==
'"'
:
answer
=
answer
[
1
:
-
1
]
if
len
(
answer
)
>
1
and
answer
[
0
]
==
'
[
'
and
answer
[
-
1
]
==
'
]
'
:
answer
=
json
.
loads
(
answer
)
question_names
=
question_name
.
split
(
"
:
"
)
subdict
=
data
for
name
in
question_names
[
0
:
-
1
]:
if
name
[
-
1
]
==
"
]
"
:
index
=
name
[
-
2
]
if
index
==
"
[
"
:
subdict
=
subdict
.
setdefault
(
name
[:
-
2
],
[])
break
# special case where json list is mapped to a list of dicts
sublist
=
subdict
.
setdefault
(
name
[:
-
3
],
[])
index
=
int
(
index
)
while
len
(
sublist
)
<=
index
:
sublist
.
append
({})
subdict
=
sublist
[
index
]
else
:
subdict
=
subdict
.
setdefault
(
name
,
{})
# print(question_names, answer)
if
type
(
subdict
)
==
list
:
# special case where json list is mapped to a list of dicts
for
answer_entry
in
answer
:
subdict
.
append
({
question_names
[
-
1
]:
answer_entry
})
else
:
subdict
[
question_names
[
-
1
]]
=
answer
return
{
"
data
"
:
data
}
def
_cli
(
app
):
with
app
.
app_context
():
...
...
@@ -132,12 +178,13 @@ def _cli(app):
db
.
session
.
add
(
survey
)
for
nren
,
answers
in
nren_surveys
.
items
():
survey_dict
=
convert_answers
(
answers
)
response
=
SurveyResponse
(
nren
=
nren
,
nren_id
=
nren
.
id
,
survey_year
=
2022
,
survey
=
survey
,
answers
=
answers
# TODO structure should be differen
t
answers
=
survey_dic
t
)
db
.
session
.
add
(
response
)
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/static/survey-bundle.js
+
1
−
1
View file @
a75cf469
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