Created
February 4, 2021 16:46
-
-
Save reizist/1aeaea8246011ec02b21464a7578424e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "gnuplot" | |
# require 'gnuplot/multiplot' | |
require "csv" | |
require 'pry-byebug' | |
data = CSV.read('./data.csv', headers: true, return_headers: false) | |
all_data = [] | |
app_labels = %w(xx yy) | |
app_names.map do |app_name| | |
date = [] | |
before = [] | |
after = [] | |
data.select{|l| l['appname'] == app_name}.sort_by{|_, v| Date.parse(v.last).to_time.to_i}.each {|line| | |
date << line['target_date'] | |
date << line['target_date'] | |
before << line['before_cnts'] | |
after << line['after_cnts'] | |
} | |
all_data << { name: app_name, date: date, before: before, after: after } | |
end | |
all_data.each do |d| | |
Gnuplot.open do |gp| | |
Gnuplot::Plot.new(gp) do |plot | |
plot.xlabel "Date" | |
plot.ylabel 'Count' | |
plot.timefmt "'%Y-%m-%d'" | |
plot.xdata "time" | |
plot.format "x '%Y/%m/%d'" | |
plot.style "data lines" | |
plot.set 'terminal postscript color eps enhanced font "Helvetica,13" size 16cm,8cm' | |
plot.set "output 'graph-#{d[:name]}.ps'" | |
plot.xrange "['#{d[:date].first}':'#{d[:date].last}']" | |
plot.data << Gnuplot::DataSet.new([d[:date], d[:before]]) {|ds| | |
ds.with = "lines" | |
ds.linecolor = 'rgbcolor "#FF0000"' # red | |
ds.linewidth = "2" | |
ds.notitle | |
ds.using = "1:2" | |
} | |
plot.data << Gnuplot::DataSet.new([d[:date], d[:after]]) {|ds| | |
ds.with = "lines" | |
ds.linecolor = "black" | |
ds.linewidth = "2" | |
ds.notitle | |
ds.using = "1:2" | |
} | |
end | |
end | |
`ps2pdf graph-#{d[:name]}.ps` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment