diff options
-rw-r--r-- | activity/dates.lua | 9 | ||||
-rw-r--r-- | activity/git.lua | 25 |
2 files changed, 19 insertions, 15 deletions
diff --git a/activity/dates.lua b/activity/dates.lua index 682ad04..c863cdb 100644 --- a/activity/dates.lua +++ b/activity/dates.lua @@ -20,4 +20,13 @@ function dates.first_week_day (year) end +function dates.day_of_year (date) + local day = tonumber(os.date("%j", os.time(date))) + if not day then + error"invalid date" + end + return day +end + + return dates diff --git a/activity/git.lua b/activity/git.lua index 2054835..c1219ad 100644 --- a/activity/git.lua +++ b/activity/git.lua @@ -1,3 +1,4 @@ +local dates = require "activity.dates" local git = {} @@ -22,23 +23,17 @@ end function git.lookup (repositories) local lookup = {} - - local function ensure (target, member, default) - if target[member] == nil then - target[member] = default - end - return target[member] - end - + local entries = {} for _, dirname in pairs(repositories) do - for _, entry in pairs(git.log(dirname)) do - local year = ensure(lookup, entry.date.year, {}) - local month = ensure(year, entry.date.month, {}) - local day = ensure(month, entry.date.day, {}) - day[entry.email] = ensure(day, entry.email, 0) + 1 - end + git.log(dirname, entries) + end + for _, entry in pairs(entries) do + local day = dates.day_of_year(entry.date) + local year = entry.date.year + lookup[year] = lookup[year] or {} + lookup[year][day] = (lookup[year][day] or 0) + 1 end - return lookup -- TODO: Days of year by year as the format: {year={[1]=1, [2]=1, [3]=6, ...}, ...} + return lookup end |