From 34f43995d2fa9689f1c8ac2700843a8cda9ba456 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Wed, 22 Jan 2014 15:07:55 +0400 Subject: [PATCH] Project type is back to UI to keep compatibility with 0.4 * To keep UI compatibility with version 0.4 project type is returned. List of project types is configured in default data, every type is a list of modules or module groups. * Module groups now have tags to distinguish between different kinds. Introduced: 'group' - for user-configured groups, 'program' - for official programs, 'project_type' - for types of projects within official programs, 'organization' - for module groups generated for github organization Change-Id: I8d5e46e18c7327e8c9d114e0a5eec021305b843e --- dashboard/decorators.py | 26 ++++- dashboard/helpers.py | 3 +- dashboard/parameters.py | 2 +- dashboard/static/css/style.css | 7 +- dashboard/static/js/stackalytics-ui.js | 15 +-- dashboard/templates/layout.html | 17 +-- dashboard/templates/overview.html | 4 +- dashboard/templates/reports/contribution.html | 6 +- dashboard/templates/widget.html | 4 +- dashboard/vault.py | 101 +++++++++++++----- dashboard/web.py | 53 +++++---- etc/default_data.json | 49 ++++++++- etc/default_data.schema.json | 29 ++++- etc/test_default_data.json | 38 ++++++- .../processor/default_data_processor.py | 10 +- stackalytics/processor/main.py | 33 +++--- tests/api/test_companies.py | 22 +++- tests/api/test_modules.py | 37 ++++--- tests/api/test_stats.py | 30 ++++-- tests/api/test_users.py | 15 ++- tests/unit/test_default_data_processor.py | 6 +- 21 files changed, 368 insertions(+), 139 deletions(-) diff --git a/dashboard/decorators.py b/dashboard/decorators.py index c012a21e9..b2491ba18 100644 --- a/dashboard/decorators.py +++ b/dashboard/decorators.py @@ -69,6 +69,14 @@ def record_filter(ignore=None, use_default=True): memory_storage_inst.get_record_ids_by_modules( vault.resolve_modules(param))) + if 'project_type' not in ignore: + param = parameters.get_parameter(kwargs, 'project_type', + 'project_types', use_default) + if param: + record_ids &= ( + memory_storage_inst.get_record_ids_by_modules( + vault.resolve_project_types(param))) + if 'user_id' not in ignore: param = parameters.get_parameter(kwargs, 'user_id', 'user_ids') param = [u for u in param @@ -157,22 +165,25 @@ def mark_finalize(record): new_record = record.copy() positive = 0 + numeric = 0 mark_distribution = [] for key in [-2, -1, 1, 2, 'A']: if key in record: if key in [1, 2]: positive += record[key] + if key in [-2, -1, 1, 2]: + numeric += record[key] mark_distribution.append(str(record[key])) else: mark_distribution.append('0') new_record[key] = 0 new_record['disagreements'] = record.get('disagreements', 0) - if record['metric']: + if numeric: positive_ratio = '%.1f%%' % ( - (positive * 100.0) / record['metric']) + (positive * 100.0) / numeric) new_record['disagreement_ratio'] = '%.1f%%' % ( - (record.get('disagreements', 0) * 100.0) / record['metric']) + (record.get('disagreements', 0) * 100.0) / numeric) else: positive_ratio = helpers.INFINITY_HTML new_record['disagreement_ratio'] = helpers.INFINITY_HTML @@ -251,6 +262,11 @@ def templated(template=None, return_code=200): ctx['metric'] = metric or parameters.get_default('metric') ctx['metric_label'] = parameters.METRIC_LABELS[ctx['metric']] + project_type = flask.request.args.get('project_type') + if not vault.is_project_type_valid(project_type): + project_type = parameters.get_default('project_type') + ctx['project_type'] = project_type + release = flask.request.args.get('release') releases = vault_inst['releases'] if release: @@ -265,6 +281,7 @@ def templated(template=None, return_code=200): ctx['review_nth'] = (flask.request.args.get('review_nth') or parameters.get_default('review_nth')) + ctx['project_type_options'] = vault.get_project_types() ctx['release_options'] = vault.get_release_options() ctx['metric_options'] = sorted(parameters.METRIC_LABELS.items(), key=lambda x: x[0]) @@ -276,7 +293,8 @@ def templated(template=None, return_code=200): module = parameters.get_single_parameter(kwargs, 'module') ctx['module'] = module - ctx['module_inst'] = vault_inst['module_id_index'][module] + if module: + ctx['module_inst'] = vault_inst['module_id_index'][module] ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id') ctx['page_title'] = helpers.make_page_title( diff --git a/dashboard/helpers.py b/dashboard/helpers.py index 462f602b7..8a23dd635 100644 --- a/dashboard/helpers.py +++ b/dashboard/helpers.py @@ -178,7 +178,8 @@ def format_launchpad_module_link(module): def make_link(title, uri=None, options=None): - param_names = ('release', 'module', 'company', 'user_id', 'metric') + param_names = ('release', 'project_type', 'module', 'company', 'user_id', + 'metric') param_values = {} for param_name in param_names: v = parameters.get_parameter({}, param_name, param_name) diff --git a/dashboard/parameters.py b/dashboard/parameters.py index 8a6091e57..85fafce35 100644 --- a/dashboard/parameters.py +++ b/dashboard/parameters.py @@ -25,7 +25,7 @@ LOG = logging.getLogger(__name__) DEFAULTS = { 'metric': 'commits', 'release': 'icehouse', - 'module': 'openstack', + 'project_type': 'openstack', 'review_nth': 5, } diff --git a/dashboard/static/css/style.css b/dashboard/static/css/style.css index 96722a58a..c617605e9 100644 --- a/dashboard/static/css/style.css +++ b/dashboard/static/css/style.css @@ -235,11 +235,16 @@ a[href^="https://launchpad"]:after { font-size: 9pt; } -.select_group { +.select_module_group { font-weight: bold; color: #4bb2c5; } +.select_module_program { + font-weight: bold; + color: #ab64c5; +} + .project_group { font-weight: bold; } diff --git a/dashboard/static/js/stackalytics-ui.js b/dashboard/static/js/stackalytics-ui.js index 3d56b1951..baa5c17de 100644 --- a/dashboard/static/js/stackalytics-ui.js +++ b/dashboard/static/js/stackalytics-ui.js @@ -276,6 +276,7 @@ function make_std_options() { var options = {}; options['release'] = $('#release').val(); options['metric'] = $('#metric').val(); + options['project_type'] = $('#project_type').val(); options['module'] = $('#module').val() || ''; options['company'] = $('#company').val() || ''; options['user_id'] = $('#user').val() || ''; @@ -370,11 +371,11 @@ function init_selectors(base_url) { results: function (data, page) { const project_types = data["project_types"]; var result = []; - result.push({id: "all", text: "all", group: true}); for (var key in project_types) { result.push({id: project_types[key].id, text: project_types[key].text, group: true}); for (var i in project_types[key].items) { - result.push({id: project_types[key].items[i], text: project_types[key].items[i]}); + var item = project_types[key].items[i]; + result.push({id: item.id, text: item.text}); } } return {results: result}; @@ -435,13 +436,13 @@ function init_selectors(base_url) { }); $("#module").select2({ - allowClear: false, + allowClear: true, ajax: { - url: make_uri(base_url + "/api/1.0/modules"), + url: make_uri(base_url + "/api/1.0/modules", {tags: "module,program,group"}), dataType: 'jsonp', data: function (term, page) { return { - module_name: term + query: term }; }, results: function (data, page) { @@ -459,8 +460,8 @@ function init_selectors(base_url) { } }, formatResultCssClass: function (item) { - if (item.group) { - return "select_group" + if (item.tag) { + return "select_module_" + item.tag; } return ""; } diff --git a/dashboard/templates/layout.html b/dashboard/templates/layout.html index 48f252b56..c4e45850b 100644 --- a/dashboard/templates/layout.html +++ b/dashboard/templates/layout.html @@ -59,7 +59,7 @@ About ↗
- + | community heartbeat
@@ -67,27 +67,32 @@
- + +
+ +
+ +
- +
- +
- +
- +
diff --git a/dashboard/templates/overview.html b/dashboard/templates/overview.html index c7c9e6187..e535c08a8 100644 --- a/dashboard/templates/overview.html +++ b/dashboard/templates/overview.html @@ -4,9 +4,9 @@ {% set show_company_breakdown = (not company) and (not user_id) %} {% set show_engineer_breakdown = (not user_id) %} {% set show_bp_breakdown = (metric in ['bpd', 'bpc']) %} -{% set show_module_breakdown = (not module) or (module_inst['group']) %} +{% set show_module_breakdown = (not module) %} {% set show_user_activity = (user_id) %} -{% set show_module_activity = (module) and (not user_id) and (not module_inst['group']) %} +{% set show_module_activity = (module) and (not user_id) %} {% set show_activity = (show_user_activity) or (show_module_activity) %} {% set show_user_contribution = (user_id) or (company) %} {% set show_module_contribution = (module) and (not user_id) %} diff --git a/dashboard/templates/reports/contribution.html b/dashboard/templates/reports/contribution.html index dd7e6cefa..a1121a98e 100644 --- a/dashboard/templates/reports/contribution.html +++ b/dashboard/templates/reports/contribution.html @@ -7,12 +7,12 @@ Contribution into {{ module }} for the last {{ days }} days {% block scripts %}