Bauke/tildes-issue-log
Bauke
/
tildes-issue-log
Archived
1
Fork 0

Add statistics function with average closed time

Add conditional check if post.md already exists
This commit is contained in:
Bauke 2018-06-24 22:49:46 +02:00
parent 5845ff60da
commit 9f03a72374
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 42 additions and 2 deletions

44
main.js
View File

@ -41,7 +41,10 @@ for (const arg of process.argv) {
}
if (!args.includes('--no-download')) download()
else createTable()
else {
createTable()
createStatistics()
}
function download() {
api.Projects
@ -62,6 +65,7 @@ function download() {
}
})
.then(createTable)
.then(createStatistics)
})
}
@ -143,6 +147,42 @@ function createTable() {
table += ` ${closedAt} |\n`
}
fs.copyFileSync(path.join(__dirname, 'template.md'), path.join(__dirname, year, month, 'post.md'))
if (!fs.existsSync(path.join(__dirname, year, month, 'post.md')))
fs.copyFileSync(path.join(__dirname, 'template.md'), path.join(__dirname, year, month, 'post.md'))
fs.writeFileSync(path.join(__dirname, year, month, 'table.md'), table, {encoding: 'UTF-8'})
}
function createStatistics() {
let opened = klaw(openedPath)
let closed = klaw(closedPath)
let statistics = '## Statistics\n\n'
statistics += `In the month of ${month} `
statistics += `${opened.length} issues were opened and `
statistics += `${closed.length} issues were closed.\n\n`
let averageClosedDays
let averageClosedHours
for (const file of closed) {
const issue = require(file.path)
const openedAt = new Date(issue.created_at)
const closedAt = new Date(issue.closed_at)
const diffDays = Math.floor((closedAt - openedAt) / (1000 * 60 * 60 * 24))
const diffHours = Math.floor((closedAt - openedAt) / (1000 * 60 * 60))
averageClosedDays = (typeof averageClosedDays === 'undefined')
? averageClosedDays = diffDays
: averageClosedDays += diffDays
averageClosedHours = (typeof averageClosedHours === 'undefined')
? averageClosedHours = diffHours
: averageClosedHours += diffHours
}
averageClosedDays = Math.floor(averageClosedDays / closed.length)
averageClosedHours = Math.floor(averageClosedHours / closed.length)
statistics += `The average time to close issues was ${averageClosedDays} days `
statistics += `or ${averageClosedHours} hours.\n\n`
fs.writeFileSync(path.join(__dirname, year, month, 'statistics.md'), statistics, {encoding: 'UTF-8'})
}