Skip to content
Snippets Groups Projects
Commit 116e500c authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

add notes to migration script and convert aliases appropriately

parent a99dcc2b
No related branches found
No related tags found
1 merge request!223Reports overhaul
...@@ -6,6 +6,8 @@ from django.db import migrations ...@@ -6,6 +6,8 @@ from django.db import migrations
import json import json
import re import re
# 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): def parse_table(table, precision):
conv_table = { conv_table = {
'fields': ['Experiment'], 'fields': ['Experiment'],
...@@ -34,6 +36,8 @@ def parse_table(table, precision): ...@@ -34,6 +36,8 @@ def parse_table(table, precision):
return conv_table return conv_table
# parses a plot from the old representation
# and returns a plot in the new representation
def parse_plot(plot): def parse_plot(plot):
conv_plot = { conv_plot = {
'name': plot['data']['output'][0], 'name': plot['data']['output'][0],
...@@ -41,20 +45,27 @@ def parse_plot(plot): ...@@ -41,20 +45,27 @@ def parse_plot(plot):
} }
return conv_plot return conv_plot
# helper func to build the experiment's full name
def experiment_fullname(exp): 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): 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): 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(): for report in Report.objects.all():
# all of the changes are in the report's content field
report_content = json.loads(report.content) report_content = json.loads(report.content)
# convert to groups format
# 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:
exps = report.experiments.all() # format:
# ----
# groups: { # groups: {
# group1 : { # group1 : {
# experiments: [], # experiments: [],
...@@ -65,17 +76,27 @@ def move_content_to_groups_format(apps, schema_editor): ...@@ -65,17 +76,27 @@ def move_content_to_groups_format(apps, schema_editor):
# }, # },
# ... # ...
# } # }
# ----
exps = report.experiments.all()
obj = {} obj = {}
groups = {} groups = {}
# default to just one group that contains all experiments/items
group1 = { group1 = {
# list of experiments in the group
'experiments': [ experiment_fullname(e) for e in exps ], 'experiments': [ experiment_fullname(e) for e in exps ],
'reportItems': [], 'reportItems': [],
# analyzer of the report
'analyzer': analyzer_fullname(report) if report.analyzer else '', 'analyzer': analyzer_fullname(report) if report.analyzer else '',
'aliases': {}, 'aliases': {},
'idx': 1 'idx': 1
} }
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
for e in exps: for e in exps:
group1['aliases'][experiment_fullname(e)] = e.name fullname = experiment_fullname(e)
group1['aliases'][fullname] = get_alias(fullname) or e.name
count_tables = 0 count_tables = 0
count_plots = 0 count_plots = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment