Merge pull request #349 from hongwei1/develop

refactor/enhanced the perfermance
This commit is contained in:
Simon Redfern 2023-12-07 11:41:35 +01:00 committed by GitHub
commit b3cb4aae05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 47 additions and 47 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -43,7 +43,7 @@ class MetricsForm(forms.Form):
'class': FORM_CONTROL,
}
),
initial=1000,
initial=5,
required=False,
)
offset = forms.IntegerField(

View File

@ -100,7 +100,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -109,7 +109,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -111,7 +111,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_names%}{{item}}, {% endfor %}</td>
</tr>
<tr>

View File

@ -102,7 +102,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -112,7 +112,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -108,7 +108,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -108,7 +108,7 @@
</tr>
<tr>
<td>{% trans "Active Apps (at least one API call in the period)" %}:</td>
<td>{% trans "Top 100 Active Apps (at least one API call in the period)" %}:</td>
<td>{%for item in active_apps_list%} <p>{{item.app_name}} ({{ item.developer_email }})</p> {% endfor %}</td>
</tr>
<tr>

View File

@ -344,14 +344,14 @@ 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_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:
@ -589,31 +589,31 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView):
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,18 +820,18 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView):
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)
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({
@ -848,10 +848,10 @@ class MonthlyMetricsSummaryView(LoginRequiredMixin, TemplateView):
'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'),