diff --git a/shynet/core/models.py b/shynet/core/models.py index 426c8f8..dac7e60 100644 --- a/shynet/core/models.py +++ b/shynet/core/models.py @@ -113,21 +113,21 @@ class Service(models.Model): start_time=timezone.now() - timezone.timedelta(days=1) ) - def get_core_stats(self, start_time=None, end_time=None, basic=False): + def get_core_stats(self, start_time=None, end_time=None): if start_time is None: start_time = timezone.now() - timezone.timedelta(days=30) if end_time is None: end_time = timezone.now() - main_data = self.get_relative_stats(start_time, end_time, basic) + main_data = self.get_relative_stats(start_time, end_time) comparison_data = self.get_relative_stats( - start_time - (end_time - start_time), start_time, basic + start_time - (end_time - start_time), start_time ) main_data["compare"] = comparison_data return main_data - def get_relative_stats(self, start_time, end_time, basic=False): + def get_relative_stats(self, start_time, end_time): Session = apps.get_model("analytics", "Session") Hit = apps.get_model("analytics", "Hit") @@ -152,28 +152,6 @@ class Service(models.Model): bounces = sessions.filter(is_bounce=True) bounce_count = bounces.count() - avg_load_time = hits.aggregate(load_time__avg=models.Avg("load_time"))[ - "load_time__avg" - ] - - avg_hits_per_session = hit_count / session_count if session_count > 0 else None - - avg_session_duration = self._get_avg_session_duration(sessions, session_count) - if basic: - return { - "currently_online": currently_online, - "session_count": session_count, - "hit_count": hit_count, - "has_hits": has_hits, - "bounce_rate_pct": bounce_count * 100 / session_count - if session_count > 0 - else None, - "avg_session_duration": avg_session_duration, - "avg_load_time": avg_load_time, - "avg_hits_per_session": avg_hits_per_session, - "online": True, - } - locations = ( hits.values("location") .annotate(count=models.Count("location")) @@ -220,6 +198,14 @@ class Service(models.Model): .order_by("-count") ) + avg_load_time = hits.aggregate(load_time__avg=models.Avg("load_time"))[ + "load_time__avg" + ] + + avg_hits_per_session = hit_count / session_count if session_count > 0 else None + + avg_session_duration = self._get_avg_session_duration(sessions, session_count) + chart_data, chart_tooltip_format, chart_granularity = self._get_chart_data( sessions, hits, start_time, end_time, tz_now ) diff --git a/shynet/dashboard/templates/dashboard/pages/service_update.html b/shynet/dashboard/templates/dashboard/pages/service_update.html index 03ff1c0..67ba6e5 100644 --- a/shynet/dashboard/templates/dashboard/pages/service_update.html +++ b/shynet/dashboard/templates/dashboard/pages/service_update.html @@ -36,17 +36,16 @@
Service data can be accessed via API on url:
{{script_protocol}}{{request.get_host}}{% url 'api:services' %}?uuid={{object.uuid}}
- There are 3 optional query parameters: + There are 2 optional query parameters:
Example using HTTPie:
-http get '{{script_protocol}}{{request.get_host}}{% url 'api:services' %}?uuid={{object.uuid}}&startDate=2021-01-01&endDate=2050-01-01&basic=1' 'Authorization:Token {{request.user.api_token}}'
+ http get '{{script_protocol}}{{request.get_host}}{% url 'api:services' %}?uuid={{object.uuid}}&startDate=2021-01-01&endDate=2050-01-01' 'Authorization:Token {{request.user.api_token}}'
Example using cURL:
-curl -H 'Authorization:Token {{request.user.api_token}}' '{{script_protocol}}{{request.get_host}}{% url 'api:services' %}?uuid={{object.uuid}}&startDate=2021-01-01&endDate=2050-01-01&basic=1'
+ curl -H 'Authorization:Token {{request.user.api_token}}' '{{script_protocol}}{{request.get_host}}{% url 'api:services' %}?uuid={{object.uuid}}&startDate=2021-01-01&endDate=2050-01-01'
{% endblock %}