diff --git a/dashboard/decorators.py b/dashboard/decorators.py index a674407c9..601359c73 100644 --- a/dashboard/decorators.py +++ b/dashboard/decorators.py @@ -88,9 +88,11 @@ def record_filter(ignore=None, use_default=True): if 'metric' not in ignore: metrics = parameters.get_parameter(kwargs, 'metric') - for metric in metrics: - record_ids &= memory_storage_inst.get_record_ids_by_type( - parameters.METRIC_TO_RECORD_TYPE[metric]) + if 'all' not in metrics: + for metric in metrics: + record_ids &= ( + memory_storage_inst.get_record_ids_by_type( + parameters.METRIC_TO_RECORD_TYPE[metric])) if 'tm_marks' in metrics: filtered_ids = [] @@ -104,6 +106,13 @@ def record_filter(ignore=None, use_default=True): filtered_ids.append(record['record_id']) record_ids = filtered_ids + if 'blueprint_id' not in ignore: + param = parameters.get_parameter(kwargs, 'blueprint_id') + if param: + record_ids &= ( + memory_storage_inst.get_record_ids_by_blueprint_ids( + param)) + kwargs['records'] = memory_storage_inst.get_records(record_ids) return f(*args, **kwargs) @@ -167,7 +176,7 @@ def aggregate_filter(): 'bpc': (incremental_filter, None), } if metric not in metric_to_filters_map: - raise Exception('Invalid metric %s' % metric) + metric = parameters.get_default('metric') kwargs['metric_filter'] = metric_to_filters_map[metric][0] kwargs['finalize_handler'] = metric_to_filters_map[metric][1] @@ -241,6 +250,9 @@ def templated(template=None, return_code=200): key=lambda x: x[0]) ctx['company'] = parameters.get_single_parameter(kwargs, 'company') + ctx['company_original'] = ( + vault.get_memory_storage().get_original_company_name( + ctx['company'])) ctx['module'] = parameters.get_single_parameter(kwargs, 'module') ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id') ctx['page_title'] = helpers.make_page_title( diff --git a/dashboard/reports.py b/dashboard/reports.py index ba1a52abe..f6730f211 100644 --- a/dashboard/reports.py +++ b/dashboard/reports.py @@ -21,7 +21,7 @@ import time import flask -from dashboard import decorators, parameters +from dashboard import decorators from dashboard import helpers from dashboard import vault from stackalytics.processor import utils @@ -34,7 +34,7 @@ blueprint = flask.Blueprint('reports', __name__, url_prefix='/report') @decorators.templated() @decorators.exception_handler() def blueprint_summary(module, blueprint_name): - blueprint_id = module + ':' + blueprint_name + blueprint_id = utils.get_blueprint_id(module, blueprint_name) bpd = vault.get_memory_storage().get_record_by_primary_key( 'bpd:' + blueprint_id) if not bpd: @@ -136,7 +136,7 @@ def _get_punch_card_data(records): if punch_card_raw[6][23] == 0: punch_card_data.append([23, 6, 0, 0]) - return punch_card_data + return json.dumps(punch_card_data) @blueprint.route('/users/') @@ -151,17 +151,13 @@ def user_activity(user_id): memory_storage_inst = vault.get_memory_storage() records = memory_storage_inst.get_records( memory_storage_inst.get_record_ids_by_user_ids([user_id])) - - activity = helpers.get_activity(records, 0, -1) - - punch_card_data = _get_punch_card_data(activity) + records = sorted(records, key=operator.itemgetter('date'), reverse=True) return { 'user': user, - 'activity': activity[:parameters.DEFAULT_STATIC_ACTIVITY_SIZE], - 'total_records': len(activity), - 'contribution': helpers.get_contribution_summary(activity), - 'punch_card_data': json.dumps(punch_card_data), + 'total_records': len(records), + 'contribution': helpers.get_contribution_summary(records), + 'punch_card_data': _get_punch_card_data(records), } @@ -175,17 +171,13 @@ def company_activity(company): memory_storage_inst = vault.get_memory_storage() records = memory_storage_inst.get_records( memory_storage_inst.get_record_ids_by_companies([original_name])) - - activity = helpers.get_activity(records, 0, -1) - - punch_card_data = _get_punch_card_data(activity) + records = sorted(records, key=operator.itemgetter('date'), reverse=True) return { - 'company': original_name, - 'activity': activity[:parameters.DEFAULT_STATIC_ACTIVITY_SIZE], - 'total_records': len(activity), - 'contribution': helpers.get_contribution_summary(activity), - 'punch_card_data': json.dumps(punch_card_data), + 'company_name': original_name, + 'total_records': len(records), + 'contribution': helpers.get_contribution_summary(records), + 'punch_card_data': _get_punch_card_data(records), } diff --git a/dashboard/templates/_macros/activity_log.html b/dashboard/templates/_macros/activity_log.html new file mode 100644 index 000000000..1435cc7a6 --- /dev/null +++ b/dashboard/templates/_macros/activity_log.html @@ -0,0 +1,131 @@ +{% macro show_activity_log(user_id=None, company=None, blueprint_id=None, show_gravatar=True, gravatar_size=32) -%} + + + + + +

