From 64edfcd7f17d2ab6635f92b33180ee947014739e Mon Sep 17 00:00:00 2001 From: moule3053 Date: Wed, 1 Aug 2018 15:17:06 +0200 Subject: [PATCH] Incorporated date time picker based on bootstrap, renamed "Include OBP" to "Include System Calls" --- apimanager/apimanager/settings.py | 16 +- apimanager/metrics/forms.py | 58 +-- .../templates/metrics/custom_summary.html | 13 +- .../templates/metrics/daily_summary.html | 19 +- .../templates/metrics/hourly_summary.html | 11 +- .../templates/metrics/quarterly_summary.html | 13 +- .../metrics/templates/metrics/summary.html | 19 +- .../templates/metrics/weekly_summary.html | 19 +- .../templates/metrics/yearly_summary.html | 13 +- apimanager/metrics/views.py | 393 +++++++++--------- requirements.txt | 6 +- 11 files changed, 321 insertions(+), 259 deletions(-) diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 77b8fe7..14fd4c7 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -43,6 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'bootstrap3', + 'bootstrap_datepicker_plus', 'mathfilters', 'base', @@ -235,4 +237,16 @@ if not OAUTH_CONSUMER_SECRET: # Settings here might use parts overwritten in local settings API_ROOT = API_HOST + API_BASE_PATH + API_VERSION # For some reason, swagger is not available at the latest API version -API_URL_SWAGGER = API_HOST + '/obp/v1.4.0/resource-docs/v' + API_VERSION + '/swagger' # noqa \ No newline at end of file +API_URL_SWAGGER = API_HOST + '/obp/v1.4.0/resource-docs/v' + API_VERSION + '/swagger' # noqa + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': 'unix:/tmp/memcached.sock', + } +} + +# Use BOOTSTRAP3 if you are using Bootstrap 3 +BOOTSTRAP4 = { + 'include_jquery': True, +} diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index bc538f1..ee07adf 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -5,9 +5,11 @@ Forms of metrics app from django import forms from django.conf import settings +from datetime import date +from django.forms.widgets import SelectMultiple,CheckboxInput,CheckboxSelectMultiple from datetime import datetime, timedelta -from time import strftime +from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput class MetricsForm(forms.Form): start_date = forms.DateTimeField( @@ -208,28 +210,30 @@ class ConnectorMetricsForm(MetricsForm): class CustomSummaryForm(forms.Form): to_date = forms.DateTimeField( label='To Date', - input_formats=[settings.API_DATEFORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': 'yyyy-mm-ddThh:mm:ss', - 'class': 'form-control', - } - ), + #input_formats=[settings.API_DATEFORMAT], + # widget=forms.DateTimeInput( + # attrs={ + # 'placeholder': 'yyyy-mm-ddThh:mm:ss', + # 'class': 'form-control', + # } + # ), + widget=DateTimePickerInput(format='%Y-%m-%d %H:%M:%S'), required=True, - initial=datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ'), + initial=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), ) from_date_custom = forms.DateTimeField( - label='Start Date', - input_formats=[settings.API_DATEFORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': 'yyyy-mm-ddThh:mm:ss', - 'class': 'form-control', - } - ), + label='From Date', + #input_formats=[settings.API_DATEFORMAT], + # widget=forms.DateTimeInput( + # attrs={ + # 'placeholder': 'yyyy-mm-ddThh:mm:ss', + # 'class': 'form-control', + # } + # ), + widget=DateTimePickerInput(format='%Y-%m-%d %H:%M:%S'), required=True, - initial= (datetime.now() - timedelta(6)).strftime('%Y-%m-%dT%H:%M:%S.%fZ'), + initial= (datetime.now() - timedelta(6)).strftime('%Y-%m-%d %H:%M:%S'), ) include_obp_apps = forms.BooleanField(required=False) @@ -241,15 +245,17 @@ class CustomSummaryForm(forms.Form): class MetricsSummaryForm(forms.Form): to_date = forms.DateTimeField( label='To Date', - input_formats=[settings.API_DATEFORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': 'yyyy-mm-ddThh:mm:ss', - 'class': 'form-control', - } - ), + #input_formats=[settings.API_DATEFORMAT], + # widget=forms.DateTimeInput( + # attrs={ + # 'placeholder': 'yyyy-mm-ddThh:mm:ss', + # 'class': 'form-control', + # } + # ), + widget=DateTimePickerInput(format='%Y-%m-%d %H:%M:%S'), required=True, - initial=datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ'), + #initial=str(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')), + initial=str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), ) include_obp_apps = forms.BooleanField(required=False) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index d3b5da5..a9026cf 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -19,12 +19,21 @@
  • Month
  • Week
  • Day
  • -
  • Hour
  • +
  • Custom
  • {% endblock nav_tabs %}
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -51,7 +60,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 19f98cf..4332cc5 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -13,17 +13,26 @@
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -44,7 +53,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index d8bc0e9..fd2cbd6 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -23,6 +23,15 @@
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock % +

    Filter

    {% if form.non_field_errors %} @@ -43,7 +52,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 63f9f6d..41a5f50 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -17,12 +17,21 @@
  • Month
  • Week
  • Day
  • -
  • Hour
  • +
  • Custom
  • {% endblock nav_tabs %}
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -43,7 +52,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/summary.html b/apimanager/metrics/templates/metrics/summary.html index cfcbdf9..fd4bbae 100644 --- a/apimanager/metrics/templates/metrics/summary.html +++ b/apimanager/metrics/templates/metrics/summary.html @@ -14,17 +14,26 @@
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -45,7 +54,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index a28fec0..68294d4 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -14,17 +14,26 @@
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -45,7 +54,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 14e5eb4..b5b98e8 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -19,12 +19,21 @@
  • Month
  • Week
  • Day
  • -
  • Hour
  • +
  • Custom
  • {% endblock nav_tabs %}
    + + + + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + + {% block extrahead %} {# Extra Resources Start #} + {{ form.media }} {# Form required JS and CSS #} + {% endblock %} +

    Filter

    {% if form.non_field_errors %} @@ -45,7 +54,7 @@
    - {{ form.include_obp_apps }} Include OBP + {{ form.include_obp_apps }} Include System Calls
    diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index a72f7d7..e968cce 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -176,8 +176,7 @@ class ConnectorMetricsView(MetricsView): class MetricsSummaryView(LoginRequiredMixin, TemplateView): """View for metrics summary (sort of abstract base class)""" form_class = MetricsSummaryForm - #template_name = 'metrics/summary.html' - template_name = 'metrics/weekly_summary.html' + template_name = 'metrics/summary.html' api_urlpath = None def get_form(self): @@ -228,7 +227,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return params - def get_aggregate_metrics(self, cleaned_data, from_date): + def get_aggregate_metrics(self, cleaned_data, from_date, to_date): """ Gets the metrics from the API, using given cleaned form data. """ @@ -240,7 +239,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): # If Include OBP Apps is selected if cleaned_data.get('include_obp_apps'): print("AFTER checking include_obp_apps .................................") - urlpath = '/management/aggregate-metrics?from_date={}&to_date={}'.format(from_date.strftime(API_DATEFORMAT), form.data["to_date"]) + urlpath = '/management/aggregate-metrics?from_date={}&to_date={}'.format(from_date, to_date) api = API(self.request.session.get('obp')) try: metrics = api.get(urlpath) @@ -252,7 +251,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): else: urlpath = '/management/aggregate-metrics?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date.strftime(API_DATEFORMAT), form.data['to_date'], ",".join(EXCLUDE_APPS), + from_date, to_date, ",".join(EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) api = API(self.request.session.get('obp')) try: @@ -263,13 +262,14 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): #return [], [] api_calls_total = metrics[0]["count"] - to_date = datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) + from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) number_of_days = abs((to_date - from_date).days) average_calls_per_day = api_calls_total / number_of_days average_response_time = metrics[0]["average_response_time"] return api_calls_total, average_response_time, int(average_calls_per_day) - def get_aggregate_metrics_api_explorer(self, from_date): + def get_aggregate_metrics_api_explorer(self, from_date, to_date): """ Gets the metrics from the API, using given cleaned form data. """ @@ -277,7 +277,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): metrics = [] #params = self.to_api(cleaned_data) - urlpath = '/management/aggregate-metrics?from_date={}&to_date={}&app_name={}'.format(from_date.strftime(API_DATEFORMAT), form.data["to_date"], API_EXPLORER_APP_NAME) + urlpath = '/management/aggregate-metrics?from_date={}&to_date={}&app_name={}'.format(from_date, to_date, API_EXPLORER_APP_NAME) api = API(self.request.session.get('obp')) try: metrics = api.get(urlpath) @@ -287,16 +287,17 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return [], [] api_calls_total = metrics[0]["count"] - to_date = datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) + from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) number_of_days = abs((to_date - from_date).days) average_calls_per_day = api_calls_total / number_of_days average_response_time = metrics[0]["average_response_time"] return api_calls_total, average_response_time, int(average_calls_per_day) - def get_active_apps(self, cleaned_data, from_date): + def get_active_apps(self, cleaned_data, from_date, to_date): form = self.get_form() active_apps_list = [] - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date.strftime(API_DATEFORMAT), form.data["to_date"]) + urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) api = API(self.request.session.get('obp')) try: apps = api.get(urlpath) @@ -313,7 +314,9 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return active_apps_list - def get_total_number_of_apps(self, cleaned_data, from_date): + def get_total_number_of_apps(self, cleaned_data, from_date, to_date): + from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) urlpath='/management/consumers' api = API(self.request.session.get('obp')) try: @@ -326,7 +329,8 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): for app in apps_list: app_created_date = datetime.datetime.strptime(app["created"], '%Y-%m-%dT%H:%M:%SZ') - if app_created_date < from_date: + + if app_created_date < from_date and app_created_date > to_date: apps_list.remove(app) app_names = [] @@ -358,15 +362,18 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email - def calls_per_delta(self, cleaned_data, from_date, **delta ): + def calls_per_delta(self, cleaned_data, from_date, to_date, **delta ): """ Prints how many calls were made in total per given delta """ form = self.get_form() - to_date = datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) + + from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) date_from = from_date - + print("PRINT TYPE OF FROM_DATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55") + print(type(from_date)) date_to = from_date + timedelta(**delta) sum = 0 @@ -416,13 +423,13 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return result_list, result_list_pure, date_list - def calls_per_month(self, cleaned_data, from_date): + def calls_per_month(self, cleaned_data, from_date, to_date): """ Convenience function to print number of calls per month It is actually 30 days, not a month """ #print('Calls per Month (Server timezone is {}):'.format('UTC')) - calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(cleaned_data, from_date, days=30) + calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(cleaned_data, from_date, to_date, days=30) print("PRINT CALLS PER MONTH AND MONTH LIST") print(len(calls_per_month_list)) @@ -430,13 +437,13 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return calls_per_month_list, calls_per_month, month_list - def calls_per_day(self, cleaned_data, from_date): + def calls_per_day(self, cleaned_data, from_date, to_date): """ Convenience function to print number of calls per day """ # print('Calls per Day (Server timezone is {}):'.format('UTC')) index = [] - calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(cleaned_data, from_date, days=1) + calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(cleaned_data, from_date, to_date, days=1) print("TYPE OF CALLS PER DAY") print(calls_per_day) print(type(calls_per_day_pure)) @@ -465,20 +472,18 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): return self.calls_per_delta(cleaned_data, from_date, hours=12) - def calls_per_hour(self, cleaned_data, from_date): + def calls_per_hour(self, cleaned_data, from_date, to_date): """ Convenience function to print number of calls per hour """ - #self.calls_per_delta(cleaned_data, from_date, hours=1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(cleaned_data, from_date, hours=1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(cleaned_data, from_date, to_date, hours=1) return calls_per_hour_list, calls_per_hour, hour_list def plot_line_chart(self, plot_data, date_month_list, period): - date_list=[] + date_list = [] month_list = [] hour_list = [] - if period == 'day': plt.title("API calls per day", fontsize=14) plt.xlabel("Dates", fontsize=8) @@ -509,7 +514,6 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): plt.ylabel("Number of API calls", fontsize=8) plt.tick_params(axis='y', labelsize=8) - plt.ylim(ymin=0) plt.tight_layout() buf = BytesIO() @@ -520,6 +524,8 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): plt.gcf().clear() return image_base64 + + def plot_bar_chart(self, data): x = [] y = [] @@ -577,9 +583,10 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): number_of_users_with_cansearchwarehouse = len(user_email_cansearchwarehouse) return user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse - def get_top_apis(self, from_date): + def get_top_apis(self, from_date, to_date): form = self.get_form() - urlpath = '/management/metrics/top-apis?from_date={}&to_date={}'.format(from_date.strftime(API_DATEFORMAT), form.data["to_date"]) + #urlpath = '/management/metrics/top-apis?from_date={}&to_date={}'.format(from_date.strftime(API_DATEFORMAT), form.data["to_date"]) + urlpath = '/management/metrics/top-apis?from_date={}&to_date={}'.format(from_date, to_date) api = API(self.request.session.get('obp')) try: top_apis = api.get(urlpath) @@ -601,38 +608,21 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): print(top_apis) return top_apis - def get_top_warehouse_apis(self, from_date): - form = self.get_form() - api = API(self.request.session.get('obp')) - urlpath_warehouse_search = '/management/metrics/top-apis?from_date={}&to_date={}&implemented_by_partial_function={}'.format( - from_date.strftime(API_DATEFORMAT), form.data["to_date"], 'elasticSearchWarehouse') + def get_top_warehouse_calls(self, from_date, to_date): + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = [] + for api in top_apis: + if "elasticSearchWarehouse" in api['Implemented_by_partial_function']: + top_warehouse_calls.append(api) + return top_warehouse_calls - - - urlpath_warehouse_search_v300 = '/management/metrics/top-apis?from_date={}&to_date={}&implemented_by_partial_function={}'.format( - from_date.strftime(API_DATEFORMAT), form.data["to_date"], 'elasticSearchWarehouseV300') - - try: - top_apis_warehouse_search = api.get(urlpath_warehouse_search) - top_apis_warehouse_search_v300 = api.get(urlpath_warehouse_search_v300) - - except APIError as err: - messages.error(self.request, err) - return [], [] - - top_apis_warehouse_search_total = top_apis_warehouse_search + top_apis_warehouse_search_v300 - - print("TOP WAREHOUSE APIS ##############$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") - print(top_apis_warehouse_search_total) - print(type(top_apis_warehouse_search_total)) - - return top_apis_warehouse_search_total - - def get_top_apps_using_warehouse(self, from_date): + def get_top_apps_using_warehouse(self, from_date, to_date): form = self.get_form() top_apps_using_warehouse = [] - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&implemented_by_partial_function={}'.format(from_date.strftime(API_DATEFORMAT), - form.data["to_date"], "elasticSearchWarehouse") + #urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&implemented_by_partial_function={}'.format(from_date.strftime(API_DATEFORMAT), + # form.data["to_date"], "elasticSearchWarehouse") + urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&implemented_by_partial_function={}'.format( + from_date, to_date, "elasticSearchWarehouse") api = API(self.request.session.get('obp')) try: top_apps_using_warehouse = api.get(urlpath) @@ -714,113 +704,71 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView): print("PRINTING DEVELOPER EMAIL ADDRESSES ...........................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") print(developer_email_list) - -# @cache_page(60 * 15) -# def get_context_data(self, **kwargs): -# form = self.get_form() -# from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT) -# from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) -# -# # from_date_custom = form.data["from_date_custom"] -# # from_date_custom = datetime.datetime.strptime(from_date_custom, API_DATEFORMAT) -# -# to_date = form.data["to_date"] -# context = super(MetricsSummaryView, self).get_context_data(**kwargs) -# api_host_name = API_HOST -# top_apis = self.get_top_apis(from_date) -# top_warehouse_apis = self.get_top_warehouse_apis(from_date) -# top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) -# user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() -# #time_to_first_api_call = self.time_to_first_api_call(from_date) -# -# top_apis_bar_chart = self.plot_bar_chart(top_apis) -# -# #most_diverse_usage = self.most_diverse_usage() -# -# -# # calls_per_day = self.calls_per_day(from_date) -# # calls_per_half_day = self.calls_per_half_day() -# print("IS FORM VALID ??????????????????????????????????????????????????????????????????????????????????????????") -# print(form.is_valid()) -# -# #if form.is_valid(): -# api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) -# calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) -# calls_per_month_list, calls_per_month, date_list = self.calls_per_month(form.cleaned_data, from_date) -# calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date) -# per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") -# unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) -# active_apps_list = self.get_active_apps(form.cleaned_data, from_date) -# -# context.update({ -# 'api_calls': api_calls, -# 'calls_by_api_explorer': calls_by_api_explorer, -# 'calls_per_month_list': calls_per_month_list, -# 'per_day_chart': per_day_chart, -# 'number_of_apps_with_unique_app_name': number_of_apps_with_unique_app_name, -# 'number_of_apps_with_unique_developer_email': number_of_apps_with_unique_developer_email, -# 'active_apps_list': active_apps_list, -# 'average_calls_per_day': average_calls_per_day, -# 'average_response_time': average_response_time, -# #'top_apis': top_apis, -# 'top_warehouse_apis': top_warehouse_apis, -# 'top_apps_using_warehouse': top_apps_using_warehouse, -# 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, -# 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, -# 'api_host_name': api_host_name, -# 'from_date': from_date.strftime('%Y-%m-%d'), -# 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), -# 'top_apis_bar_chart': top_apis_bar_chart, -# #'time_to_first_api_call': time_to_first_api_call, -# # ##'calls_per_day': calls_per_day, -# # ##'calls_per_half_day': calls_per_half_day, -# 'form': form, -# }) -# return context - def get_context_data(self, **kwargs): form = self.get_form() - from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + + print("TYPE of TO-DATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") + print(to_date) + + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT) + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + + + print("PRINTING FROM DATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5555") + print(type(from_date)) + + + context = super(MetricsSummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() - # calls_per_day = self.calls_per_day(from_date) - # calls_per_half_day = self.calls_per_half_day() + #time_to_first_api_call = self.time_to_first_api_call(from_date) + top_apis_bar_chart = self.plot_bar_chart(top_apis) - if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date) - per_day_chart = self.plot_line_chart(calls_per_day, date_list[1:], 'day') - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) - print("TOTAL NUMBER OF API CALLS IN CONTEXT") - print(api_calls) + #most_diverse_usage = self.most_diverse_usage() + + + # calls_per_day = self.calls_per_day(from_date) + # calls_per_half_day = self.calls_per_half_day() + print("IS FORM VALID ??????????????????????????????????????????????????????????????????????????????????????????") + print(form.is_valid()) + + #if form.is_valid(): + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_month_list, calls_per_month, date_list = self.calls_per_month(form.cleaned_data, from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date, to_date) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_list = self.get_active_apps(form.cleaned_data, from_date, to_date) context.update({ 'api_calls': api_calls, 'calls_by_api_explorer': calls_by_api_explorer, + 'calls_per_month_list': calls_per_month_list, 'per_day_chart': per_day_chart, 'number_of_apps_with_unique_app_name': number_of_apps_with_unique_app_name, 'number_of_apps_with_unique_developer_email': number_of_apps_with_unique_developer_email, - 'active_apps_names': active_apps_names, + 'active_apps_list': active_apps_list, 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, - 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + #'top_apis': top_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, + #'time_to_first_api_call': time_to_first_api_call, # ##'calls_per_day': calls_per_day, # ##'calls_per_half_day': calls_per_half_day, 'form': form, @@ -832,26 +780,30 @@ class YearlySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() - from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + #from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT) + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + #to_date = form.data["to_date"] + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT) + context = super(YearlySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() # calls_per_day = self.calls_per_day(from_date) # calls_per_half_day = self.calls_per_half_day() top_apis_bar_chart = self.plot_bar_chart(top_apis) if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(form.cleaned_data, from_date) + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(form.cleaned_data, from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list[1:], "month") - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_names = self.get_active_apps(form.cleaned_data, from_date, to_date) print("TOTAL NUMBER OF API CALLS IN CONTEXT") print(api_calls) @@ -866,12 +818,12 @@ class YearlySummaryView(MetricsSummaryView): 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, # ##'calls_per_day': calls_per_day, @@ -885,28 +837,33 @@ class QuarterlySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() - from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + #from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + #to_date = form.data["to_date"] + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + + context = super(QuarterlySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() # calls_per_day = self.calls_per_day(from_date) # calls_per_half_day = self.calls_per_half_day() top_apis_bar_chart = self.plot_bar_chart(top_apis) if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(form.cleaned_data, from_date) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date) + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(form.cleaned_data, from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list[1:], 'month') per_day_chart = self.plot_line_chart(calls_per_day, date_list, 'day') - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_names = self.get_active_apps(form.cleaned_data, from_date, to_date) print("TOTAL NUMBER OF API CALLS IN CONTEXT") print(api_calls) @@ -922,12 +879,13 @@ class QuarterlySummaryView(MetricsSummaryView): 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + #'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, # ##'calls_per_day': calls_per_day, @@ -941,26 +899,30 @@ class WeeklySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() - from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + #from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT) + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + #to_date = form.data["to_date"] + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT) + context = super(WeeklySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() # calls_per_day = self.calls_per_day(from_date) # calls_per_half_day = self.calls_per_half_day() top_apis_bar_chart = self.plot_bar_chart(top_apis) if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date) + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list[1:], 'day') - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_names = self.get_active_apps(form.cleaned_data, from_date, to_date) print("TOTAL NUMBER OF API CALLS IN CONTEXT") print(api_calls) @@ -974,12 +936,13 @@ class WeeklySummaryView(MetricsSummaryView): 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + #'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, # ##'calls_per_day': calls_per_day, @@ -994,27 +957,32 @@ class DailySummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() - from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + #from_date = (datetime.datetime.strptime(form.data['to_date'], API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT) + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + #to_date = form.data["to_date"] + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT) + context = super(DailySummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() # calls_per_day = self.calls_per_day(from_date) # calls_per_half_day = self.calls_per_half_day() top_apis_bar_chart = self.plot_bar_chart(top_apis) if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(form.cleaned_data, from_date) + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(form.cleaned_data, from_date, to_date) per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list[1:], 'hour') + # calls_per_hour_list, calls_per_hour = self.calls_per_hour(form.cleaned_data, from_date) # per_hour_chart = self.get_per_hour_chart(form.cleaned_data, from_date) - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_names = self.get_active_apps(form.cleaned_data, from_date, to_date) print("TOTAL NUMBER OF API CALLS IN CONTEXT") print(api_calls) @@ -1029,12 +997,13 @@ class DailySummaryView(MetricsSummaryView): 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + #'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, # ##'calls_per_day': calls_per_day, @@ -1052,26 +1021,34 @@ class CustomSummaryView(MetricsSummaryView): def get_context_data(self, **kwargs): form = self.get_form() - from_date = form.data["from_date_custom"] - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = form.data["to_date"] + + to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S') + to_date = to_date.strftime(API_DATEFORMAT) + + from_date = datetime.datetime.strptime(form.data['from_date_custom'], '%Y-%m-%d %H:%M:%S') + from_date = from_date.strftime(API_DATEFORMAT) + + #from_date = form.data["from_date_custom"] + #from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + #to_date = form.data["to_date"] context = super(CustomSummaryView, self).get_context_data(**kwargs) api_host_name = API_HOST - top_apis = self.get_top_apis(from_date) - top_warehouse_apis = self.get_top_warehouse_apis(from_date) - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date) + top_apis = self.get_top_apis(from_date, to_date) + top_warehouse_calls = self.get_top_warehouse_calls(from_date, to_date) + top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse = self.get_users_cansearchwarehouse() # calls_per_day = self.calls_per_day(from_date) # calls_per_half_day = self.calls_per_half_day() top_apis_bar_chart = self.plot_bar_chart(top_apis) if form.is_valid(): - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date) - calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date) + #if form: + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(form.cleaned_data, from_date, to_date) + calls_by_api_explorer, average_response_time_api_explorer, average_calls_per_day_api_explorer = self.get_aggregate_metrics_api_explorer(from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(form.cleaned_data, from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list[1:], 'day') - unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date) - active_apps_names = self.get_active_apps(form.cleaned_data, from_date) + unique_app_names, number_of_apps_with_unique_app_name, number_of_apps_with_unique_developer_email = self.get_total_number_of_apps(form.cleaned_data, from_date, to_date) + active_apps_names = self.get_active_apps(form.cleaned_data, from_date, to_date) print("TOTAL NUMBER OF API CALLS IN CONTEXT") print(api_calls) @@ -1085,12 +1062,12 @@ class CustomSummaryView(MetricsSummaryView): 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, 'top_apis': top_apis, - 'top_warehouse_apis': top_warehouse_apis, + 'top_warehouse_calls': top_warehouse_calls, 'top_apps_using_warehouse': top_apps_using_warehouse, 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': from_date.strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'to_date': (datetime.datetime.strptime(to_date, API_DATEFORMAT)).strftime('%Y-%m-%d'), 'top_apis_bar_chart': top_apis_bar_chart, # ##'calls_per_day': calls_per_day, diff --git a/requirements.txt b/requirements.txt index c8480dc..2c879a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ -Django==1.11.7 +#Django==1.11.7 +Django==2.0.7 oauthlib==2.0.0 requests==2.11.1 requests-oauthlib==0.6.2 PyJWT==1.5.3 gunicorn==19.6.0 matplotlib -django-mathfilters \ No newline at end of file +django-mathfilters +django-bootstrap3 \ No newline at end of file