Class: Flukso::DailyLine
- Inherits:
-
Object
- Object
- Flukso::DailyLine
- Defined in:
- lib/flukso/plots.rb
Overview
Plot a single day as a line.
Instance Method Summary collapse
- #addReading(reading) ⇒ Object
- #cmd ⇒ Object
- #create_dataframe_cmd ⇒ Object
-
#initialize(annotation, day, month, year) ⇒ DailyLine
constructor
A new instance of DailyLine.
Constructor Details
#initialize(annotation, day, month, year) ⇒ DailyLine
Returns a new instance of DailyLine.
73 74 75 76 77 78 79 80 |
# File 'lib/flukso/plots.rb', line 73 def initialize(annotation, day, month, year) @annotation=annotation; @day=day @month=month @year=year @readings=Array.new() @dataset_id="data"+generateRandomString(); end |
Instance Method Details
#addReading(reading) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/flukso/plots.rb', line 81 def addReading(reading); # Check wether the reading is on our day. if reading.isOnDay?(@day, @month, @year) @readings << reading # puts "adding reading." if $verbose #else # puts "skipping reading (not on desired day)" if $verbose end end |
#cmd ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/flukso/plots.rb', line 111 def cmd() if @readings.empty? raise "no values selected - cannot create DailyLine plot for #{@year}-#{@month}-#{@day}" end dataframe=create_dataframe_cmd(); cmd= <<-END_OF_CMD # plot commmands. library(lattice); y_max=max(#{@dataset_id}$value); title<-paste("Daily Power Consumption", "#{@annotation}") data_points<-paste("Number of data points:",nrow(#{@dataset_id})); plot(#{@dataset_id}$value ~ #{@dataset_id}$period, main=title, type="l", ylab="Power Usage [W]", xlab="Time Period [15min Intervals]", sub=data_points, ylim=c(0,y_max), xlim=c(0,95)); END_OF_CMD return dataframe << cmd end |
#create_dataframe_cmd ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/flukso/plots.rb', line 90 def create_dataframe_cmd() cmd_create_dataframe= <<-END_OF_CMD #{@dataset_id} <- data.frame( date=character(), dayofweek=character(), period=numeric(), value=numeric() ); END_OF_CMD @readings.each{|reading| # calculate some values. currenttime=Time.at(reading.); cmd_compose_data= <<-END_OF_CMD newline<-data.frame(#{reading.}, "#{reading.dayOfWeek}", #{reading.period}, #{reading.value}); colnames(newline)<- colnames(#{@dataset_id}); #{@dataset_id} <- rbind(#{@dataset_id}, newline); END_OF_CMD cmd_create_dataframe << cmd_compose_data; } return cmd_create_dataframe end |