Skip to content

Commit

Permalink
Merge pull request #349 from hongwei1/develop
Browse files Browse the repository at this point in the history
refactor/enhanced the perfermance
  • Loading branch information
simonredfern committed Dec 7, 2023
2 parents b2ffa95 + ad283e8 commit b3cb4aa
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions apimanager/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apimanager/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apimanager/locale/hi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MetricsForm(forms.Form):
'class': FORM_CONTROL,
}
),
initial=1000,
initial=5,
required=False,
)
offset = forms.IntegerField(
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/custom_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2>{% trans "Custom Date Range " %}</h2>
</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>
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/daily_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/hourly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/monthly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/weekly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/templates/metrics/yearly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>{% if include_app_names != "" %} {{ include_app_names }} : {% endif %}{{ fro
</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>
Expand Down
68 changes: 34 additions & 34 deletions apimanager/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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']:
Expand Down Expand Up @@ -820,18 +820,18 @@ 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)
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({
Expand All @@ -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'),
Expand Down

0 comments on commit b3cb4aa

Please sign in to comment.