mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 16:46:57 +00:00
Merge pull request #61 from shanhuhai/master
Fix the datetime problem in "KPI Dashboard" of "Metrics"
This commit is contained in:
commit
bad89e8233
@ -19,6 +19,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -29,6 +30,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
per_day_call_limit = forms.IntegerField(
|
||||
@ -38,6 +40,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
per_week_call_limit = forms.IntegerField(
|
||||
@ -47,6 +50,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -57,5 +61,6 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -205,7 +205,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
"""
|
||||
for metric in metrics:
|
||||
metric['date'] = datetime.datetime.strptime(
|
||||
metric['date'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
metric['date'], API_DATEFORMAT)
|
||||
return metrics
|
||||
|
||||
def to_api(self, cleaned_data):
|
||||
@ -392,7 +392,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
if cleaned_data.get('include_obp_apps'):
|
||||
while date_to <= to_date:
|
||||
urlpath = '/management/aggregate-metrics?from_date={}&to_date={}'.format(
|
||||
date_from.strftime(API_DATEFORMAT)[:-4].__add__("Z"), date_to.strftime(API_DATEFORMAT)[:-4].__add__("Z"))
|
||||
date_from.strftime(API_DATEFORMAT), date_to.strftime(API_DATEFORMAT))
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
metrics = api.get(urlpath)
|
||||
@ -409,7 +409,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
else:
|
||||
while date_to <= to_date:
|
||||
urlpath = '/management/aggregate-metrics?from_date={}&to_date={}&exclude_app_names={}'.format(
|
||||
date_from.strftime(API_DATEFORMAT)[:-4].__add__("Z"), date_to.strftime(API_DATEFORMAT)[:-4].__add__("Z"), ",".join(EXCLUDE_APPS))
|
||||
date_from.strftime(API_DATEFORMAT), date_to.strftime(API_DATEFORMAT), ",".join(EXCLUDE_APPS))
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
metrics = api.get(urlpath)
|
||||
@ -625,13 +625,10 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
top_apps_using_warehouse = api.get(urlpath)
|
||||
top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2]
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
|
||||
top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2]
|
||||
|
||||
|
||||
|
||||
return top_apps_using_warehouse
|
||||
|
||||
def median_time_to_first_api_call(self, from_date, to_date):
|
||||
@ -650,7 +647,7 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
|
||||
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)[:-4].__add__("Z")
|
||||
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)
|
||||
@ -684,9 +681,9 @@ class MetricsSummaryView(LoginRequiredMixin, TemplateView):
|
||||
form = self.get_form()
|
||||
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(30)).strftime(API_DATEFORMAT)
|
||||
context = super(MetricsSummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date)
|
||||
@ -734,8 +731,8 @@ class YearlySummaryView(MetricsSummaryView):
|
||||
def get_context_data(self, **kwargs):
|
||||
form = self.get_form()
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(365)).strftime(API_DATEFORMAT)
|
||||
|
||||
context = super(YearlySummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
@ -784,8 +781,8 @@ class QuarterlySummaryView(MetricsSummaryView):
|
||||
def get_context_data(self, **kwargs):
|
||||
form = self.get_form()
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(90)).strftime(API_DATEFORMAT)
|
||||
|
||||
context = super(QuarterlySummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
@ -838,8 +835,8 @@ class WeeklySummaryView(MetricsSummaryView):
|
||||
def get_context_data(self, **kwargs):
|
||||
form = self.get_form()
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(7)).strftime(API_DATEFORMAT)
|
||||
|
||||
context = super(WeeklySummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
@ -890,8 +887,8 @@ class DailySummaryView(MetricsSummaryView):
|
||||
def get_context_data(self, **kwargs):
|
||||
form = self.get_form()
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
from_date = (datetime.datetime.strptime(to_date, API_DATEFORMAT) - timedelta(1)).strftime(API_DATEFORMAT)
|
||||
|
||||
context = super(DailySummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
@ -947,10 +944,10 @@ class CustomSummaryView(MetricsSummaryView):
|
||||
form = self.get_form()
|
||||
|
||||
to_date = datetime.datetime.strptime(form.data['to_date'], '%Y-%m-%d %H:%M:%S')
|
||||
to_date = to_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
to_date = to_date.strftime(API_DATEFORMAT)
|
||||
|
||||
from_date = datetime.datetime.strptime(form.data['from_date_custom'], '%Y-%m-%d %H:%M:%S')
|
||||
from_date = from_date.strftime(API_DATEFORMAT)[:-4].__add__("Z")
|
||||
from_date = from_date.strftime(API_DATEFORMAT)
|
||||
context = super(CustomSummaryView, self).get_context_data(**kwargs)
|
||||
api_host_name = API_HOST
|
||||
top_apps_using_warehouse = self.get_top_apps_using_warehouse(from_date, to_date)
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
<form class="form-inline" method="get">
|
||||
<div class="form-group">
|
||||
<label for="offset">Offset:</label>
|
||||
<input type="number" class="form-control" name="offset" id="offset" placeholder="0" value="{{ offset }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="limit">Limit:</label>
|
||||
<input type="number" class="form-control" name="limit" id="limit" placeholder="50" value="{{ limit }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Get user list</button>
|
||||
</form>
|
||||
@ -28,6 +28,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
|
||||
<h2>Pagination</h2>
|
||||
{% include "users/includes/filter_pagination.html" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Statistics</h2>
|
||||
<ul id="statistics">
|
||||
<li>Total number of users: {{ statistics.users_num }}
|
||||
|
||||
@ -49,20 +49,19 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "users/index.html"
|
||||
|
||||
def get_users_rolenames(self, context):
|
||||
users = []
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/users'
|
||||
users = api.get(urlpath)
|
||||
urlpath = '/entitlements'
|
||||
entitlements = api.get(urlpath)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return [], []
|
||||
|
||||
role_names = []
|
||||
try:
|
||||
for user in users['users']:
|
||||
for entitlement in user['entitlements']['list']:
|
||||
role_names.append(entitlement['role_name'])
|
||||
for entitlement in entitlements['list']:
|
||||
role_names.append(entitlement['role_name'])
|
||||
# fail gracefully in case API provides new structure
|
||||
except KeyError as err:
|
||||
messages.error(self.request, 'KeyError: {}'.format(err))
|
||||
@ -70,23 +69,42 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
||||
|
||||
role_names = list(set(role_names))
|
||||
role_names.sort()
|
||||
users = FilterRoleName(context, self.request.GET)\
|
||||
.apply(users['users'])
|
||||
users = FilterEmail(context, self.request.GET)\
|
||||
.apply(users)
|
||||
users = FilterUsername(context, self.request.GET)\
|
||||
.apply(users)
|
||||
return users, role_names
|
||||
|
||||
return role_names
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
users, role_names = self.get_users_rolenames(context)
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
limit = self.request.GET.get('limit', 50)
|
||||
offset = self.request.GET.get('offset', 0)
|
||||
email = self.request.GET.get('email')
|
||||
username = self.request.GET.get('username')
|
||||
|
||||
if email:
|
||||
urlpath = '/users/email/{}/terminator'.format(email)
|
||||
elif username:
|
||||
urlpath = '/users/username/{}'.format(username)
|
||||
else:
|
||||
urlpath = '/users?limit={}&offset={}'.format(limit, offset)
|
||||
|
||||
try:
|
||||
users = api.get(urlpath)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return [], []
|
||||
|
||||
role_names = self.get_users_rolenames(context)
|
||||
users = FilterRoleName(context, self.request.GET) \
|
||||
.apply([users] if username else users['users'])
|
||||
context.update({
|
||||
'role_names': role_names,
|
||||
'statistics': {
|
||||
'users_num': len(users),
|
||||
},
|
||||
'users': users,
|
||||
'limit': limit,
|
||||
'offset': offset
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
@ -8,5 +8,4 @@ gunicorn==19.6.0
|
||||
matplotlib
|
||||
django-bootstrap-datepicker-plus
|
||||
django-mathfilters
|
||||
django-bootstrap3
|
||||
django-bootstrap-datepicker-plus
|
||||
django-bootstrap3
|
||||
Loading…
Reference in New Issue
Block a user