From fdbc3ad8a7ce49ab9745a61e79a34b59d754bbc0 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 25 Sep 2018 20:51:40 +0200 Subject: Add svg-graph gem to plot schedule. Not quite what I expected, but at least we're on to something. --- Gemfile | 5 +++++ Gemfile.lock | 4 ++++ ramaskrik-program.rb | 25 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4592615..ac8d438 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,8 @@ source "https://rubygems.org" gem "nokogiri" +gem "svg-graph" + +group :development do + gem "byebug" +end diff --git a/Gemfile.lock b/Gemfile.lock index d6f0963..5aff6f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,19 @@ GEM remote: https://rubygems.org/ specs: + byebug (10.0.2) mini_portile2 (2.3.0) nokogiri (1.8.4) mini_portile2 (~> 2.3.0) + svg-graph (2.1.3) PLATFORMS ruby DEPENDENCIES + byebug nokogiri + svg-graph BUNDLED WITH 1.16.1 diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb index 0ca62e2..9097522 100644 --- a/ramaskrik-program.rb +++ b/ramaskrik-program.rb @@ -1,6 +1,7 @@ require 'date' require 'nokogiri' require 'open-uri' +require 'SVG/Graph/Schedule' class Movie attr_reader :title, :start_time, :end_time, :venue @@ -16,8 +17,30 @@ class Movie def to_s "#{title} #{start_time} - #{end_time}, #{venue}" end + + def triplet + [@title, @start_time.strftime("%d.%m.%Y %H:%M"), @end_time.strftime("%d.%m.%Y %H:%M")] + end end doc = Nokogiri::HTML(open("program.html")) ## open("https://ramaskrik.no/program/")) movies = doc.css(".kultur-type-movie").map { |movie| Movie.new(movie) } -puts movies +days = movies.group_by { |movie| movie.start_time.strftime("%A %d.%m.%Y") } +days.each do |d, movies| + graph = SVG::Graph::Schedule.new({ + graph_title: d, + show_graph_title: true, + show_x_guidelines: true, + width: 1024, + key: false, + x_label_format: "%H:%M" + }) + + venues = movies.group_by { |m| m.venue } + venues.each do |v, m| + data = m.flat_map { |m| m.triplet } + graph.add_data({ title: v, data: data }) + end + + IO.write("#{d}-program.svg", graph.burn()) +end -- cgit v1.2.3