Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.web
Commits
cbd33276
Commit
cbd33276
authored
Sep 09, 2020
by
Samuel GAIST
Committed by
Flavio TARSETTI
Sep 14, 2020
Browse files
[reports][migrations] Pre-commit cleanup
parent
97f67db3
Changes
4
Hide whitespace changes
Inline
Side-by-side
beat/web/reports/migrations/0001_initial.py
View file @
cbd33276
...
...
@@ -27,37 +27,104 @@
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.conf
import
settings
from
django.db
import
migrations
from
django.db
import
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
experiments
'
,
'
0001_initial
'
),
(
'
algorithms
'
,
'
0001_initial
'
),
(
"
experiments
"
,
"
0001_initial
"
),
(
"
algorithms
"
,
"
0001_initial
"
),
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'
plotters
'
,
'
0001_initial
'
),
(
"
plotters
"
,
"
0001_initial
"
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
Report
'
,
name
=
"
Report
"
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'status'
,
models
.
CharField
(
default
=
b
'E'
,
max_length
=
1
,
choices
=
[(
b
'E'
,
b
'Editable'
),
(
b
'L'
,
b
'Locked'
),
(
b
'P'
,
b
'Published'
)])),
(
'name'
,
models
.
CharField
(
help_text
=
b
'The name for this object (space-like characters will be automatically replaced by dashes)'
,
max_length
=
200
)),
(
'number'
,
models
.
IntegerField
(
blank
=
True
)),
(
'creation_date'
,
models
.
DateTimeField
()),
(
'publication_date'
,
models
.
DateTimeField
(
null
=
True
,
blank
=
True
)),
(
'short_description'
,
models
.
CharField
(
default
=
b
''
,
help_text
=
b
'Describe the object succinctly (try to keep it under 80 characters)'
,
max_length
=
100
,
blank
=
True
)),
(
'description'
,
models
.
TextField
(
default
=
b
''
,
blank
=
True
)),
(
'content'
,
models
.
TextField
(
default
=
b
'{}'
,
blank
=
True
)),
(
'analyzer'
,
models
.
ForeignKey
(
related_name
=
'reports'
,
blank
=
True
,
to
=
'algorithms.Algorithm'
,
null
=
True
,
on_delete
=
models
.
SET_NULL
)),
(
'author'
,
models
.
ForeignKey
(
related_name
=
'reports'
,
to
=
settings
.
AUTH_USER_MODEL
,
on_delete
=
models
.
CASCADE
)),
(
'experiments'
,
models
.
ManyToManyField
(
related_name
=
'reports'
,
to
=
'experiments.Experiment'
,
blank
=
True
)),
(
'referenced_plotterparameters'
,
models
.
ManyToManyField
(
related_name
=
'reports'
,
to
=
'plotters.PlotterParameter'
,
blank
=
True
)),
(
'referenced_plotters'
,
models
.
ManyToManyField
(
related_name
=
'reports'
,
to
=
'plotters.Plotter'
,
blank
=
True
)),
(
"id"
,
models
.
AutoField
(
verbose_name
=
"ID"
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
,
),
),
(
"status"
,
models
.
CharField
(
default
=
b
"E"
,
max_length
=
1
,
choices
=
[
(
b
"E"
,
b
"Editable"
),
(
b
"L"
,
b
"Locked"
),
(
b
"P"
,
b
"Published"
),
],
),
),
(
"name"
,
models
.
CharField
(
help_text
=
b
"The name for this object (space-like characters will be automatically replaced by dashes)"
,
max_length
=
200
,
),
),
(
"number"
,
models
.
IntegerField
(
blank
=
True
)),
(
"creation_date"
,
models
.
DateTimeField
()),
(
"publication_date"
,
models
.
DateTimeField
(
null
=
True
,
blank
=
True
)),
(
"short_description"
,
models
.
CharField
(
default
=
b
""
,
help_text
=
b
"Describe the object succinctly (try to keep it under 80 characters)"
,
max_length
=
100
,
blank
=
True
,
),
),
(
"description"
,
models
.
TextField
(
default
=
b
""
,
blank
=
True
)),
(
"content"
,
models
.
TextField
(
default
=
b
"{}"
,
blank
=
True
)),
(
"analyzer"
,
models
.
ForeignKey
(
related_name
=
"reports"
,
blank
=
True
,
to
=
"algorithms.Algorithm"
,
null
=
True
,
on_delete
=
models
.
SET_NULL
,
),
),
(
"author"
,
models
.
ForeignKey
(
related_name
=
"reports"
,
to
=
settings
.
AUTH_USER_MODEL
,
on_delete
=
models
.
CASCADE
,
),
),
(
"experiments"
,
models
.
ManyToManyField
(
related_name
=
"reports"
,
to
=
"experiments.Experiment"
,
blank
=
True
),
),
(
"referenced_plotterparameters"
,
models
.
ManyToManyField
(
related_name
=
"reports"
,
to
=
"plotters.PlotterParameter"
,
blank
=
True
,
),
),
(
"referenced_plotters"
,
models
.
ManyToManyField
(
related_name
=
"reports"
,
to
=
"plotters.Plotter"
,
blank
=
True
),
),
],
),
]
beat/web/reports/migrations/0002_report_expiration_date.py
View file @
cbd33276
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
datetime
import
datetime
from
datetime
import
timedelta
from
datetime
import
datetime
,
timedelta
from
django.conf
import
settings
from
django.db
import
migrations
from
django.db
import
models
def
add_timeout_to_existing_locked_report
(
apps
,
schema_editor
):
report_model
=
apps
.
get_model
(
"reports"
,
"report"
)
for
single_report
in
report_model
.
objects
.
all
():
if
single_report
.
status
==
'L'
:
single_report
.
expiration_date
=
datetime
.
now
()
+
timedelta
(
days
=
settings
.
EXPIRATION_DELTA
)
if
single_report
.
status
==
"L"
:
single_report
.
expiration_date
=
datetime
.
now
()
+
timedelta
(
days
=
settings
.
EXPIRATION_DELTA
)
single_report
.
save
()
def
backward_dummy
(
apps
,
schema_editor
):
pass
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
reports
'
,
'
0001_initial
'
),
(
"
reports
"
,
"
0001_initial
"
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'
report
'
,
name
=
'
expiration_date
'
,
model_name
=
"
report
"
,
name
=
"
expiration_date
"
,
field
=
models
.
DateTimeField
(
null
=
True
,
blank
=
True
),
),
migrations
.
RunPython
(
add_timeout_to_existing_locked_report
,
backward_dummy
)
migrations
.
RunPython
(
add_timeout_to_existing_locked_report
,
backward_dummy
),
]
beat/web/reports/migrations/0003_report_last_edited_date.py
View file @
cbd33276
...
...
@@ -2,19 +2,20 @@
# Generated by Django 1.9.5 on 2017-03-13 15:11
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
from
django.db
import
migrations
from
django.db
import
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
reports
'
,
'
0002_report_expiration_date
'
),
(
"
reports
"
,
"
0002_report_expiration_date
"
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'
report
'
,
name
=
'
last_edited_date
'
,
model_name
=
"
report
"
,
name
=
"
last_edited_date
"
,
field
=
models
.
DateTimeField
(
null
=
True
),
),
]
beat/web/reports/migrations/0004_auto_20170410_1121.py
View file @
cbd33276
...
...
@@ -2,65 +2,77 @@
# Generated by Django 1.9.5 on 2017-04-10 11:21
from
__future__
import
unicode_literals
from
django.db
import
migrations
import
json
import
re
from
django.db
import
migrations
# parses a table from the old representation (a list of column objects)
# and returns a table in the new representation
def
parse_table
(
table
,
precision
):
conv_table
=
{
'itemName'
:
'Table'
,
'fields'
:
[
'Experiment'
],
'precision'
:
precision
}
conv_table
=
{
"itemName"
:
"Table"
,
"fields"
:
[
"Experiment"
],
"precision"
:
precision
}
for
row
in
table
:
if
not
row
[
'
selected
'
]:
if
not
row
[
"
selected
"
]:
continue
name
=
row
[
'
name
'
]
name
=
re
.
sub
(
r
'
\[.*\]$
'
,
''
,
name
)
name
=
row
[
"
name
"
]
name
=
re
.
sub
(
r
"
\[.*\]$
"
,
""
,
name
)
if
name
==
'
experiment
'
:
if
name
==
"
experiment
"
:
continue
if
name
==
'
experiment.execution_time
'
or
name
==
'
execution_time
'
:
name
=
'
total_execution_time
'
elif
re
.
match
(
r
'
^execution_time\.
'
,
name
):
name
=
re
.
sub
(
r
'
execution_time
'
,
'
linear_execution_time
'
,
name
)
if
name
==
"
experiment.execution_time
"
or
name
==
"
execution_time
"
:
name
=
"
total_execution_time
"
elif
re
.
match
(
r
"
^execution_time\.
"
,
name
):
name
=
re
.
sub
(
r
"
execution_time
"
,
"
linear_execution_time
"
,
name
)
if
name
.
startswith
(
'
experiment.
'
):
name
=
re
.
sub
(
r
'
experiment\.
'
,
''
,
name
)
if
name
.
startswith
(
"
experiment.
"
):
name
=
re
.
sub
(
r
"
experiment\.
"
,
""
,
name
)
if
'.'
in
name
:
segs
=
name
.
split
(
'.'
)
name
=
segs
[
1
]
+
'.'
+
segs
[
0
]
conv_table
[
'
fields
'
].
append
(
name
)
if
"."
in
name
:
segs
=
name
.
split
(
"."
)
name
=
segs
[
1
]
+
"."
+
segs
[
0
]
conv_table
[
"
fields
"
].
append
(
name
)
return
conv_table
# parses a plot from the old representation
# and returns a plot in the new representation
def
parse_plot
(
plot
):
conv_plot
=
{
'
itemName
'
:
plot
[
'
required_plotter
'
][
0
],
'
name
'
:
plot
[
'
data
'
][
'
output
'
][
0
],
'
type
'
:
plot
[
'
required_plotter
'
][
0
]
"
itemName
"
:
plot
[
"
required_plotter
"
][
0
],
"
name
"
:
plot
[
"
data
"
][
"
output
"
][
0
],
"
type
"
:
plot
[
"
required_plotter
"
][
0
]
,
}
return
conv_plot
# helper func to build the experiment's full name
def
experiment_fullname
(
exp
):
return
'%s/%s/%s/%s/%s'
%
(
exp
.
author
.
username
,
exp
.
toolchain
.
author
.
username
,
exp
.
toolchain
.
name
,
exp
.
toolchain
.
version
,
exp
.
name
)
return
"%s/%s/%s/%s/%s"
%
(
exp
.
author
.
username
,
exp
.
toolchain
.
author
.
username
,
exp
.
toolchain
.
name
,
exp
.
toolchain
.
version
,
exp
.
name
,
)
# helper func to build the analyzer's full name
def
analyzer_fullname
(
report
):
return
'%s/%s/%s'
%
(
report
.
analyzer
.
author
.
username
,
report
.
analyzer
.
name
,
report
.
analyzer
.
version
)
return
"%s/%s/%s"
%
(
report
.
analyzer
.
author
.
username
,
report
.
analyzer
.
name
,
report
.
analyzer
.
version
,
)
# converts an old report into the new report format
def
move_content_to_groups_format
(
apps
,
schema_editor
):
Report
=
apps
.
get_model
(
'
reports
'
,
'
Report
'
)
Report
=
apps
.
get_model
(
"
reports
"
,
"
Report
"
)
for
report
in
Report
.
objects
.
all
():
# all of the changes are in the report's content field
...
...
@@ -68,7 +80,7 @@ def move_content_to_groups_format(apps, schema_editor):
# convert to groups format, but don't touch any report thats
# already using the new system
if
'
groups
'
not
in
report_content
:
if
"
groups
"
not
in
report_content
:
# format:
# ----
# groups: {
...
...
@@ -88,50 +100,64 @@ def move_content_to_groups_format(apps, schema_editor):
# default to just one group that contains all experiments/items
group1
=
{
# list of experiments in the group
'
experiments
'
:
[
experiment_fullname
(
e
)
for
e
in
exps
],
'
reportItems
'
:
[],
# analyzer of the report
'
analyzer
'
:
analyzer_fullname
(
report
)
if
report
.
analyzer
else
''
,
'
aliases
'
:
{},
'
idx
'
:
1
"
experiments
"
:
[
experiment_fullname
(
e
)
for
e
in
exps
],
"
reportItems
"
:
[],
# analyzer of the report
"
analyzer
"
:
analyzer_fullname
(
report
)
if
report
.
analyzer
else
""
,
"
aliases
"
:
{},
"
idx
"
:
1
,
}
old_aliases
=
report_content
[
'alias_experiments'
]
if
'alias_experiments'
in
report_content
else
{}
old_aliases
=
(
report_content
[
"alias_experiments"
]
if
"alias_experiments"
in
report_content
else
{}
)
# assign aliases
get_alias
=
lambda
exp_name
:
old_aliases
[
exp_name
]
if
exp_name
in
old_aliases
else
None
get_alias
=
(
lambda
exp_name
:
old_aliases
[
exp_name
]
if
exp_name
in
old_aliases
else
None
)
for
e
in
exps
:
fullname
=
experiment_fullname
(
e
)
group1
[
'
aliases
'
][
fullname
]
=
get_alias
(
fullname
)
or
e
.
name
group1
[
"
aliases
"
][
fullname
]
=
get_alias
(
fullname
)
or
e
.
name
count_tables
=
0
count_plots
=
0
for
item_name
in
report_content
:
if
item_name
==
'floating_point_precision'
or
item_name
==
'alias_experiments'
:
if
(
item_name
==
"floating_point_precision"
or
item_name
==
"alias_experiments"
):
continue
item
=
report_content
[
item_name
]
item_type
=
'table'
if
item_name
.
startswith
(
'table'
)
else
'plot'
fpp
=
report_content
[
'floating_point_precision'
]
if
'floating_point_precision'
in
report_content
else
10
converted_content
=
parse_table
(
item
,
fpp
)
if
item_type
==
'table'
else
parse_plot
(
item
)
converted_id
=
''
if
item_type
==
'table'
:
converted_id
=
'table_'
+
str
(
count_tables
)
item_type
=
"table"
if
item_name
.
startswith
(
"table"
)
else
"plot"
fpp
=
(
report_content
[
"floating_point_precision"
]
if
"floating_point_precision"
in
report_content
else
10
)
converted_content
=
(
parse_table
(
item
,
fpp
)
if
item_type
==
"table"
else
parse_plot
(
item
)
)
converted_id
=
""
if
item_type
==
"table"
:
converted_id
=
"table_"
+
str
(
count_tables
)
count_tables
+=
1
else
:
converted_id
=
'
plot_
'
+
str
(
count_plots
)
converted_id
=
"
plot_
"
+
str
(
count_plots
)
count_plots
+=
1
converted_item
=
{
'id'
:
converted_id
,
'content'
:
converted_content
}
converted_item
=
{
"id"
:
converted_id
,
"content"
:
converted_content
}
group1
[
'
reportItems
'
].
append
(
converted_item
)
group1
[
"
reportItems
"
].
append
(
converted_item
)
groups
[
'
group1
'
]
=
group1
obj
[
'
groups
'
]
=
groups
groups
[
"
group1
"
]
=
group1
obj
[
"
groups
"
]
=
groups
report
.
content
=
json
.
dumps
(
obj
)
report
.
save
()
...
...
@@ -139,9 +165,7 @@ def move_content_to_groups_format(apps, schema_editor):
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
reports
'
,
'
0003_report_last_edited_date
'
),
(
"
reports
"
,
"
0003_report_last_edited_date
"
),
]
operations
=
[
migrations
.
RunPython
(
move_content_to_groups_format
)
]
operations
=
[
migrations
.
RunPython
(
move_content_to_groups_format
)]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment