-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rb
More file actions
64 lines (51 loc) · 2.45 KB
/
server.rb
File metadata and controls
64 lines (51 loc) · 2.45 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require "sinatra"
require "sinatra/reloader"
require "pstore"
require "pp"
def difference(new_value, old_value)
diff = (new_value - old_value)
diff_s = diff > 0 ? "+#{'%.2f' % diff}" : '%.2f' % diff
diff_s.rjust(20) + "#{('%.1f' % ((1 - (old_value.to_f / new_value)) * 100))}%".rjust(20)
end
set :bind, '0.0.0.0'
get "/" do
content_type "text/plain"
store = PStore.new("stats.store")
out = ""
store.transaction(:read_only) do
yesterday = Hash.new(0).merge(store[Date.today-1])
last_week = Hash.new(0).merge(store[Date.today-8])
summary = ->(name, key) do
"#{name}: ".ljust(25) + "#{'%.2f' % yesterday[key]}".rjust(10) + "#{difference(yesterday[key], last_week[key])}\n\n".rjust(30)
end
out << "Summary (with change since last week):\n"
out << "---------------------------------------------------------------------------\n\n"
out << summary["30-day visitors", "visits_30_day"]
out << summary["7-day visitors", "visits_7_day"]
out << summary["1-day visitors", "visits_yesterday"]
out << "............................................................................\n\n"
out << summary["30-day GTB work days", "gtb_work_days"]
out << summary["30-day GTB pay", "gtb_pay_last_30"]
out << "............................................................................\n\n"
out << summary["Subscribers", "subscriber_count"]
out << summary["30-day Transfers", "transfers_last_30"]
out << "............................................................................\n\n"
out << summary["Twitter Followers", "twitter_followers"]
out << summary["Twitter Mentioners", "twitter_mentioners"]
out << summary["Twitter Linkers", "twitter_linkers"]
out << "---------------------------------------------------------------------------\n\n\n"
out << summary["30-day Slack chatters", "slack_participants_30_day"]
out << summary["7-day Slack chatters", "slack_participants_7_day"]
out << summary["1-day Slack chatters", "slack_participants_1_day"]
out << "---------------------------------------------------------------------------\n\n"
out << "TODO: Publication schedule stats, discourse, blog, etc.\n\n"
out << "---------------------------------------------------------------------------\n\n\n"
store.roots.sort.reverse_each do |date|
out << "#{date}\n"
out << "--------------------------\n\n"
out << store[date].pretty_inspect
out << "\n\n"
end
end
out
end