From 516422b654edcfd1178ac0157f78987a33f9feff Mon Sep 17 00:00:00 2001 From: hidekita Date: Mon, 29 Jun 2020 00:55:07 +0900 Subject: [PATCH] add 'Done' data --- cli.js | 4 +++- lib/trello-csv.js | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cli.js b/cli.js index 5f3a42d..f757973 100644 --- a/cli.js +++ b/cli.js @@ -73,13 +73,15 @@ const writeListGroup = (trelloCsv, list, groupby) => { pointsByGroup, resultTimeByGroup, reviewTimeByGroup, + doneByGroup, } = trelloCsv.makeStatisticsUseGroupBy(list, groupby) let csv = trelloCsv.makeCsvUseGroupBy( groupby, totalByGroup, pointsByGroup, resultTimeByGroup, - reviewTimeByGroup + reviewTimeByGroup, + doneByGroup ) console.log(csv) console.log(`total: ${total} hrs`) diff --git a/lib/trello-csv.js b/lib/trello-csv.js index a8b782c..fb4dda3 100644 --- a/lib/trello-csv.js +++ b/lib/trello-csv.js @@ -339,6 +339,28 @@ class TrelloCSV { return csv } + checkListNameByCardId(listName, cardId) { + // get list id + let listId = undefined + for (let boardId in this._lists) { + for (let listItem of this._lists[boardId]) { + if (listItem.name === listName) { + listId = listItem.id + } + } + } + if (!listId || !this._cards[listId]) { + return false + } + // check card + for (let c of this._cards[listId]) { + if (c.id === cardId) { + return true + } + } + return false + } + makeStatisticsUseGroupBy(list, groupby) { let total = 0 let totalResultTime = 0 @@ -349,7 +371,13 @@ class TrelloCSV { let relatedCardIds = {} let pointsByGroup = {} let cardPointMap = {} + let doneByGroup = {} for (let d of list) { + doneByGroup[d[groupby]] = + doneByGroup[d[groupby]] === false || + !this.checkListNameByCardId('Done', d.cardId) + ? false + : true total += d.resultTime + d.reviewTime totalResultTime += d.resultTime totalReviewTime += d.reviewTime @@ -388,6 +416,7 @@ class TrelloCSV { pointsByGroup, resultTimeByGroup, reviewTimeByGroup, + doneByGroup, } } @@ -396,11 +425,12 @@ class TrelloCSV { totalByGroup, pointsByGroup, resultTimeByGroup, - reviewTimeByGroup + reviewTimeByGroup, + doneByGroup ) { - let csv = `"${groupby}","totalPoint","totalTime","totalResult","totalReview"\n` + let csv = `"${groupby}","totalPoint","totalTime","totalResult","totalReview","done"\n` for (let k in totalByGroup) { - csv += `"${k}","${pointsByGroup[k]}","${totalByGroup[k]}","${resultTimeByGroup[k]}","${reviewTimeByGroup[k]}"\n` + csv += `"${k}","${pointsByGroup[k]}","${totalByGroup[k]}","${resultTimeByGroup[k]}","${reviewTimeByGroup[k]}","${doneByGroup[k]}"\n` } return csv }