[MediaWiki-commits] [Gerrit] Added user_name information for CSV output - change (analytics/wikimetrics)

2014-01-18 Thread Milimetric (Code Review)
Milimetric has submitted this change and it was merged.

Change subject: Added user_name information for CSV output
..


Added user_name information for CSV output

Changed the CSV output on simple CSV and timeseries CSV to display the
user_name in addition to the user_id.

Created new function get_username_via_id(user_id) to map the user_name from the
id given.

Change-Id: I839eb8cf9dc7f31e84782bd66ad882e96d54b6f7
---
M tests/test_controllers/test_reports.py
M wikimetrics/controllers/reports.py
2 files changed, 28 insertions(+), 12 deletions(-)

Approvals:
  Milimetric: Verified; Looks good to me, approved



diff --git a/tests/test_controllers/test_reports.py 
b/tests/test_controllers/test_reports.py
index c0904d4..5c729ed 100644
--- a/tests/test_controllers/test_reports.py
+++ b/tests/test_controllers/test_reports.py
@@ -199,7 +199,7 @@
 
 # Check the csv result
 response = self.app.get('/reports/result/{0}.csv'.format(result_key))
-assert_true(response.data.find('Average,2.0') = 0)
+assert_true(response.data.find('Average,,2.0') = 0)
 
 # Testing to see if the parameters are also in the CSV
 # (related to Mingle 1089)
@@ -245,8 +245,7 @@
 
 # Check the csv result
 response = self.app.get('/reports/result/{0}.csv'.format(result_key))
-print(response.data)
-assert_true(response.data.find('Sum,8.0') = 0)
+assert_true(response.data.find('Sum,,8.0') = 0)
 
 def test_report_result_std_dev_only_csv(self):
 # Make the request
@@ -324,18 +323,20 @@
 # Check the csv result
 response = self.app.get('/reports/result/{0}.csv'.format(result_key))
 assert_true(response.data.find(
-'user_id,submetric,'
+'user_id,user_name,submetric,'
 '2013-01-01 00:00:00,2013-02-01 00:00:00,'
 '2013-03-01 00:00:00,2013-04-01 00:00:00'
 ) = 0)
 assert_true(response.data.find(
-'{0},edits,1,2,1,0'.format(self.editors[0].user_id)
+'{0},{1},edits,1,2,1,0'.format(
+self.editors[0].user_id, self.editors[0].user_name)
 ) = 0)
 assert_true(response.data.find(
-'{0},edits,1,2,1,0'.format(self.editors[1].user_id)
+'{0},{1},edits,1,2,1,0'.format(
+self.editors[1].user_id, self.editors[1].user_name)
 ) = 0)
 assert_true(response.data.find(
-'Average,edits,0.5000,1.,0.5000,0.'
+'Average,,edits,0.5000,1.,0.5000,0.'
 ) = 0)
 
 # Testing to see if the parameters are also in the CSV
diff --git a/wikimetrics/controllers/reports.py 
b/wikimetrics/controllers/reports.py
index 4f47c17..18f579c 100644
--- a/wikimetrics/controllers/reports.py
+++ b/wikimetrics/controllers/reports.py
@@ -6,7 +6,7 @@
 from flask.ext.login import current_user
 
 from wikimetrics.configurables import app, db
