Skip to content

Commit

Permalink
Merge pull request #16 from weni-ai/feature/dashboard-filter-grid-and-h
Browse files Browse the repository at this point in the history
Feature/dashboard filter grid and h
  • Loading branch information
AlanJaeger authored Jun 20, 2024
2 parents 3ba5ecd + d9afe93 commit fc8b24f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions insights/dashboards/usecases/dashboard_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create_widgets(self, dashboard_atendimento_humano):
"op_field": "waiting_time",
},
dashboard=dashboard_atendimento_humano,
position={"rows": [2, 2], "columns": [5, 8]},
position={"rows": [3, 3], "columns": [5, 8]},
)
encerrados = Widget.objects.create(
name="Encerrados",
Expand Down Expand Up @@ -102,7 +102,7 @@ def create_widgets(self, dashboard_atendimento_humano):
},
},
dashboard=dashboard_atendimento_humano,
position={"rows": [3, 3], "columns": [5, 8]},
position={"rows": [2, 2], "columns": [5, 8]},
)
Widget.objects.create(
name="Tempo de interação",
Expand Down
8 changes: 7 additions & 1 deletion insights/dashboards/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from rest_framework.decorators import action
from rest_framework.response import Response

from django.conf import settings
from django.db.models import Q

from insights.authentication.permissions import ProjectAuthPermission
from insights.dashboards.models import Dashboard
from insights.dashboards.utils import DefaultPagination
Expand Down Expand Up @@ -31,7 +34,10 @@ def get_queryset(self):
if project_id is not None:
return (
Dashboard.objects.filter(project_id=project_id)
.exclude(name="Resultados de fluxos")
.exclude(
Q(name="Resultados de fluxos")
& ~Q(project_id__in=settings.PROJECT_ALLOW_LIST)
)
.order_by("created_on")
)

Expand Down
2 changes: 2 additions & 0 deletions insights/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,5 @@
FLOWS_QUEUE_EXCHANGE = env("FLOWS_QUEUE_EXCHANGE", default="queues.topic")

CHATS_URL = env("CHATS_URL")

PROJECT_ALLOW_LIST = env("PROJECT_ALLOW_LIST", default=[])
3 changes: 1 addition & 2 deletions insights/sources/rooms/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def timeseries_hour_group_count(
):
if not self.is_valid:
self.build_query()
query = f"WITH hourly_data AS (SELECT EXTRACT(HOUR FROM r.{time_field}) AS hour, COUNT(*) AS rooms_count FROM public.rooms_room as r {self.join_clause} WHERE {self.where_clause} GROUP BY hour) SELECT hours.label, COALESCE(hourly_data.rooms_count, 0) AS value FROM generate_series(0, 23) AS hours(label) LEFT JOIN hourly_data ON hours.label = hourly_data.hour ORDER BY value DESC FETCH FIRST {limit} ROWS ONLY;"

query = f"WITH hourly_data AS (SELECT EXTRACT(HOUR FROM r.{time_field}) AS hour, COUNT(*) AS rooms_count FROM public.rooms_room as r {self.join_clause} WHERE {self.where_clause} GROUP BY hour) SELECT CONCAT(hours.label, 'h') AS label, COALESCE(hourly_data.rooms_count, 0) AS value FROM generate_series(0, 23) AS hours(label) LEFT JOIN hourly_data ON hours.label = hourly_data.hour ORDER BY value DESC FETCH FIRST {limit} ROWS ONLY;"
return query, self.params

def count(self):
Expand Down

0 comments on commit fc8b24f

Please sign in to comment.