Class: Flukso::DailyLine

Inherits:
Object
  • Object
show all
Defined in:
lib/flukso/plots.rb

Overview

Plot a single day as a line.

Instance Method Summary collapse

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

#cmdObject



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= "    # plot commmands. \n    library(lattice);\n    y_max=max(\#{@dataset_id}$value);\n    title<-paste(\"Daily Power Consumption\", \"\#{@annotation}\")\n    data_points<-paste(\"Number of data points:\",nrow(\#{@dataset_id}));\n    plot(\#{@dataset_id}$value ~ \#{@dataset_id}$period, main=title, type=\"l\",\n    ylab=\"Power Usage [W]\", xlab=\"Time Period [15min Intervals]\", \n    sub=data_points, ylim=c(0,y_max), xlim=c(0,95));\n  END_OF_CMD\n  return dataframe << cmd\nend\n"

#create_dataframe_cmdObject



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= "    \#{@dataset_id} <- data.frame( \n      date=character(), \n      dayofweek=character(), \n      period=numeric(), \n      value=numeric() \n    );\n  END_OF_CMD\n  @readings.each{|reading|\n    # calculate some values.\n    currenttime=Time.at(reading.utc_timestamp);\n    cmd_compose_data= <<-END_OF_CMD\n      newline<-data.frame(\#{reading.utc_timestamp}, \"\#{reading.dayOfWeek}\", \#{reading.period}, \#{reading.value}); \n      colnames(newline)<- colnames(\#{@dataset_id});\n      \#{@dataset_id} <- rbind(\#{@dataset_id}, newline);\n    END_OF_CMD\n    cmd_create_dataframe << cmd_compose_data;\n  }\n  return cmd_create_dataframe\nend\n"