Skip to content

Commit

Permalink
Merge pull request #72 from SmartReports/dev
Browse files Browse the repository at this point in the history
bugfux
  • Loading branch information
matteotolloso authored Dec 5, 2023
2 parents 748e44a + 679143c commit ac368d4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ httpx==0.19.0
idna==2.10
iniconfig==2.0.0
kombu==5.3.4
numpy==1.26.1
packaging==23.2
pandas==2.1.2
Pillow==10.1.0
Expand Down
13 changes: 11 additions & 2 deletions smartreport_app/kb_interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .sync_db_kb import get_kpi_value
import numpy as np
import random


def kb_interface(params):
plot_type = params['chart_type']
Expand All @@ -13,7 +14,15 @@ def kb_interface(params):
value = resp['value'][-1]
response = {
'value': value, # should be only one or take the last one
'color' : np.random.choice(['red', 'orange', 'green'])
'color' : random.choice(['red', 'orange', 'green'])
}
return response

if plot_type == 'value':
resp = get_kpi_value(kpi_list[0]) # is only one
value = resp['value'][-1]
response = {
'value': value, # should be only one or take the last one
}
return response

Expand Down
3 changes: 2 additions & 1 deletion smartreport_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class UserType(models.TextChoices):
"pie",
"doughnut",
"radar",
"semaphore"
"semaphore",
"value",
)
def DEFAULT_CHART_CHOICES():
return [*CHART_CHOICES]
Expand Down
4 changes: 2 additions & 2 deletions smartreport_app/sync_db_kb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
from .models import Kpi
import numpy as np
import random


BASE_URL = 'https://vornao.dev:8888'
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_kpi_value(kpi_uid, start_time=0, end_time=0):
kpi_value = {
'data' : {
'name' : kpi_uid,
'value' : np.random.rand(7)
'value' : [random.random() for _ in range(7)]
}
}

Expand Down
4 changes: 2 additions & 2 deletions smartreport_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def list(self, request):
if not params["chart_type"] in kpi.allowed_charts:
return Response({"message": f"Kpi {kpi.pk} does not support {params['chart_type']} plot"}, status=status.HTTP_400_BAD_REQUEST)

if params["chart_type"] == "semaphore" and len(list_of_KB_uids) > 1:
return Response({"message": "The semaphore plot only supports one kpi"}, status=status.HTTP_400_BAD_REQUEST)
if params["chart_type"] in ["semaphore", "value"] and len(list_of_KB_uids) > 1:
return Response({"message": "This plot only supports one kpi"}, status=status.HTTP_400_BAD_REQUEST)


# TODO implement start and end time
Expand Down

0 comments on commit ac368d4

Please sign in to comment.