dump session target objectives to csv

This commit is contained in:
yangdsh 2020-04-28 03:11:25 +00:00 committed by Dana Van Aken
parent 3584dff8d8
commit 2916330e89
3 changed files with 27 additions and 0 deletions

View File

@ -65,6 +65,7 @@ caption span {float: right;}
(<a href="{% url 'edit_session' project.pk session.pk %}">edit</a>)
(<a href="{% url 'edit_knobs' project.pk session.pk %}">edit knobs</a>)
(<a href="{% url 'dump_debug_data' project.pk session.pk %}">dump debug info</a>)
(<a href="{% url 'dump_objectives' project.pk session.pk %}">dump objectives</a>)
</h4></caption>
<tbody>
<tr>

View File

@ -38,6 +38,7 @@ urlpatterns = [
url(r'^projects/(?P<project_id>[0-9]+)/sessions/(?P<session_id>[0-9]+)/editKnobs/$', website_views.edit_knobs, name='edit_knobs'),
url(r'^projects/(?P<project_id>[0-9]+)/sessions/delete/$', website_views.delete_session, name='delete_session'),
url(r'^projects/(?P<project_id>[0-9]+)/sessions/(?P<session_id>[0-9]+)/dump/$', website_views.download_debug_info, name='dump_debug_data'),
url(r'^projects/(?P<project_id>[0-9]+)/sessions/(?P<session_id>[0-9]+)/dump_objectives/$', website_views.download_objectives, name='dump_objectives'),
# URLs for result views
url(r'^new_result/', website_views.new_result, name='new_result'),

View File

@ -1008,6 +1008,31 @@ def download_debug_info(request, project_id, session_id): # pylint: disable=unu
return response
@login_required(login_url=reverse_lazy('login'))
def download_objectives(request, project_id, session_id): # pylint: disable=unused-argument
session = Session.objects.get(pk=session_id)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename={}_objectives.csv'.format(session.name)
writer = csv.writer(response)
objectives = target_objectives.get_all(session.dbms.pk)
labels = ['id']
for objective_name in objectives.keys():
labels.append(objective_name)
writer.writerow(labels)
metric_files = MetricData.objects.filter(session=session)
row_cnt = 0
for metric_file in metric_files:
if 'range_test' not in metric_file.name:
metric_data = JSONUtil.loads(metric_file.data)
row_data = [str(row_cnt)]
for objective_name in objectives.keys():
row_data.append(metric_data.get(objective_name, -1))
writer.writerow(row_data)
row_cnt += 1
return response
@login_required(login_url=reverse_lazy('login'))
def pipeline_data_view(request, pipeline_id):
pipeline_data = PipelineData.objects.get(pk=pipeline_id)