summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-08-31 23:34:36 +0200
committerAki <please@ignore.pl>2023-08-31 23:34:36 +0200
commit340ef1c6a353680f71700d23b0f54d4d6ae76011 (patch)
treefdd2ce48ffeeb160db57dc7a770f9a5d2daf0cdd
parent1e81f505fc56efba701ba62a6d858d5fb5b70a7f (diff)
downloadactivity-340ef1c6a353680f71700d23b0f54d4d6ae76011.zip
activity-340ef1c6a353680f71700d23b0f54d4d6ae76011.tar.gz
activity-340ef1c6a353680f71700d23b0f54d4d6ae76011.tar.bz2
Changed format of git log lookup to year - day of year - mentions
-rw-r--r--activity/dates.lua9
-rw-r--r--activity/git.lua25
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