dcav-stats/plot.rb
2017-05-23 00:09:29 +02:00

79 lines
1.7 KiB
Ruby

# coding: utf-8
load 'config.rb'
users = USERNAMES
log_dir = LOG_DIR
colors = {"christoffermadsen" => "1d6a6f",
"jmaa" => "9db512",
"jacob" => "e01476",
"alexander" => "00c0c7"}
def rand_color
"%06x" % (rand * 0xffffff)
end
def color_dist (c1, c2)
(c1[0..1].hex - c2[0..1].hex).abs +
(c1[2..3].hex - c2[2..3].hex).abs +
(c1[4..5].hex - c2[4..5].hex).abs
end
#users.each do |user|
# tentative_color = rand_color
# while (colors.detect {|k,v| color_dist(v,tentat#ive_color) < 200}) do
# tentative_color = rand_color
# end
#
# colors[user] = tentative_color
#end
plotstring = %Q[set terminal 'svg' size 800,400 fname 'Verdana, Helvetica, Arial, sans-serif' \
fsize '14' rounded dashed
set key bottom center outside horizontal
set style line 1 lt 1 lw 2 pt 7 ps 0.4
set xlabel "Time"
set xdata time
set timefmt "%s"
set format x "%m/%d"
set xtics 60*60*24*7*2
set xrange [1485275000:]
set mxtics 2
set grid ytics mytics xtics mxtics
set title "Screenshot count"
set output "/home/christoffermadsen/public_html/img/screenshot_count.svg"
set ylabel "Count"
set yrange [0:]
set ytics 100
set mytics 2
plot ]
users.each do |user|
plotstring += %Q["log/#{user}.log" using 1:2 with lines ls 1 lc rgb '##{colors[user]}' t "#{user}", \\\n]
end
plotstring += %Q[
set title "Screenshot size"
set output "/home/christoffermadsen/public_html/img/screenshot_size.svg"
set ylabel "Size (MB)"
set yrange [0:]
set ytics 10
set mytics 1
plot ]
users.each do |user|
colour = "%06x" % (rand * 0xffffff)
plotstring += %Q["log/#{user}.log" using 1:($3/10**6) with lines ls 1 lc rgb '##{colors[user]}' t "#{user}", \\\n]
end
output = File.open("plotscript","w")
output << plotstring
output.close
`gnuplot plotscript`