From fabbf30412ca24db488df73a0b1de77b22acf74a Mon Sep 17 00:00:00 2001 From: Hongwei Date: Wed, 6 Dec 2023 23:56:45 +0100 Subject: [PATCH 1/3] refactor/tweaked the default limit to 5 --- 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 53fd84ac..36692785 100644 --- a/apimanager/metrics/forms.py +++ b/apimanager/metrics/forms.py @@ -43,7 +43,7 @@ class MetricsForm(forms.Form): 'class': FORM_CONTROL, } ), - initial=1000, + initial=5, required=False, ) offset = forms.IntegerField( From 4d197d0776ec83e32dbb8f46e4a34547df23a5aa Mon Sep 17 00:00:00 2001 From: Hongwei Date: Thu, 7 Dec 2023 00:08:11 +0100 Subject: [PATCH 2/3] refactor/tweaked Active Apps to Top 100 --- apimanager/metrics/templates/metrics/custom_summary.html | 2 +- apimanager/metrics/views.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apimanager/metrics/templates/metrics/custom_summary.html b/apimanager/metrics/templates/metrics/custom_summary.html index 77e31152..deee2fcb 100644 --- a/apimanager/metrics/templates/metrics/custom_summary.html +++ b/apimanager/metrics/templates/metrics/custom_summary.html @@ -100,7 +100,7 @@

{% trans "Custom Date Range " %}

- {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index 008a2647..cf48df86 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -344,14 +344,14 @@ def get_internal_api_call_metrics(self, api_calls_total, average_response_time, 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_active_apps(self, from_date, to_date): + def get_top_100_active_apps(self, from_date, to_date): """ Gets the metrics from the API, using given parameters, """ apps = [] form = self.get_form() active_apps_list = [] - urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format( + urlpath = '/management/metrics/top-consumers?limit=100&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: @@ -831,7 +831,7 @@ def prepare_general_context(self, web_page_type, **kwargs): 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) + active_apps_list = self.get_top_100_active_apps(from_date, to_date) context = super(MonthlyMetricsSummaryView, self).get_context_data(**kwargs) context.update({ From ad283e84adadff2291bc48315d12fb6019add78c Mon Sep 17 00:00:00 2001 From: Hongwei Date: Thu, 7 Dec 2023 00:27:41 +0100 Subject: [PATCH 3/3] refactor/comment not used logic - enhanced performance --- apimanager/locale/de/LC_MESSAGES/django.po | 4 +- apimanager/locale/es/LC_MESSAGES/django.po | 4 +- apimanager/locale/hi/LC_MESSAGES/django.po | 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 | 2 +- apimanager/metrics/views.py | 62 +++++++++---------- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/apimanager/locale/de/LC_MESSAGES/django.po b/apimanager/locale/de/LC_MESSAGES/django.po index 481f951e..c4a6de88 100644 --- a/apimanager/locale/de/LC_MESSAGES/django.po +++ b/apimanager/locale/de/LC_MESSAGES/django.po @@ -1090,8 +1090,8 @@ msgstr "Unterschiedliche Entwickler-E-Mail-Adressen" #: metrics/templates/metrics/quarterly_summary.html:117 #: metrics/templates/metrics/weekly_summary.html:115 #: metrics/templates/metrics/yearly_summary.html:115 -msgid "Active Apps (at least one API call in the period)" -msgstr "Aktive Apps (mindestens ein API-Aufruf im Zeitraum)" +msgid "Top 100 Active Apps (at least one API call in the period)" +msgstr "Top 100 Aktive Apps (mindestens ein API-Aufruf im Zeitraum)" #: metrics/templates/metrics/custom_summary.html:124 #: metrics/templates/metrics/daily_summary.html:118 diff --git a/apimanager/locale/es/LC_MESSAGES/django.po b/apimanager/locale/es/LC_MESSAGES/django.po index 0e8b9a34..30519bac 100644 --- a/apimanager/locale/es/LC_MESSAGES/django.po +++ b/apimanager/locale/es/LC_MESSAGES/django.po @@ -1427,8 +1427,8 @@ msgstr "Distintas direcciones de correo electrónico para desarrolladores" #: metrics/templates/metrics/quarterly_summary.html:124 #: metrics/templates/metrics/weekly_summary.html:120 #: metrics/templates/metrics/yearly_summary.html:122 -msgid "Active Apps (at least one API call in the period)" -msgstr "Aplicaciones activas (al menos una llamada API en el periodo)" +msgid "Top 100 Active Apps (at least one API call in the period)" +msgstr "Top 100 Aplicaciones activas (al menos una llamada API en el periodo)" #: metrics/templates/metrics/custom_summary.html:122 #: metrics/templates/metrics/daily_summary.html:125 diff --git a/apimanager/locale/hi/LC_MESSAGES/django.po b/apimanager/locale/hi/LC_MESSAGES/django.po index 53d974a6..98ecc377 100644 --- a/apimanager/locale/hi/LC_MESSAGES/django.po +++ b/apimanager/locale/hi/LC_MESSAGES/django.po @@ -1069,7 +1069,7 @@ msgstr "MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NE #: metrics/templates/metrics/quarterly_summary.html:117 #: metrics/templates/metrics/weekly_summary.html:115 #: metrics/templates/metrics/yearly_summary.html:115 -msgid "Active Apps (at least one API call in the period)" +msgid "Top 100 Active Apps (at least one API call in the period)" msgstr "MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 00 HOURS 04 MINUTES 14 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE" #: metrics/templates/metrics/custom_summary.html:124 diff --git a/apimanager/metrics/templates/metrics/daily_summary.html b/apimanager/metrics/templates/metrics/daily_summary.html index 4547c777..7842673e 100644 --- a/apimanager/metrics/templates/metrics/daily_summary.html +++ b/apimanager/metrics/templates/metrics/daily_summary.html @@ -109,7 +109,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/templates/metrics/hourly_summary.html b/apimanager/metrics/templates/metrics/hourly_summary.html index 85963d43..16cdffa8 100644 --- a/apimanager/metrics/templates/metrics/hourly_summary.html +++ b/apimanager/metrics/templates/metrics/hourly_summary.html @@ -111,7 +111,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_names%}{{item}}, {% endfor %} diff --git a/apimanager/metrics/templates/metrics/monthly_summary.html b/apimanager/metrics/templates/metrics/monthly_summary.html index e39c7996..6eaeb261 100644 --- a/apimanager/metrics/templates/metrics/monthly_summary.html +++ b/apimanager/metrics/templates/metrics/monthly_summary.html @@ -102,7 +102,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/templates/metrics/quarterly_summary.html b/apimanager/metrics/templates/metrics/quarterly_summary.html index 6c239eee..f169e805 100644 --- a/apimanager/metrics/templates/metrics/quarterly_summary.html +++ b/apimanager/metrics/templates/metrics/quarterly_summary.html @@ -112,7 +112,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/templates/metrics/weekly_summary.html b/apimanager/metrics/templates/metrics/weekly_summary.html index 077ae698..07227ece 100644 --- a/apimanager/metrics/templates/metrics/weekly_summary.html +++ b/apimanager/metrics/templates/metrics/weekly_summary.html @@ -108,7 +108,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/templates/metrics/yearly_summary.html b/apimanager/metrics/templates/metrics/yearly_summary.html index b2ce28a6..8fd2daf6 100644 --- a/apimanager/metrics/templates/metrics/yearly_summary.html +++ b/apimanager/metrics/templates/metrics/yearly_summary.html @@ -108,7 +108,7 @@

{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro - {% trans "Active Apps (at least one API call in the period)" %}: + {% trans "Top 100 Active Apps (at least one API call in the period)" %}: {%for item in active_apps_list%}

{{item.app_name}} ({{ item.developer_email }})

{% endfor %} diff --git a/apimanager/metrics/views.py b/apimanager/metrics/views.py index cf48df86..b75e289a 100644 --- a/apimanager/metrics/views.py +++ b/apimanager/metrics/views.py @@ -589,31 +589,31 @@ def plot_topconsumer_bar_chart(self, data): plt.gcf().clear() return image_base64 - def get_users_cansearchwarehouse(self): - users = [] - users_with_cansearchwarehouse = [] - email_with_cansearchwarehouse = [] - api = API(self.request.session.get('obp')) - try: - urlpath = '/users' - users = api.get(urlpath) - if users is not None and 'code' in users and users['code'] == 403: - 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) - - 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 get_users_cansearchwarehouse(self): + # users = [] + # users_with_cansearchwarehouse = [] + # email_with_cansearchwarehouse = [] + # api = API(self.request.session.get('obp')) + # try: + # urlpath = '/users' + # users = api.get(urlpath) + # if users is not None and 'code' in users and users['code'] == 403: + # 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) + # + # 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']: @@ -820,14 +820,14 @@ def prepare_general_context(self, web_page_type, **kwargs): api_host_name = API_HOST 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() + # 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) top_apis = self.get_top_apis(form.cleaned_data, from_date, to_date) top_apis_bar_chart = self.plot_bar_chart(top_apis) 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) + # 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) 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) @@ -848,10 +848,10 @@ def prepare_general_context(self, web_page_type, **kwargs): 'active_apps_list': active_apps_list, 'average_calls_per_day': average_calls_per_day, 'average_response_time': average_response_time, - 'top_warehouse_calls': top_warehouse_calls, - 'top_apps_using_warehouse': top_apps_using_warehouse, - 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, - 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, + # 'top_warehouse_calls': top_warehouse_calls, + # 'top_apps_using_warehouse': top_apps_using_warehouse, + # 'user_email_cansearchwarehouse': user_email_cansearchwarehouse, + # 'number_of_users_with_cansearchwarehouse': number_of_users_with_cansearchwarehouse, 'api_host_name': api_host_name, 'from_date': (datetime.datetime.strptime(from_date, API_DATE_FORMAT_WITH_MILLISECONDS)).strftime('%d %B %Y'), 'to_date': (datetime.datetime.strptime(to_date, API_DATE_FORMAT_WITH_MILLISECONDS)).strftime('%d %B %Y'),