Activity Log

+
+ +
+
+ More... +
+
+ +{%- endmacro %} \ No newline at end of file diff --git a/dashboard/templates/overview.html b/dashboard/templates/overview.html index 3e70b1029..f163b2667 100644 --- a/dashboard/templates/overview.html +++ b/dashboard/templates/overview.html @@ -11,7 +11,6 @@ {% set show_module_contribution = (module) and (not user_id) %} {% set show_contribution = (show_user_contribution) or (show_module_contribution) %} {% set show_user_profile = (user_id) %} -{% set show_module_profile = (module) and (not user_id) and (not company) %} {% set show_top_mentors_options = (metric == 'tm_marks') %} {% set show_review_ratio = (metric in ['marks', 'tm_marks']) %} @@ -187,6 +186,15 @@
Draft Blueprints: ${drafted_blueprint_count}
Completed Blueprints: ${completed_blueprint_count}
Emails: ${email_count}
+{% if module %} +
Show open reviews for {{ module }}↗
+{% endif %} +{% if company %} +
Show activity report for {{ company_original }}↗
+{% endif %} +{% if user_id %} +
Show activity report for {{ user_id }}↗
+{% endif %} {% endblock %} @@ -291,6 +299,10 @@ {% endif %} + {% if show_module_contribution %} +
+ {% endif %} + {% endblock %} {% block right_frame %} @@ -316,13 +328,6 @@ {% endif %} - {% if show_module_profile %} -

Module {{ module }}

-
Open reviews report↗
- -
- {% endif %} - {% if show_bp_breakdown %}

Blueprint popularity

diff --git a/dashboard/templates/reports/base_report.html b/dashboard/templates/reports/base_report.html index 388a9fd80..cabb8082c 100644 --- a/dashboard/templates/reports/base_report.html +++ b/dashboard/templates/reports/base_report.html @@ -1,7 +1,10 @@ - - - +{% extends "base.html" %} + +{% block head %} {% block title %}{% endblock %} + + + @@ -34,10 +37,8 @@ -{% block head %}{% endblock %} - - - + {% block scripts %}{% endblock %} +{% endblock %} {% macro show_activity_log(activity, show_gravatar) -%} @@ -143,12 +144,16 @@ {%- endmacro %} +{% block body %} + +
| community heartbeat
-{% block body %}{% endblock %} +{% block content %} +{% endblock %} - - +
+{% endblock %} diff --git a/dashboard/templates/reports/blueprint_summary.html b/dashboard/templates/reports/blueprint_summary.html index d11fec9c4..d6e8d54bc 100644 --- a/dashboard/templates/reports/blueprint_summary.html +++ b/dashboard/templates/reports/blueprint_summary.html @@ -1,10 +1,11 @@ {% extends "reports/base_report.html" %} +{% import '_macros/activity_log.html' as activity_log %} {% block title %} Blueprint “{{ blueprint.title }}” report {% endblock %} -{% block body %} +{% block content %}

Blueprint “{{ blueprint.name }}”