-from wikimetrics.models import Report, RunReport, PersistentReport
+from wikimetrics.models import Report, RunReport, PersistentReport, WikiUser
 from wikimetrics.metrics import TimeseriesChoices
 from wikimetrics.models.report_nodes import Aggregation
 from wikimetrics.utils import (
@@ -126,6 +126,19 @@
 return json_response(status=celery_task.status)
 
 
+def get_username_via_id(user_id):
+
+Parameters
+user_id : id to match for user_name
+
+db_session = db.get_session()
+ret = db_session.query(WikiUser.mediawiki_userid, 
WikiUser.mediawiki_username)\
+.filter(WikiUser.mediawiki_userid.in_([user_id]))\
+.all()
+db_session.close()
+return ret[0][1]
+
+
 def get_timeseries_csv(task_result, pj, parameters):
 
 Parameters
@@ -150,9 +163,9 @@
 columns = task_result[Aggregation.STD].values()[0].keys()
 
 # if task_result is not empty find header in first row
-fieldnames = ['user_id', 'submetric'] + sorted(columns)
+fieldnames = ['user_id', 'user_name', 'submetric'] + sorted(columns)
 else:
-fieldnames = ['user_id', 'submetric']
+fieldnames = ['user_id', 'user_name', 'submetric']
 writer = DictWriter(csv_io, fieldnames)
 
 # collect rows to output in CSV
@@ -165,6 +178,7 @@
 for subrow in row.keys():
 task_row = row[subrow].copy()
 task_row['user_id'] = user_id
+task_row['user_name'] = get_username_via_id(user_id)
 task_row['submetric'] = subrow
 task_rows.append(task_row)
 
@@ -234,9 +248,9 @@
 columns = task_result[Aggregation.STD].keys()
 
 # if task_result is not empty find header in first row
-fieldnames = ['user_id'] + columns
+fieldnames = ['user_id', 'user_name'] + columns
 else:
-fieldnames = ['user_id']
+fieldnames = ['user_id', 

[MediaWiki-commits] [Gerrit] Added user_name information for CSV output - change (analytics/wikimetrics)

2013-12-31 Thread Terrrydactyl (Code Review)
Terrrydactyl has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104731


Change subject: Added user_name information for CSV output
..

Added user_name information for CSV output

Changed the CSV output on simple CSV and timeseries CSV to display the
user_name in addition to the user_id.

Created new function get_username_via_id(user_id) to map the user_name from the
id given.

Change-Id: I839eb8cf9dc7f31e84782bd66ad882e96d54b6f7
---
M wikimetrics/controllers/reports.py
1 file changed, 18 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics 
refs/changes/31/104731/1

diff --git a/wikimetrics/controllers/reports.py 
b/wikimetrics/controllers/reports.py
index eb1751d..f64d904 100644
--- a/wikimetrics/controllers/reports.py
+++ b/wikimetrics/controllers/reports.py
@@ -6,7 +6,7 @@
 from flask.ext.login import current_user
 
 from wikimetrics.configurables import app, db
-from wikimetrics.models import Report, RunReport, PersistentReport
+from wikimetrics.models import Report, RunReport, PersistentReport, WikiUser
 from wikimetrics.metrics import TimeseriesChoices
 from wikimetrics.models.report_nodes import Aggregation
 from wikimetrics.utils import (
@@ -122,6 +122,17 @@
 return json_response(status=celery_task.status)
 
 
+def get_username_via_id(user_id):
+
+Parameters
+user_id : id to match for user_name
+
+db_session = db.get_session()
+ret = db_session.query(WikiUser.mediawiki_userid, 
WikiUser.mediawiki_username).filter(WikiUser.mediawiki_userid.in_([user_id])).all()
+db_session.close()
+return ret[0][1]
+
+
 def get_timeseries_csv(task_result, pj, parameters):
 
 Parameters
@@ -146,9 +157,9 @@
 columns = task_result[Aggregation.STD].values()[0].keys()
 
 # if task_result is not empty find header in first row
-fieldnames = ['user_id', 'submetric'] + sorted(columns)
+fieldnames = ['user_id', 'user_name', 'submetric'] + sorted(columns)
 else:
-fieldnames = ['user_id', 'submetric']
+fieldnames = ['user_id', 'user_name', 'submetric']
 writer = DictWriter(csv_io, fieldnames)
 
 # collect rows to output in CSV
@@ -161,6 +172,7 @@
 for subrow in row.keys():
 task_row = row[subrow].copy()
 task_row['user_id'] = user_id
+task_row['user_name'] = get_username_via_id(user_id)
 task_row['submetric'] = subrow
 task_rows.append(task_row)
 
@@ -230,9 +242,9 @@
 columns = task_result[Aggregation.STD].keys()
 
 # if task_result is not empty find header in first row
-fieldnames = ['user_id'] + columns
+fieldnames = ['user_id', 'user_name'] + columns
 else:
-fieldnames = ['user_id']
+fieldnames = ['user_id', 'user_name']
 writer = DictWriter(csv_io, fieldnames)
 
 # collect rows to output in CSV
@@ -244,6 +256,7 @@
 for user_id, row in task_result[Aggregation.IND][0].iteritems():
 task_row = row.copy()
 task_row['user_id'] = user_id
+task_row['user_name'] = get_username_via_id(user_id)
 task_rows.append(task_row)
 
 # Aggregate Results

-- 
To view, visit https://gerrit.wikimedia.org/r/104731
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I839eb8cf9dc7f31e84782bd66ad882e96d54b6f7
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Terrrydactyl tcho...@gmail.com

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits