Class: Flukso::ScatterPlotDaily

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

Overview

a simple scatterplot

Instance Method Summary collapse

Constructor Details

#initialize(annotation) ⇒ ScatterPlotDaily

Returns a new instance of ScatterPlotDaily.



25
26
27
28
29
# File 'lib/flukso/plots.rb', line 25

def initialize(annotation)
  @annotation=annotation;
  @readings=Array.new()
  @dataset_id="data"+generateRandomString();
end

Instance Method Details

#addReading(reading) ⇒ Object



30
31
32
# File 'lib/flukso/plots.rb', line 30

def addReading(reading);
  @readings << reading
end

#cmdObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/flukso/plots.rb', line 54

def cmd()
  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    cat(\"Plotting scatterplot:\", title, data_points, \"\\n\");\n    xyplot(\#{@dataset_id}$value ~ \#{@dataset_id}$period, main=title, \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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flukso/plots.rb', line 33

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"