summaryrefslogtreecommitdiff
path: root/activity.lua
diff options
context:
space:
mode:
Diffstat (limited to 'activity.lua')
-rw-r--r--activity.lua47
1 files changed, 27 insertions, 20 deletions
diff --git a/activity.lua b/activity.lua
index 405dc05..e0f6c07 100644
--- a/activity.lua
+++ b/activity.lua
@@ -4,18 +4,42 @@ local activity = {}
local
+function level (count)
+ if 0 < count and count <= 2 then
+ return 1
+ end
+ if 2 < count and count <= 4 then
+ return 2
+ end
+ if 4 < count and count <= 6 then
+ return 3
+ end
+ if 6 < count then
+ return 4
+ end
+ return 0
+end
+
+
+local
function generate_rolling (lookup, format, date)
date = date or os.date"*t"
local rows = ""
local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""}
+ local function year_and_day (week, weekday)
+ local days = week * 7 + date.wday - weekday
+ local at = dates.before(date, days)
+ return at.year, dates.day_of_year(at)
+ end
+
for index, weekday in pairs(weekdays) do
rows = rows .. format.label(weekday)
for week=0,51 do
- rows = rows .. format.cell(0)
+ rows = rows .. format.cell(level(lookup(year_and_day(52 - week, index))))
end
if date.wday >= index then
- rows = rows .. format.cell(0)
+ rows = rows .. format.cell(level(lookup(year_and_day(0, index))))
else
rows = rows .. format.spot()
end
@@ -35,22 +59,6 @@ function activity.generate_table (year, lookup, format, ...)
return week * 7 + weekday - first_weekday + 1
end
- local function level (count)
- if 0 < count and count <= 2 then
- return 1
- end
- if 2 < count and count <= 4 then
- return 2
- end
- if 4 < count and count <= 6 then
- return 3
- end
- if 6 < count then
- return 4
- end
- return 0
- end
-
local function day_level (first_weekday, week, weekday)
return level(lookup(year, day_of_year(first_weekday, week, weekday)))
end
@@ -81,8 +89,7 @@ function activity.generate_table (year, lookup, format, ...)
for index, weekday in pairs(weekdays) do
rows = rows .. row(weekday, index, start_from, index >= start_from, index <= end_at)
end
- return
- format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document()
+ return format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document()
end