From bdf930c0c8c73c2cb4118a7051277dc90ce253f9 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Tue, 1 Nov 2022 13:13:14 +0100 Subject: [PATCH 01/85] API collection list and create page --- apimanager/apicollectionlist/__init__.py | 0 apimanager/apicollectionlist/apps.py | 5 ++ apimanager/apicollectionlist/forms.py | 0 .../css/apicollectionlist.css | 18 +++++ .../apicollectionlist/js/apicollectionlist.js | 5 ++ .../apicollectionlist/apicollectionlist.html | 43 +++++++++++ apimanager/apicollectionlist/urls.py | 16 ++++ apimanager/apicollectionlist/views.py | 74 +++++++++++++++++++ .../templates/apicollections/index.html | 2 +- apimanager/apicollections/views.py | 12 +-- apimanager/apimanager/settings.py | 3 +- apimanager/apimanager/urls.py | 1 + apimanager/base/templates/base.html | 3 +- 13 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 apimanager/apicollectionlist/__init__.py create mode 100644 apimanager/apicollectionlist/apps.py create mode 100644 apimanager/apicollectionlist/forms.py create mode 100644 apimanager/apicollectionlist/static/apicollectionlist/css/apicollectionlist.css create mode 100644 apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js create mode 100644 apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html create mode 100644 apimanager/apicollectionlist/urls.py create mode 100644 apimanager/apicollectionlist/views.py diff --git a/apimanager/apicollectionlist/__init__.py b/apimanager/apicollectionlist/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apimanager/apicollectionlist/apps.py b/apimanager/apicollectionlist/apps.py new file mode 100644 index 0000000..3ebc4d0 --- /dev/null +++ b/apimanager/apicollectionlist/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CustomersConfig(AppConfig): + name = 'customers_list' diff --git a/apimanager/apicollectionlist/forms.py b/apimanager/apicollectionlist/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/apimanager/apicollectionlist/static/apicollectionlist/css/apicollectionlist.css b/apimanager/apicollectionlist/static/apicollectionlist/css/apicollectionlist.css new file mode 100644 index 0000000..38c1c62 --- /dev/null +++ b/apimanager/apicollectionlist/static/apicollectionlist/css/apicollectionlist.css @@ -0,0 +1,18 @@ +#apicollectionlist div { + margin: 5px 0; +} + +/* The actual popup (appears on top) */ +.popuptext { + width: 250px; + background-color: #555; + color: #fff; + text-align: left; + border-radius: 6px; + padding: 8px 0; + z-index: 1; + /*bottom: 125%;*/ + top:100% + left: 50%; + margin-left: -80px; +} diff --git a/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js b/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js new file mode 100644 index 0000000..338fe9e --- /dev/null +++ b/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js @@ -0,0 +1,5 @@ +$(document).ready(function($) { + $('#info').click(function() { + alert("Hello World") + }); +}); diff --git a/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html b/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html new file mode 100644 index 0000000..d029878 --- /dev/null +++ b/apimanager/apicollectionlist/templates/apicollectionlist/apicollectionlist.html @@ -0,0 +1,43 @@ +{% extends 'base.html' %} {% load static %} {% load i18n %} +{% block page_title %} {{ block.super }} / {% trans "Customer List" %}{% endblock page_title %} {% block content %} +
+

{% trans "My API Collection List" %}

+
+ +
+
+ + + + + + + + + {% for apicollection in apicollections_list %} + + {% url 'apicollection_update' apicollection.api_collection_id apicollection.user_id as url_apicollection_update %} + + + + + + + + {% endfor %} + +
{% trans "API Collection Id" %}{% trans "User Id" %}{% trans "API Collection Name" %}{% trans "More info" %}
{{ apicollection.api_collection_id }}{{ apicollection.user_id }}{{ apicollection.api_collection_name }} +
+
    +
  • {% trans "Other Info" %}: +
      +
    • {{apicollection.is_sharable}}
    • +
    +
  • +
+
+
{% trans "View" %}
+
+
+{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %} + {% endblock extracss %} \ No newline at end of file diff --git a/apimanager/apicollectionlist/urls.py b/apimanager/apicollectionlist/urls.py new file mode 100644 index 0000000..2b0e83c --- /dev/null +++ b/apimanager/apicollectionlist/urls.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +URLs for Api Collection list app +""" + +from django.conf.urls import url +from .views import ApiCollectionListView, ExportCsvView + +urlpatterns = [ + url(r'^$', + ApiCollectionListView.as_view(), + name='apicollection-list'), + url(r'^export_csv$', + ExportCsvView.as_view(), + name='export-csv-apicollection') +] diff --git a/apimanager/apicollectionlist/views.py b/apimanager/apicollectionlist/views.py new file mode 100644 index 0000000..2f0182a --- /dev/null +++ b/apimanager/apicollectionlist/views.py @@ -0,0 +1,74 @@ +from django.shortcuts import render + +# Create your views here. +# -*- coding: utf-8 -*- +""" +Views of Api Collection list app +""" +import datetime +from django.contrib import messages +from django.contrib.auth.mixins import LoginRequiredMixin +import json +from django.urls import reverse_lazy +from django.http import HttpResponse +from django.views.generic import FormView,TemplateView, View +from apicollections.views import IndexView +from obp.api import API, APIError +import csv + + + +class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): + template_name = "apicollectionlist/apicollectionlist.html" + success_url = '/apicollections/list' + + def get_apicollections(self, context): + api = API(self.request.session.get('obp')) + try: + apicollections_list = [] + urlpath = '/my/api-collections' + result = api.get(urlpath) + if 'api_collections' in result: + apicollections_list.extend(result['api_collections']) + except APIError as err: + messages.error(self.request, err) + return [] + except Exception as inst: + messages.error(self.request, "Unknown Error {}".format(type(inst).__name__)) + return [] + + return apicollections_list + + def get_context_data(self, **kwargs): + context = super(IndexView, self).get_context_data(**kwargs) + apicollections_list = self.get_apicollections(context) + context.update({ + 'apicollections_list': apicollections_list, + }) + return context + +class ExportCsvView(LoginRequiredMixin, View): + """View to export the user to csv""" + + def get(self, request, *args, **kwargs): + api = API(self.request.session.get('obp')) + try: + apicollections_list = [] + urlpath = '/my/api-collections' + result = api.get(urlpath) + if 'api_collections' in result: + apicollections_list.extend(result['api_collections']) + except APIError as err: + messages.error(self.request, err) + except Exception as inst: + messages.error(self.request, "Unknown Error {}".format(type(inst).__name__)) + response = HttpResponse(content_type = 'text/csv') + response['Content-Disposition'] = 'attachment;filename= ApiCollections'+ str(datetime.datetime.now())+'.csv' + writer = csv.writer(response) + writer.writerow(["api_collection_id","user_id","api_collection_name","is_sharable","description"]) + for user in apicollections_list: + writer.writerow([user['api_collection_id'],user['user_id'], user['api_collection_name'], user["is_sharable"], + user["description"]]) + return response + + diff --git a/apimanager/apicollections/templates/apicollections/index.html b/apimanager/apicollections/templates/apicollections/index.html index 05d0a46..3555a48 100644 --- a/apimanager/apicollections/templates/apicollections/index.html +++ b/apimanager/apicollections/templates/apicollections/index.html @@ -3,7 +3,7 @@ {% block page_title %}{{ block.super }} / API Collections{% endblock page_title %} {% block content %} -

{% trans "API Collections" %}

+

{% trans "My API Collections" %}


diff --git a/apimanager/apicollections/views.py b/apimanager/apicollections/views.py index 665a31c..4db4df6 100644 --- a/apimanager/apicollections/views.py +++ b/apimanager/apicollections/views.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Views of config app +Views of API Collection app """ import json @@ -16,7 +16,7 @@ from django.views.decorators.csrf import csrf_exempt class IndexView(LoginRequiredMixin, FormView): - """Index view for config""" + """Index view for API Collection""" template_name = "apicollections/index.html" form_class = ApiCollectionsForm success_url = reverse_lazy('apicollections-index') @@ -97,9 +97,7 @@ class DetailView(LoginRequiredMixin, FormView): else: api_collection_endpoints=response['api_collection_endpoints'] except APIError as err: - error_once_only(self.request, Exception("OBP-API server is not running or do not response properly. " - "Please check OBP-API server. " - "Details: " + str(err))) + messages.error(self.request, result['message']) except BaseException as err: error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err)))) else: @@ -115,8 +113,7 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView): """Deletes api collection endpoint from API""" api = API(self.request.session.get('obp')) try: - urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'\ - .format(kwargs['api_collection_id'],kwargs['operation_id']) + urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'.format(kwargs['api_collection_id'],kwargs['operation_id']) result = api.delete(urlpath) if result is not None and 'code' in result and result['code']>=400: messages.error(request, result['message']) @@ -127,7 +124,6 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView): messages.error(request, err) except: messages.error(self.request, 'Unknown Error') - redirect_url = reverse('my-api-collection-detail',kwargs={"api_collection_id":kwargs['api_collection_id']}) return HttpResponseRedirect(redirect_url) diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index d9f1922..682674e 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -68,7 +68,8 @@ INSTALLED_APPS = [ 'methodrouting', 'connectormethod', 'dynamicendpoints', - 'apicollections' + 'apicollections', + 'apicollectionlist' ] MIDDLEWARE = [ diff --git a/apimanager/apimanager/urls.py b/apimanager/apimanager/urls.py index 8e84678..891248e 100644 --- a/apimanager/apimanager/urls.py +++ b/apimanager/apimanager/urls.py @@ -53,6 +53,7 @@ urlpatterns += i18n_patterns( url(r'^connectormethod/', include('connectormethod.urls')), url(r'^dynamicendpoints/', include('dynamicendpoints.urls')), url(r'^apicollections/', include('apicollections.urls')), + url(r'^apicollections/list', include('apicollectionlist.urls')), ) #prefix_default_language=False, #)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index f599dcf..51e9e70 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -75,7 +75,7 @@
  • {% trans "Product List" %}
  • - {% url "config-index" as config_index_url %} {% url "webui-index" as webui_props_index_url %} {% url "methodrouting-index" as methodrouting_index_url %} {% url "connectormethod" as connectormethod_url %} {% url "dynamicendpoints-index" as dynamic_endpoints_index_url %} {% url "apicollections-index" as api_collections_index_url %} + {% url "config-index" as config_index_url %} {% url "webui-index" as webui_props_index_url %} {% url "methodrouting-index" as methodrouting_index_url %} {% url "connectormethod" as connectormethod_url %} {% url "dynamicendpoints-index" as dynamic_endpoints_index_url %} {% url "apicollections-index" as api_collections_index_url %} {% url "apicollection-list" as api_collections_list_url %} {% if SHOW_API_TESTER %} From 8cc46a326eae1611160b7494da108af147267473 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 2 Nov 2022 14:36:45 +0100 Subject: [PATCH 02/85] API collection create and list page --- .../static/apicollectionlist/js/apicollectionlist.js | 5 ----- apimanager/apicollections/views.py | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js b/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js index 338fe9e..e69de29 100644 --- a/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js +++ b/apimanager/apicollectionlist/static/apicollectionlist/js/apicollectionlist.js @@ -1,5 +0,0 @@ -$(document).ready(function($) { - $('#info').click(function() { - alert("Hello World") - }); -}); diff --git a/apimanager/apicollections/views.py b/apimanager/apicollections/views.py index 4db4df6..7349283 100644 --- a/apimanager/apicollections/views.py +++ b/apimanager/apicollections/views.py @@ -113,7 +113,7 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView): """Deletes api collection endpoint from API""" api = API(self.request.session.get('obp')) try: - urlpath = '/my/api-collections-ids/{}/api-collection-endpoints/{}'.format(kwargs['api_collection_id'],kwargs['operation_id']) + urlpath = '/my/api-collections/{}/api-collection-endpoints/{}'.format(kwargs['api_collection_name'],kwargs['operation_id']) result = api.delete(urlpath) if result is not None and 'code' in result and result['code']>=400: messages.error(request, result['message']) From f952210d9ed126e025de9a56b4012d563241d7fd Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 4 Nov 2022 10:45:15 +0100 Subject: [PATCH 03/85] Account List Page --- apimanager/accountlist/__init__.py | 0 apimanager/accountlist/admin.py | 3 + apimanager/accountlist/apps.py | 5 ++ apimanager/accountlist/forms.py | 0 apimanager/accountlist/models.py | 4 + .../static/accountlist/css/accountlist.css | 18 +++++ .../static/accountlist/js/accountlist.js | 0 .../templates/accountlist/accountlist.html | 43 +++++++++++ apimanager/accountlist/tests.py | 3 + apimanager/accountlist/urls.py | 16 ++++ apimanager/accountlist/views.py | 75 +++++++++++++++++++ apimanager/apimanager/settings.py | 1 + apimanager/apimanager/urls.py | 1 + apimanager/base/templates/base.html | 3 +- apimanager/customerlist/views.py | 2 - 15 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 apimanager/accountlist/__init__.py create mode 100644 apimanager/accountlist/admin.py create mode 100644 apimanager/accountlist/apps.py create mode 100644 apimanager/accountlist/forms.py create mode 100644 apimanager/accountlist/models.py create mode 100644 apimanager/accountlist/static/accountlist/css/accountlist.css create mode 100644 apimanager/accountlist/static/accountlist/js/accountlist.js create mode 100644 apimanager/accountlist/templates/accountlist/accountlist.html create mode 100644 apimanager/accountlist/tests.py create mode 100644 apimanager/accountlist/urls.py create mode 100644 apimanager/accountlist/views.py diff --git a/apimanager/accountlist/__init__.py b/apimanager/accountlist/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apimanager/accountlist/admin.py b/apimanager/accountlist/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/apimanager/accountlist/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/apimanager/accountlist/apps.py b/apimanager/accountlist/apps.py new file mode 100644 index 0000000..50a7695 --- /dev/null +++ b/apimanager/accountlist/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountConfig(AppConfig): + name = 'account-list' diff --git a/apimanager/accountlist/forms.py b/apimanager/accountlist/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/apimanager/accountlist/models.py b/apimanager/accountlist/models.py new file mode 100644 index 0000000..3b5ea8d --- /dev/null +++ b/apimanager/accountlist/models.py @@ -0,0 +1,4 @@ +from django.db import models + +# Create your models here. +# -*- coding: utf-8 -*- diff --git a/apimanager/accountlist/static/accountlist/css/accountlist.css b/apimanager/accountlist/static/accountlist/css/accountlist.css new file mode 100644 index 0000000..5e85ae8 --- /dev/null +++ b/apimanager/accountlist/static/accountlist/css/accountlist.css @@ -0,0 +1,18 @@ +#accounts_list div { + margin: 5px 0; +} + +/* The actual popup (appears on top) */ +.popuptext { + width: 250px; + background-color: #555; + color: #fff; + text-align: left; + border-radius: 6px; + padding: 8px 0; + z-index: 1; + /*bottom: 125%;*/ + top:100% + left: 50%; + margin-left: -80px; +} diff --git a/apimanager/accountlist/static/accountlist/js/accountlist.js b/apimanager/accountlist/static/accountlist/js/accountlist.js new file mode 100644 index 0000000..e69de29 diff --git a/apimanager/accountlist/templates/accountlist/accountlist.html b/apimanager/accountlist/templates/accountlist/accountlist.html new file mode 100644 index 0000000..99cc0d7 --- /dev/null +++ b/apimanager/accountlist/templates/accountlist/accountlist.html @@ -0,0 +1,43 @@ +{% extends 'base.html' %} {% load static %} {% load i18n %} +{% block page_title %} {{ block.super }} / {% trans "Account List" %}{% endblock page_title %} {% block content %} +
    +

    {% trans "Account List" %}

    +
    + +
    +
    + + + + + + + + + {% for account in accounts_list %} + {% url 'account_update' account.id account.bank_id as url_account_update %} + + + + + + + + {% endfor %} + + +
    {% trans "Account Id" %}{% trans "Bank Id" %}{% trans "Label" %}{% trans "More info" %}
    {{ account.id }}{{ account.bank_id }}{{ account.label }} +
    +
      +
    • {% trans "Other Info" %}: +
        +
      • {{account.account_type}}
      • +
      +
    • +
    +
    +
    {% trans "View" %}
    +
    +
    +{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %} + {% endblock extracss %} \ No newline at end of file diff --git a/apimanager/accountlist/tests.py b/apimanager/accountlist/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/apimanager/accountlist/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apimanager/accountlist/urls.py b/apimanager/accountlist/urls.py new file mode 100644 index 0000000..66d4b9a --- /dev/null +++ b/apimanager/accountlist/urls.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +URLs for Account list app +""" + +from django.conf.urls import url +from .views import AccountListView, ExportCsvView + +urlpatterns = [ + url(r'^$', + AccountListView.as_view(), + name='account-list'), + url(r'^export_csv$', + ExportCsvView.as_view(), + name='export-csv-account') +] diff --git a/apimanager/accountlist/views.py b/apimanager/accountlist/views.py new file mode 100644 index 0000000..156c905 --- /dev/null +++ b/apimanager/accountlist/views.py @@ -0,0 +1,75 @@ +from django.shortcuts import render + +# Create your views here. +# -*- coding: utf-8 -*- +""" +Views of Account List app +""" +import datetime +from django.contrib import messages +from django.contrib.auth.mixins import LoginRequiredMixin +import json +from django.urls import reverse_lazy +from django.http import HttpResponse +from django.views.generic import FormView,TemplateView, View +from accounts.views import IndexAccountsView +from obp.api import API, APIError +from base.views import get_banks +import csv + +class AccountListView(IndexAccountsView, LoginRequiredMixin, FormView ): + template_name = "accountlist/accountlist.html" + success_url = '/accounts/list' + + def get_accountlist(self, context): + api = API(self.request.session.get('obp')) + try: + #self.bankids = self.get_banks() + accounts_list = [] + #for bank_id in self.bankids: + urlpath = '/my/accounts' + result = api.get(urlpath) + if 'accounts' in result: + accounts_list.extend(result['accounts']) + except APIError as err: + messages.error(self.request, err) + return [] + except Exception as inst: + messages.error(self.request, "Unknown Error {}".format(type(inst).__name__)) + return [] + return accounts_list + def get_context_data(self, **kwargs): + context = super(IndexAccountsView, self).get_context_data(**kwargs) + accounts_list = self.get_accountlist(context) + context.update({ + 'accounts_list': accounts_list, + #'bankids': bankids + }) + return context +class ExportCsvView(LoginRequiredMixin, View): + """View to export the user to csv""" + + def get(self, request, *args, **kwargs): + api = API(self.request.session.get('obp')) + try: + self.bankids = get_banks(self.request) + accounts_list = [] + for bank_id in self.bankids: + urlpath = 'banks/{}/accounts'.format(bank_id) + result = api.get(urlpath) + if 'accounts' in result: + accounts_list.extend(result['accounts']) + except APIError as err: + messages.error(self.request, err) + except Exception as inst: + messages.error(self.request, "Unknown Error {}".format(type(inst).__name__)) + response = HttpResponse(content_type = 'text/csv') + response['Content-Disposition'] = 'attachment;filename= Account'+ str(datetime.datetime.now())+'.csv' + writer = csv.writer(response) + writer.writerow(["id","label","bank_id","account_type","scheme","address","id", "short_name", "description", "is_public"]) + for user in accounts_list: + writer.writerow([user['id'],user['label'], user['bank_id'], user["account_type"], user["scheme"], user["address"], user["views"]['id'], + user["views"]['short_name'], user["views"]['description'], user["views"]['is_public']]) + return response + + diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 682674e..45e4a3b 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -52,6 +52,7 @@ INSTALLED_APPS = [ 'obp', 'consumers', 'accounts', + 'accountlist', 'systemviews', 'users', 'branches', diff --git a/apimanager/apimanager/urls.py b/apimanager/apimanager/urls.py index 891248e..5051e2a 100644 --- a/apimanager/apimanager/urls.py +++ b/apimanager/apimanager/urls.py @@ -36,6 +36,7 @@ urlpatterns += i18n_patterns( LogoutView.as_view(), name='oauth-logout'), url(r'^systemviews/', include('systemviews.urls')), url(r'^accounts/', include('accounts.urls')), + url(r'^account/list', include('accountlist.urls')), url(r'^consumers/', include('consumers.urls')), url(r'^entitlementrequests/', include('entitlementrequests.urls')), url(r'^users/', include('users.urls')), diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 51e9e70..f69836b 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -59,13 +59,14 @@
  • {% trans "KPI Dashboard" %}
  • - {% url "system_view" as system_view_url %} {% url "accounts-create" as accounts_create_url %} {% url "branches_list" as branches_list_url %} {% url "customers-create" as customers_create_url %} {% url "customer-list" as customer_list_url %} {% url "atms_create" as atms_create_url %} {% url "atm-list" as atm_list_url %} {% url "product-list" as product_list_url %} {% url "products-create" as product_create_url %} + {% url "system_view" as system_view_url %} {% url "accounts-create" as accounts_create_url %} {% url "account-list" as accounts_list_url %} {% url "branches_list" as branches_list_url %} {% url "customers-create" as customers_create_url %} {% url "customer-list" as customer_list_url %} {% url "atms_create" as atms_create_url %} {% url "atm-list" as atm_list_url %} {% url "product-list" as product_list_url %} {% url "products-create" as product_create_url %}
    -{% endblock %} {% block extrajs %} {% endblock extrajs %} {% block extracss %} +{% endblock %} +{% block extrajs %} + +{% endblock extrajs %} {% block extracss %} {% endblock extracss %} \ No newline at end of file diff --git a/apimanager/apicollectionlist/views.py b/apimanager/apicollectionlist/views.py index 65d1509..5b58658 100644 --- a/apimanager/apicollectionlist/views.py +++ b/apimanager/apicollectionlist/views.py @@ -14,6 +14,7 @@ from django.http import HttpResponse from django.views.generic import FormView,TemplateView, View from apicollections.views import IndexView from obp.api import API, APIError +from django.conf import settings import csv @@ -38,6 +39,8 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): api_collections_for_user = api.get(api_collections_for_user_url_path) if 'api_collections' in api_collections_for_user: apicollections_list.extend(api_collections_for_user['api_collections']) + for locale in apicollections_list: + locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={locale['api_collection_id']}" except APIError as err: messages.error(self.request, err) return [] From 7a37d23afc86ea53c786772fefa06011502879cc Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 13 Jan 2023 15:24:29 +0100 Subject: [PATCH 37/85] feature/ add API-Explorer url in API-Collection list --- apimanager/apicollectionlist/views.py | 4 ++-- apimanager/apicollections/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apimanager/apicollectionlist/views.py b/apimanager/apicollectionlist/views.py index 5b58658..a6961d2 100644 --- a/apimanager/apicollectionlist/views.py +++ b/apimanager/apicollectionlist/views.py @@ -39,8 +39,8 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): api_collections_for_user = api.get(api_collections_for_user_url_path) if 'api_collections' in api_collections_for_user: apicollections_list.extend(api_collections_for_user['api_collections']) - for locale in apicollections_list: - locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={locale['api_collection_id']}" + for api_collection_id_with_locale in apicollections_list: + api_collection_id_with_locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={api_collection_id_with_locale['api_collection_id']}" except APIError as err: messages.error(self.request, err) return [] diff --git a/apimanager/apicollections/views.py b/apimanager/apicollections/views.py index 35327ef..f7cf4c1 100644 --- a/apimanager/apicollections/views.py +++ b/apimanager/apicollections/views.py @@ -32,8 +32,8 @@ class IndexView(LoginRequiredMixin, FormView): error_once_only(self.request, response['message']) else: api_collections=response['api_collections'] - for locale in api_collections: - locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={locale['api_collection_id']}" + for api_collection_id_with_locale in api_collections: + api_collection_id_with_locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={api_collection_id_with_locale['api_collection_id']}" except APIError as err: messages.error(self.request, err) except Exception as err: From d0f71cb399deff36fe36dc94e9393d9da59b62dc Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 20 Jan 2023 12:04:55 +0100 Subject: [PATCH 38/85] changes in API_Explorer_Host name --- apimanager/apicollectionlist/views.py | 4 ++-- apimanager/apicollections/views.py | 4 ++-- apimanager/apimanager/settings.py | 2 +- apimanager/dynamicendpoints/views.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apimanager/apicollectionlist/views.py b/apimanager/apicollectionlist/views.py index a6961d2..3c6b125 100644 --- a/apimanager/apicollectionlist/views.py +++ b/apimanager/apicollectionlist/views.py @@ -39,8 +39,8 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ): api_collections_for_user = api.get(api_collections_for_user_url_path) if 'api_collections' in api_collections_for_user: apicollections_list.extend(api_collections_for_user['api_collections']) - for api_collection_id_with_locale in apicollections_list: - api_collection_id_with_locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={api_collection_id_with_locale['api_collection_id']}" + for ac in apicollections_list: + ac["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER_HOST}/?api-collection-id={ac['api_collection_id']}" except APIError as err: messages.error(self.request, err) return [] diff --git a/apimanager/apicollections/views.py b/apimanager/apicollections/views.py index f7cf4c1..42ce06c 100644 --- a/apimanager/apicollections/views.py +++ b/apimanager/apicollections/views.py @@ -32,8 +32,8 @@ class IndexView(LoginRequiredMixin, FormView): error_once_only(self.request, response['message']) else: api_collections=response['api_collections'] - for api_collection_id_with_locale in api_collections: - api_collection_id_with_locale["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-collection-id={api_collection_id_with_locale['api_collection_id']}" + for ac in api_collections: + ac["collection_on_api_explorer_url"] = f"{settings.API_EXPLORER_HOST}/?api-collection-id={ac['api_collection_id']}" except APIError as err: messages.error(self.request, err) except Exception as err: diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 2e24796..9cc7a5f 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -253,7 +253,7 @@ API_MANAGER_DATE_FORMAT= '%Y-%m-%d' API_HOST = 'http://127.0.0.1:8080' -API_EXPLORER = 'http://127.0.0.1:8082' +API_EXPLORER_HOST = 'http://127.0.0.1:8082' # Only override this if you have a separate portal instance API_PORTAL = API_HOST API_BASE_PATH = '/obp/v' diff --git a/apimanager/dynamicendpoints/views.py b/apimanager/dynamicendpoints/views.py index e095318..e2f3e3c 100644 --- a/apimanager/dynamicendpoints/views.py +++ b/apimanager/dynamicendpoints/views.py @@ -37,8 +37,8 @@ class IndexView(LoginRequiredMixin, FormView): else: dynamic_endpoints=response['dynamic_endpoints'] #Accessing API-Explorer URL, parameters API-Collection Id and selected Language eg. locale=en_GB (for English) - for locale in dynamic_endpoints: - locale["dynamicendpoint_on_api_explorer_url"] = f"{settings.API_EXPLORER}/?api-dynamic_endpoint-id={locale['dynamic_endpoint_id']}" + for ac in dynamic_endpoints: + ac["dynamicendpoint_on_api_explorer_url"] = f"{settings.API_EXPLORER_HOST}/?api-dynamic_endpoint-id={ac['dynamic_endpoint_id']}" except APIError as err: messages.error(self.request, err) except Exception as err: From 6c3217bb8b0c59c04a8457deee50b9c66b9cfca5 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 20 Jan 2023 13:39:40 +0100 Subject: [PATCH 39/85] renaming variable in dynamic endpoint --- apimanager/dynamicendpoints/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apimanager/dynamicendpoints/views.py b/apimanager/dynamicendpoints/views.py index e2f3e3c..5084211 100644 --- a/apimanager/dynamicendpoints/views.py +++ b/apimanager/dynamicendpoints/views.py @@ -37,8 +37,8 @@ class IndexView(LoginRequiredMixin, FormView): else: dynamic_endpoints=response['dynamic_endpoints'] #Accessing API-Explorer URL, parameters API-Collection Id and selected Language eg. locale=en_GB (for English) - for ac in dynamic_endpoints: - ac["dynamicendpoint_on_api_explorer_url"] = f"{settings.API_EXPLORER_HOST}/?api-dynamic_endpoint-id={ac['dynamic_endpoint_id']}" + for de in dynamic_endpoints: + de["dynamicendpoint_on_api_explorer_url"] = f"{settings.API_EXPLORER_HOST}/?api-dynamic_endpoint-id={de['dynamic_endpoint_id']}" except APIError as err: messages.error(self.request, err) except Exception as err: From c056ec4ae4dea86d26fb770c4ec155b4d9f74dd1 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 23 Jan 2023 11:13:15 +0100 Subject: [PATCH 40/85] debug/ resolve to_date issue --- apimanager/metrics/forms.py | 52 ++- .../templates/metrics/custom_summary.html | 3 +- .../templates/metrics/daily_summary.html | 6 +- .../templates/metrics/hourly_summary.html | 6 +- .../templates/metrics/monthly_summary.html | 4 +- .../templates/metrics/quarterly_summary.html | 6 +- .../templates/metrics/weekly_summary.html | 6 +- .../templates/metrics/yearly_summary.html | 6 +- apimanager/metrics/views.py | 329 +++++++++++------- 9 files changed, 244 insertions(+), 174 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 58b0d15..1ea643c 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -11,16 +11,13 @@ from datetime import datetime, timedelta from django.utils.translation import ugettext_lazy as _ from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput -from apimanager.settings import API_MANAGER_DATE_FORMAT - API_DATEFORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" -FORM_CONTROL = "FORM_CONTROL" -FROM_DATE = "From Date" -TO_DATE = "To Date" - +FORM_CONTROL = 'form-control' +FROM_DATE = 'From Date' +TO_DATE = 'To Date' class MetricsForm(forms.Form): from_date = forms.DateTimeField( - label=_(FROM_DATE), + label=_(FROM_DATE ), input_formats=[settings.API_DATEFORMAT], widget=forms.DateTimeInput( attrs={ @@ -73,7 +70,7 @@ class APIMetricsForm(MetricsForm): ('true', 'Yes'), ('false', 'No'), ) - SELECT_VERB = ( + VERB = ( ('', _('Any')), ('DELETE', 'DELETE'), ('GET', 'GET'), @@ -130,9 +127,9 @@ class APIMetricsForm(MetricsForm): ), required=False, ) - verb_selection = forms.ChoiceField( - label=_('Verb Select'), - choices=SELECT_VERB, + verb = forms.ChoiceField( + label=_('Verb'), + choices=VERB, widget=forms.Select( attrs={ 'class': FORM_CONTROL, @@ -164,7 +161,7 @@ class APIMetricsForm(MetricsForm): choices=VERSION, widget=forms.Select( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), initial='', @@ -175,12 +172,12 @@ class APIMetricsForm(MetricsForm): class ConnectorMetricsForm(MetricsForm): # override from_date until API returns values without given date from_date = forms.DateTimeField( - label=_(FROM_DATE), + label=_(FROM_DATE ), input_formats=[settings.API_DATEFORMAT], widget=forms.DateTimeInput( attrs={ 'placeholder': API_DATEFORMAT_PLACEHOLDER, - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), initial='2020-01-01T00:00:00.000Z', @@ -190,7 +187,7 @@ class ConnectorMetricsForm(MetricsForm): label=_('Connector Name'), widget=forms.TextInput( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), required=False, @@ -199,7 +196,7 @@ class ConnectorMetricsForm(MetricsForm): label=_('Function Name'), widget=forms.TextInput( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), required=False, @@ -208,7 +205,7 @@ class ConnectorMetricsForm(MetricsForm): label=_('Correlation ID'), widget=forms.TextInput( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), required=False, @@ -218,22 +215,22 @@ class ConnectorMetricsForm(MetricsForm): class CustomSummaryForm(forms.Form): to_date = forms.DateField( label=_(TO_DATE), - widget=DatePickerInput(format='API_MANAGER_DATE_FORMAT'), + widget=DatePickerInput(format='%Y-%m-%d'), required=True, - initial=str(datetime.now().strftime('API_MANAGER_DATE_FORMAT')), + initial=str(datetime.now().strftime('%Y-%m-%d')), ) from_date_custom = forms.DateField( - label=_(FROM_DATE), - widget=DatePickerInput(format='API_MANAGER_DATE_FORMAT'), + label=_(FROM_DATE ), + widget=DatePickerInput(format='%Y-%m-%d'), required=True, - initial=(datetime.now() - timedelta(6)).strftime('API_MANAGER_DATE_FORMAT'), + initial=(datetime.now() - timedelta(6)).strftime('%Y-%m-%d'), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), widget=forms.TextInput( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), required=False, @@ -248,15 +245,16 @@ class CustomSummaryForm(forms.Form): class MonthlyMetricsSummaryForm(forms.Form): to_date = forms.DateField( label=_(TO_DATE), - widget=DatePickerInput(format='API_MANAGER_DATE_FORMAT'), + widget=DatePickerInput(format='%Y-%m-%d'), required=True, - initial=str(datetime.now().strftime('API_MANAGER_DATE_FORMAT')), + #initial=str(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')), + initial=str(datetime.now().strftime('%Y-%m-%d')), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), widget=forms.TextInput( attrs={ - 'class': 'FORM_CONTROL', + 'class': FORM_CONTROL, } ), required=False, @@ -266,4 +264,4 @@ class MonthlyMetricsSummaryForm(forms.Form): def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') - super(MonthlyMetricsSummaryForm, self).__init__(*args, **kwargs) + super(MonthlyMetricsSummaryForm, self).__init__(*args, **kwargs) \ No newline at end of file diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 6282827..8ee8dbb 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -2,6 +2,7 @@ {% load static %} {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} +{% load bootstrap3 %} {% block content %}

    {% trans "API Usage Report" %}

    @@ -20,7 +21,7 @@
    - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 7230b1f..67eca17 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -4,7 +4,7 @@ {% load mathfilters %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
    @@ -25,9 +25,7 @@
    - - - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 4a7a10e..3056cf4 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -2,7 +2,7 @@ {% load static %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
    @@ -24,9 +24,7 @@
    - - - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 4e3620f..7833bbb 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -2,6 +2,8 @@ {% load static %} {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} +{% load bootstrap3 %} + {% block content %}

    {% trans "API Usage Report" %}

    @@ -20,7 +22,7 @@
    - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 7c1fd81..2f8ce92 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -3,7 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
    @@ -24,9 +24,7 @@
    - - - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index cca5c54..cb51547 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -3,7 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
    @@ -26,9 +26,7 @@
    - - - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 7eb2c62..8c83b1a 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -3,7 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} - +{% load bootstrap3 %} {% block content %}
    @@ -26,9 +26,7 @@
    - - - {% static bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} + {% bootstrap_javascript jquery='full' %} {# Embed Bootstrap JS+jQuery #} {% block extrahead %} {# Extra Resources Start #} {{ form.media }} {# Form required JS and CSS #} diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index f04aa95..a66f91a 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -11,7 +11,7 @@ from enum import Enum from django.conf import settings from apimanager import local_settings -from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT, API_DATETIMEFORMAT +from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView @@ -19,6 +19,7 @@ from base.utils import error_once_only, get_cache_key_for_current_call, convert_ return_to_days_ago from obp.api import API, APIError, LOGGER from .forms import APIMetricsForm, ConnectorMetricsForm, MonthlyMetricsSummaryForm, CustomSummaryForm +from pylab import * from django.core.cache import cache import traceback try: @@ -269,7 +270,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if apicaches is not None: + if not apicaches is None: metrics = apicaches else: api = API(self.request.session.get('obp')) @@ -307,6 +308,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ apps = [] + form = self.get_form() active_apps_list = [] if is_included_obp_apps: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}'.format(from_date, to_date, exclude_app_names) @@ -343,7 +345,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apps_list = self.get_all_consumers() for app in apps_list: - app_created_date = datetime.datetime.strptime(app["created"], API_DATETIMEFORMAT) + app_created_date = datetime.datetime.strptime(app["created"], '%Y-%m-%dT%H:%M:%SZ') if app_created_date < from_date and app_created_date > to_date: apps_list.remove(app) @@ -354,7 +356,9 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): app_names.append(apps["app_name"]) # If include OBP Apps is selected - if not cleaned_data.get('include_obp_apps'): + if cleaned_data.get('include_obp_apps'): + app_names = app_names + else: for app in app_names: if app in local_settings.EXCLUDE_APPS: app_names.remove(app) @@ -384,7 +388,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if apicaches is not None: + if not apicaches is None: apps_list = apicaches else: try: @@ -446,6 +450,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): """ Convenience function to print number of calls per day """ + index = [] calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date,exclude_app_names, days=1) if len(calls_per_day) >= 90: @@ -480,13 +485,40 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): hour_list = [] if period == 'day': - self._day(plot_data, date_month_list, date_list) + if len(plot_data) == 0: + plt.xlabel("Dates", fontsize=8) + plt.plot() + else: + plt.title("API calls per day", fontsize=14) + plt.xlabel("Dates", fontsize=8) + for date in date_month_list: + date = date.strftime('%B %d') + date_list.append(str(date)) + plt.plot(date_list, plot_data, linewidth=1, marker='o') elif period == 'month': - self._month(plot_data, date_month_list, month_list) + if len(plot_data) == 0: + plt.xlabel("Months", fontsize=8) + plt.plot() + else: + plt.title("API calls per month", fontsize=14) + plt.xlabel("Months", fontsize=8) + for date in date_month_list: + month = date.strftime('%B %Y') + month_list.append(str(month)) + plt.plot(month_list, plot_data, linewidth=1, marker='o') elif period == 'hour': - self._hour(plot_data, date_month_list, hour_list) + if len(plot_data) == 0: + plt.xlabel("Hours", fontsize=8) + plt.plot() + else: + plt.title("API calls per hour", fontsize=14) + plt.xlabel("Hours", fontsize=8) + for date in date_month_list: + hour = date.strftime('%B %d -- %H : %m') + hour_list.append(str(hour)) + plt.plot(hour_list, plot_data, linewidth=1, marker='o') plt.xticks(rotation=90, fontsize=6) @@ -503,41 +535,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): plt.gcf().clear() return image_base64 - def _day(self, plot_data, date_month_list, date_list): - if len(plot_data) == 0: - plt.xlabel("Dates", fontsize=8) - plt.plot() - else: - plt.title("API calls per day", fontsize=14) - plt.xlabel("Dates", fontsize=8) - for date in date_month_list: - date = date.strftime('%B %d') - date_list.append(str(date)) - plt.plot(date_list, plot_data, linewidth=1, marker='o') - def _month(self, plot_data, date_month_list, month_list): - if len(plot_data) == 0: - plt.xlabel("Months", fontsize=8) - plt.plot() - else: - plt.title("API calls per month", fontsize=14) - plt.xlabel("Months", fontsize=8) - for date in date_month_list: - month = date.strftime('%B %Y') - month_list.append(str(month)) - plt.plot(month_list, plot_data, linewidth=1, marker='o') - - def _hour(self, plot_data, date_month_list, hour_list): - if len(plot_data) == 0: - plt.xlabel("Hours", fontsize=8) - plt.plot() - else: - plt.title("API calls per hour", fontsize=14) - plt.xlabel("Hours", fontsize=8) - for date in date_month_list: - hour = date.strftime('%B %d -- %H : %m') - hour_list.append(str(hour)) - plt.plot(hour_list, plot_data, linewidth=1, marker='o') def plot_bar_chart(self, data): x = [] @@ -597,51 +595,60 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, users['message']) if 'users' not in users: users['users']=[] - else: - self._update_user_with_cansearchwarehouse(users, users_with_cansearchwarehouse, email_with_cansearchwarehouse) - # fail gracefully in case API provides new structure except APIError as err: error_once_only(self.request, err) - except KeyError as err: - messages.error(self.request, 'KeyError: {}'.format(err)) except Exception as err: error_once_only(self.request, err) + else: + try: + for user in users['users']: + for entitlement in user['entitlements']['list']: + if 'CanSearchWarehouse' in entitlement['role_name']: + users_with_cansearchwarehouse.append(user["username"]) + email_with_cansearchwarehouse.append(user["email"]) + # fail gracefully in case API provides new structure + except KeyError as err: + messages.error(self.request, 'KeyError: {}'.format(err)) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) + user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse)) number_of_users_with_cansearchwarehouse = len(user_email_cansearchwarehouse) return user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse - def _update_user_with_cansearchwarehouse(self, users, users_with_cansearchwarehouse, email_with_cansearchwarehouse): - for user in users['users']: - for entitlement in user['entitlements']['list']: - if 'CanSearchWarehouse' in entitlement['role_name']: - users_with_cansearchwarehouse.append(user["username"]) - email_with_cansearchwarehouse.append(user["email"]) - - def _api_data(self, urlpath, data_key): - api = API(self.request.session.get('obp')) - data = [] - try: - data = api.get(urlpath) - if data is not None and 'code' in data and data['code']==403: - error_once_only(self.request, data['message']) - data=[] - else: - data = data[data_key] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, err) - return data - def get_top_apis(self, cleaned_data, from_date, to_date): top_apis = [] + form = self.get_form() if cleaned_data.get('include_obp_apps'): 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) + if top_apis is not None and 'code' in top_apis and top_apis['code']==403: + error_once_only(self.request, top_apis['message']) + top_apis=[] + else: + top_apis = top_apis['top_apis'] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - top_apis = self._api_data(urlpath, 'top_apis') + api = API(self.request.session.get('obp')) + try: + top_apis = api.get(urlpath) + if top_apis is not None and 'code' in top_apis and top_apis['code']==403: + error_once_only(self.request, top_apis['message']) + top_apis=[] + else: + top_apis = top_apis['top_apis'] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) for api in top_apis: if api['Implemented_by_partial_function'] == "": @@ -655,13 +662,36 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_top_consumers(self, cleaned_data, from_date, to_date): top_consumers = [] + form = self.get_form() if cleaned_data.get('include_obp_apps'): urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) + api = API(self.request.session.get('obp')) + try: + top_consumers = api.get(urlpath) + if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: + error_once_only(self.request, top_consumers['message']) + top_consumers=[] + else: + top_consumers = top_consumers['top_consumers'] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - top_consumers = self._api_data(urlpath, 'top_consumers') - + api = API(self.request.session.get('obp')) + try: + top_consumers = api.get(urlpath) + if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: + error_once_only(self.request, top_consumers['message']) + top_consumers=[] + else: + top_consumers = top_consumers['top_consumers'] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) for consumer in top_consumers: if consumer['app_name'] == "": top_consumers.remove(consumer) @@ -685,6 +715,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return top_warehouse_calls def get_top_apps_using_warehouse(self, from_date, to_date, exclude_app_names): + form = self.get_form() top_apps_using_warehouse = [] urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&implemented_by_partial_function={}'.format( @@ -700,12 +731,73 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except APIError as err: error_once_only(self.request, err) except Exception as err: - error_once_only(self.request, err) + error_once_only(self.request, 'Unknown Error. {}'.format(err)) return top_apps_using_warehouse def median_time_to_first_api_call(self, from_date, to_date): - return 0 + return 0 #TODO this cost too much time, do not use this at the moment. + form = self.get_form() + new_apps_list = [] + apps = [] + apps_list = self.get_all_consumers() + + + for app in apps_list: + created_date = datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') + created_date = created_date.strftime(API_DATEFORMAT) + created_date = datetime.datetime.strptime(created_date, API_DATEFORMAT) + if created_date >= datetime.datetime.strptime(from_date, API_DATEFORMAT): + new_apps_list.append(app) + + times_to_first_call = [] + + strfrom_date=datetime.datetime.strptime(from_date, API_DATEFORMAT) + strto_date=datetime.datetime.strptime(to_date, API_DATEFORMAT) + for app in new_apps_list: + urlpath_metrics = '/management/metrics?from_date={}&to_date={}&consumer_id={}&sort_by={}&direction={}&limit={}'.format( + from_date, to_date, app['consumer_id'], 'date', 'asc', '1') + cache_key = get_cache_key_for_current_call(self.request, urlpath_metrics) + api = API(self.request.session.get('obp')) + try: + apicaches=None + try: + apicaches=cache.get(cache_key) + except Exception as err: + apicaches=None + metrics=[] + if not apicaches is None: + metrics=apicaches + else: + metrics = api.get(urlpath_metrics) + + if metrics is not None and 'code' in metrics and metrics['code'] == 403: + error_once_only(self.request, metrics['message']) + if(metrics['message'].startswith('OBP-20006')): + break + metrics = [] + else: + metrics = list(metrics['metrics']) + cache.set(cache_key, metrics) + LOGGER.warning('The cache is setting, url is: {}'.format(urlpath_metrics)) + LOGGER.warning('The cache is setting key is: {}'.format(cache_key)) + if metrics: + time_difference = datetime.datetime.strptime(metrics[0]['date'], '%Y-%m-%dT%H:%M:%S.%fZ') - datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') + times_to_first_call.append(time_difference.total_seconds()) + + + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) + + if times_to_first_call: + median = statistics.median(times_to_first_call) + delta = datetime.timedelta(seconds=median) + else: + delta = 0 + + return delta def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) @@ -720,14 +812,46 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if form.is_valid(): is_included_obp_apps = form.cleaned_data.get('include_obp_apps') exclude_app_names = form.cleaned_data.get("exclude_app_names") + #if exclude_app_names not in local_settings.EXCLUDE_APPS: + # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] to_date = convert_form_date_to_obpapi_datetime_format(form_to_date_string) - (per_hour_chart, per_day_chart) = self._daily_and_weekly(web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart) + if (web_page_type == SummaryType.DAILY): + # for one day, the from_date is 1 day ago. + from_date = return_to_days_ago(to_date, 1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') - (per_day_chart, per_month_chart) = self._monthly_and_quarterly(web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart) + if (web_page_type == SummaryType.WEEKLY): + # for one month, the from_date is 7 days ago. + from_date = return_to_days_ago(to_date, 7) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - (per_day_chart, per_month_chart) = self._yearly_and_custom(web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart) + if (web_page_type == SummaryType.MONTHLY): + # for one month, the from_date is 30 days ago. + from_date = return_to_days_ago(to_date, 30) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + if (web_page_type == SummaryType.QUARTERLY): + # for one quarter, the from_date is 90 days ago. + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') + + if (web_page_type == SummaryType.YEARLY): + from_date = return_to_days_ago(to_date, 365) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") + + if (web_page_type == SummaryType.CUSTOM): + # for one month, the from_date is x day ago. + form_from_date_string = form.data['from_date_custom'] + from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date, exclude_app_names) @@ -779,52 +903,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: error_once_only(self.request, str(form.errors)) except Exception as err: - error_once_only(self.request, err) - - def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart): - if (web_page_type == SummaryType.DAILY): - # for one day, the from_date is 1 day ago. - from_date = return_to_days_ago(to_date, 1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') - - if (web_page_type == SummaryType.WEEKLY): - # for one month, the from_date is 7 days ago. - from_date = return_to_days_ago(to_date, 7) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - return (per_hour_chart, per_day_chart) - - def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart): - if (web_page_type == SummaryType.MONTHLY): - # for one month, the from_date is 30 days ago. - from_date = return_to_days_ago(to_date, 30) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - if (web_page_type == SummaryType.QUARTERLY): - # for one quarter, the from_date is 90 days ago. - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') - - return (per_day_chart, per_month_chart) - - def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart): - if (web_page_type == SummaryType.YEARLY): - from_date = return_to_days_ago(to_date, 365) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") - - if (web_page_type == SummaryType.CUSTOM): - # for one month, the from_date is x day ago. - form_from_date_string = form.data['from_date_custom'] - from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - return (per_month_chart, per_day_chart) + error_once_only(self.request, 'Unknown Error. {}'.format(err)) class YearlySummaryView(MonthlyMetricsSummaryView): template_name = 'metrics/yearly_summary.html' @@ -849,4 +928,4 @@ class HourlySummaryView(MonthlyMetricsSummaryView): class CustomSummaryView(MonthlyMetricsSummaryView): form_class = CustomSummaryForm template_name = 'metrics/custom_summary.html' - def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) + def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) \ No newline at end of file From 1cc2c846c17346172fd93278ecf412becf1f7110 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 23 Jan 2023 11:45:45 +0100 Subject: [PATCH 41/85] Correct list name in Resources --- apimanager/metrics/forms.py | 5 +++-- apimanager/metrics/templates/metrics/daily_summary.html | 1 + apimanager/metrics/templates/metrics/hourly_summary.html | 1 + apimanager/metrics/templates/metrics/monthly_summary.html | 1 - apimanager/metrics/templates/metrics/quarterly_summary.html | 1 + apimanager/metrics/templates/metrics/weekly_summary.html | 1 + apimanager/metrics/templates/metrics/yearly_summary.html | 1 + 7 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 1ea643c..7df3063 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -15,9 +15,10 @@ API_DATEFORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" FORM_CONTROL = 'form-control' FROM_DATE = 'From Date' TO_DATE = 'To Date' + class MetricsForm(forms.Form): from_date = forms.DateTimeField( - label=_(FROM_DATE ), + label=_(FROM_DATE), input_formats=[settings.API_DATEFORMAT], widget=forms.DateTimeInput( attrs={ @@ -172,7 +173,7 @@ class APIMetricsForm(MetricsForm): class ConnectorMetricsForm(MetricsForm): # override from_date until API returns values without given date from_date = forms.DateTimeField( - label=_(FROM_DATE ), + label=_(FROM_DATE), input_formats=[settings.API_DATEFORMAT], widget=forms.DateTimeInput( attrs={ diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 67eca17..0e3a782 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -4,6 +4,7 @@ {% load mathfilters %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} + {% load bootstrap3 %} {% block content %} diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 3056cf4..197fcef 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -2,6 +2,7 @@ {% load static %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} + {% load bootstrap3 %} {% block content %} diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 7833bbb..0c7c50b 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -3,7 +3,6 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} {% load bootstrap3 %} - {% block content %}

    {% trans "API Usage Report" %}

    diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 2f8ce92..57d4fd3 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -3,6 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} + {% load bootstrap3 %} {% block content %} diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index cb51547..7911c06 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -3,6 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} + {% load bootstrap3 %} {% block content %} diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 8c83b1a..928e85d 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -3,6 +3,7 @@ {% load i18n %} {% block page_title %}{{ block.super }} / API Usage Report{% endblock page_title %} + {% load bootstrap3 %} {% block content %} From 32ab189f71a0eefda15b37bae71494e264c0d3d8 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 23 Jan 2023 12:46:45 +0100 Subject: [PATCH 42/85] bugfix/ to_date in metrics --- apimanager/metrics/forms.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 7df3063..4153b32 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -9,7 +9,7 @@ from datetime import date from django.forms.widgets import SelectMultiple, CheckboxInput, CheckboxSelectMultiple from datetime import datetime, timedelta from django.utils.translation import ugettext_lazy as _ - +from apimanager.settings import API_MANAGER_DATE_FORMAT from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput API_DATEFORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" FORM_CONTROL = 'form-control' @@ -216,16 +216,16 @@ class ConnectorMetricsForm(MetricsForm): class CustomSummaryForm(forms.Form): to_date = forms.DateField( label=_(TO_DATE), - widget=DatePickerInput(format='%Y-%m-%d'), + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, - initial=str(datetime.now().strftime('%Y-%m-%d')), + initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) from_date_custom = forms.DateField( label=_(FROM_DATE ), - widget=DatePickerInput(format='%Y-%m-%d'), + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, - initial=(datetime.now() - timedelta(6)).strftime('%Y-%m-%d'), + initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), @@ -246,10 +246,10 @@ class CustomSummaryForm(forms.Form): class MonthlyMetricsSummaryForm(forms.Form): to_date = forms.DateField( label=_(TO_DATE), - widget=DatePickerInput(format='%Y-%m-%d'), + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, #initial=str(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')), - initial=str(datetime.now().strftime('%Y-%m-%d')), + initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), From 2c39c84dd7c67c4ea1bb4423da560d49fd23772e Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 23 Jan 2023 12:50:13 +0100 Subject: [PATCH 43/85] bugfix/ to_date in metrics --- apimanager/metrics/forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 4153b32..5dbfbbd 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -9,8 +9,10 @@ from datetime import date from django.forms.widgets import SelectMultiple, CheckboxInput, CheckboxSelectMultiple from datetime import datetime, timedelta from django.utils.translation import ugettext_lazy as _ -from apimanager.settings import API_MANAGER_DATE_FORMAT + from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput +from apimanager.settings import API_MANAGER_DATE_FORMAT + API_DATEFORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" FORM_CONTROL = 'form-control' FROM_DATE = 'From Date' From 788ce40a31a7feeba3f133e63baa5e2f6e9aaef2 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 23 Jan 2023 14:19:06 +0100 Subject: [PATCH 44/85] bugfix/ to_date in metrics --- apimanager/metrics/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 5dbfbbd..0a5261f 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -224,7 +224,7 @@ class CustomSummaryForm(forms.Form): ) from_date_custom = forms.DateField( - label=_(FROM_DATE ), + label=_(FROM_DATE), widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), From 2c3b84fd2e4f5724456bc39b67af6e6f0e1d81c6 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 25 Jan 2023 22:30:03 +0100 Subject: [PATCH 45/85] Update View.py in Metric --- .../templates/metrics/daily_summary.html | 2 +- .../templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/views.py | 288 ++++++++---------- 3 files changed, 123 insertions(+), 169 deletions(-) diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 0e3a782..a51b248 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -45,7 +45,7 @@
    {% if form.to_date.errors %}
    {{ form.to_date.errors }}
    {% endif %}
    - {% trans "to_date" %} + {% trans "To Date" %} {{ form.to_date }}
    diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 0c7c50b..baca72f 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -40,7 +40,7 @@
    {% if form.to_date.errors %}
    {{ form.to_date.errors }}
    {% endif %}
    - {% trans "to_date" %} + {% trans "To Date" %} {{ form.to_date }}
    diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index a66f91a..c9312ae 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -11,7 +11,7 @@ from enum import Enum from django.conf import settings from apimanager import local_settings -from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT +from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT, API_DATETIMEFORMAT from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView @@ -270,7 +270,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if not apicaches is None: + if apicaches is not None: metrics = apicaches else: api = API(self.request.session.get('obp')) @@ -308,7 +308,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ apps = [] - form = self.get_form() active_apps_list = [] if is_included_obp_apps: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}'.format(from_date, to_date, exclude_app_names) @@ -345,7 +344,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apps_list = self.get_all_consumers() for app in apps_list: - app_created_date = datetime.datetime.strptime(app["created"], '%Y-%m-%dT%H:%M:%SZ') + app_created_date = datetime.datetime.strptime(app["created"], API_DATETIMEFORMAT) if app_created_date < from_date and app_created_date > to_date: apps_list.remove(app) @@ -356,9 +355,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): app_names.append(apps["app_name"]) # If include OBP Apps is selected - if cleaned_data.get('include_obp_apps'): - app_names = app_names - else: + if not cleaned_data.get('include_obp_apps'): for app in app_names: if app in local_settings.EXCLUDE_APPS: app_names.remove(app) @@ -388,7 +385,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if not apicaches is None: + if apicaches is not None: apps_list = apicaches else: try: @@ -450,7 +447,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): """ Convenience function to print number of calls per day """ - index = [] calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date,exclude_app_names, days=1) if len(calls_per_day) >= 90: @@ -485,40 +481,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): hour_list = [] if period == 'day': - if len(plot_data) == 0: - plt.xlabel("Dates", fontsize=8) - plt.plot() - else: - plt.title("API calls per day", fontsize=14) - plt.xlabel("Dates", fontsize=8) - for date in date_month_list: - date = date.strftime('%B %d') - date_list.append(str(date)) - plt.plot(date_list, plot_data, linewidth=1, marker='o') + self._day(plot_data, date_month_list, date_list) elif period == 'month': - if len(plot_data) == 0: - plt.xlabel("Months", fontsize=8) - plt.plot() - else: - plt.title("API calls per month", fontsize=14) - plt.xlabel("Months", fontsize=8) - for date in date_month_list: - month = date.strftime('%B %Y') - month_list.append(str(month)) - plt.plot(month_list, plot_data, linewidth=1, marker='o') + self._month(plot_data, date_month_list, month_list) elif period == 'hour': - if len(plot_data) == 0: - plt.xlabel("Hours", fontsize=8) - plt.plot() - else: - plt.title("API calls per hour", fontsize=14) - plt.xlabel("Hours", fontsize=8) - for date in date_month_list: - hour = date.strftime('%B %d -- %H : %m') - hour_list.append(str(hour)) - plt.plot(hour_list, plot_data, linewidth=1, marker='o') + self._hour(plot_data, date_month_list, hour_list) plt.xticks(rotation=90, fontsize=6) @@ -535,7 +504,41 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): plt.gcf().clear() return image_base64 + def _day(self, plot_data, date_month_list, date_list): + if len(plot_data) == 0: + plt.xlabel("Dates", fontsize=8) + plt.plot() + else: + plt.title("API calls per day", fontsize=14) + plt.xlabel("Dates", fontsize=8) + for date in date_month_list: + date = date.strftime('%B %d') + date_list.append(str(date)) + plt.plot(date_list, plot_data, linewidth=1, marker='o') + def _month(self, plot_data, date_month_list, month_list): + if len(plot_data) == 0: + plt.xlabel("Months", fontsize=8) + plt.plot() + else: + plt.title("API calls per month", fontsize=14) + plt.xlabel("Months", fontsize=8) + for date in date_month_list: + month = date.strftime('%B %Y') + month_list.append(str(month)) + plt.plot(month_list, plot_data, linewidth=1, marker='o') + + def _hour(self, plot_data, date_month_list, hour_list): + if len(plot_data) == 0: + plt.xlabel("Hours", fontsize=8) + plt.plot() + else: + plt.title("API calls per hour", fontsize=14) + plt.xlabel("Hours", fontsize=8) + for date in date_month_list: + hour = date.strftime('%B %d -- %H : %m') + hour_list.append(str(hour)) + plt.plot(hour_list, plot_data, linewidth=1, marker='o') def plot_bar_chart(self, data): x = [] @@ -595,60 +598,51 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, users['message']) if 'users' not in users: users['users']=[] + else: + self._update_user_with_cansearchwarehouse(users, users_with_cansearchwarehouse, email_with_cansearchwarehouse) + # fail gracefully in case API provides new structure except APIError as err: error_once_only(self.request, err) + except KeyError as err: + messages.error(self.request, 'KeyError: {}'.format(err)) except Exception as err: error_once_only(self.request, err) - else: - try: - for user in users['users']: - for entitlement in user['entitlements']['list']: - if 'CanSearchWarehouse' in entitlement['role_name']: - users_with_cansearchwarehouse.append(user["username"]) - email_with_cansearchwarehouse.append(user["email"]) - # fail gracefully in case API provides new structure - except KeyError as err: - messages.error(self.request, 'KeyError: {}'.format(err)) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) - user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse)) number_of_users_with_cansearchwarehouse = len(user_email_cansearchwarehouse) return user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse + def _update_user_with_cansearchwarehouse(self, users, users_with_cansearchwarehouse, email_with_cansearchwarehouse): + for user in users['users']: + for entitlement in user['entitlements']['list']: + if 'CanSearchWarehouse' in entitlement['role_name']: + users_with_cansearchwarehouse.append(user["username"]) + email_with_cansearchwarehouse.append(user["email"]) + + def _api_data(self, urlpath, data_key): + api = API(self.request.session.get('obp')) + data = [] + try: + data = api.get(urlpath) + if data is not None and 'code' in data and data['code']==403: + error_once_only(self.request, data['message']) + data=[] + else: + data = data[data_key] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, err) + return data + def get_top_apis(self, cleaned_data, from_date, to_date): top_apis = [] - form = self.get_form() if cleaned_data.get('include_obp_apps'): 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) - if top_apis is not None and 'code' in top_apis and top_apis['code']==403: - error_once_only(self.request, top_apis['message']) - top_apis=[] - else: - top_apis = top_apis['top_apis'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - api = API(self.request.session.get('obp')) - try: - top_apis = api.get(urlpath) - if top_apis is not None and 'code' in top_apis and top_apis['code']==403: - error_once_only(self.request, top_apis['message']) - top_apis=[] - else: - top_apis = top_apis['top_apis'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + top_apis = self._api_data(urlpath, 'top_apis') for api in top_apis: if api['Implemented_by_partial_function'] == "": @@ -662,36 +656,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_top_consumers(self, cleaned_data, from_date, to_date): top_consumers = [] - form = self.get_form() if cleaned_data.get('include_obp_apps'): urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) - api = API(self.request.session.get('obp')) - try: - top_consumers = api.get(urlpath) - if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: - error_once_only(self.request, top_consumers['message']) - top_consumers=[] - else: - top_consumers = top_consumers['top_consumers'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - api = API(self.request.session.get('obp')) - try: - top_consumers = api.get(urlpath) - if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: - error_once_only(self.request, top_consumers['message']) - top_consumers=[] - else: - top_consumers = top_consumers['top_consumers'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + top_consumers = self._api_data(urlpath, 'top_consumers') + for consumer in top_consumers: if consumer['app_name'] == "": top_consumers.remove(consumer) @@ -715,7 +686,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return top_warehouse_calls def get_top_apps_using_warehouse(self, from_date, to_date, exclude_app_names): - form = self.get_form() top_apps_using_warehouse = [] urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&implemented_by_partial_function={}'.format( @@ -731,73 +701,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except APIError as err: error_once_only(self.request, err) except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + error_once_only(self.request, err) return top_apps_using_warehouse def median_time_to_first_api_call(self, from_date, to_date): - return 0 #TODO this cost too much time, do not use this at the moment. - form = self.get_form() - new_apps_list = [] - apps = [] - apps_list = self.get_all_consumers() - - - for app in apps_list: - created_date = datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') - created_date = created_date.strftime(API_DATEFORMAT) - created_date = datetime.datetime.strptime(created_date, API_DATEFORMAT) - if created_date >= datetime.datetime.strptime(from_date, API_DATEFORMAT): - new_apps_list.append(app) - - times_to_first_call = [] - - strfrom_date=datetime.datetime.strptime(from_date, API_DATEFORMAT) - strto_date=datetime.datetime.strptime(to_date, API_DATEFORMAT) - for app in new_apps_list: - urlpath_metrics = '/management/metrics?from_date={}&to_date={}&consumer_id={}&sort_by={}&direction={}&limit={}'.format( - from_date, to_date, app['consumer_id'], 'date', 'asc', '1') - cache_key = get_cache_key_for_current_call(self.request, urlpath_metrics) - api = API(self.request.session.get('obp')) - try: - apicaches=None - try: - apicaches=cache.get(cache_key) - except Exception as err: - apicaches=None - metrics=[] - if not apicaches is None: - metrics=apicaches - else: - metrics = api.get(urlpath_metrics) - - if metrics is not None and 'code' in metrics and metrics['code'] == 403: - error_once_only(self.request, metrics['message']) - if(metrics['message'].startswith('OBP-20006')): - break - metrics = [] - else: - metrics = list(metrics['metrics']) - cache.set(cache_key, metrics) - LOGGER.warning('The cache is setting, url is: {}'.format(urlpath_metrics)) - LOGGER.warning('The cache is setting key is: {}'.format(cache_key)) - if metrics: - time_difference = datetime.datetime.strptime(metrics[0]['date'], '%Y-%m-%dT%H:%M:%S.%fZ') - datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') - times_to_first_call.append(time_difference.total_seconds()) - - - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) - - if times_to_first_call: - median = statistics.median(times_to_first_call) - delta = datetime.timedelta(seconds=median) - else: - delta = 0 - - return delta + return 0 def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) @@ -903,7 +812,52 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: error_once_only(self.request, str(form.errors)) except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + error_once_only(self.request, err) + + def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.DAILY): + # for one day, the from_date is 1 day ago. + from_date = return_to_days_ago(to_date, 1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') + + if (web_page_type == SummaryType.WEEKLY): + # for one month, the from_date is 7 days ago. + from_date = return_to_days_ago(to_date, 7) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_hour_chart, per_day_chart) + + def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart, from_date): + if (web_page_type == SummaryType.MONTHLY): + # for one month, the from_date is 30 days ago. + from_date = return_to_days_ago(to_date, 30) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + if (web_page_type == SummaryType.QUARTERLY): + # for one quarter, the from_date is 90 days ago. + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') + + return (from_date, per_day_chart, per_month_chart) + + def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.YEARLY): + from_date = return_to_days_ago(to_date, 365) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") + + if (web_page_type == SummaryType.CUSTOM): + # for one month, the from_date is x day ago. + form_from_date_string = form.data['from_date_custom'] + from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_month_chart, per_day_chart) class YearlySummaryView(MonthlyMetricsSummaryView): template_name = 'metrics/yearly_summary.html' From c4252abb4d665890abee63822a624d46065eb000 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 25 Jan 2023 22:30:03 +0100 Subject: [PATCH 46/85] Update View.py and Include System Data in Metric --- apimanager/metrics/forms.py | 4 +- .../templates/metrics/daily_summary.html | 2 +- .../templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/views.py | 288 ++++++++---------- 4 files changed, 125 insertions(+), 171 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 0a5261f..353c542 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -239,7 +239,7 @@ class CustomSummaryForm(forms.Form): required=False, initial='API-Manager', ) - include_obp_apps = forms.BooleanField(required=False, label=_('Include System Date')) + include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') @@ -263,7 +263,7 @@ class MonthlyMetricsSummaryForm(forms.Form): required=False, initial='API-Manager', ) - include_obp_apps = forms.BooleanField(required=False, label=_('Include System Date')) + include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 0e3a782..a51b248 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -45,7 +45,7 @@
    {% if form.to_date.errors %}
    {{ form.to_date.errors }}
    {% endif %}
    - {% trans "to_date" %} + {% trans "To Date" %} {{ form.to_date }}
    diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 0c7c50b..baca72f 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -40,7 +40,7 @@
    {% if form.to_date.errors %}
    {{ form.to_date.errors }}
    {% endif %}
    - {% trans "to_date" %} + {% trans "To Date" %} {{ form.to_date }}
    diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index a66f91a..c9312ae 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -11,7 +11,7 @@ from enum import Enum from django.conf import settings from apimanager import local_settings -from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT +from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT, API_DATETIMEFORMAT from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView @@ -270,7 +270,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if not apicaches is None: + if apicaches is not None: metrics = apicaches else: api = API(self.request.session.get('obp')) @@ -308,7 +308,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ apps = [] - form = self.get_form() active_apps_list = [] if is_included_obp_apps: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}'.format(from_date, to_date, exclude_app_names) @@ -345,7 +344,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apps_list = self.get_all_consumers() for app in apps_list: - app_created_date = datetime.datetime.strptime(app["created"], '%Y-%m-%dT%H:%M:%SZ') + app_created_date = datetime.datetime.strptime(app["created"], API_DATETIMEFORMAT) if app_created_date < from_date and app_created_date > to_date: apps_list.remove(app) @@ -356,9 +355,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): app_names.append(apps["app_name"]) # If include OBP Apps is selected - if cleaned_data.get('include_obp_apps'): - app_names = app_names - else: + if not cleaned_data.get('include_obp_apps'): for app in app_names: if app in local_settings.EXCLUDE_APPS: app_names.remove(app) @@ -388,7 +385,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apicaches = cache.get(cache_key) except Exception as err: apicaches = None - if not apicaches is None: + if apicaches is not None: apps_list = apicaches else: try: @@ -450,7 +447,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): """ Convenience function to print number of calls per day """ - index = [] calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date,exclude_app_names, days=1) if len(calls_per_day) >= 90: @@ -485,40 +481,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): hour_list = [] if period == 'day': - if len(plot_data) == 0: - plt.xlabel("Dates", fontsize=8) - plt.plot() - else: - plt.title("API calls per day", fontsize=14) - plt.xlabel("Dates", fontsize=8) - for date in date_month_list: - date = date.strftime('%B %d') - date_list.append(str(date)) - plt.plot(date_list, plot_data, linewidth=1, marker='o') + self._day(plot_data, date_month_list, date_list) elif period == 'month': - if len(plot_data) == 0: - plt.xlabel("Months", fontsize=8) - plt.plot() - else: - plt.title("API calls per month", fontsize=14) - plt.xlabel("Months", fontsize=8) - for date in date_month_list: - month = date.strftime('%B %Y') - month_list.append(str(month)) - plt.plot(month_list, plot_data, linewidth=1, marker='o') + self._month(plot_data, date_month_list, month_list) elif period == 'hour': - if len(plot_data) == 0: - plt.xlabel("Hours", fontsize=8) - plt.plot() - else: - plt.title("API calls per hour", fontsize=14) - plt.xlabel("Hours", fontsize=8) - for date in date_month_list: - hour = date.strftime('%B %d -- %H : %m') - hour_list.append(str(hour)) - plt.plot(hour_list, plot_data, linewidth=1, marker='o') + self._hour(plot_data, date_month_list, hour_list) plt.xticks(rotation=90, fontsize=6) @@ -535,7 +504,41 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): plt.gcf().clear() return image_base64 + def _day(self, plot_data, date_month_list, date_list): + if len(plot_data) == 0: + plt.xlabel("Dates", fontsize=8) + plt.plot() + else: + plt.title("API calls per day", fontsize=14) + plt.xlabel("Dates", fontsize=8) + for date in date_month_list: + date = date.strftime('%B %d') + date_list.append(str(date)) + plt.plot(date_list, plot_data, linewidth=1, marker='o') + def _month(self, plot_data, date_month_list, month_list): + if len(plot_data) == 0: + plt.xlabel("Months", fontsize=8) + plt.plot() + else: + plt.title("API calls per month", fontsize=14) + plt.xlabel("Months", fontsize=8) + for date in date_month_list: + month = date.strftime('%B %Y') + month_list.append(str(month)) + plt.plot(month_list, plot_data, linewidth=1, marker='o') + + def _hour(self, plot_data, date_month_list, hour_list): + if len(plot_data) == 0: + plt.xlabel("Hours", fontsize=8) + plt.plot() + else: + plt.title("API calls per hour", fontsize=14) + plt.xlabel("Hours", fontsize=8) + for date in date_month_list: + hour = date.strftime('%B %d -- %H : %m') + hour_list.append(str(hour)) + plt.plot(hour_list, plot_data, linewidth=1, marker='o') def plot_bar_chart(self, data): x = [] @@ -595,60 +598,51 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, users['message']) if 'users' not in users: users['users']=[] + else: + self._update_user_with_cansearchwarehouse(users, users_with_cansearchwarehouse, email_with_cansearchwarehouse) + # fail gracefully in case API provides new structure except APIError as err: error_once_only(self.request, err) + except KeyError as err: + messages.error(self.request, 'KeyError: {}'.format(err)) except Exception as err: error_once_only(self.request, err) - else: - try: - for user in users['users']: - for entitlement in user['entitlements']['list']: - if 'CanSearchWarehouse' in entitlement['role_name']: - users_with_cansearchwarehouse.append(user["username"]) - email_with_cansearchwarehouse.append(user["email"]) - # fail gracefully in case API provides new structure - except KeyError as err: - messages.error(self.request, 'KeyError: {}'.format(err)) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) - user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse)) number_of_users_with_cansearchwarehouse = len(user_email_cansearchwarehouse) return user_email_cansearchwarehouse, number_of_users_with_cansearchwarehouse + def _update_user_with_cansearchwarehouse(self, users, users_with_cansearchwarehouse, email_with_cansearchwarehouse): + for user in users['users']: + for entitlement in user['entitlements']['list']: + if 'CanSearchWarehouse' in entitlement['role_name']: + users_with_cansearchwarehouse.append(user["username"]) + email_with_cansearchwarehouse.append(user["email"]) + + def _api_data(self, urlpath, data_key): + api = API(self.request.session.get('obp')) + data = [] + try: + data = api.get(urlpath) + if data is not None and 'code' in data and data['code']==403: + error_once_only(self.request, data['message']) + data=[] + else: + data = data[data_key] + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, err) + return data + def get_top_apis(self, cleaned_data, from_date, to_date): top_apis = [] - form = self.get_form() if cleaned_data.get('include_obp_apps'): 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) - if top_apis is not None and 'code' in top_apis and top_apis['code']==403: - error_once_only(self.request, top_apis['message']) - top_apis=[] - else: - top_apis = top_apis['top_apis'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - api = API(self.request.session.get('obp')) - try: - top_apis = api.get(urlpath) - if top_apis is not None and 'code' in top_apis and top_apis['code']==403: - error_once_only(self.request, top_apis['message']) - top_apis=[] - else: - top_apis = top_apis['top_apis'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + top_apis = self._api_data(urlpath, 'top_apis') for api in top_apis: if api['Implemented_by_partial_function'] == "": @@ -662,36 +656,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_top_consumers(self, cleaned_data, from_date, to_date): top_consumers = [] - form = self.get_form() if cleaned_data.get('include_obp_apps'): urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) - api = API(self.request.session.get('obp')) - try: - top_consumers = api.get(urlpath) - if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: - error_once_only(self.request, top_consumers['message']) - top_consumers=[] - else: - top_consumers = top_consumers['top_consumers'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) else: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) - api = API(self.request.session.get('obp')) - try: - top_consumers = api.get(urlpath) - if top_consumers is not None and 'code' in top_consumers and top_consumers['code']==403: - error_once_only(self.request, top_consumers['message']) - top_consumers=[] - else: - top_consumers = top_consumers['top_consumers'] - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + top_consumers = self._api_data(urlpath, 'top_consumers') + for consumer in top_consumers: if consumer['app_name'] == "": top_consumers.remove(consumer) @@ -715,7 +686,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return top_warehouse_calls def get_top_apps_using_warehouse(self, from_date, to_date, exclude_app_names): - form = self.get_form() top_apps_using_warehouse = [] urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&implemented_by_partial_function={}'.format( @@ -731,73 +701,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except APIError as err: error_once_only(self.request, err) except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + error_once_only(self.request, err) return top_apps_using_warehouse def median_time_to_first_api_call(self, from_date, to_date): - return 0 #TODO this cost too much time, do not use this at the moment. - form = self.get_form() - new_apps_list = [] - apps = [] - apps_list = self.get_all_consumers() - - - for app in apps_list: - created_date = datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') - created_date = created_date.strftime(API_DATEFORMAT) - created_date = datetime.datetime.strptime(created_date, API_DATEFORMAT) - if created_date >= datetime.datetime.strptime(from_date, API_DATEFORMAT): - new_apps_list.append(app) - - times_to_first_call = [] - - strfrom_date=datetime.datetime.strptime(from_date, API_DATEFORMAT) - strto_date=datetime.datetime.strptime(to_date, API_DATEFORMAT) - for app in new_apps_list: - urlpath_metrics = '/management/metrics?from_date={}&to_date={}&consumer_id={}&sort_by={}&direction={}&limit={}'.format( - from_date, to_date, app['consumer_id'], 'date', 'asc', '1') - cache_key = get_cache_key_for_current_call(self.request, urlpath_metrics) - api = API(self.request.session.get('obp')) - try: - apicaches=None - try: - apicaches=cache.get(cache_key) - except Exception as err: - apicaches=None - metrics=[] - if not apicaches is None: - metrics=apicaches - else: - metrics = api.get(urlpath_metrics) - - if metrics is not None and 'code' in metrics and metrics['code'] == 403: - error_once_only(self.request, metrics['message']) - if(metrics['message'].startswith('OBP-20006')): - break - metrics = [] - else: - metrics = list(metrics['metrics']) - cache.set(cache_key, metrics) - LOGGER.warning('The cache is setting, url is: {}'.format(urlpath_metrics)) - LOGGER.warning('The cache is setting key is: {}'.format(cache_key)) - if metrics: - time_difference = datetime.datetime.strptime(metrics[0]['date'], '%Y-%m-%dT%H:%M:%S.%fZ') - datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') - times_to_first_call.append(time_difference.total_seconds()) - - - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) - - if times_to_first_call: - median = statistics.median(times_to_first_call) - delta = datetime.timedelta(seconds=median) - else: - delta = 0 - - return delta + return 0 def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) @@ -903,7 +812,52 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: error_once_only(self.request, str(form.errors)) except Exception as err: - error_once_only(self.request, 'Unknown Error. {}'.format(err)) + error_once_only(self.request, err) + + def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.DAILY): + # for one day, the from_date is 1 day ago. + from_date = return_to_days_ago(to_date, 1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') + + if (web_page_type == SummaryType.WEEKLY): + # for one month, the from_date is 7 days ago. + from_date = return_to_days_ago(to_date, 7) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_hour_chart, per_day_chart) + + def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart, from_date): + if (web_page_type == SummaryType.MONTHLY): + # for one month, the from_date is 30 days ago. + from_date = return_to_days_ago(to_date, 30) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + if (web_page_type == SummaryType.QUARTERLY): + # for one quarter, the from_date is 90 days ago. + from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') + + return (from_date, per_day_chart, per_month_chart) + + def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.YEARLY): + from_date = return_to_days_ago(to_date, 365) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") + + if (web_page_type == SummaryType.CUSTOM): + # for one month, the from_date is x day ago. + form_from_date_string = form.data['from_date_custom'] + from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_month_chart, per_day_chart) class YearlySummaryView(MonthlyMetricsSummaryView): template_name = 'metrics/yearly_summary.html' From d747bb34347da7a0c520d233160baca029aaf68f Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 26 Jan 2023 11:01:53 +0100 Subject: [PATCH 47/85] Update View.py and Include System Data in Metric --- apimanager/metrics/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index c9312ae..d9496a4 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -253,9 +253,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): There are different use cases, so we accept different parameters. only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ + api_calls_total = 0 + average_response_time = 0 + average_calls_per_day = 0 try: - api_calls_total = 0 - average_response_time = 0 urlpath = '/management/aggregate-metrics' if only_show_api_explorer_metrics: urlpath = urlpath + '?from_date={}&to_date={}&app_name={}'.format(from_date, to_date, API_EXPLORER_APP_NAME) @@ -281,11 +282,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): api_calls_total, average_calls_per_day, average_response_time = self.get_internal_api_call_metrics( api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, urlpath) - return api_calls_total, average_response_time, int(average_calls_per_day) except APIError as err: error_once_only(self.request, err) except Exception as err: error_once_only(self.request, err) + finally: + return api_calls_total, average_response_time, int(average_calls_per_day) def get_internal_api_call_metrics(self, api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, urlpath): From a13d63260404b72e872f55080cac33e83fa0bd2f Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 26 Jan 2023 14:12:40 +0100 Subject: [PATCH 48/85] update Date and time Variables name --- README.md | 4 +- apimanager/apimanager/settings.py | 4 +- apimanager/base/filters.py | 2 +- apimanager/base/utils.py | 6 +-- apimanager/consumers/views.py | 4 +- apimanager/customers/forms.py | 10 ++--- apimanager/customers/views.py | 4 +- apimanager/entitlementrequests/views.py | 2 +- apimanager/metrics/forms.py | 14 +++--- apimanager/metrics/views.py | 59 +++++++++++++------------ 10 files changed, 55 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index f28a663..31aad70 100644 --- a/README.md +++ b/README.md @@ -227,9 +227,9 @@ EXCLUDE_URL_PATTERN = [] API_EXPLORER_APP_NAME = 'xxx' #Map Java: yyyy-MM-dd'T'HH:mm'Z' -API_DATETIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ' +API_DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ' #Map Java: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' -API_DATEFORMAT = '%Y-%m-%dT%H:%M:%S.000Z' +API_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.000Z' ``` diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 9cc7a5f..2c134a6 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -244,9 +244,9 @@ LOGGING = { LOGIN_URL = reverse_lazy('home') #Map Java: yyyy-MM-dd'T'HH:mm'Z' -API_DATETIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ' +API_DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%SZ' #Map Java: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' -API_DATEFORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' +API_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' # the API_Manager the web form date format, eg: 2020-10-11 API_MANAGER_DATE_FORMAT= '%Y-%m-%d' diff --git a/apimanager/base/filters.py b/apimanager/base/filters.py index e6d7743..a0f74c2 100644 --- a/apimanager/base/filters.py +++ b/apimanager/base/filters.py @@ -77,7 +77,7 @@ class FilterTime(BaseFilter): print(filtered) for item in data: item_date = datetime.strptime( - item[self.time_fieldname], settings.API_DATETIMEFORMAT) + item[self.time_fieldname], settings.API_DATE_TIME_FORMAT) if now - item_date <= delta: filtered.append(item) return filtered diff --git a/apimanager/base/utils.py b/apimanager/base/utils.py index 54df439..a1418b5 100644 --- a/apimanager/base/utils.py +++ b/apimanager/base/utils.py @@ -4,7 +4,7 @@ Base utilities """ from django.contrib.humanize.templatetags.humanize import naturaltime from datetime import datetime, timedelta -from apimanager.settings import API_DATEFORMAT, API_MANAGER_DATE_FORMAT +from apimanager.settings import API_DATE_FORMAT, API_MANAGER_DATE_FORMAT from base import context_processors from django.contrib import messages import functools @@ -61,7 +61,7 @@ def convert_form_date_to_obpapi_datetime_format(form_to_date_string): """ convert the String 2020-10-22 to 2020-10-22T00:00:00.000000Z """ - return datetime.strptime(form_to_date_string, API_MANAGER_DATE_FORMAT).strftime(API_DATEFORMAT) + return datetime.strptime(form_to_date_string, API_MANAGER_DATE_FORMAT).strftime(API_DATE_FORMAT) def return_to_days_ago(date, days): """ @@ -70,4 +70,4 @@ def return_to_days_ago(date, days): days =1 return 2020-10-21T00:00:00.000000Z """ - return (datetime.strptime(date, API_DATEFORMAT) - timedelta(days)).strftime(API_DATEFORMAT) \ No newline at end of file + return (datetime.strptime(date, API_DATE_FORMAT) - timedelta(days)).strftime(API_DATE_FORMAT) \ No newline at end of file diff --git a/apimanager/consumers/views.py b/apimanager/consumers/views.py index b1fb37e..ecfdb93 100644 --- a/apimanager/consumers/views.py +++ b/apimanager/consumers/views.py @@ -44,7 +44,7 @@ class IndexView(LoginRequiredMixin, TemplateView): """Scrubs data in the given consumers to adher to certain formats""" for consumer in consumers: consumer['created'] = datetime.strptime( - consumer['created'], settings.API_DATETIMEFORMAT) + consumer['created'], settings.API_DATE_TIME_FORMAT) return consumers def compile_statistics(self, consumers): @@ -146,7 +146,7 @@ class DetailView(LoginRequiredMixin, FormView): urlpath = '/management/consumers/{}'.format(self.kwargs['consumer_id']) consumer = api.get(urlpath) consumer['created'] = datetime.strptime( - consumer['created'], settings.API_DATETIMEFORMAT) + consumer['created'], settings.API_DATE_TIME_FORMAT) call_limits_urlpath = '/management/consumers/{}/consumer/call-limits'.format(self.kwargs['consumer_id']) consumer_call_limtis = api.get(call_limits_urlpath) diff --git a/apimanager/customers/forms.py b/apimanager/customers/forms.py index b94d783..925375e 100644 --- a/apimanager/customers/forms.py +++ b/apimanager/customers/forms.py @@ -81,7 +81,7 @@ class CreateCustomerForm(forms.Form): ) face_image_date = forms.DateTimeField( label=_('Face Image Date'), - input_formats=[settings.API_DATETIMEFORMAT], + input_formats=[settings.API_DATE_TIME_FORMAT], widget=forms.DateTimeInput( attrs={ 'placeholder': PLACEHOLDER, @@ -92,7 +92,7 @@ class CreateCustomerForm(forms.Form): ) date_of_birth = forms.DateTimeField( label=_('Date of Birth'), - input_formats=[settings.API_DATETIMEFORMAT], + input_formats=[settings.API_DATE_TIME_FORMAT], widget=forms.DateTimeInput( attrs={ 'placeholder': PLACEHOLDER, @@ -204,7 +204,7 @@ class CreateCustomerForm(forms.Form): ) last_ok_date = forms.DateTimeField( label=_('Last OK Date'), - input_formats=[settings.API_DATETIMEFORMAT], + input_formats=[settings.API_DATE_TIME_FORMAT], widget=forms.DateTimeInput( attrs={ 'placeholder': PLACEHOLDER, @@ -221,14 +221,14 @@ class CreateCustomerForm(forms.Form): def clean_face_image_date(self): data = self.cleaned_data['face_image_date'] if data: - return data.strftime(settings.API_DATETIMEFORMAT) + return data.strftime(settings.API_DATE_TIME_FORMAT) else: return None def clean_date_of_birth(self): data = self.cleaned_data['date_of_birth'] if data: - return data.strftime(settings.API_DATETIMEFORMAT) + return data.strftime(settings.API_DATE_TIME_FORMAT) else: return None diff --git a/apimanager/customers/views.py b/apimanager/customers/views.py index 0e0b843..ca4ad3f 100644 --- a/apimanager/customers/views.py +++ b/apimanager/customers/views.py @@ -38,7 +38,7 @@ class CreateView(LoginRequiredMixin, FormView): except Exception as err: messages.error(self.request, err) fields['last_ok_date'].initial =\ - datetime.datetime.now().strftime(settings.API_DATETIMEFORMAT) + datetime.datetime.now().strftime(settings.API_DATE_TIME_FORMAT) return form def form_valid(self, form): @@ -71,7 +71,7 @@ class CreateView(LoginRequiredMixin, FormView): 'employment_status': data['employment_status'], 'kyc_status': data['kyc_status'], 'last_ok_date': - data['last_ok_date'].strftime(settings.API_DATETIMEFORMAT), + data['last_ok_date'].strftime(settings.API_DATE_TIME_FORMAT), } try: result = self.api.post(urlpath, payload=payload) diff --git a/apimanager/entitlementrequests/views.py b/apimanager/entitlementrequests/views.py index 89fe120..8662014 100644 --- a/apimanager/entitlementrequests/views.py +++ b/apimanager/entitlementrequests/views.py @@ -24,7 +24,7 @@ class IndexView(LoginRequiredMixin, TemplateView): """Scrubs data in the given entitlement requests to adher to certain formats""" for entitlement_request in entitlement_requests: entitlement_request['created'] = datetime.strptime( - entitlement_request['created'], settings.API_DATETIMEFORMAT) + entitlement_request['created'], settings.API_DATE_TIME_FORMAT) return entitlement_requests def get_context_data(self, **kwargs): diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 353c542..1d086bb 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -13,7 +13,7 @@ from django.utils.translation import ugettext_lazy as _ from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput from apimanager.settings import API_MANAGER_DATE_FORMAT -API_DATEFORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" +API_DATE_FORMAT_PLACEHOLDER = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" FORM_CONTROL = 'form-control' FROM_DATE = 'From Date' TO_DATE = 'To Date' @@ -21,10 +21,10 @@ TO_DATE = 'To Date' class MetricsForm(forms.Form): from_date = forms.DateTimeField( label=_(FROM_DATE), - input_formats=[settings.API_DATEFORMAT], + input_formats=[settings.API_DATE_FORMAT], widget=forms.DateTimeInput( attrs={ - 'placeholder': API_DATEFORMAT_PLACEHOLDER, + 'placeholder': API_DATE_FORMAT_PLACEHOLDER, 'class': FORM_CONTROL, } ), @@ -33,10 +33,10 @@ class MetricsForm(forms.Form): ) to_date = forms.DateTimeField( label=_(TO_DATE), - input_formats=[settings.API_DATEFORMAT], + input_formats=[settings.API_DATE_FORMAT], widget=forms.DateTimeInput( attrs={ - 'placeholder': API_DATEFORMAT_PLACEHOLDER, + 'placeholder': API_DATE_FORMAT_PLACEHOLDER, 'class': FORM_CONTROL, } ), @@ -176,10 +176,10 @@ class ConnectorMetricsForm(MetricsForm): # override from_date until API returns values without given date from_date = forms.DateTimeField( label=_(FROM_DATE), - input_formats=[settings.API_DATEFORMAT], + input_formats=[settings.API_DATE_FORMAT], widget=forms.DateTimeInput( attrs={ - 'placeholder': API_DATEFORMAT_PLACEHOLDER, + 'placeholder': API_DATE_FORMAT_PLACEHOLDER, 'class': FORM_CONTROL, } ), diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index d9496a4..1cd506c 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -11,7 +11,7 @@ from enum import Enum from django.conf import settings from apimanager import local_settings -from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT, API_DATETIMEFORMAT +from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATE_FORMAT, API_DATE_TIME_FORMAT from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView @@ -112,7 +112,7 @@ class MetricsView(LoginRequiredMixin, TemplateView): """ for metric in metrics: metric['date'] = datetime.datetime.strptime( - metric['date'], settings.API_DATETIMEFORMAT) + metric['date'], settings.API_DATE_TIME_FORMAT) return metrics def to_api(self, cleaned_data): @@ -127,7 +127,7 @@ class MetricsView(LoginRequiredMixin, TemplateView): # Maybe we should define the API format as Django format to not # have to convert in places like this? if value.__class__.__name__ == 'datetime': - value = value.strftime(settings.API_DATEFORMAT) + value = value.strftime(settings.API_DATE_FORMAT) if value: # API does not like quoted data params.append('{}={}'.format(name, value)) @@ -224,7 +224,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): """ for metric in metrics: metric['date'] = datetime.datetime.strptime( - metric['date'], API_DATEFORMAT) + metric['date'], API_DATE_FORMAT) return metrics def to_api(self, cleaned_data): @@ -239,7 +239,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): # Maybe we should define the API format as Django format to not # have to convert in places like this? if value.__class__.__name__ == 'datetime': - value = value.strftime(settings.API_DATEFORMAT) + value = value.strftime(settings.API_DATE_FORMAT) if value: # API does not like quoted data params.append('{}={}'.format(name, value)) @@ -266,17 +266,18 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: urlpath = urlpath + '?from_date={}&to_date={}'.format(from_date, to_date) cache_key = get_cache_key_for_current_call(self.request, urlpath) - apicaches = None + #api_cache = None + api_cache = None try: - apicaches = cache.get(cache_key) + api_cache = cache.get(cache_key) except Exception as err: - apicaches = None - if apicaches is not None: - metrics = apicaches + api_cache = None + if api_cache is not None: + metrics = api_cache else: api = API(self.request.session.get('obp')) metrics = api.get(urlpath) - apicaches = cache.set(cache_key, metrics) + api_cache = cache.set(cache_key, metrics) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, urlpath)) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key)) @@ -293,8 +294,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): to_date, urlpath): api_calls_total = metrics[0]["count"] average_response_time = metrics[0]["average_response_time"] - to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATE_FORMAT) + from_date = datetime.datetime.strptime(from_date, API_DATE_FORMAT) number_of_days = abs((to_date - from_date).days) # if number_of_days= 0, then it means calls_per_hour average_calls_per_day = api_calls_total if (number_of_days == 0) else api_calls_total / number_of_days @@ -341,12 +342,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_total_number_of_apps(self, cleaned_data, from_date, to_date): apps = [] - from_date = datetime.datetime.strptime(from_date, API_DATEFORMAT) - to_date = datetime.datetime.strptime(to_date, API_DATEFORMAT) + from_date = datetime.datetime.strptime(from_date, API_DATE_FORMAT) + to_date = datetime.datetime.strptime(to_date, API_DATE_FORMAT) apps_list = self.get_all_consumers() for app in apps_list: - app_created_date = datetime.datetime.strptime(app["created"], API_DATETIMEFORMAT) + app_created_date = datetime.datetime.strptime(app["created"], API_DATE_TIME_FORMAT) if app_created_date < from_date and app_created_date > to_date: apps_list.remove(app) @@ -382,13 +383,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): urlpath = '/management/consumers' api = API(self.request.session.get('obp')) cache_key = get_cache_key_for_current_call(self.request, urlpath) - apicaches = None + api_cache = None try: - apicaches = cache.get(cache_key) + api_cache = cache.get(cache_key) except Exception as err: - apicaches = None - if apicaches is not None: - apps_list = apicaches + api_cache = None + if api_cache is not None: + apps_list = api_cache else: try: apps = api.get(urlpath) @@ -409,8 +410,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): """ # we need to convert string to datetime object, then we can calculate the date - from_datetime_object = datetime.datetime.strptime(from_date_string, API_DATEFORMAT) - to_datetime_object = datetime.datetime.strptime(to_date_string , API_DATEFORMAT) + from_datetime_object = datetime.datetime.strptime(from_date_string, API_DATE_FORMAT) + to_datetime_object = datetime.datetime.strptime(to_date_string , API_DATE_FORMAT) time_delta_in_loop = from_datetime_object + timedelta(**delta) result_list = [] @@ -419,8 +420,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): while time_delta_in_loop <= to_datetime_object: try: # here we need to first convert datetime object to String - form_date= from_datetime_object.strftime(API_DATEFORMAT) - to_date= time_delta_in_loop.strftime(API_DATEFORMAT) + form_date= from_datetime_object.strftime(API_DATE_FORMAT) + to_date= time_delta_in_loop.strftime(API_DATE_FORMAT) aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, is_included_obp_apps) result = aggregate_metrics[0] result_list_pure.append(result) @@ -748,7 +749,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') @@ -802,8 +803,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - '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'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), + 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), 'top_apis': top_apis, 'top_apis_bar_chart': top_apis_bar_chart, 'top_consumers_bar_chart': top_consumers_bar_chart, @@ -840,7 +841,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. - from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT) + from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') From d99763c223097507c3275cd21e301234b3e380c8 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 26 Jan 2023 14:35:00 +0100 Subject: [PATCH 49/85] update Date and time Variables name --- apimanager/metrics/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 1cd506c..ea414bc 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -709,7 +709,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return top_apps_using_warehouse def median_time_to_first_api_call(self, from_date, to_date): - return 0 + return 0 #TODO this cost too much time, do not use this at the moment. + form = self.get_form() def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) From 1449d1ff427e5753e5b17b03e12bdc640ea84742 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 26 Jan 2023 16:39:04 +0100 Subject: [PATCH 50/85] Update code in Metric view.py --- apimanager/metrics/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index ea414bc..cee33bc 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -711,6 +711,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def median_time_to_first_api_call(self, from_date, to_date): return 0 #TODO this cost too much time, do not use this at the moment. form = self.get_form() + form = self.get_form() + new_apps_list = [] + apps = [] + apps_list = self.get_all_consumers() def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) From f3527586c7331b823caadca3f95de9b40f5a81b4 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 27 Jan 2023 15:34:30 +0100 Subject: [PATCH 51/85] Update code in Metric view.py --- apimanager/metrics/views.py | 57 ++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index cee33bc..e25d3cb 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -266,7 +266,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: urlpath = urlpath + '?from_date={}&to_date={}'.format(from_date, to_date) cache_key = get_cache_key_for_current_call(self.request, urlpath) - #api_cache = None api_cache = None try: api_cache = cache.get(cache_key) @@ -716,6 +715,62 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apps = [] apps_list = self.get_all_consumers() + for app in apps_list: + created_date = datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') + created_date = created_date.strftime(API_DATE_FORMAT) + created_date = datetime.datetime.strptime(created_date, API_DATE_FORMAT) + if created_date >= datetime.datetime.strptime(from_date, API_DATE_FORMAT): + new_apps_list.append(app) + + times_to_first_call = [] + + strfrom_date=datetime.datetime.strptime(from_date, API_DATE_FORMAT) + strto_date=datetime.datetime.strptime(to_date, API_DATE_FORMAT) + for app in new_apps_list: + urlpath_metrics = '/management/metrics?from_date={}&to_date={}&consumer_id={}&sort_by={}&direction={}&limit={}'.format( + from_date, to_date, app['consumer_id'], 'date', 'asc', '1') + cache_key = get_cache_key_for_current_call(self.request, urlpath_metrics) + api = API(self.request.session.get('obp')) + try: + api_cache=None + try: + api_cache=cache.get(cache_key) + except Exception as err: + api_cache=None + metrics=[] + if not api_cache is None: + metrics=api_cache + else: + metrics = api.get(urlpath_metrics) + + if metrics is not None and 'code' in metrics and metrics['code'] == 403: + error_once_only(self.request, metrics['message']) + if(metrics['message'].startswith('OBP-20006')): + break + metrics = [] + else: + metrics = list(metrics['metrics']) + cache.set(cache_key, metrics) + LOGGER.warning('The cache is setting, url is: {}'.format(urlpath_metrics)) + LOGGER.warning('The cache is setting key is: {}'.format(cache_key)) + if metrics: + time_difference = datetime.datetime.strptime(metrics[0]['date'], '%Y-%m-%dT%H:%M:%S.%fZ') - datetime.datetime.strptime(app['created'], '%Y-%m-%dT%H:%M:%SZ') + times_to_first_call.append(time_difference.total_seconds()) + + + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, 'Unknown Error. {}'.format(err)) + + if times_to_first_call: + median = statistics.median(times_to_first_call) + delta = datetime.timedelta(seconds=median) + else: + delta = 0 + + return delta + def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.MONTHLY) def prepare_general_context(self, web_page_type, **kwargs): From eb7c34ee177ccee9817d8e2561250db54571b875 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Mon, 30 Jan 2023 13:31:47 +0100 Subject: [PATCH 52/85] bugfix/ username in Lock/unlock --- apimanager/apimanager/settings.py | 2 +- apimanager/users/views.py | 69 ++++++++++++++----------------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index 2c134a6..dd26105 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -257,7 +257,7 @@ API_EXPLORER_HOST = 'http://127.0.0.1:8082' # Only override this if you have a separate portal instance API_PORTAL = API_HOST API_BASE_PATH = '/obp/v' -API_VERSION = '5.1.0' +API_VERSION = '5.0.0' # URL to API Tester API_TESTER_URL = 'https://www.example.com' diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 4482f21..6144dd1 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -248,7 +248,7 @@ class MyDetailView(LoginRequiredMixin, FormView): messages.error(self.request, err) except Exception as err: messages.error(self.request, err) - user["entitlements"]["list"] = sorted(user["entitlements"]["list"], key=lambda d: d['role_name']) + context.update({ 'apiuser': user, # 'user' is logged-in user in template context }) @@ -340,7 +340,7 @@ class DeleteEntitlementView(LoginRequiredMixin, View): except Exception as err: messages.error(self.request, err) - # from sonarcloud: Change this code to not perform redirects based on user-controlled data. + # from sonarcloud: Change this code to not perform redirects based on user-controlled data. redirect_url_from_gui = request.POST.get('next', reverse('users-index')) if "/users/all/user_id/" in str(redirect_url_from_gui): redirect_url = reverse('users-detail',kwargs={"user_id":kwargs['user_id']}) @@ -348,7 +348,7 @@ class DeleteEntitlementView(LoginRequiredMixin, View): redirect_url = reverse('my-user-detail',kwargs={"user_id":kwargs['user_id']}) else: redirect_url = reverse('users-index') - + return HttpResponseRedirect(redirect_url) @@ -360,16 +360,38 @@ class UserStatusUpdateView(LoginRequiredMixin, View): api = API(self.request.session.get('obp')) try: if(request.POST.get("Delete")): - self._delete_user(api, request, args, kwargs) + urlpath = '/users/{}'.format(kwargs['user_id']) + result = api.delete(urlpath) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) + messages.success(request, msg) elif(request.POST.get("Lock")): - self._lock_user(api, request, args, kwargs) + urlpath = '/users/{}/locks'.format(kwargs['username']) + result = api.post(urlpath, None) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User {} has been lock.'.format(kwargs['username']) + messages.success(request, msg) else: - self._lock_status_user(api, request, args, kwargs) + urlpath = '/users/{}/lock-status'.format(kwargs['username']) + result = api.put(urlpath, None) + #if result is not None and 'code' in result and result['code'] >= 400: + if 'code' in result and result['code'] == 404: + msg = 'User {} has been unlocked.'.format(kwargs['username']) + messages.success(request, msg) + else: + messages.error(request, result['message']) + #else: + # msg = 'User {} has been unlocked.'.format(kwargs['username']) + # messages.success(request, msg) except APIError as err: messages.error(request, err) - except Exception as err: - messages.error(self.request, err) + except Exception as e: + messages.error(self.request, 'Unknown Error' + str(e)) # from sonarcloud: Change this code to not perform redirects based on user-controlled data. redirect_url_from_gui = request.POST.get('next', reverse('users-index')) @@ -382,36 +404,6 @@ class UserStatusUpdateView(LoginRequiredMixin, View): return HttpResponseRedirect(redirect_url) - def _delete_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}'.format(kwargs['user_id']) - result = api.delete(urlpath) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) - messages.success(request, msg) - - def _lock_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}/locks'.format(kwargs['username']) - result = api.post(urlpath, None) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User {} has been lock.'.format(kwargs['username']) - messages.success(request, msg) - - def _lock_status_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}/lock-status'.format(kwargs['username']) - result = api.put(urlpath, None) - #if result is not None and 'code' in result and result['code'] >= 400: - if 'code' in result and result['code'] == 404: - msg = 'User {} has been unlocked.'.format(kwargs['username']) - messages.success(request, msg) - else: - messages.error(request, result['message']) - #else: - # msg = 'User {} has been unlocked.'.format(kwargs['username']) - # messages.success(request, msg) class ExportCsvView(LoginRequiredMixin, View): """View to export the user to csv""" @@ -449,4 +441,3 @@ class ExportCsvView(LoginRequiredMixin, View): writer.writerow([user['username'], user['user_id'], user['email'], user['provider_id'], user['provider'], user['last_marketing_agreement_signed_date']]) return response - From 965a76c5ed5eb57aeb1be0eccbe1a92c8cfa6b75 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Tue, 31 Jan 2023 11:49:32 +0100 Subject: [PATCH 53/85] bugfix/ username in Lock/unlock --- apimanager/users/views.py | 64 ++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 6144dd1..3237db2 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -248,7 +248,7 @@ class MyDetailView(LoginRequiredMixin, FormView): messages.error(self.request, err) except Exception as err: messages.error(self.request, err) - + user["entitlements"]["list"] = sorted(user["entitlements"]["list"], key=lambda d: d['role_name']) context.update({ 'apiuser': user, # 'user' is logged-in user in template context }) @@ -360,38 +360,16 @@ class UserStatusUpdateView(LoginRequiredMixin, View): api = API(self.request.session.get('obp')) try: if(request.POST.get("Delete")): - urlpath = '/users/{}'.format(kwargs['user_id']) - result = api.delete(urlpath) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) - messages.success(request, msg) + self._delete_user(api, request, args, kwargs) elif(request.POST.get("Lock")): - urlpath = '/users/{}/locks'.format(kwargs['username']) - result = api.post(urlpath, None) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User {} has been lock.'.format(kwargs['username']) - messages.success(request, msg) + self._lock_user(api, request, args, kwargs) else: - urlpath = '/users/{}/lock-status'.format(kwargs['username']) - result = api.put(urlpath, None) - #if result is not None and 'code' in result and result['code'] >= 400: - if 'code' in result and result['code'] == 404: - msg = 'User {} has been unlocked.'.format(kwargs['username']) - messages.success(request, msg) - else: - messages.error(request, result['message']) - #else: - # msg = 'User {} has been unlocked.'.format(kwargs['username']) - # messages.success(request, msg) + self._lock_status_user(api, request, args, kwargs) except APIError as err: messages.error(request, err) - except Exception as e: - messages.error(self.request, 'Unknown Error' + str(e)) + except Exception as err: + messages.error(self.request, err) # from sonarcloud: Change this code to not perform redirects based on user-controlled data. redirect_url_from_gui = request.POST.get('next', reverse('users-index')) @@ -404,6 +382,36 @@ class UserStatusUpdateView(LoginRequiredMixin, View): return HttpResponseRedirect(redirect_url) + def _delete_user(self, api, request, *args, **kwargs): + urlpath = '/users/{}'.format(kwargs['user_id']) + result = api.delete(urlpath) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) + messages.success(request, msg) + + def _lock_user(self, api, request, *args, **kwargs): + urlpath = '/users/{}/locks'.format(kwargs['username']) + result = api.post(urlpath, None) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User {} has been lock.'.format(kwargs['username']) + messages.success(request, msg) + + def _lock_status_user(self, api, request, *args, **kwargs): + urlpath = '/users/{}/lock-status'.format(kwargs['username']) + result = api.put(urlpath, None) + #if result is not None and 'code' in result and result['code'] >= 400: + if 'code' in result and result['code'] == 404: + msg = 'User {} has been unlocked.'.format(kwargs['username']) + messages.success(request, msg) + else: + messages.error(request, result['message']) + #else: + # msg = 'User {} has been unlocked.'.format(kwargs['username']) + # messages.success(request, msg) class ExportCsvView(LoginRequiredMixin, View): """View to export the user to csv""" From 5948163164b2501b1f43fb9a4e3a8aceaaf79d56 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Tue, 31 Jan 2023 11:50:31 +0100 Subject: [PATCH 54/85] bugfix/ username in Lock/unlock --- apimanager/base/templates/base.html | 2 +- .../templates/metrics/custom_summary.html | 4 +- apimanager/users/views.py | 64 ++++++++----------- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 6c5fc6f..e5facb6 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -66,7 +66,7 @@
  • {% trans "Account Create" %}
  • {% trans "Account List" %}
  • -
  • {% trans "Customers" %}
  • +
  • {% trans "Customer Create" %}
  • {% trans "Customer List" %}
  • {% trans "Branches" %}
  • {% trans "ATM Create" %}
  • diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 8ee8dbb..0b0f413 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -38,14 +38,14 @@
    {% if form.from_date_custom.errors %}
    {{ form.from_date_custom.errors }}
    {% endif %}
    - {% trans "from_date_custom" %} + {% trans "From Date Custom" %} {{ form.from_date_custom }}
    {% if form.to_date.errors %}
    {{ form.to_date.errors }}
    {% endif %}
    - {% trans "to_date" %} + {% trans "To Date Custom" %} {{ form.to_date }}
    diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 3237db2..6144dd1 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -248,7 +248,7 @@ class MyDetailView(LoginRequiredMixin, FormView): messages.error(self.request, err) except Exception as err: messages.error(self.request, err) - user["entitlements"]["list"] = sorted(user["entitlements"]["list"], key=lambda d: d['role_name']) + context.update({ 'apiuser': user, # 'user' is logged-in user in template context }) @@ -360,16 +360,38 @@ class UserStatusUpdateView(LoginRequiredMixin, View): api = API(self.request.session.get('obp')) try: if(request.POST.get("Delete")): - self._delete_user(api, request, args, kwargs) + urlpath = '/users/{}'.format(kwargs['user_id']) + result = api.delete(urlpath) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) + messages.success(request, msg) elif(request.POST.get("Lock")): - self._lock_user(api, request, args, kwargs) + urlpath = '/users/{}/locks'.format(kwargs['username']) + result = api.post(urlpath, None) + if result is not None and 'code' in result and result['code'] >= 400: + messages.error(request, result['message']) + else: + msg = 'User {} has been lock.'.format(kwargs['username']) + messages.success(request, msg) else: - self._lock_status_user(api, request, args, kwargs) + urlpath = '/users/{}/lock-status'.format(kwargs['username']) + result = api.put(urlpath, None) + #if result is not None and 'code' in result and result['code'] >= 400: + if 'code' in result and result['code'] == 404: + msg = 'User {} has been unlocked.'.format(kwargs['username']) + messages.success(request, msg) + else: + messages.error(request, result['message']) + #else: + # msg = 'User {} has been unlocked.'.format(kwargs['username']) + # messages.success(request, msg) except APIError as err: messages.error(request, err) - except Exception as err: - messages.error(self.request, err) + except Exception as e: + messages.error(self.request, 'Unknown Error' + str(e)) # from sonarcloud: Change this code to not perform redirects based on user-controlled data. redirect_url_from_gui = request.POST.get('next', reverse('users-index')) @@ -382,36 +404,6 @@ class UserStatusUpdateView(LoginRequiredMixin, View): return HttpResponseRedirect(redirect_url) - def _delete_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}'.format(kwargs['user_id']) - result = api.delete(urlpath) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User with ID {} has been deleted.'.format(kwargs['user_id']) - messages.success(request, msg) - - def _lock_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}/locks'.format(kwargs['username']) - result = api.post(urlpath, None) - if result is not None and 'code' in result and result['code'] >= 400: - messages.error(request, result['message']) - else: - msg = 'User {} has been lock.'.format(kwargs['username']) - messages.success(request, msg) - - def _lock_status_user(self, api, request, *args, **kwargs): - urlpath = '/users/{}/lock-status'.format(kwargs['username']) - result = api.put(urlpath, None) - #if result is not None and 'code' in result and result['code'] >= 400: - if 'code' in result and result['code'] == 404: - msg = 'User {} has been unlocked.'.format(kwargs['username']) - messages.success(request, msg) - else: - messages.error(request, result['message']) - #else: - # msg = 'User {} has been unlocked.'.format(kwargs['username']) - # messages.success(request, msg) class ExportCsvView(LoginRequiredMixin, View): """View to export the user to csv""" From 0f9cfece628d02bfb3e66e5ea313e6172abdbb87 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Tue, 31 Jan 2023 11:54:22 +0100 Subject: [PATCH 55/85] bugfix/ username in Lock/unlock --- apimanager/users/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apimanager/users/views.py b/apimanager/users/views.py index 6144dd1..da04aa4 100644 --- a/apimanager/users/views.py +++ b/apimanager/users/views.py @@ -248,7 +248,6 @@ class MyDetailView(LoginRequiredMixin, FormView): messages.error(self.request, err) except Exception as err: messages.error(self.request, err) - context.update({ 'apiuser': user, # 'user' is logged-in user in template context }) @@ -348,7 +347,6 @@ class DeleteEntitlementView(LoginRequiredMixin, View): redirect_url = reverse('my-user-detail',kwargs={"user_id":kwargs['user_id']}) else: redirect_url = reverse('users-index') - return HttpResponseRedirect(redirect_url) @@ -390,8 +388,8 @@ class UserStatusUpdateView(LoginRequiredMixin, View): except APIError as err: messages.error(request, err) - except Exception as e: - messages.error(self.request, 'Unknown Error' + str(e)) + except Exception as err: + messages.error(self.request, err) # from sonarcloud: Change this code to not perform redirects based on user-controlled data. redirect_url_from_gui = request.POST.get('next', reverse('users-index')) From af1834ddd80705515b849c8d7a9c85d8c027b71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Wed, 1 Feb 2023 10:33:37 +0100 Subject: [PATCH 56/85] bugfix/Fix chart: Metrics -> Summary by Partial Function --- apimanager/metrics/static/metrics/js/metrics.js | 2 +- .../templates/metrics/api_summary_partial_function.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apimanager/metrics/static/metrics/js/metrics.js b/apimanager/metrics/static/metrics/js/metrics.js index 90be4d9..621f8a1 100644 --- a/apimanager/metrics/static/metrics/js/metrics.js +++ b/apimanager/metrics/static/metrics/js/metrics.js @@ -1,5 +1,5 @@ $(document).ready(function($) { - let barChart = Chart($("#barchart"), { + let barChart = new Chart($("#barchart"), { type: 'horizontalBar', data: { labels: BarchartData['labels'], diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index ac28d08..fb2f312 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -3,8 +3,8 @@ {% load i18n %} {% block nav_tabs %} - {% trans "List" %} - {% trans "Summary by Partial Function" %} +
  • {% trans "List" %}
  • +
  • {% trans "Summary by Partial Function" %}
  • {% endblock nav_tabs %} {% block tab_content %} From 1ef3fdbb0d688cf023e5e8a67fb0ce4aa8854bea Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 1 Feb 2023 11:57:13 +0100 Subject: [PATCH 57/85] Some improvements in metric --- apimanager/base/templates/base.html | 2 +- apimanager/metrics/forms.py | 29 ++++--------------- .../metrics/static/metrics/js/metrics.js | 2 +- apimanager/metrics/templates/metrics/api.html | 6 ++-- .../metrics/api_summary_partial_function.html | 2 +- .../metrics/templates/metrics/connector.html | 16 +++++----- .../templates/metrics/custom_summary.html | 2 +- .../templates/metrics/daily_summary.html | 2 +- .../templates/metrics/hourly_summary.html | 2 +- .../templates/metrics/monthly_summary.html | 2 +- .../templates/metrics/quarterly_summary.html | 2 +- .../templates/metrics/weekly_summary.html | 2 +- .../templates/metrics/yearly_summary.html | 4 +-- 13 files changed, 28 insertions(+), 45 deletions(-) diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index e5facb6..3759d93 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -68,7 +68,7 @@
  • {% trans "Account List" %}
  • {% trans "Customer Create" %}
  • {% trans "Customer List" %}
  • -
  • {% trans "Branches" %}
  • +
  • {% trans "Branche Create" %}
  • {% trans "ATM Create" %}
  • {% trans "ATM List" %}
  • {% trans "Product Create" %}
  • diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 1d086bb..daf29b0 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -21,26 +21,15 @@ TO_DATE = 'To Date' class MetricsForm(forms.Form): from_date = forms.DateTimeField( label=_(FROM_DATE), - input_formats=[settings.API_DATE_FORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': API_DATE_FORMAT_PLACEHOLDER, - 'class': FORM_CONTROL, - } - ), - initial='2020-01-01T00:00:00.000Z', + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=False, + initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) to_date = forms.DateTimeField( label=_(TO_DATE), - input_formats=[settings.API_DATE_FORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': API_DATE_FORMAT_PLACEHOLDER, - 'class': FORM_CONTROL, - } - ), + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=False, + initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) limit = forms.IntegerField( label=_('Limit'), @@ -176,15 +165,9 @@ class ConnectorMetricsForm(MetricsForm): # override from_date until API returns values without given date from_date = forms.DateTimeField( label=_(FROM_DATE), - input_formats=[settings.API_DATE_FORMAT], - widget=forms.DateTimeInput( - attrs={ - 'placeholder': API_DATE_FORMAT_PLACEHOLDER, - 'class': FORM_CONTROL, - } - ), - initial='2020-01-01T00:00:00.000Z', + widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, + initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) connector_name = forms.CharField( label=_('Connector Name'), diff --git a/apimanager/metrics/static/metrics/js/metrics.js b/apimanager/metrics/static/metrics/js/metrics.js index 90be4d9..621f8a1 100644 --- a/apimanager/metrics/static/metrics/js/metrics.js +++ b/apimanager/metrics/static/metrics/js/metrics.js @@ -1,5 +1,5 @@ $(document).ready(function($) { - let barChart = Chart($("#barchart"), { + let barChart = new Chart($("#barchart"), { type: 'horizontalBar', data: { labels: BarchartData['labels'], diff --git a/apimanager/metrics/templates/metrics/api.html b/apimanager/metrics/templates/metrics/api.html index 7512ac7..cca977c 100644 --- a/apimanager/metrics/templates/metrics/api.html +++ b/apimanager/metrics/templates/metrics/api.html @@ -85,10 +85,10 @@
    - {% if form.verb_selection.errors %}
    {{ form.verb_selection.errors }}
    {% endif %} + {% if form.verb.errors %}
    {{ form.verb.errors }}
    {% endif %}
    - {{ form.verb_selection.label_tag }} - {{ form.verb_selection }} + {{ form.verb.label_tag }} + {{ form.verb }}
    diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index ac28d08..f25d11a 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -4,7 +4,7 @@ {% block nav_tabs %} {% trans "List" %} - {% trans "Summary by Partial Function" %} +
    • {% trans "Summary by Partial Function" %} {% endblock nav_tabs %} {% block tab_content %} diff --git a/apimanager/metrics/templates/metrics/connector.html b/apimanager/metrics/templates/metrics/connector.html index 3ef2dc9..a214f95 100644 --- a/apimanager/metrics/templates/metrics/connector.html +++ b/apimanager/metrics/templates/metrics/connector.html @@ -21,28 +21,28 @@
      {% if form.from_date.errors %}
      {{ form.from_date.errors }}
      {% endif %}
      - {% trans "from_date" %} + {% trans "From Date" %} {{ form.from_date }}
      {% if form.to_date.errors %}
      {{ form.to_date.errors }}
      {% endif %}
      - {% trans "to_date" %} + {% trans "To Date" %} {{ form.to_date }}
      {% if form.limit.errors %}
      {{ form.limit.errors }}
      {% endif %}
      - {% trans "limit" %} + {% trans "Limit" %} {{ form.limit }}
      {% if form.offset.errors %}
      {{ form.offset.errors }}
      {% endif %}
      - {% trans "offset" %} + {% trans "Offset" %} {{ form.offset }}
      @@ -52,27 +52,27 @@
      {% if form.connector_name.errors %}
      {{ form.connector_name.errors }}
      {% endif %}
      - {% trans "connector_name" %} + {% trans "Connector Name" %} {{ form.connector_name }}
      {% if form.function_name.errors %}
      {{ form.function_name.errors }}
      {% endif %}
      - {% trans "function_name" %} + {% trans "Function Name" %} {{ form.function_name }}
      {% if form.correlation_id.errors %}
      {{ form.correlation_id.errors }}
      {% endif %}
      - {% trans "correlation_id" %} + {% trans "Correlation Id" %} {{ form.correlation_id }}
      - +
      diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 0b0f413..bc337d9 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,7 @@
      - +
      diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index a51b248..237f3c7 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -63,7 +63,7 @@
      - +
      diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 197fcef..9d72f3b 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -62,7 +62,7 @@
      - +
      diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index baca72f..5a293fc 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -58,7 +58,7 @@
      - +
      diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 57d4fd3..5adfb75 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -62,7 +62,7 @@ - + diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 7911c06..9029bb5 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@ - +
      diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 928e85d..99f531b 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
      - +
      @@ -112,7 +112,7 @@ {{ number_of_apps_with_unique_app_name }} - {% trans "Apps with distinct developer email addresses: + {% trans "Apps with distinct developer email addresses:" %} {{ number_of_apps_with_unique_developer_email }} From 6774b365aed32241b09e89aa2d9a067aa049ed5b Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 1 Feb 2023 11:59:28 +0100 Subject: [PATCH 58/85] Some improvements in metric --- .../metrics/templates/metrics/api_summary_partial_function.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index f25d11a..af43c34 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -4,7 +4,7 @@ {% block nav_tabs %} {% trans "List" %} -
      • {% trans "Summary by Partial Function" %} +
      • {% endblock nav_tabs %} {% block tab_content %} From b571e1a676fc1fd3901624d9ba372b0e424e6d5c Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Wed, 1 Feb 2023 23:12:16 +0100 Subject: [PATCH 59/85] spelling correction --- apimanager/base/templates/base.html | 2 +- apimanager/metrics/forms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 3759d93..577f0b7 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -68,7 +68,7 @@
      • {% trans "Account List" %}
      • {% trans "Customer Create" %}
      • {% trans "Customer List" %}
      • -
      • {% trans "Branche Create" %}
      • +
      • {% trans "Branch Create" %}
      • {% trans "ATM Create" %}
      • {% trans "ATM List" %}
      • {% trans "Product Create" %}
      • diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index daf29b0..f940852 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -23,7 +23,7 @@ class MetricsForm(forms.Form): label=_(FROM_DATE), widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=False, - initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), + initial=(datetime.now() - timedelta(30)).strftime(API_MANAGER_DATE_FORMAT), ) to_date = forms.DateTimeField( label=_(TO_DATE), From e746d890725fd7539039755dc94857d9ae1cb13b Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 2 Feb 2023 11:26:04 +0100 Subject: [PATCH 60/85] Some improvements in metric --- .../metrics/templates/metrics/api_summary_partial_function.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index af43c34..be40cee 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -4,7 +4,7 @@ {% block nav_tabs %} {% trans "List" %} -
      • +
      • {% endblock nav_tabs %} {% block tab_content %} From 62ea5f14738efd3d358ab6b1aa9fcad636f8a735 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Thu, 2 Feb 2023 16:06:37 +0100 Subject: [PATCH 61/85] Some improvements in metric --- .../metrics/static/metrics/js/include_system_calls.js | 3 +-- .../metrics/api_summary_partial_function.html | 4 ++-- .../metrics/templates/metrics/custom_summary.html | 4 ++-- apimanager/metrics/views.py | 11 ++++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apimanager/metrics/static/metrics/js/include_system_calls.js b/apimanager/metrics/static/metrics/js/include_system_calls.js index ed7015b..fd81a16 100644 --- a/apimanager/metrics/static/metrics/js/include_system_calls.js +++ b/apimanager/metrics/static/metrics/js/include_system_calls.js @@ -1,6 +1,5 @@ document.getElementsByClassName("include_system_calls")[0].innerHTML=`
        - +
        ` diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index be40cee..55baaa2 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -3,8 +3,8 @@ {% load i18n %} {% block nav_tabs %} - {% trans "List" %} -
      • +
      • {% trans "List" %}
      • +
      • {% trans "Summary by Partial Function" %}
      • {% endblock nav_tabs %} {% block tab_content %} diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index bc337d9..e308d4f 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,11 +63,11 @@
        - +
        - {% if form.include_obp_apps.value %} + {% if not form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %}{{ to_date }}

        diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index e25d3cb..bce0b01 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -504,6 +504,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): buf.close() # Clear the previous plot. plt.gcf().clear() + print(image_base64, "image_base64") return image_base64 def _day(self, plot_data, date_month_list, date_list): @@ -783,11 +784,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): per_hour_chart=[] if form.is_valid(): is_included_obp_apps = form.cleaned_data.get('include_obp_apps') + print(is_included_obp_apps, "is_included_obp_apps") exclude_app_names = form.cleaned_data.get("exclude_app_names") #if exclude_app_names not in local_settings.EXCLUDE_APPS: # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] to_date = convert_form_date_to_obpapi_datetime_format(form_to_date_string) + print(to_date, "to_date") if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. @@ -821,9 +824,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.CUSTOM): # for one month, the from_date is x day ago. form_from_date_string = form.data['from_date_custom'] + print(form_from_date_string, "form_from_date_string") from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) + print(from_date, "from_date123") calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + print(calls_per_day_list, calls_per_day, date_list, "list") per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + print(per_day_chart, "per_day_chart123") api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date, exclude_app_names) @@ -945,4 +952,6 @@ class HourlySummaryView(MonthlyMetricsSummaryView): class CustomSummaryView(MonthlyMetricsSummaryView): form_class = CustomSummaryForm template_name = 'metrics/custom_summary.html' - def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) \ No newline at end of file + def get_context_data(self, **kwargs): + print(self.prepare_general_context(SummaryType.CUSTOM, **kwargs), "self.elf.prepare_general_context(SummaryType.CUSTOM, **kwargs)") + return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) From e83e5ab5111d2c6880c9602e3895ef3956e9f9d0 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 3 Feb 2023 13:46:19 +0100 Subject: [PATCH 62/85] WIP Custom Metric --- .../templates/metrics/custom_summary.html | 6 +- apimanager/metrics/views.py | 69 ++----------------- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index e308d4f..83a9283 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -67,10 +67,10 @@
        - {% if not form.include_obp_apps.value %} + {% if form.include_obp_apps.value %} {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %}{{ to_date }}

        +

        {% trans "Period" %}: {% trans "From: " %}{{ from_date }} {% trans "To: " %}{{ to_date }}

        @@ -146,7 +146,7 @@ {% endblock tab_content %} {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {% trans "Period: " %} : {% trans "From: " %} {{ from_date }} {% trans "To: " %} {{ to_date }}

        {% endif %} diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index bce0b01..7d22f34 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -206,7 +206,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): We need a bound form because we already send a request to the API without user intervention on initial request """ - if (self.request.GET) and (web_page_type != SummaryType.CUSTOM): + if (self.request.GET) and (web_page_type == SummaryType.CUSTOM): data = self.request.GET else: fields = self.form_class.declared_fields @@ -253,10 +253,9 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): There are different use cases, so we accept different parameters. only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ - api_calls_total = 0 - average_response_time = 0 - average_calls_per_day = 0 try: + api_calls_total = 0 + average_response_time = 0 urlpath = '/management/aggregate-metrics' if only_show_api_explorer_metrics: urlpath = urlpath + '?from_date={}&to_date={}&app_name={}'.format(from_date, to_date, API_EXPLORER_APP_NAME) @@ -271,7 +270,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): api_cache = cache.get(cache_key) except Exception as err: api_cache = None - if api_cache is not None: + if not api_cache is None: metrics = api_cache else: api = API(self.request.session.get('obp')) @@ -282,12 +281,11 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): api_calls_total, average_calls_per_day, average_response_time = self.get_internal_api_call_metrics( api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, urlpath) + return api_calls_total, average_response_time, int(average_calls_per_day) except APIError as err: error_once_only(self.request, err) except Exception as err: error_once_only(self.request, err) - finally: - return api_calls_total, average_response_time, int(average_calls_per_day) def get_internal_api_call_metrics(self, api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, urlpath): @@ -310,6 +308,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ apps = [] + form = self.get_form() active_apps_list = [] if is_included_obp_apps: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}'.format(from_date, to_date, exclude_app_names) @@ -504,7 +503,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): buf.close() # Clear the previous plot. plt.gcf().clear() - print(image_base64, "image_base64") return image_base64 def _day(self, plot_data, date_month_list, date_list): @@ -784,13 +782,11 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): per_hour_chart=[] if form.is_valid(): is_included_obp_apps = form.cleaned_data.get('include_obp_apps') - print(is_included_obp_apps, "is_included_obp_apps") exclude_app_names = form.cleaned_data.get("exclude_app_names") #if exclude_app_names not in local_settings.EXCLUDE_APPS: # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] to_date = convert_form_date_to_obpapi_datetime_format(form_to_date_string) - print(to_date, "to_date") if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. @@ -824,13 +820,9 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.CUSTOM): # for one month, the from_date is x day ago. form_from_date_string = form.data['from_date_custom'] - print(form_from_date_string, "form_from_date_string") from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) - print(from_date, "from_date123") calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - print(calls_per_day_list, calls_per_day, date_list, "list") per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - print(per_day_chart, "per_day_chart123") api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date, exclude_app_names) @@ -884,51 +876,6 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except Exception as err: error_once_only(self.request, err) - def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart, from_date): - if (web_page_type == SummaryType.DAILY): - # for one day, the from_date is 1 day ago. - from_date = return_to_days_ago(to_date, 1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') - - if (web_page_type == SummaryType.WEEKLY): - # for one month, the from_date is 7 days ago. - from_date = return_to_days_ago(to_date, 7) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - return (from_date, per_hour_chart, per_day_chart) - - def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart, from_date): - if (web_page_type == SummaryType.MONTHLY): - # for one month, the from_date is 30 days ago. - from_date = return_to_days_ago(to_date, 30) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - if (web_page_type == SummaryType.QUARTERLY): - # for one quarter, the from_date is 90 days ago. - from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') - - return (from_date, per_day_chart, per_month_chart) - - def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart, from_date): - if (web_page_type == SummaryType.YEARLY): - from_date = return_to_days_ago(to_date, 365) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") - - if (web_page_type == SummaryType.CUSTOM): - # for one month, the from_date is x day ago. - form_from_date_string = form.data['from_date_custom'] - from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") - - return (from_date, per_month_chart, per_day_chart) - class YearlySummaryView(MonthlyMetricsSummaryView): template_name = 'metrics/yearly_summary.html' def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.YEARLY, **kwargs) @@ -952,6 +899,4 @@ class HourlySummaryView(MonthlyMetricsSummaryView): class CustomSummaryView(MonthlyMetricsSummaryView): form_class = CustomSummaryForm template_name = 'metrics/custom_summary.html' - def get_context_data(self, **kwargs): - print(self.prepare_general_context(SummaryType.CUSTOM, **kwargs), "self.elf.prepare_general_context(SummaryType.CUSTOM, **kwargs)") - return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) + def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) \ No newline at end of file From cda1dc96b6b7ce9dd1845ffc705f6284b84a1d1c Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 3 Feb 2023 14:06:50 +0100 Subject: [PATCH 63/85] WIP Custom Metric --- apimanager/metrics/forms.py | 2 +- apimanager/metrics/views.py | 46 ++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index f940852..c6afadd 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -210,7 +210,7 @@ class CustomSummaryForm(forms.Form): label=_(FROM_DATE), widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, - initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), + initial=(datetime.now() - timedelta(30)).strftime(API_MANAGER_DATE_FORMAT), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 7d22f34..65b01de 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -206,7 +206,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): We need a bound form because we already send a request to the API without user intervention on initial request """ - if (self.request.GET) and (web_page_type == SummaryType.CUSTOM): + if (self.request.GET) or (web_page_type == SummaryType.CUSTOM): data = self.request.GET else: fields = self.form_class.declared_fields @@ -875,6 +875,50 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, str(form.errors)) except Exception as err: error_once_only(self.request, err) + def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.DAILY): + # for one day, the from_date is 1 day ago. + from_date = return_to_days_ago(to_date, 1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') + + if (web_page_type == SummaryType.WEEKLY): + # for one month, the from_date is 7 days ago. + from_date = return_to_days_ago(to_date, 7) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_hour_chart, per_day_chart) + + def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart, from_date): + if (web_page_type == SummaryType.MONTHLY): + # for one month, the from_date is 30 days ago. + from_date = return_to_days_ago(to_date, 30) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + if (web_page_type == SummaryType.QUARTERLY): + # for one quarter, the from_date is 90 days ago. + from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') + + return (from_date, per_day_chart, per_month_chart) + + def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart, from_date): + if (web_page_type == SummaryType.YEARLY): + from_date = return_to_days_ago(to_date, 365) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") + + if (web_page_type == SummaryType.CUSTOM): + # for one month, the from_date is x day ago. + form_from_date_string = form.data['from_date_custom'] + from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + + return (from_date, per_month_chart, per_day_chart) class YearlySummaryView(MonthlyMetricsSummaryView): template_name = 'metrics/yearly_summary.html' From 7e35068f52bbeaba43b86e1764a1676b820bce8d Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Fri, 3 Feb 2023 14:08:14 +0100 Subject: [PATCH 64/85] WIP Custom Metric --- apimanager/metrics/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index c6afadd..f940852 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -210,7 +210,7 @@ class CustomSummaryForm(forms.Form): label=_(FROM_DATE), widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), required=True, - initial=(datetime.now() - timedelta(30)).strftime(API_MANAGER_DATE_FORMAT), + initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) exclude_app_names = forms.CharField( label=_('Exclude App Names'), From 938bf87ac7e576a8902deb49dd0387e140e1c473 Mon Sep 17 00:00:00 2001 From: Reena-cell Date: Sat, 4 Feb 2023 00:23:36 +0100 Subject: [PATCH 65/85] Bugfix/ Custom in Metric --- apimanager/base/templates/base.html | 2 +- .../templates/metrics/api_summary_partial_function.html | 2 +- apimanager/metrics/views.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apimanager/base/templates/base.html b/apimanager/base/templates/base.html index 577f0b7..aaa00f9 100644 --- a/apimanager/base/templates/base.html +++ b/apimanager/base/templates/base.html @@ -134,7 +134,7 @@

        API ROOT: {{ API_ROOT }} | Open Bank Project | Powered by TESOBE | - Copyright © 2016 - 2020 + Copyright © 2016 - 2023

        diff --git a/apimanager/metrics/templates/metrics/api_summary_partial_function.html b/apimanager/metrics/templates/metrics/api_summary_partial_function.html index 55baaa2..733068c 100644 --- a/apimanager/metrics/templates/metrics/api_summary_partial_function.html +++ b/apimanager/metrics/templates/metrics/api_summary_partial_function.html @@ -4,7 +4,7 @@ {% block nav_tabs %}
      • {% trans "List" %}
      • -
      • {% trans "Summary by Partial Function" %}
      • +
      • {% trans "Summary by Partial Function" %}
      • {% endblock nav_tabs %} {% block tab_content %} diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 65b01de..27152a2 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -200,13 +200,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): template_name = 'metrics/monthly_summary.html' api_urlpath = None - def get_form(self, web_page_type = ""): + def get_form(self): """ Get bound form either from request.GET or initials We need a bound form because we already send a request to the API without user intervention on initial request """ - if (self.request.GET) or (web_page_type == SummaryType.CUSTOM): + if self.request.GET: data = self.request.GET else: fields = self.form_class.declared_fields @@ -261,7 +261,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): urlpath = urlpath + '?from_date={}&to_date={}&app_name={}'.format(from_date, to_date, API_EXPLORER_APP_NAME) elif ((not only_show_api_explorer_metrics) and (not is_included_obp_apps)): urlpath = urlpath + '?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date, to_date, ",".join(local_settings.EXCLUDE_APPS),",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + from_date, to_date, ",".join(local_settings.EXCLUDE_APPS),",".join(local_settings.EXCLUDE_FUNCTIONS), ",".join(local_settings.EXCLUDE_URL_PATTERN)) else: urlpath = urlpath + '?from_date={}&to_date={}'.format(from_date, to_date) cache_key = get_cache_key_for_current_call(self.request, urlpath) @@ -774,7 +774,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def prepare_general_context(self, web_page_type, **kwargs): try: - form = self.get_form(web_page_type) + form = self.get_form() per_day_chart=[] calls_per_month_list=[] per_month_chart=[] From ee0453e9449325982ef59f1bdc2f852c7321fd59 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 6 Feb 2023 12:33:27 +0100 Subject: [PATCH 66/85] Refactor/ Remove include_system_data checkbox --- apimanager/metrics/forms.py | 6 ++++-- .../static/metrics/js/include_system_calls.js | 13 ------------- .../templates/metrics/custom_summary.html | 12 +----------- .../metrics/templates/metrics/daily_summary.html | 10 ---------- .../templates/metrics/hourly_summary.html | 10 ---------- .../templates/metrics/monthly_summary.html | 10 ---------- .../templates/metrics/quarterly_summary.html | 10 ---------- .../templates/metrics/weekly_summary.html | 10 ---------- .../templates/metrics/yearly_summary.html | 16 ++-------------- 9 files changed, 7 insertions(+), 90 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index f940852..2edef8a 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -222,7 +222,8 @@ class CustomSummaryForm(forms.Form): required=False, initial='API-Manager', ) - include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) + #include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) + include_obp_apps = forms.BooleanField(required=False) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') @@ -246,7 +247,8 @@ class MonthlyMetricsSummaryForm(forms.Form): required=False, initial='API-Manager', ) - include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) + #include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) + include_obp_apps = forms.BooleanField(required=False) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') diff --git a/apimanager/metrics/static/metrics/js/include_system_calls.js b/apimanager/metrics/static/metrics/js/include_system_calls.js index fd81a16..e69de29 100644 --- a/apimanager/metrics/static/metrics/js/include_system_calls.js +++ b/apimanager/metrics/static/metrics/js/include_system_calls.js @@ -1,13 +0,0 @@ -document.getElementsByClassName("include_system_calls")[0].innerHTML=`
        - - -
        ` - - function systemCalls(){ - let checkbox = document.getElementById('include_system_calls_id'); - if (checkbox.checked == false) { - document.getElementById("obp_app_table").style.display = "none"; - }else{ - document.getElementById("obp_app_table").style.display = ""; - } -} \ No newline at end of file diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 83a9283..fc18666 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -56,18 +56,11 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        - +
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %}: {% trans "From: " %}{{ from_date }} {% trans "To: " %}{{ to_date }}

        @@ -145,9 +138,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period: " %} : {% trans "From: " %} {{ from_date }} {% trans "To: " %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 237f3c7..861adce 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -56,12 +56,6 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        @@ -69,7 +63,6 @@
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        @@ -148,9 +141,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 9d72f3b..703fb2e 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -55,12 +55,6 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        @@ -68,7 +62,6 @@
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %} {{ to_date }}

        @@ -147,9 +140,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 5a293fc..4d696a5 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -51,12 +51,6 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        @@ -64,7 +58,6 @@
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %}: {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        @@ -142,9 +135,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 5adfb75..932378a 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -55,12 +55,6 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        @@ -68,7 +62,6 @@
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %}:{% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        @@ -151,9 +144,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 9029bb5..91d4c45 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -57,18 +57,11 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        - {% if form.include_obp_apps.value %} {% block tab_content %}

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        @@ -147,9 +140,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 99f531b..d6a2735 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -57,24 +57,15 @@ {{ form.exclude_app_names }} -
        -
        - {{ form.include_obp_apps }} - {{ form.include_obp_apps.label_tag }} -
        -
        - +
        - {% if form.include_obp_apps.value %} {% block tab_content %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - - +
        @@ -149,9 +140,6 @@
        {% endblock tab_content %} - {% else %} -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - {% endif %}
        From 8e25bd77406f06cd84aa8026b070a4b858a49d77 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 6 Feb 2023 12:43:30 +0100 Subject: [PATCH 67/85] Refactor/ Remove include_system_data checkbox --- apimanager/metrics/templates/metrics/daily_summary.html | 2 +- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- apimanager/metrics/templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/templates/metrics/quarterly_summary.html | 2 +- apimanager/metrics/templates/metrics/weekly_summary.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 861adce..4145f7a 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -67,7 +67,7 @@

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        - +
        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 703fb2e..f48abe8 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -66,7 +66,7 @@

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %} {{ to_date }}

        -
        +
        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 4d696a5..5a095ac 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -62,7 +62,7 @@

        {% trans "Period" %}: {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        -
        +
        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 932378a..e9d121d 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -66,7 +66,7 @@

        {% trans "Period" %}:{% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        -
        +
        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 91d4c45..7d0c39b 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -66,7 +66,7 @@

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        -
        +
        From fd01579f8ec2df4bc2222376a9ef326ae74027b0 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Tue, 7 Feb 2023 13:29:24 +0100 Subject: [PATCH 68/85] simplify/ Metric --- apimanager/metrics/forms.py | 42 +++-- .../templates/metrics/custom_summary.html | 10 +- .../templates/metrics/daily_summary.html | 10 +- .../templates/metrics/hourly_summary.html | 12 +- .../templates/metrics/monthly_summary.html | 10 +- .../templates/metrics/quarterly_summary.html | 10 +- .../templates/metrics/weekly_summary.html | 10 +- .../templates/metrics/yearly_summary.html | 10 +- apimanager/metrics/views.py | 169 +++++++++--------- 9 files changed, 139 insertions(+), 144 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 2edef8a..916ac52 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -212,16 +212,16 @@ class CustomSummaryForm(forms.Form): required=True, initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) - exclude_app_names = forms.CharField( - label=_('Exclude App Names'), - widget=forms.TextInput( - attrs={ - 'class': FORM_CONTROL, - } - ), - required=False, - initial='API-Manager', - ) + #exclude_app_names = forms.CharField( + # label=_('Exclude App Names'), + # widget=forms.TextInput( + # attrs={ + # 'class': FORM_CONTROL, + # } + # ), + # required=False, + # initial='API-Manager', + #) #include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) include_obp_apps = forms.BooleanField(required=False) @@ -237,18 +237,16 @@ class MonthlyMetricsSummaryForm(forms.Form): #initial=str(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')), initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) - exclude_app_names = forms.CharField( - label=_('Exclude App Names'), - widget=forms.TextInput( - attrs={ - 'class': FORM_CONTROL, - } - ), - required=False, - initial='API-Manager', - ) - #include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) - include_obp_apps = forms.BooleanField(required=False) + #exclude_app_names = forms.CharField( + # label=_('Exclude App Names'), + # widget=forms.TextInput( + # attrs={ + # 'class': FORM_CONTROL, + # } + # ), + # required=False, + # initial='API-Manager', + #) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index fc18666..2733fb2 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -57,7 +57,7 @@ - +
        @@ -74,10 +74,10 @@
        - + @@ -117,7 +117,7 @@ - +
        {% trans "Total API calls" %}: {{ api_calls }}
        {% trans "Calls per day (last 30 days)" %}:{% trans "Top 10 Consumers" %}: somealt
        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 4145f7a..ada32fe 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -57,7 +57,7 @@ - + @@ -76,10 +76,10 @@ {% trans "Total API calls" %}: {{ api_calls }} - + {% trans "Calls per hour" %}: @@ -120,7 +120,7 @@ {% trans "Top 10 Consumers" %}: somealt - + diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index f48abe8..1decf1a 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -56,7 +56,7 @@ - + @@ -75,13 +75,13 @@ {% trans "API calls" %}: {{ api_calls }} - + {% trans "Calls per minute" %}: - {%for item in calls_per_hour_list%}
        1. {{item}}
      • {% endfor %} + {%for item in calls_per_hour_list%}
      • {{item}}
      • {% endfor %} {% trans "Calls per minute" %}: @@ -118,7 +118,7 @@ {% trans "Top APIs" %}: somealt - + diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 5a095ac..c0cee4f 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -52,7 +52,7 @@ - + @@ -71,10 +71,10 @@ {% trans "Total API calls" %}: {{ api_calls }} - + {% trans "Calls per day" %}: @@ -114,7 +114,7 @@ {% trans "Top 10 Consumers" %}: somealt - + diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index e9d121d..3490cb3 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -56,7 +56,7 @@ - + @@ -75,10 +75,10 @@ {% trans "Total API calls" %}: {{ api_calls }} - + {% trans "Calls per month" %}: @@ -123,7 +123,7 @@ {% trans "Top 10 Consumers" %}: somealt - + diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 7d0c39b..18a8257 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -58,7 +58,7 @@ - +
        @@ -75,10 +75,10 @@ {% trans "Total API calls" %}: {{ api_calls }} - + {% trans "Calls per day" %}: @@ -119,7 +119,7 @@ {% trans "Top 10 Consumers" %}: somealt - +
        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index d6a2735..505c8dd 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -58,7 +58,7 @@ - +
        @@ -75,10 +75,10 @@ {% trans "Total API calls" %}: {{ api_calls }} - + {% trans "Calls per month" %}: @@ -119,7 +119,7 @@ {% trans "Top 10 Consumers" %}: somealt - +
        diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 27152a2..6cde57d 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -247,7 +247,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return params - def get_aggregate_metrics(self, from_date, to_date, is_included_obp_apps, only_show_api_explorer_metrics = False): + def get_aggregate_metrics(self, from_date, to_date): """ Gets the metrics from the API, using given parameters, There are different use cases, so we accept different parameters. @@ -256,15 +256,16 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): try: api_calls_total = 0 average_response_time = 0 - urlpath = '/management/aggregate-metrics' - if only_show_api_explorer_metrics: - urlpath = urlpath + '?from_date={}&to_date={}&app_name={}'.format(from_date, to_date, API_EXPLORER_APP_NAME) - elif ((not only_show_api_explorer_metrics) and (not is_included_obp_apps)): - urlpath = urlpath + '?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date, to_date, ",".join(local_settings.EXCLUDE_APPS),",".join(local_settings.EXCLUDE_FUNCTIONS), ",".join(local_settings.EXCLUDE_URL_PATTERN)) - else: - urlpath = urlpath + '?from_date={}&to_date={}'.format(from_date, to_date) - cache_key = get_cache_key_for_current_call(self.request, urlpath) + url_path = '/management/aggregate-metrics' + #if only_show_api_explorer_metrics: + # urlpath = urlpath + '?from_date={}&to_date={}&app_name={}'.format(from_date, to_date) + #elif (not only_show_api_explorer_metrics): + # urlpath = urlpath + '?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + # from_date, to_date, ",".join(local_settings.EXCLUDE_FUNCTIONS), ",".join(local_settings.EXCLUDE_URL_PATTERN)) + # + #else: + url_path = url_path + '?from_date={}&to_date={}'.format(from_date, to_date) + cache_key = get_cache_key_for_current_call(self.request, url_path) api_cache = None try: api_cache = cache.get(cache_key) @@ -274,13 +275,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): metrics = api_cache else: api = API(self.request.session.get('obp')) - metrics = api.get(urlpath) + metrics = api.get(url_path) api_cache = cache.set(cache_key, metrics) - LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, urlpath)) + LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, url_path)) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key)) api_calls_total, average_calls_per_day, average_response_time = self.get_internal_api_call_metrics( - api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, urlpath) + api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, url_path) return api_calls_total, average_response_time, int(average_calls_per_day) except APIError as err: error_once_only(self.request, err) @@ -298,34 +299,28 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): average_calls_per_day = api_calls_total if (number_of_days == 0) else api_calls_total / number_of_days return api_calls_total, average_calls_per_day, average_response_time - def get_aggregate_metrics_api_explorer(self, from_date, to_date): - return self.get_aggregate_metrics(from_date, to_date, True, True) - - def get_active_apps(self, is_included_obp_apps, from_date, to_date, exclude_app_names): + def get_active_apps(self, from_date, to_date): """ Gets the metrics from the API, using given parameters, - There are different use cases, so we accept different parameters. - only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ apps = [] form = self.get_form() active_apps_list = [] - if is_included_obp_apps: - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}'.format(from_date, to_date, exclude_app_names) - api = API(self.request.session.get('obp')) - try: - apps = api.get(urlpath) - if apps is not None and 'code' in apps and apps['code']==403: - error_once_only(self.request, apps['message']) - else: - active_apps_list = list(apps) - except APIError as err: - error_once_only(self.request, err) - except Exception as err: - error_once_only(self.request, err) + 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) + if apps is not None and 'code' in apps and apps['code']==403: + error_once_only(self.request, apps['message']) + else: + active_apps_list = list(apps) + except APIError as err: + error_once_only(self.request, err) + except Exception as err: + error_once_only(self.request, err) else: - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + from_date, to_date, ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) api = API(self.request.session.get('obp')) try: apps = api.get(urlpath) @@ -356,10 +351,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): app_names.append(apps["app_name"]) # If include OBP Apps is selected - if not cleaned_data.get('include_obp_apps'): - for app in app_names: - if app in local_settings.EXCLUDE_APPS: - app_names.remove(app) + #if not cleaned_data.get('include_obp_apps'): + # for app in app_names: + # if app in local_settings.EXCLUDE_APPS: + # app_names.remove(app) app_names = list(filter(None, app_names)) @@ -401,7 +396,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, err) return apps_list - def calls_per_delta(self, is_included_obp_apps, from_date_string, to_date_string, exclude_app_names, **delta ): + def calls_per_delta(self, from_date_string, to_date_string, **delta ): """ return how many calls were made in total per given delta. Here we need to convert date_string to datetime object, and calculate the dates. @@ -420,7 +415,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): # here we need to first convert datetime object to String form_date= from_datetime_object.strftime(API_DATE_FORMAT) to_date= time_delta_in_loop.strftime(API_DATE_FORMAT) - aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, is_included_obp_apps) + aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, ) result = aggregate_metrics[0] result_list_pure.append(result) result_list.append('{} - {} # {}'.format(from_datetime_object, time_delta_in_loop, result)) @@ -435,20 +430,20 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return (result_list, result_list_pure, date_list) - def calls_per_month(self, is_included_obp_apps, from_date, to_date, exclude_app_names): + def calls_per_month(self,from_date, to_date): """ Convenience function to print number of calls per month It is actually 30 days, not a month """ - calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date, exclude_app_names, days=30) + calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(from_date, to_date, days=30) return calls_per_month_list, calls_per_month, month_list - def calls_per_day(self, is_included_obp_apps, from_date, to_date, exclude_app_names): + def calls_per_day(self,from_date, to_date): """ Convenience function to print number of calls per day """ - calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date,exclude_app_names, days=1) + calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(from_date, to_date, days=1) if len(calls_per_day) >= 90: calls_per_day = calls_per_day[-90:] @@ -462,18 +457,18 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return calls_per_day, calls_per_day_pure, date_list - def calls_per_half_day(self, is_included_obp_apps, from_date): + def calls_per_half_day(self,from_date): """ Convenience function to print number of calls per half day """ - return self.calls_per_delta(is_included_obp_apps, from_date, exclude_app_names, hours=12) + return self.calls_per_delta(from_date, hours=12) - def calls_per_hour(self, is_included_obp_apps, from_date, to_date, exclude_app_names): + def calls_per_hour(self,from_date, to_date): """ Convenience function to print number of calls per hour """ - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(is_included_obp_apps, from_date, to_date, exclude_app_names, hours=1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(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): @@ -638,11 +633,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_top_apis(self, cleaned_data, from_date, to_date): top_apis = [] - if cleaned_data.get('include_obp_apps'): - urlpath = '/management/metrics/top-apis?from_date={}&to_date={}'.format(from_date, to_date) - else: - urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + #if cleaned_data.get('include_obp_apps'): + # urlpath = '/management/metrics/top-apis?from_date={}&to_date={}'.format(from_date, to_date) + #else: + # urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + # from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + urlpath = '/management/metrics/top-apis?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + from_date, to_date, ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) top_apis = self._api_data(urlpath, 'top_apis') for api in top_apis: @@ -657,11 +654,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def get_top_consumers(self, cleaned_data, from_date, to_date): top_consumers = [] - if cleaned_data.get('include_obp_apps'): - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) - else: - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( - from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + #if cleaned_data.get('include_obp_apps'): + # urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}'.format(from_date, to_date) + #else: + # urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + # from_date, to_date, ",".join(local_settings.EXCLUDE_APPS), ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) + urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + from_date, to_date, ",".join(EXCLUDE_FUNCTIONS), ",".join(EXCLUDE_URL_PATTERN)) top_consumers = self._api_data(urlpath, 'top_consumers') for consumer in top_consumers: @@ -686,11 +685,11 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): error_once_only(self.request, err) return top_warehouse_calls - def get_top_apps_using_warehouse(self, from_date, to_date, exclude_app_names): + def get_top_apps_using_warehouse(self, from_date, to_date): top_apps_using_warehouse = [] - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_app_names={}&implemented_by_partial_function={}'.format( - from_date, to_date, exclude_app_names, "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) @@ -781,8 +780,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): calls_per_hour_list=[] per_hour_chart=[] if form.is_valid(): - is_included_obp_apps = form.cleaned_data.get('include_obp_apps') - exclude_app_names = form.cleaned_data.get("exclude_app_names") + # = form.cleaned_data.get('include_obp_apps') + #exclude_app_names = form.cleaned_data.get("exclude_app_names") #if exclude_app_names not in local_settings.EXCLUDE_APPS: # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] @@ -791,41 +790,43 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. from_date = return_to_days_ago(to_date, 1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(from_date, to_date) per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') if (web_page_type == SummaryType.WEEKLY): # for one month, the from_date is 7 days ago. from_date = return_to_days_ago(to_date, 7) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") if (web_page_type == SummaryType.MONTHLY): # for one month, the from_date is 30 days ago. from_date = return_to_days_ago(to_date, 30) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') if (web_page_type == SummaryType.YEARLY): from_date = return_to_days_ago(to_date, 365) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + #calls_per_month_list, calls_per_month, month_list = self.calls_per_month(, from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") if (web_page_type == SummaryType.CUSTOM): # for one month, the from_date is x day ago. form_from_date_string = form.data['from_date_custom'] from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + #calls_per_day_list, calls_per_day, date_list = self.calls_per_day(, from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") api_host_name = API_HOST - top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date, exclude_app_names) + 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() median_time_to_first_api_call = self.median_time_to_first_api_call(from_date, to_date) @@ -834,19 +835,15 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): top_consumers = self.get_top_consumers(form.cleaned_data, from_date, to_date) top_consumers_bar_chart = self.plot_topconsumer_bar_chart(top_consumers) top_warehouse_calls = self.get_top_warehouse_calls(form.cleaned_data, from_date, to_date) - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(from_date, to_date,is_included_obp_apps) - 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) - + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(from_date, to_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_list = self.get_active_apps(is_included_obp_apps, from_date, to_date, exclude_app_names) + active_apps_list = self.get_active_apps(from_date, to_date) context = super(MonthlyMetricsSummaryView, self).get_context_data(**kwargs) context.update({ 'form': form, 'api_calls': api_calls, - 'calls_by_api_explorer': calls_by_api_explorer, 'calls_per_month_list': calls_per_month_list, 'per_month_chart': per_month_chart, 'per_day_chart': per_day_chart, @@ -868,54 +865,54 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): 'top_apis_bar_chart': top_apis_bar_chart, 'top_consumers_bar_chart': top_consumers_bar_chart, 'median_time_to_first_api_call': median_time_to_first_api_call, - 'excluded_apps':[exclude_app_names if exclude_app_names in local_settings.EXCLUDE_APPS else "null"], + #'excluded_apps':[exclude_app_names if exclude_app_names in local_settings.EXCLUDE_APPS else "null"], }) return context else: error_once_only(self.request, str(form.errors)) except Exception as err: error_once_only(self.request, err) - def _daily_and_weekly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_hour_chart, per_day_chart, from_date): + def _daily_and_weekly(self, web_page_type,to_date, per_hour_chart, per_day_chart, from_date): if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. from_date = return_to_days_ago(to_date, 1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(from_date, to_date) per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') if (web_page_type == SummaryType.WEEKLY): # for one month, the from_date is 7 days ago. from_date = return_to_days_ago(to_date, 7) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") return (from_date, per_hour_chart, per_day_chart) - def _monthly_and_quarterly(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_day_chart, per_month_chart, from_date): + def _monthly_and_quarterly(self, web_page_type,to_date, per_day_chart, per_month_chart, from_date): if (web_page_type == SummaryType.MONTHLY): # for one month, the from_date is 30 days ago. from_date = return_to_days_ago(to_date, 30) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') return (from_date, per_day_chart, per_month_chart) - def _yearly_and_custom(self, web_page_type, is_included_obp_apps, to_date, exclude_app_names, per_month_chart, per_day_chart, from_date): + def _yearly_and_custom(self, web_page_type,to_date, per_month_chart, per_day_chart, from_date): if (web_page_type == SummaryType.YEARLY): from_date = return_to_days_ago(to_date, 365) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") if (web_page_type == SummaryType.CUSTOM): # for one month, the from_date is x day ago. form_from_date_string = form.data['from_date_custom'] from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(is_included_obp_apps, from_date, to_date, exclude_app_names) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") return (from_date, per_month_chart, per_day_chart) From 40f815bb8b3012945f9b757012d4048500c495d3 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Tue, 7 Feb 2023 13:30:10 +0100 Subject: [PATCH 69/85] simplify/ Metric --- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 1decf1a..74e3661 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -81,7 +81,7 @@ --> {% trans "Calls per minute" %}: - {%for item in calls_per_hour_list%}
      • {{item}}
      • {% endfor %} + {%for item in calls_per_hour_list%}
        1. {{item}}
      • {% endfor %} {% trans "Calls per minute" %}: From 5b4580fc1c62ab53df8fe653432b928274dfecea Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 10:15:45 +0100 Subject: [PATCH 70/85] add filed Include_app_name --- apimanager/metrics/forms.py | 41 +++++++++---------- .../templates/metrics/monthly_summary.html | 6 +-- .../templates/metrics/yearly_summary.html | 6 +-- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index 916ac52..fd680c2 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -212,18 +212,16 @@ class CustomSummaryForm(forms.Form): required=True, initial=(datetime.now() - timedelta(6)).strftime(API_MANAGER_DATE_FORMAT), ) - #exclude_app_names = forms.CharField( - # label=_('Exclude App Names'), - # widget=forms.TextInput( - # attrs={ - # 'class': FORM_CONTROL, - # } - # ), - # required=False, - # initial='API-Manager', - #) - #include_obp_apps = forms.BooleanField(required=False, label=_('Include System Data')) - include_obp_apps = forms.BooleanField(required=False) + include_app_names = forms.CharField( + label=_('Include App Names'), + widget=forms.TextInput( + attrs={ + 'class': FORM_CONTROL, + } + ), + required=False, + ) + def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') @@ -237,16 +235,15 @@ class MonthlyMetricsSummaryForm(forms.Form): #initial=str(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')), initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) - #exclude_app_names = forms.CharField( - # label=_('Exclude App Names'), - # widget=forms.TextInput( - # attrs={ - # 'class': FORM_CONTROL, - # } - # ), - # required=False, - # initial='API-Manager', - #) + include_app_names = forms.CharField( + label=_('Include App Names'), + widget=forms.TextInput( + attrs={ + 'class': FORM_CONTROL, + } + ), + required=False, + ) def __init__(self, *args, **kwargs): kwargs.setdefault('label_suffix', '') diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index c0cee4f..5cc4082 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -45,10 +45,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 505c8dd..28ce3eb 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -51,10 +51,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        From 42b7b0a3762498900845d59a66141dc4c886b049 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 10:18:38 +0100 Subject: [PATCH 71/85] add filed Include_app_names --- apimanager/metrics/templates/metrics/custom_summary.html | 6 +++--- apimanager/metrics/templates/metrics/daily_summary.html | 6 +++--- apimanager/metrics/templates/metrics/hourly_summary.html | 6 +++--- apimanager/metrics/templates/metrics/quarterly_summary.html | 6 +++--- apimanager/metrics/templates/metrics/weekly_summary.html | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 2733fb2..dce0171 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -50,10 +50,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index ada32fe..74f8915 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -50,10 +50,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 74e3661..ea7f147 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -49,10 +49,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 3490cb3..dd48a2d 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -49,10 +49,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 18a8257..76c9e27 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -51,10 +51,10 @@
        - {% if form.exclude_app_names.errors %}
        {{ form.exclude_app_names.errors }}
        {% endif %} + {% if form.include_app_names.errors %}
        {{ form.include_app_names.errors }}
        {% endif %}
        - {{ form.exclude_app_names.label_tag }} - {{ form.exclude_app_names }} + {{ form.include_app_names.label_tag }} + {{ form.include_app_names }}
        From a5d8d1ad690e842e45c61a23168c9e42bcce5810 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 11:25:09 +0100 Subject: [PATCH 72/85] add raise if debug and add include_app_names --- apimanager/apimanager/settings.py | 2 +- apimanager/metrics/views.py | 87 +++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/apimanager/apimanager/settings.py b/apimanager/apimanager/settings.py index dd26105..9c918ae 100644 --- a/apimanager/apimanager/settings.py +++ b/apimanager/apimanager/settings.py @@ -27,7 +27,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = None # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 6cde57d..c3b82d0 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -11,7 +11,7 @@ from enum import Enum from django.conf import settings from apimanager import local_settings -from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATE_FORMAT, API_DATE_TIME_FORMAT +from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATE_FORMAT, API_DATE_TIME_FORMAT, DEBUG from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView @@ -146,10 +146,16 @@ class MetricsView(LoginRequiredMixin, TemplateView): metrics = api.get(urlpath) metrics = self.to_django(metrics['metrics']) except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except KeyError as err: + if DEBUG: + raise(err) error_once_only(self.request, metrics['message']) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return metrics @@ -246,14 +252,17 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): params = '&'.join(params) return params + def get_app_name_parameters(self, include_app_names): + return "Simon Say" + include_app_names - def get_aggregate_metrics(self, from_date, to_date): + def get_aggregate_metrics(self, from_date, to_date, include_app_names): """ Gets the metrics from the API, using given parameters, There are different use cases, so we accept different parameters. only_show_api_explorer_metrics has the default value False, because it is just used for app = API_Explorer. """ try: + print("get_app_name_parameters is: ", self.get_app_name_parameters(include_app_names)) api_calls_total = 0 average_response_time = 0 url_path = '/management/aggregate-metrics' @@ -284,8 +293,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, url_path) return api_calls_total, average_response_time, int(average_calls_per_day) except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) def get_internal_api_call_metrics(self, api_calls_total, average_response_time, cache_key, from_date, metrics, @@ -317,6 +330,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except APIError as err: error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) else: urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( @@ -326,8 +341,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): apps = api.get(urlpath) active_apps_list = list(apps['top_consumers']) except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return active_apps_list @@ -391,12 +410,16 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, urlpath)) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key)) except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return apps_list - def calls_per_delta(self, from_date_string, to_date_string, **delta ): + def calls_per_delta(self, from_date_string, to_date_string, include_app_names, **delta ): """ return how many calls were made in total per given delta. Here we need to convert date_string to datetime object, and calculate the dates. @@ -415,12 +438,14 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): # here we need to first convert datetime object to String form_date= from_datetime_object.strftime(API_DATE_FORMAT) to_date= time_delta_in_loop.strftime(API_DATE_FORMAT) - aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, ) + aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, include_app_names) result = aggregate_metrics[0] result_list_pure.append(result) result_list.append('{} - {} # {}'.format(from_datetime_object, time_delta_in_loop, result)) date_list.append(from_datetime_object) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) break @@ -430,20 +455,20 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return (result_list, result_list_pure, date_list) - def calls_per_month(self,from_date, to_date): + def calls_per_month(self,from_date, to_date, include_app_names): """ Convenience function to print number of calls per month It is actually 30 days, not a month """ - calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(from_date, to_date, days=30) + calls_per_month_list, calls_per_month, month_list = self.calls_per_delta(from_date, to_date, include_app_names, days=30) return calls_per_month_list, calls_per_month, month_list - def calls_per_day(self,from_date, to_date): + def calls_per_day(self,from_date, to_date, include_app_names): """ Convenience function to print number of calls per day """ - calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(from_date, to_date, days=1) + calls_per_day, calls_per_day_pure, date_list = self.calls_per_delta(from_date, to_date, include_app_names, days=1) if len(calls_per_day) >= 90: calls_per_day = calls_per_day[-90:] @@ -457,18 +482,18 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return calls_per_day, calls_per_day_pure, date_list - def calls_per_half_day(self,from_date): + def calls_per_half_day(self,from_date, include_app_names): """ Convenience function to print number of calls per half day """ return self.calls_per_delta(from_date, hours=12) - def calls_per_hour(self,from_date, to_date): + def calls_per_hour(self,from_date, to_date, include_app_names): """ Convenience function to print number of calls per hour """ - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(from_date, to_date, hours=1) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_delta(from_date, to_date, include_app_names, hours=1) return calls_per_hour_list, calls_per_hour, hour_list def plot_line_chart(self, plot_data, date_month_list, period): @@ -602,6 +627,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except KeyError as err: messages.error(self.request, 'KeyError: {}'.format(err)) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse)) @@ -626,8 +653,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: data = data[data_key] except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return data @@ -680,8 +711,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if "elasticSearchWarehouse" in api['Implemented_by_partial_function']: top_warehouse_calls.append(api) except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return top_warehouse_calls @@ -699,8 +734,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2] except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) return top_apps_using_warehouse @@ -757,8 +796,12 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): except APIError as err: + if DEBUG: + raise(err) error_once_only(self.request, err) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, 'Unknown Error. {}'.format(err)) if times_to_first_call: @@ -781,7 +824,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): per_hour_chart=[] if form.is_valid(): # = form.cleaned_data.get('include_obp_apps') - #exclude_app_names = form.cleaned_data.get("exclude_app_names") + include_app_names = form.cleaned_data.get("include_app_names") #if exclude_app_names not in local_settings.EXCLUDE_APPS: # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] @@ -790,31 +833,31 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. from_date = return_to_days_ago(to_date, 1) - calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(from_date, to_date) + calls_per_hour_list, calls_per_hour, hour_list = self.calls_per_hour(from_date, to_date, include_app_names) per_hour_chart = self.plot_line_chart(calls_per_hour, hour_list, 'hour') if (web_page_type == SummaryType.WEEKLY): # for one month, the from_date is 7 days ago. from_date = return_to_days_ago(to_date, 7) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date, include_app_names) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") if (web_page_type == SummaryType.MONTHLY): # for one month, the from_date is 30 days ago. from_date = return_to_days_ago(to_date, 30) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date, include_app_names) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date, include_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') if (web_page_type == SummaryType.YEARLY): from_date = return_to_days_ago(to_date, 365) #calls_per_month_list, calls_per_month, month_list = self.calls_per_month(, from_date, to_date) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date, include_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") if (web_page_type == SummaryType.CUSTOM): @@ -822,7 +865,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): form_from_date_string = form.data['from_date_custom'] from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) #calls_per_day_list, calls_per_day, date_list = self.calls_per_day(, from_date, to_date) - calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date) + calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date,include_app_names) per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") api_host_name = API_HOST @@ -835,7 +878,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): top_consumers = self.get_top_consumers(form.cleaned_data, from_date, to_date) top_consumers_bar_chart = self.plot_topconsumer_bar_chart(top_consumers) top_warehouse_calls = self.get_top_warehouse_calls(form.cleaned_data, from_date, to_date) - api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(from_date, to_date) + api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(from_date, to_date, include_app_names) 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(from_date, to_date) @@ -871,6 +914,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): else: error_once_only(self.request, str(form.errors)) except Exception as err: + if DEBUG: + raise(err) error_once_only(self.request, err) def _daily_and_weekly(self, web_page_type,to_date, per_hour_chart, per_day_chart, from_date): if (web_page_type == SummaryType.DAILY): @@ -897,7 +942,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): if (web_page_type == SummaryType.QUARTERLY): # for one quarter, the from_date is 90 days ago. from_date = (datetime.datetime.strptime(to_date, API_DATE_FORMAT) - timedelta(90)).strftime(API_DATE_FORMAT) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date, include_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, 'month') return (from_date, per_day_chart, per_month_chart) @@ -905,7 +950,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): def _yearly_and_custom(self, web_page_type,to_date, per_month_chart, per_day_chart, from_date): if (web_page_type == SummaryType.YEARLY): from_date = return_to_days_ago(to_date, 365) - calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date) + calls_per_month_list, calls_per_month, month_list = self.calls_per_month(from_date, to_date, include_app_names) per_month_chart = self.plot_line_chart(calls_per_month, month_list, "month") if (web_page_type == SummaryType.CUSTOM): From c49f044b8d06f32e2f02c523aa34ccddaa3bc3b8 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 13:32:20 +0100 Subject: [PATCH 73/85] add get_app_name_parameters --- apimanager/metrics/views.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index c3b82d0..42c69b7 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -253,8 +253,34 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): return params def get_app_name_parameters(self, include_app_names): - return "Simon Say" + include_app_names - + #if len(app_names) == 1: + # return + #1. Parse include_app_names create a list using a commo (,) separator + #2. Trim each word (remove space), + #3. Then is one word, &app_name = thing + #4. IF IT IS MORE than one word then return number of app without space + #5. return either &app_name=thing + #6. Or + #7. return &include_app_names=thing1,thing2, + #8. url encode + #app_names = [] + #input_string = "simon says, foo, bar , App 2 " + input_string = include_app_names.strip() + result = "" + if input_string != "": + input_list = input_string.split(",") + print("input_list is:", input_list) + cleaned_list = [item.strip() for item in input_list] + print("cleaned_list is: ", cleaned_list) + cleaned_string=', '.join([str(item) for item in cleaned_list]) + url_encoded_string = cleaned_string + if len(cleaned_list) == 0: + result = "" + elif len(cleaned_list) == 1: + result = "&app_name={}".format(url_encoded_string) + else: + result = "&include_app_names={}".format(url_encoded_string) + return result def get_aggregate_metrics(self, from_date, to_date, include_app_names): """ Gets the metrics from the API, using given parameters, @@ -273,7 +299,9 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): # from_date, to_date, ",".join(local_settings.EXCLUDE_FUNCTIONS), ",".join(local_settings.EXCLUDE_URL_PATTERN)) # #else: - url_path = url_path + '?from_date={}&to_date={}'.format(from_date, to_date) + url_path = url_path + '?from_date={}&to_date={}{}'.format(from_date, to_date, self.get_app_name_parameters(include_app_names)) + print("get_app_name_parameters(include_app_names) is:", self.get_app_name_parameters(include_app_names)) + print("url_path is: ", url_path) cache_key = get_cache_key_for_current_call(self.request, url_path) api_cache = None try: From b581072ed9bced35c0e7eff290505bf4340ab5b5 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 14:18:03 +0100 Subject: [PATCH 74/85] add urlencode --- apimanager/metrics/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 42c69b7..b5704c0 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -33,6 +33,8 @@ import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import statistics +import urllib.parse + CACHE_SETTING_URL_MSG = "The cache setting url is" CACHE_SETTING_KEY_MSG = "The cache setting key is" @@ -268,12 +270,14 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): input_string = include_app_names.strip() result = "" if input_string != "": - input_list = input_string.split(",") + input_list = input_string.strip().split(",") print("input_list is:", input_list) cleaned_list = [item.strip() for item in input_list] print("cleaned_list is: ", cleaned_list) cleaned_string=', '.join([str(item) for item in cleaned_list]) - url_encoded_string = cleaned_string + print("cleaned_string is:", cleaned_string) + url_encoded_string = urllib.parse.quote(cleaned_string) + print("url_encoded_string is:", url_encoded_string) if len(cleaned_list) == 0: result = "" elif len(cleaned_list) == 1: From ccb25015014f9f9347175e211950fd8d1f5b7a82 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Thu, 9 Feb 2023 14:22:21 +0100 Subject: [PATCH 75/85] improved include_app_names --- apimanager/metrics/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index b5704c0..c18a8ea 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -271,13 +271,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): result = "" if input_string != "": input_list = input_string.strip().split(",") - print("input_list is:", input_list) + #print("input_list is:", input_list) cleaned_list = [item.strip() for item in input_list] - print("cleaned_list is: ", cleaned_list) + #print("cleaned_list is: ", cleaned_list) cleaned_string=', '.join([str(item) for item in cleaned_list]) - print("cleaned_string is:", cleaned_string) + #print("cleaned_string is:", cleaned_string) url_encoded_string = urllib.parse.quote(cleaned_string) - print("url_encoded_string is:", url_encoded_string) + #print("url_encoded_string is:", url_encoded_string) if len(cleaned_list) == 0: result = "" elif len(cleaned_list) == 1: @@ -304,8 +304,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): # #else: url_path = url_path + '?from_date={}&to_date={}{}'.format(from_date, to_date, self.get_app_name_parameters(include_app_names)) - print("get_app_name_parameters(include_app_names) is:", self.get_app_name_parameters(include_app_names)) - print("url_path is: ", url_path) + #print("get_app_name_parameters(include_app_names) is:", self.get_app_name_parameters(include_app_names)) + #print("url_path is: ", url_path) cache_key = get_cache_key_for_current_call(self.request, url_path) api_cache = None try: From a54ca83035eb3d7fd541207f41520b7c5aa170e5 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 10:29:28 +0100 Subject: [PATCH 76/85] finish all changes like date, spinner and matric --- apimanager/metrics/forms.py | 23 ++++++++++---- apimanager/metrics/templates/metrics/api.html | 2 +- .../metrics/templates/metrics/connector.html | 2 +- .../templates/metrics/custom_summary.html | 14 ++++++++- .../templates/metrics/daily_summary.html | 2 +- .../templates/metrics/hourly_summary.html | 2 +- .../templates/metrics/monthly_summary.html | 2 +- .../templates/metrics/quarterly_summary.html | 2 +- .../templates/metrics/weekly_summary.html | 2 +- .../templates/metrics/yearly_summary.html | 2 +- apimanager/metrics/views.py | 30 ++++++++++++++----- 11 files changed, 61 insertions(+), 22 deletions(-) diff --git a/apimanager/metrics/forms.py b/apimanager/metrics/forms.py index fd680c2..bcbd0e0 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -20,16 +20,27 @@ TO_DATE = 'To Date' class MetricsForm(forms.Form): from_date = forms.DateTimeField( - label=_(FROM_DATE), - widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), + label=_('From Date'), + input_formats=[settings.API_DATEFORMAT], + widget=forms.DateTimeInput( + attrs={ + 'placeholder': str((datetime.now()-timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%S.%fZ')), + 'class': 'form-control', + } + ), + #initial='2020-01-01T00:00:00.000Z', required=False, - initial=(datetime.now() - timedelta(30)).strftime(API_MANAGER_DATE_FORMAT), ) to_date = forms.DateTimeField( - label=_(TO_DATE), - widget=DatePickerInput(format=API_MANAGER_DATE_FORMAT), + label=_('To Date'), + input_formats=[settings.API_DATEFORMAT], + widget=forms.DateTimeInput( + attrs={ + 'placeholder': str((datetime.now()).strftime('%Y-%m-%dT%H:%M:%S.%fZ')), + 'class': 'form-control', + } + ), required=False, - initial=str(datetime.now().strftime(API_MANAGER_DATE_FORMAT)), ) limit = forms.IntegerField( label=_('Limit'), diff --git a/apimanager/metrics/templates/metrics/api.html b/apimanager/metrics/templates/metrics/api.html index cca977c..f6a6be4 100644 --- a/apimanager/metrics/templates/metrics/api.html +++ b/apimanager/metrics/templates/metrics/api.html @@ -120,7 +120,7 @@ - + diff --git a/apimanager/metrics/templates/metrics/connector.html b/apimanager/metrics/templates/metrics/connector.html index a214f95..cc67afc 100644 --- a/apimanager/metrics/templates/metrics/connector.html +++ b/apimanager/metrics/templates/metrics/connector.html @@ -72,7 +72,7 @@ - + diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index dce0171..4cb3001 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -58,12 +58,24 @@ +
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From: " %}{{ from_date }} {% trans "To: " %}{{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 74f8915..3233c4e 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -65,7 +65,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index ea7f147..a10e180 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 5cc4082..cc1a553 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -60,7 +60,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index dd48a2d..64c220b 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}:{% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 76c9e27..7624d7b 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 28ce3eb..7832d6b 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index c18a8ea..1033dd2 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -305,26 +305,32 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): #else: url_path = url_path + '?from_date={}&to_date={}{}'.format(from_date, to_date, self.get_app_name_parameters(include_app_names)) #print("get_app_name_parameters(include_app_names) is:", self.get_app_name_parameters(include_app_names)) - #print("url_path is: ", url_path) cache_key = get_cache_key_for_current_call(self.request, url_path) + #print("cache_key is: ", cache_key) #return cache_key api_cache = None try: api_cache = cache.get(cache_key) + print("Cache HIT is:", api_cache) + #print("api_cache is: ", api_cache) #return fields name,which use cashe e.g. [{'count': 39814, 'average_response_time': 71.01, 'minimum_response_time': 1.0, 'maximum_response_time': 20229.0}] except Exception as err: api_cache = None if not api_cache is None: metrics = api_cache + #print("metrics1 is:", metrics) #same response like api_cache is: else: api = API(self.request.session.get('obp')) + print("Cache MISS is:", api) metrics = api.get(url_path) + print("Cache HIT is: ", metrics) ##same response like api_cache is: api_cache = cache.set(cache_key, metrics) + #print("api_cache is", api_cache) #return none LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, url_path)) LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key)) api_calls_total, average_calls_per_day, average_response_time = self.get_internal_api_call_metrics( api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, url_path) return api_calls_total, average_response_time, int(average_calls_per_day) - except APIError as err: + except APIError as err: #if API rasie any error then going for debug bug. if DEBUG: raise(err) error_once_only(self.request, err) @@ -471,6 +477,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): form_date= from_datetime_object.strftime(API_DATE_FORMAT) to_date= time_delta_in_loop.strftime(API_DATE_FORMAT) aggregate_metrics = self.get_aggregate_metrics(form_date, to_date, include_app_names) + print("aggregate_metrics is", aggregate_metrics) result = aggregate_metrics[0] result_list_pure.append(result) result_list.append('{} - {} # {}'.format(from_datetime_object, time_delta_in_loop, result)) @@ -856,11 +863,13 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): per_hour_chart=[] if form.is_valid(): # = form.cleaned_data.get('include_obp_apps') - include_app_names = form.cleaned_data.get("include_app_names") + include_app_names = form.cleaned_data.get("include_app_names") #getting a element out of dictionary #if exclude_app_names not in local_settings.EXCLUDE_APPS: # error_once_only(self.request, "Invalid Exclude App Name, Please select" + str(local_settings.EXCLUDE_APPS) + "Anyone of these") form_to_date_string = form.data['to_date'] + print("form_to_date_string is:", form_to_date_string) to_date = convert_form_date_to_obpapi_datetime_format(form_to_date_string) + print("to_date is:", to_date) if (web_page_type == SummaryType.DAILY): # for one day, the from_date is 1 day ago. @@ -898,7 +907,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) #calls_per_day_list, calls_per_day, date_list = self.calls_per_day(, from_date, to_date) calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date,include_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + if (len(calls_per_day) <= 31): + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + else: + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "month") api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) @@ -911,6 +923,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): top_consumers_bar_chart = self.plot_topconsumer_bar_chart(top_consumers) top_warehouse_calls = self.get_top_warehouse_calls(form.cleaned_data, from_date, to_date) api_calls, average_response_time, average_calls_per_day = self.get_aggregate_metrics(from_date, to_date, include_app_names) + print("api_calls, average_response_time, average_calls_per_day is:", api_calls, average_response_time, average_calls_per_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(from_date, to_date) @@ -934,8 +947,11 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), - 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), + 'include_app_names': include_app_names, + #'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%d %B %Y'), + #'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), + 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%d %B %Y'), 'top_apis': top_apis, 'top_apis_bar_chart': top_apis_bar_chart, 'top_consumers_bar_chart': top_consumers_bar_chart, @@ -1017,4 +1033,4 @@ class HourlySummaryView(MonthlyMetricsSummaryView): class CustomSummaryView(MonthlyMetricsSummaryView): form_class = CustomSummaryForm template_name = 'metrics/custom_summary.html' - def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) \ No newline at end of file + def get_context_data(self, **kwargs): return self.prepare_general_context(SummaryType.CUSTOM, **kwargs) From d5d5c43dfdfdbeecc7406288d6564caaca8efd04 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 10:41:49 +0100 Subject: [PATCH 77/85] change selecting Date format in Metric --- apimanager/metrics/templates/metrics/api.html | 2 +- apimanager/metrics/templates/metrics/connector.html | 2 +- apimanager/metrics/templates/metrics/custom_summary.html | 2 +- apimanager/metrics/templates/metrics/daily_summary.html | 2 +- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- apimanager/metrics/templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/templates/metrics/quarterly_summary.html | 2 +- apimanager/metrics/templates/metrics/weekly_summary.html | 2 +- apimanager/metrics/templates/metrics/yearly_summary.html | 2 +- apimanager/metrics/views.py | 5 +++-- 10 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apimanager/metrics/templates/metrics/api.html b/apimanager/metrics/templates/metrics/api.html index cca977c..f6a6be4 100644 --- a/apimanager/metrics/templates/metrics/api.html +++ b/apimanager/metrics/templates/metrics/api.html @@ -120,7 +120,7 @@ - + diff --git a/apimanager/metrics/templates/metrics/connector.html b/apimanager/metrics/templates/metrics/connector.html index a214f95..cc67afc 100644 --- a/apimanager/metrics/templates/metrics/connector.html +++ b/apimanager/metrics/templates/metrics/connector.html @@ -72,7 +72,7 @@ - + diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index dce0171..5b3df85 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From: " %}{{ from_date }} {% trans "To: " %}{{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 74f8915..be1bc3b 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -65,7 +65,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index ea7f147..a318b9f 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From" %}{{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index 5cc4082..e445745 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -60,7 +60,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}: {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index dd48a2d..40db960 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %}:{% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 76c9e27..d0eb52d 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 28ce3eb..500b051 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% trans "Period" %} : {% trans "From" %} {{ from_date }} {% trans "to" %} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index c18a8ea..9b49519 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -919,6 +919,7 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): context.update({ 'form': form, 'api_calls': api_calls, + 'include_app_names': include_app_names, 'calls_per_month_list': calls_per_month_list, 'per_month_chart': per_month_chart, 'per_day_chart': per_day_chart, @@ -934,8 +935,8 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, - 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), - 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%Y-%m-%d'), + 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT)).strftime('%d %B %Y'), + 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT)).strftime('%d %B %Y'), 'top_apis': top_apis, 'top_apis_bar_chart': top_apis_bar_chart, 'top_consumers_bar_chart': top_consumers_bar_chart, From f66cdc85774cc8d2ccec5a08772978b5f14d1a55 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 11:44:46 +0100 Subject: [PATCH 78/85] change selecting Date format in Metric --- apimanager/metrics/templates/metrics/custom_summary.html | 2 +- apimanager/metrics/templates/metrics/daily_summary.html | 2 +- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- apimanager/metrics/templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/templates/metrics/quarterly_summary.html | 2 +- apimanager/metrics/templates/metrics/weekly_summary.html | 2 +- apimanager/metrics/templates/metrics/yearly_summary.html | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 5b3df85..42b18a0 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index be1bc3b..3233c4e 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -65,7 +65,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index a318b9f..a10e180 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index e445745..cc1a553 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -60,7 +60,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 40db960..64c220b 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index d0eb52d..7624d7b 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 500b051..7832d6b 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} {{ to_date }}

        +

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        From dd6006b4eaab7bcb32dff8cfc789e66a8ae1d3e9 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 12:16:38 +0100 Subject: [PATCH 79/85] change selecting --- apimanager/metrics/templates/metrics/custom_summary.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 42b18a0..99e589a 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,9 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {{ include_app_names }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +
        From 81800b168fc22050ee5dbdebae6c9676d5079424 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 12:46:45 +0100 Subject: [PATCH 80/85] remove colon if not entered any app --- apimanager/metrics/templates/metrics/custom_summary.html | 3 +-- apimanager/metrics/templates/metrics/daily_summary.html | 2 +- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- apimanager/metrics/templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/templates/metrics/quarterly_summary.html | 2 +- apimanager/metrics/templates/metrics/weekly_summary.html | 2 +- apimanager/metrics/templates/metrics/yearly_summary.html | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 99e589a..1bd2651 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,8 +63,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }}

        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 3233c4e..167ca88 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -65,7 +65,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index a10e180..0278d25 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index cc1a553..fe62a84 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -60,7 +60,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 64c220b..cfd701d 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 7624d7b..5c1b126 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 7832d6b..935c879 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {{ include_app_names }} : {{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        From df39ed325a3d5a20768bae05cf04501d787e9d28 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 12:50:20 +0100 Subject: [PATCH 81/85] remove colon if not entered any app --- apimanager/metrics/templates/metrics/custom_summary.html | 1 - 1 file changed, 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 1bd2651..ce7ec5e 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -65,7 +65,6 @@

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        -
        From 86600f9da4eebd63d0494ecce2ecf1d63f22e6db Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Mon, 13 Feb 2023 12:52:21 +0100 Subject: [PATCH 82/85] remove colon if not entered any app --- apimanager/metrics/templates/metrics/custom_summary.html | 2 +- apimanager/metrics/templates/metrics/daily_summary.html | 2 +- apimanager/metrics/templates/metrics/hourly_summary.html | 2 +- apimanager/metrics/templates/metrics/monthly_summary.html | 2 +- apimanager/metrics/templates/metrics/quarterly_summary.html | 2 +- apimanager/metrics/templates/metrics/weekly_summary.html | 2 +- apimanager/metrics/templates/metrics/yearly_summary.html | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index ce7ec5e..f44dbe1 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 167ca88..02c2eb4 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -65,7 +65,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 0278d25..bef6d8d 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index fe62a84..2932ed6 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -60,7 +60,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index cfd701d..d47fcfc 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 5c1b126..91d2857 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index 935c879..67d7f76 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -64,7 +64,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        From 7489072e4b348437b624362855907eb95d5fb82c Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Wed, 15 Feb 2023 11:56:23 +0100 Subject: [PATCH 83/85] Change aggregate Metric View from date to month --- apimanager/metrics/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 9b49519..c21657d 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -898,7 +898,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView): from_date = convert_form_date_to_obpapi_datetime_format(form_from_date_string) #calls_per_day_list, calls_per_day, date_list = self.calls_per_day(, from_date, to_date) calls_per_day_list, calls_per_day, date_list = self.calls_per_day(from_date, to_date,include_app_names) - per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + if (len(calls_per_day) <= 31): + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "day") + else: + per_day_chart = self.plot_line_chart(calls_per_day, date_list, "month") api_host_name = API_HOST top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date) From 2463680ab8a3c7aebac71043bb950905ea56dd67 Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Fri, 17 Feb 2023 09:32:25 +0100 Subject: [PATCH 84/85] Add spinner in Search button --- .../static/metrics/js/include_system_calls.js | 10 ++++++++++ .../templates/metrics/custom_summary.html | 17 ++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apimanager/metrics/static/metrics/js/include_system_calls.js b/apimanager/metrics/static/metrics/js/include_system_calls.js index e69de29..461a7f2 100644 --- a/apimanager/metrics/static/metrics/js/include_system_calls.js +++ b/apimanager/metrics/static/metrics/js/include_system_calls.js @@ -0,0 +1,10 @@ +$(document).ready(function () { + $('.spinner').on('click', function() { + var e=this; + setTimeout(function() { + e.innerHTML=' Loading...'; + e.disabled=true; + },0); + return true; + }); +}); diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 4cb3001..358ff21 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -57,19 +57,7 @@ - - +
        @@ -157,6 +145,9 @@ {% endblock %} +{% block extrajs %} + +{% endblock extrajs %} {% block extracss %} {% endblock extracss %} \ No newline at end of file From bc0d050f25399718e44b5eefc8d50e0f638d3a6c Mon Sep 17 00:00:00 2001 From: Reena Aheer Date: Fri, 17 Feb 2023 10:34:59 +0100 Subject: [PATCH 85/85] remove colon if not entered any app --- apimanager/metrics/templates/metrics/custom_summary.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index bb822fa..a95e0b2 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -63,7 +63,7 @@
        {% block tab_content %}
        -

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        +

        {% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ from_date }} - {{ to_date }}

        @@ -144,6 +144,7 @@ {% endblock %} + {% block extrajs %} {% endblock extrajs %}