Skip to content

Commit

Permalink
Bug fixes, initial support CSV result files uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
v0devil committed Jan 9, 2018
1 parent 26f4f47 commit 8808bec
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
10 changes: 10 additions & 0 deletions analyzer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class Meta:
("test", "server", 'source'),
]

class TestResultFile(models.Model):
project = models.ForeignKey(Project, on_delete=models.CASCADE, default=1)
test = models.ForeignKey(Test)
file = models.FileField(upload_to='test_result_files/')
uploaded_at = models.DateTimeField(auto_now_add=True)

class Meta:
db_table = 'test_result_file'





5 changes: 3 additions & 2 deletions analyzer/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import url
from . import views

app_name = 'analyzer'
urlpatterns = [
url(r'^projects_list', views.projects_list),
url(r'^analyze$', views.Analyze.as_view()),
Expand Down Expand Up @@ -48,5 +48,6 @@
url(r'^test/(?P<test_id>\d+)/action_graphs/$',
views.action_graphs),
url(r'^test/(?P<test_id_1>\d+)/(?P<test_id_2>\d+)/compare_aggregate_data/$',
views.tests_compare_aggregate_new),
views.tests_compare_aggregate_new),
url(r'^test-result-file-upload/$', views.TestResultFileUploadView.as_view(), name='test_result_file_upload'),
]
48 changes: 37 additions & 11 deletions analyzer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.views.generic import TemplateView
from django.views import View

import pandas as pd
from administrator.models import Configuration
from analyzer.confluence import confluenceposter
from controller.views import update_test_graphite_data
from analyzer.confluence.utils import generate_confluence_graph
from models import (Action, Project, Server, ServerMonitoringData,
Test, TestActionAggregateData, TestActionData, TestData,
Error, TestError)
from models import (Action, Project, Server, ServerMonitoringData, Test,
TestActionAggregateData, TestActionData, TestData, Error,
TestError, TestResultFile)
from scipy import stats
from django.db.models import Func
from django.template.loader import render_to_string
Expand Down Expand Up @@ -62,6 +63,26 @@ def to_pivot(data, a, b, c):
return df_pivot


class TestResultFileUploadView(View):
def get(self, request):
test_result_file_list = TestResultFile.objects.all()
return render(self.request, 'test_result_upload/index.html',
{'test_result_files': test_result_file_list})

def post(self, request):
form = TestResultFileUploadForm(self.request.POST, self.request.FILES)
if form.is_valid():
test_result_file = form.save()
data = {
'is_valid': True,
'name': test_result_file.file.name,
'url': test_result_file.file.url
}
else:
data = {'is_valid': False}
return JsonResponse(data)


def configure_page(request, project_id):
'''Generate HTML page to configure test`s attributes'''

Expand Down Expand Up @@ -603,16 +624,21 @@ def tests_compare_aggregate_new(request, test_id_1, test_id_2):
'action_id', 'action_name', 'mean')
for action in action_data_1:
action_id = action['action_id']
action_data_2 = TestActionAggregateData.objects.annotate(
action_name=F('action__url')).annotate(mean=RawSQL(
"((data->>%s)::numeric)", ('mean', ))).filter(
action_id=action_id, test_id=test_id_2).values(
'action_name', 'mean')[0]
mean_1 = action['mean']
mean_2 = action_data_2['mean']
if TestActionAggregateData.objects.filter(
action_id=action_id, test_id=test_id_2).exists():
action_data_2 = TestActionAggregateData.objects.annotate(
action_name=F('action__url')).annotate(mean=RawSQL(
"((data->>%s)::numeric)", ('mean', ))).filter(
action_id=action_id, test_id=test_id_2).values(
'action_name', 'mean')[0]
mean_1 = action['mean']
mean_2 = action_data_2['mean']
mean_diff_percent = (mean_1 - mean_2) / mean_2 * 100
else:
mean_diff_percent = 0
response.append({
'action_name': action['action_name'],
'mean_diff_percent': ((mean_1 - mean_2) / mean_2) * 100
'mean_diff_percent': mean_diff_percent
})
return JsonResponse(response, safe=False)

Expand Down
9 changes: 6 additions & 3 deletions datagenerator_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import os
import zipfile
import sqlalchemy
import time
import shutil
import time
from xml.etree.ElementTree import ElementTree
from os.path import basename
from sqlalchemy import create_engine
Expand Down Expand Up @@ -575,10 +575,13 @@ def zip_dir(dirPath, zipPath):
stm4 = test_data.delete().where(test_data.c.test_id == test_id)
stm5 = test_action_aggregate_data.delete().where(
test_action_aggregate_data.c.test_id == test_id)
stm6 = test.delete().where(test.c.id == test_id)
stm6 = test_error.delete().where(
test_error.c.test_id == test_id)
stm7 = test.delete().where(test.c.id == test_id)

result2 = db_connection.execute(stm2)
result3 = db_connection.execute(stm3)
result4 = db_connection.execute(stm4)
result5 = db_connection.execute(stm5)
result6 = db_connection.execute(stm6)
result6 = db_connection.execute(stm6)
result6 = db_connection.execute(stm7)
2 changes: 2 additions & 0 deletions jltc_web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ <h4>
<a href='#administrator'>
<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> ADMINISTRATOR</a>
</li>
<button id="test_result_upload_btn" class="btn btn-success btn-small" onclick="return popitup('/analyzer/test-result-file-upload/')">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Upload file with test results</button>
<div class="greeting"></div>
</ul>
<div id="dashboard">
Expand Down

0 comments on commit 8808bec

Please sign in to comment.