From 996894cf8e2426d3387f83cec1e95020f0cb120b Mon Sep 17 00:00:00 2001 From: Chris Schlaeger Date: Tue, 31 Jan 2017 21:53:28 +0100 Subject: First attempt to show monitoring data in browser. --- lib/postrunner/DailyMonitoringView.rb | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/postrunner/DailyMonitoringView.rb (limited to 'lib') diff --git a/lib/postrunner/DailyMonitoringView.rb b/lib/postrunner/DailyMonitoringView.rb new file mode 100644 index 0000000..e062b98 --- /dev/null +++ b/lib/postrunner/DailyMonitoringView.rb @@ -0,0 +1,85 @@ +#!/usr/bin/env ruby -w +# encoding: UTF-8 +# +# = DailyMonitoringView.rb -- PostRunner - Manage the data from your Garmin sport devices. +# +# Copyright (c) 2016 by Chris Schlaeger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# + +require 'fit4ruby' + +require 'postrunner/View' +require 'postrunner/MonitoringStatistics' + +module PostRunner + + class DailyMonitoringView < View + + attr_reader :file_name + + def initialize(db, date, monitoring_files) + @db = db + @ffs = db['file_store'] + views = @ffs.views + views.current_page = nil + @date = date + @monitoring_files = monitoring_files + + @file_name = File.join(@db['config']['html_dir'], "#{date}.html") + + pages = PagingButtons.new([ date ]) + #pages.current_page = "#{date}.html" + + super("PostRunner Daily Monitoring: #{date}", views, pages) + generate_html(@doc) + write(@file_name) + end + + private + + def generate_html(doc) + doc.unique(:dailymonitoringview_style) { + doc.head { + [ 'jquery/jquery-2.1.1.min.js', 'flot/jquery.flot.js', + 'flot/jquery.flot.time.js' ].each do |js| + doc.script({ 'language' => 'javascript', + 'type' => 'text/javascript', 'src' => js }) + end + doc.style(style) + } + } + #doc.meta({ 'name' => 'viewport', + # 'content' => 'width=device-width, ' + + # 'initial-scale=1.0, maximum-scale=1.0, ' + + # 'user-scalable=0' }) + + body { + doc.body { + doc.div({ :class => 'main' }) { + MonitoringStatistics.new(@monitoring_files).daily_html(@date, doc) + } + } + } + end + + def style + <