diff --git a/cloud/endagaweb/stats_app/stats_client.py b/cloud/endagaweb/stats_app/stats_client.py index 5ebe043f..b256d02e 100644 --- a/cloud/endagaweb/stats_app/stats_client.py +++ b/cloud/endagaweb/stats_app/stats_client.py @@ -369,3 +369,61 @@ def timeseries(self, key=None, **kwargs): if 'aggregation' not in kwargs: kwargs['aggregation'] = 'average_value' return self.aggregate_timeseries(key, **kwargs) + +class SubscriberStatsClient(StatsClientBase): + """Gathers data on SubscriberStats instance at tower and network level""" + + def __init__(self, *args, **kwargs): + super(SubscriberStatsClient, self).__init__(*args, **kwargs) + + def timeseries(self, key=None, **kwargs): + if 'aggregation' not in kwargs: + kwargs['aggregation'] = 'average_value' + return self.aggregate_timeseries(key, **kwargs) + +class BTSStatsClient(StatsClientBase): + """Gathers data on BTSStats instances at a tower and network level""" + + def __init__(self, *args, **kwargs): + super(BTSStatsClient, self).__init__(*args, **kwargs) + + def timeseries(self, kind=None, **kwargs): + results, usage, bts_values = ([] for i in range(3)) + + start_time = datetime.fromtimestamp(kwargs['start_time_epoch'], + pytz.utc) + + # Limit end time to 7 days. + kwargs['end_time'] = start_time + timedelta(days=7) + + try: + previous_state = models.SystemEvent.objects.filter( + bts_id=self.level_id, date__lt=start_time).order_by('-date')[0] + previous_state = previous_state.type + except IndexError: + previous_state = 'bts up' + + for call_kind in BTS_KINDS: + # bts up + usage = self.aggregate_timeseries(call_kind, **kwargs) + values = [u[1] for u in usage] + results.append(values) + dates = [u[0] for u in usage] + # Get last state + last_val = None + bts_status = [sum(v) for v in zip(*results)] + for value in bts_status: + if last_val is None: + if previous_state == 'bts up': + last_val = 1 + elif previous_state == 'bts up': + last_val = 0 + # last_val = value + if value > 0: + last_val = 1 + elif value < 0: + last_val = 0 + bts_values.append(last_val) + return zip(dates, bts_values) + + diff --git a/cloud/endagaweb/templates/dashboard/report/health.html b/cloud/endagaweb/templates/dashboard/report/health.html new file mode 100644 index 00000000..e6ad8442 --- /dev/null +++ b/cloud/endagaweb/templates/dashboard/report/health.html @@ -0,0 +1,83 @@ +{% extends "dashboard/layout.html" %} +{% comment %} +Copyright (c) 2016-present, Facebook, Inc. +All rights reserved. + +This source code is licensed under the BSD-style license found in the +LICENSE file in the root directory of this source tree. An additional grant +of patent rights can be found in the PATENTS file in the same directory. +{% endcomment %} +{% load apptags %} + +{% block title %} +{% tmpl_const "SITENAME" %} | towers +{% endblock %} + +{% block pagestyle %} + + +{% endblock %} + +{% block content %} + {% include "dashboard/report/header.html" with header='Health' %} + +
+ {% include "dashboard/report/nav.html" with active_tab='health_reports' %} +
+ {% include "dashboard/report/health-filter-action.html" with action_url='/dashboard/reports/health' %} + {% if network_has_activity %} +
+
+
+ {% include 'dashboard/timezone-notice.html' %} + {% else %} +

There is no network activity to display.

+ {% endif %} +
+
+ +{% endblock %} +{% block js %} + + + + + + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/cloud/endagaweb/templates/dashboard/report/subscriber.html b/cloud/endagaweb/templates/dashboard/report/subscriber.html new file mode 100644 index 00000000..c5989bc7 --- /dev/null +++ b/cloud/endagaweb/templates/dashboard/report/subscriber.html @@ -0,0 +1,100 @@ +{% extends "dashboard/layout.html" %} +{% comment %} +Copyright (c) 2016-present, Facebook, Inc. +All rights reserved. + +This source code is licensed under the BSD-style license found in the +LICENSE file in the root directory of this source tree. An additional grant +of patent rights can be found in the PATENTS file in the same directory. +{% endcomment %} +{% load apptags %} + +{% block title %} +{% tmpl_const "SITENAME" %} | towers +{% endblock %} + +{% block pagestyle %} + + + +{% endblock %} + +{% block content %} + {% include "dashboard/report/header.html" with header='Subscriber' %} + +
+ {% include "dashboard/report/nav.html" with active_tab='subscriber_reports' %} +
+ {% include "dashboard/report/filter.html" with action_url='/dashboard/reports/subscriber' %} + {% if network_has_activity %} +
+
+
+
+ {% include 'dashboard/timezone-notice.html' %} + {% else %} +

There is no network activity to display.

+ {% endif %} +
+
+ +{% endblock %} +{% block js %} + + + + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/cloud/endagaweb/views/__init__.py b/cloud/endagaweb/views/__init__.py index 02f215ba..1fc905a6 100644 --- a/cloud/endagaweb/views/__init__.py +++ b/cloud/endagaweb/views/__init__.py @@ -19,3 +19,4 @@ import debug import internalapi import file_upload +import reports diff --git a/cloud/endagaweb/views/reports.py b/cloud/endagaweb/views/reports.py new file mode 100644 index 00000000..775cab42 --- /dev/null +++ b/cloud/endagaweb/views/reports.py @@ -0,0 +1,38 @@ + + +class SubscriberReportView(BaseReport): + """View Subscriber reports on basis of Network or tower level.""" + + def __init__(self, **kwargs): + template = "dashboard/report/subscriber.html" + url_namespace = "subscriber-report" + reports = {'Subscriber': ['Subscriber Activity', + 'Subscriber Status']} + super(SubscriberReportView, self).__init__(reports, template, + url_namespace, **kwargs) + + def get(self, request): + return self.handle_request(request) + + def post(self, request): + return self.handle_request(request) + + +class HealthReportView(BaseReport): + """View System health reports.""" + + def __init__(self, **kwargs): + template = "dashboard/report/health.html" + url_namespace = "health-report" + reports = {'Health': ['BTS Health']} + super(HealthReportView, self).__init__(reports, template, + url_namespace, **kwargs) + + def get(self, request): + return self.handle_request(request) + + def post(self, request): + return self.handle_request(request) + + +