summaryrefslogtreecommitdiff
path: root/activity.lua
blob: cece167771f248288886caab81580ad9c25273bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local dates = require "activity.dates"
local activity = {}


function activity.generate_table (year)
	year = year or dates.this_year()

	local function spot ()
		return [[<td>]]
	end

	local function day (level)
		return ([[<td data-activity-level="%d">]]):format(level)
	end

	local function cell (exists)
		if not exists then
			return spot
		end
		return day
	end

	local function row (weekday, first, last)
		first = cell(first)
		last = cell(last)
		local row = ([[<tr><td class="activity-chart-label"><span>%s</span>]]):format(weekday)
		row = row .. first(math.random(0, 4))
		for _=1,51 do
			row = row .. day(math.random(0, 4))
		end
		row = row .. last(math.random(0, 4)) .. "\n"
		return row
	end

	local rows = ""
	local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""}
	local start_from = dates.first_week_day(year)
	local end_at = (start_from + dates.days_in(year) - 1) % 7
	for index, weekday in pairs(weekdays) do
		rows = rows .. row(weekday, index >= start_from, index <= end_at)
	end
	return [[<table class="activity-chart">]] .. "\n" .. rows .. "</table>"
end


return activity