fix(plugins/isocalendar): Improve padding to support years better
This commit is contained in:
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@@ -110,6 +110,17 @@ jobs:
|
|||||||
plugins_errors_fatal: yes
|
plugins_errors_fatal: yes
|
||||||
dryrun: yes
|
dryrun: yes
|
||||||
|
|
||||||
|
- name: Isocalendar plugin (full year)
|
||||||
|
uses: lowlighter/metrics@master
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.METRICS_TOKEN }}
|
||||||
|
base: ""
|
||||||
|
repositories: 1
|
||||||
|
plugin_isocalendar: yes
|
||||||
|
plugin_isocalendar_duration: full-year
|
||||||
|
plugins_errors_fatal: yes
|
||||||
|
dryrun: yes
|
||||||
|
|
||||||
- name: Habits plugin
|
- name: Habits plugin
|
||||||
uses: lowlighter/metrics@master
|
uses: lowlighter/metrics@master
|
||||||
with:
|
with:
|
||||||
|
|||||||
34
action/dist/index.js
vendored
34
action/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -8,31 +8,46 @@
|
|||||||
//Parameters override
|
//Parameters override
|
||||||
let {"isocalendar.duration":duration = "half-year"} = q
|
let {"isocalendar.duration":duration = "half-year"} = q
|
||||||
//Duration in days
|
//Duration in days
|
||||||
const leap = (new Date(new Date().getYear(), 1, 29).getDate() === 29)
|
duration = ["full-year", "half-year"].includes(duration) ? duration : "full-year"
|
||||||
const days = {"half-year":180, "full-year":365 + leap}[duration] ?? 180
|
//Compute start day
|
||||||
//Compute start day (to ensure last row is complete, we'll retrieve one more week that we'll shift later)
|
const now = new Date()
|
||||||
const from = new Date(Date.now()-days*24*60*60*1000)
|
const start = new Date(now)
|
||||||
from.setHours(-24*7)
|
if (duration === "full-year")
|
||||||
|
start.setFullYear(now.getFullYear()-1)
|
||||||
|
else
|
||||||
|
start.setHours(-24*180)
|
||||||
|
//Compute padding to ensure last row is complete
|
||||||
|
const padding = new Date(start)
|
||||||
|
padding.setHours(-14*24)
|
||||||
//Retrieve contribution calendar from graphql api
|
//Retrieve contribution calendar from graphql api
|
||||||
const {user:{calendar:{contributionCalendar:calendar}}} = await graphql(`
|
const calendar = {}
|
||||||
query Calendar {
|
for (const [name, from, to] of [["padding", padding, start], ["weeks", start, now]]) {
|
||||||
user(login: "${login}") {
|
console.debug(`metrics/compute/${login}/plugins > isocalendar > loading "${name}" from "${from.toISOString()}" to "${to.toISOString()}"`)
|
||||||
calendar:contributionsCollection(from: "${from.toISOString()}", to: "${(new Date()).toISOString()}") {
|
const {user:{calendar:{contributionCalendar:{weeks}}}} = await graphql(`
|
||||||
contributionCalendar {
|
query Calendar {
|
||||||
weeks {
|
user(login: "${login}") {
|
||||||
contributionDays {
|
calendar:contributionsCollection(from: "${from.toISOString()}", to: "${to.toISOString()}") {
|
||||||
contributionCount
|
contributionCalendar {
|
||||||
color
|
weeks {
|
||||||
date
|
contributionDays {
|
||||||
|
contributionCount
|
||||||
|
color
|
||||||
|
date
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
`
|
||||||
`
|
)
|
||||||
)
|
calendar[name] = weeks
|
||||||
calendar.weeks.shift()
|
}
|
||||||
|
//Apply padding
|
||||||
|
const firstweek = calendar.weeks[0].contributionDays
|
||||||
|
const padded = calendar.padding.flatMap(({contributionDays}) => contributionDays).filter(({date}) => !firstweek.map(({date}) => date).includes(date))
|
||||||
|
while (firstweek.length < 7)
|
||||||
|
firstweek.unshift(padded.pop())
|
||||||
//Compute the highest contributions in a day, streaks and average commits per day
|
//Compute the highest contributions in a day, streaks and average commits per day
|
||||||
let max = 0, streak = {max:0, current:0}, values = [], average = 0
|
let max = 0, streak = {max:0, current:0}, values = [], average = 0
|
||||||
for (const week of calendar.weeks) {
|
for (const week of calendar.weeks) {
|
||||||
|
|||||||
Reference in New Issue
Block a user