Skip to content

Commit

Permalink
refactor/comment not used logic - enhanced performance
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Dec 6, 2023
1 parent 4d197d0 commit ad283e8
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 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/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
62 changes: 31 additions & 31 deletions apimanager/metrics/views.py
Original file line number Diff line number Diff line change
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,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)
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 ad283e8

Please sign in to comment.