Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
f09fb3fc
Commit
f09fb3fc
authored
4 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
subject importer uses the same functionality that visit importer does
parent
6fd4eef8
No related branches found
No related tags found
1 merge request
!275
Resolve "update automatic visit/subject importer"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/importer/etl_common.py
+6
-4
6 additions, 4 deletions
smash/web/importer/etl_common.py
smash/web/importer/importer.py
+11
-66
11 additions, 66 deletions
smash/web/importer/importer.py
smash/web/importer/subject_import_reader.py
+1
-1
1 addition, 1 deletion
smash/web/importer/subject_import_reader.py
with
18 additions
and
71 deletions
smash/web/importer/etl_common.py
+
6
−
4
View file @
f09fb3fc
import
codecs
import
datetime
import
logging
from
typing
import
Type
,
Optional
from
django.db
import
models
from
importer.subject_import_reader
import
logger
from
models
import
Provenance
from
models.etl.etl
import
EtlData
from
web.models
import
Provenance
from
web.models.etl.etl
import
EtlData
logger
=
logging
.
getLogger
(
__name__
)
class
EtlCommon
:
...
...
@@ -87,4 +89,4 @@ class EtlCommon:
if
type
(
line
)
==
str
:
return
line
[
3
:]
if
line
.
encode
(
'
utf8
'
).
startswith
(
codecs
.
BOM_UTF8
)
else
line
else
:
return
line
[
3
:]
if
line
.
startswith
(
codecs
.
BOM_UTF8
)
else
line
\ No newline at end of file
return
line
[
3
:]
if
line
.
startswith
(
codecs
.
BOM_UTF8
)
else
line
This diff is collapsed.
Click to expand it.
smash/web/importer/importer.py
+
11
−
66
View file @
f09fb3fc
...
...
@@ -3,7 +3,7 @@ import logging
import
sys
import
traceback
from
web.models
import
StudySubject
,
Subject
,
Provenance
from
web.models
import
StudySubject
,
Subject
from
.etl_common
import
EtlCommon
from
.subject_import_reader
import
SubjectImportReader
from
.warning_counter
import
MsgCounterHandler
...
...
@@ -56,82 +56,27 @@ class Importer(EtlCommon):
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
old_value
=
getattr
(
db_study_subject
.
subject
,
field
.
name
)
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
old_value
,
new_value
)
p
=
Provenance
(
modified_table
=
Subject
.
_meta
.
db_table
,
modified_table_id
=
db_study_subject
.
subject
.
id
,
modification_author
=
self
.
etl_data
.
import_worker
,
previous_value
=
old_value
,
new_value
=
new_value
,
modification_description
=
description
,
modified_field
=
field
,
)
setattr
(
db_study_subject
.
subject
,
field
.
name
,
new_value
)
p
.
save
()
old_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
new_value
=
self
.
get_new_value
(
old_value
,
field
.
name
,
study_subject
.
subject
)
self
.
create_provenance_and_change_data
(
db_study_subject
.
subject
,
field
.
name
,
new_value
,
Subject
)
db_study_subject
.
subject
.
save
()
for
field
in
StudySubject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
old_value
=
getattr
(
db_study_subject
,
field
.
name
)
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
old_value
,
new_value
)
p
=
Provenance
(
modified_table
=
Subject
.
_meta
.
db_table
,
modified_table_id
=
db_study_subject
.
id
,
modification_author
=
self
.
etl_data
.
import_worker
,
previous_value
=
old_value
,
new_value
=
new_value
,
modification_description
=
description
,
modified_field
=
field
,
)
setattr
(
db_study_subject
,
field
.
name
,
new_value
)
p
.
save
()
old_value
=
getattr
(
study_subject
,
field
.
name
)
new_value
=
self
.
get_new_value
(
old_value
,
field
.
name
,
study_subject
.
subject
)
self
.
create_provenance_and_change_data
(
db_study_subject
,
field
.
name
,
new_value
,
StudySubject
)
db_study_subject
.
save
()
self
.
merged_count
+=
1
else
:
study_subject
.
subject
.
save
()
study_subject
.
subject
=
Subject
.
objects
.
filter
(
id
=
study_subject
.
subject
.
id
)
[
0
]
study_subject
.
subject
=
Subject
.
objects
.
get
(
pk
=
study_subject
.
subject
.
id
)
study_subject
.
save
()
for
field
in
Subject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
''
,
new_value
)
p
=
Provenance
(
modified_table
=
Subject
.
_meta
.
db_table
,
modified_table_id
=
study_subject
.
subject
.
id
,
modification_author
=
self
.
etl_data
.
import_worker
,
previous_value
=
''
,
new_value
=
new_value
,
modification_description
=
description
,
modified_field
=
field
,
)
p
.
save
()
for
field
in
StudySubject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
''
,
new_value
)
p
=
Provenance
(
modified_table
=
Subject
.
_meta
.
db_table
,
modified_table_id
=
study_subject
.
id
,
modification_author
=
self
.
etl_data
.
import_worker
,
previous_value
=
''
,
new_value
=
new_value
,
modification_description
=
description
,
modified_field
=
field
,
)
p
.
save
()
self
.
create_provenance_for_new_object
(
Subject
,
study_subject
.
subject
)
self
.
create_provenance_for_new_object
(
StudySubject
,
study_subject
)
self
.
added_count
+=
1
def
get_summary
(
self
):
...
...
This diff is collapsed.
Click to expand it.
smash/web/importer/subject_import_reader.py
+
1
−
1
View file @
f09fb3fc
import
logging
from
typing
import
List
from
importer.etl_common
import
EtlCommon
from
web.
importer.etl_common
import
EtlCommon
from
web.models
import
SubjectImportData
from
web.models.study_subject
import
StudySubject
...
...
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