Title: {{ blueprint.title }}
@@ -31,5 +32,6 @@ Blueprint “{{ blueprint.title }}” report
{{ blueprint.whiteboard }}
{% endif %} -{{ show_activity_log(activity, true) }} +{{ activity_log.show_activity_log(blueprint_id=blueprint.id, show_gravatar=false, gravatar_size=64) }} + {% endblock %} diff --git a/dashboard/templates/reports/company_activity.html b/dashboard/templates/reports/company_activity.html index 110efa6f0..52561c83e 100644 --- a/dashboard/templates/reports/company_activity.html +++ b/dashboard/templates/reports/company_activity.html @@ -1,10 +1,11 @@ {% extends "reports/base_report.html" %} +{% import '_macros/activity_log.html' as activity_log %} {% block title %} -{{ company }} activity report +{{ company_name }} activity in OpenStack {% endblock %} -{% block head %} +{% block scripts %} {% endblock %} -{% block body %} -

{{ company }} activity report

+{% block content %} +

{{ company_name }} activity report

{{ show_contribution_summary(contribution) }}
-{{ show_activity_log(activity, false) }} +{{ activity_log.show_activity_log(company=company_name, show_gravatar=false, gravatar_size=64) }} {% endblock %} diff --git a/dashboard/templates/reports/open_reviews.html b/dashboard/templates/reports/open_reviews.html index 779f44fdf..25ab645d8 100644 --- a/dashboard/templates/reports/open_reviews.html +++ b/dashboard/templates/reports/open_reviews.html @@ -4,7 +4,7 @@ Open reviews report for {{ module }} {% endblock %} -{% block head %} +{% block scripts %} {% endblock %} -{% block body %} +{% block content %}

Open reviews for {{ module }}

Summary

diff --git a/dashboard/templates/reports/user_activity.html b/dashboard/templates/reports/user_activity.html index 9076de92b..fe53c2a75 100644 --- a/dashboard/templates/reports/user_activity.html +++ b/dashboard/templates/reports/user_activity.html @@ -1,10 +1,11 @@ {% extends "reports/base_report.html" %} +{% import '_macros/activity_log.html' as activity_log %} {% block title %} -{{ user.user_name }} activity report +{{ user.user_name }} activity in OpenStack {% endblock %} -{% block head %} +{% block scripts %} {% endblock %} -{% block body %} +{% block content %}

{{ user.user_name }} activity report

{{ show_contribution_summary(contribution) }}
-{{ show_activity_log(activity, false) }} +{{ activity_log.show_activity_log(user_id=user.user_id, show_gravatar=false, gravatar_size=64) }} {% endblock %} diff --git a/dashboard/web.py b/dashboard/web.py index 079b3c219..600528177 100644 --- a/dashboard/web.py +++ b/dashboard/web.py @@ -142,14 +142,16 @@ def get_activity_json(records): start_record = int(flask.request.args.get('start_record') or 0) page_size = int(flask.request.args.get('page_size') or parameters.DEFAULT_RECORDS_LIMIT) + records_sorted = sorted(records, key=lambda x: x['date'], reverse=True) + records_sorted = records_sorted[start_record:start_record + page_size] + result = [] - for record in records: + for record in records_sorted: processed_record = helpers.extend_record(record) if processed_record: result.append(processed_record) - result.sort(key=lambda x: x['date'], reverse=True) - return result[start_record:start_record + page_size] + return result @app.route('/api/1.0/contribution') diff --git a/stackalytics/processor/lp.py b/stackalytics/processor/lp.py index a16f27b70..436e17733 100644 --- a/stackalytics/processor/lp.py +++ b/stackalytics/processor/lp.py @@ -49,7 +49,7 @@ def log(repo): record[field] = utils.iso8601_to_timestamp(date) record['module'] = module - record['id'] = module + ':' + record['name'] + record['id'] = utils.get_blueprint_id(module, record['name']) LOG.debug('New blueprint: %s', record) yield record diff --git a/stackalytics/processor/utils.py b/stackalytics/processor/utils.py index 548397002..6ac144da8 100644 --- a/stackalytics/processor/utils.py +++ b/stackalytics/processor/utils.py @@ -133,3 +133,7 @@ def merge_records(original, new): need_update = True original[key] = value return need_update + + +def get_blueprint_id(module, name): + return module + ':' + name