From 07d28e32ae499af1ac68e06772380d179034bd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCrl?= Date: Tue, 21 May 2019 17:21:13 +0200 Subject: [PATCH 1/3] Output: sort user list by time --- src/models/owner.js | 2 +- src/output/base.js | 8 ++++++-- src/output/csv.js | 6 +++--- src/output/markdown.js | 6 ++++-- src/output/table.js | 6 ++++-- src/output/xlsx.js | 4 ++-- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/models/owner.js b/src/models/owner.js index 55bdd68..af95062 100755 --- a/src/models/owner.js +++ b/src/models/owner.js @@ -131,4 +131,4 @@ class owner extends Base { } } -module.exports = owner; \ No newline at end of file +module.exports = owner; diff --git a/src/output/base.js b/src/output/base.js index 297b682..57f3f3a 100755 --- a/src/output/base.js +++ b/src/output/base.js @@ -136,7 +136,11 @@ class base { return a.date.isBefore(b.date) ? 1 : -1; }); - this.users = _.mapObject(users, user => this.config.toHumanReadable(user, 'stats')); + let userArr = []; + _.each(users, (time, name) => userArr.push([name, this.config.toHumanReadable(time, 'stats'), time])); + userArr = userArr.sort((a,b) => b[2] - a[2]); + this.users = userArr; + this.projects = _.mapObject(projects, project => this.config.toHumanReadable(project, 'stats')); this.stats = { 'total estimate': this.config.toHumanReadable(totalEstimate, 'stats'), @@ -166,4 +170,4 @@ class base { } } -module.exports = base; \ No newline at end of file +module.exports = base; diff --git a/src/output/csv.js b/src/output/csv.js index 58c188e..ee9cb2d 100755 --- a/src/output/csv.js +++ b/src/output/csv.js @@ -24,10 +24,10 @@ class csv extends Base { }); } - _.each(this.users, (time, name) => { + for (let [name, time, seconds] of this.users) { stats[0].push(name); stats[1].push(time); - }); + } this.csvStats = Csv.stringify(stats); } @@ -101,4 +101,4 @@ class csv extends Base { } } -module.exports = csv; \ No newline at end of file +module.exports = csv; diff --git a/src/output/markdown.js b/src/output/markdown.js index 5116abd..786ba90 100755 --- a/src/output/markdown.js +++ b/src/output/markdown.js @@ -30,7 +30,9 @@ class markdown extends Base { stats += `\n`; } - _.each(this.users, (time, name) => stats += `\n* **${name}**: ${time}`); + for (let [name, time, seconds] of this.users) { + stats += `\n* **${name}**: ${time}`; + } this.write(stats.substr(1)); } @@ -69,4 +71,4 @@ class markdown extends Base { } } -module.exports = markdown; \ No newline at end of file +module.exports = markdown; diff --git a/src/output/table.js b/src/output/table.js index 157e5dd..e397106 100755 --- a/src/output/table.js +++ b/src/output/table.js @@ -30,7 +30,9 @@ class table extends Base { stats += `\n`; } - _.each(this.users, (time, name) => stats += `\n* ${name.red}: ${time}`); + for (let [name, time, seconds] of this.users) { + stats += `\n* ${name.red}: ${time}`; + } this.write(stats.substr(1)); } @@ -65,4 +67,4 @@ class table extends Base { } } -module.exports = table; \ No newline at end of file +module.exports = table; diff --git a/src/output/xlsx.js b/src/output/xlsx.js index 9581ad1..130f5cc 100644 --- a/src/output/xlsx.js +++ b/src/output/xlsx.js @@ -26,10 +26,10 @@ class xlsx extends Base { }); } - _.each(this.users, (time, name) => { + for (let [name, time, seconds] of this.users) { stats[0].push(name); stats[1].push(time); - }); + } this.xlsxStats = XLSX.utils.aoa_to_sheet(stats); } From 26cd2df56ca57fae862cbcfb7fdbd93ba7f12bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCrl?= Date: Thu, 23 May 2019 15:24:23 +0200 Subject: [PATCH 2/3] Stats show full names in statistics --- src/models/hasTimes.js | 2 ++ src/models/project.js | 2 +- src/models/user.js | 47 ++++++++++++++++++++++++++++++++++++++++++ src/output/base.js | 3 +++ src/output/markdown.js | 3 ++- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/models/user.js diff --git a/src/models/hasTimes.js b/src/models/hasTimes.js index 87cd1fe..80ce0f1 100755 --- a/src/models/hasTimes.js +++ b/src/models/hasTimes.js @@ -15,6 +15,7 @@ class hasTimes extends Base { constructor(config) { super(config); this.times = []; + this.fullNames = {}; } /** @@ -101,6 +102,7 @@ class hasTimes extends Base { // add to time spent & add to user specific time spent timeSpent += time.seconds; timeUsers[note.author.username] += time.seconds; + this.fullNames[note.author.username] = note.author.name; time.project_namespace = this.project_namespace; times.push(time); diff --git a/src/models/project.js b/src/models/project.js index eba3d5b..ca4b9ce 100755 --- a/src/models/project.js +++ b/src/models/project.js @@ -67,4 +67,4 @@ class project extends Base { } } -module.exports = project; \ No newline at end of file +module.exports = project; diff --git a/src/models/user.js b/src/models/user.js new file mode 100644 index 0000000..dc5e2c6 --- /dev/null +++ b/src/models/user.js @@ -0,0 +1,47 @@ +const _ = require('underscore'); + +/** + * user model + */ +class user { + constructor(data = {}) { + this.data = data; + } + + make(username) { + let promise; + + promise = this.get(`users?username=${username}`); + + promise.then(user => { + this.data = user.body; + return promise; + }); + + return promise; + } + + /* + * properties + */ + + get id() { + return this.data.id; + } + + get name() { + return this.data.name; + } + + get state() { + return this.data.state === "active" ? true : false; + } + + get avatar_url() { + return this.data.avatar_url; + } + + get web_url() { + return this.data.web_url; + } +} diff --git a/src/output/base.js b/src/output/base.js index 57f3f3a..76e7cb1 100755 --- a/src/output/base.js +++ b/src/output/base.js @@ -101,6 +101,7 @@ class base { let totalSpent = 0; let spent = 0; let users = {}; + let userNames = {}; let projects = {}; let times = []; @@ -110,6 +111,7 @@ class base { if (!users[time.user]) users[time.user] = 0; if (!projects[time.project_namespace]) projects[time.project_namespace] = 0; + userNames[time.user] = issue.fullNames[time.user]; users[time.user] += time.seconds; projects[time.project_namespace] += time.seconds; @@ -142,6 +144,7 @@ class base { this.users = userArr; this.projects = _.mapObject(projects, project => this.config.toHumanReadable(project, 'stats')); + this.userNames = userNames; this.stats = { 'total estimate': this.config.toHumanReadable(totalEstimate, 'stats'), 'total spent': this.config.toHumanReadable(totalSpent, 'stats'), diff --git a/src/output/markdown.js b/src/output/markdown.js index 786ba90..2074f39 100755 --- a/src/output/markdown.js +++ b/src/output/markdown.js @@ -31,7 +31,8 @@ class markdown extends Base { } for (let [name, time, seconds] of this.users) { - stats += `\n* **${name}**: ${time}`; + let fullName = this.userNames[name]; + stats += `\n* **${fullName}**: ${time}`; } this.write(stats.substr(1)); From 01e792247173b00cd7d38d3f2f4d8f7d66ea731a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCrl?= Date: Sun, 26 May 2019 18:38:26 +0200 Subject: [PATCH 3/3] Only remove time of user on drop time --- src/models/hasTimes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/hasTimes.js b/src/models/hasTimes.js index 80ce0f1..2a701f4 100755 --- a/src/models/hasTimes.js +++ b/src/models/hasTimes.js @@ -83,7 +83,7 @@ class hasTimes extends Base { if(subMatch && subMatch[2]) created = moment(subMatch[2]); // create a time string and a time object - let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent)}`); + let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeUsers[note.author.username])}`); let time = new Time(null, created, note, this, this.config); time.seconds = Time.parse(timeString, 8, 5, 4);