SimpleOutput 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dabf64a2f40b67501750813071a68bb813282841
4
- data.tar.gz: 2ee609d2217d23d835217e9e8e242c676ebebe41
3
+ metadata.gz: e7ebf0691394ba5cf34bb6e47d6afe3598e2fa03
4
+ data.tar.gz: 800416135fda502c21d9c79f957b91fe96b43c71
5
5
  SHA512:
6
- metadata.gz: 5a749e77cb1011758d526d5ca52733d9476e27ba67b80626d30a09cb5b645de1f64ea182020f3f85b9f69d53854b62789ab599a7faac5d6759eda0e1c1ef1ca0
7
- data.tar.gz: 6120f548b60baa12d598826aa5974fc6b9d63b6092dd7d2408ee579dd444865bd353f36a20738d800b73db2ac228a9cf3c3657df107e048c644a81a59188901f
6
+ metadata.gz: 1d59d2d9dc4fa97e42029ded815c5653ce715bc26b939c51b170688c7292c6e3d667cec2b6ef96493464a00466f6fd59e0cb67c97c1f4073bbcd78819afe3bd0
7
+ data.tar.gz: 8b2cd13fe965ed7678dfa315d280c52a0e443b6688cd50025d7a4976d3c282bfb11c6e65614998fdbcbad1aca1845168efc707ee41fa7b390b4dc72fc00c8dea
@@ -23,17 +23,34 @@ class SimpleChartkick < SimpleOutput::SimpleOutputPlugin
23
23
  def initialize(filename="results.html", title="Html Results Page", javascript_path="../include")
24
24
  super()
25
25
  @filename = filename
26
- @chart_type = {}
26
+ @metadata = {}
27
27
  chartkick_path = javascript_path + ((javascript_path[-1] == "/") ? "chartkick.js" : "/chartkick.js");
28
28
  @html = "<html>\n<title>\n#{title}\n</title>\n<script src='http://www.google.com/jsapi'></script>\n
29
29
  <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
30
30
  <script src='#{chartkick_path}'></script>\n<body>\n"
31
31
 
32
32
  end
33
+ def new_data_callback(name)
34
+ @metadata[name] = {'chart_type' => 'LineChart', 'bincount' => 10}
35
+ end
33
36
 
34
37
  def options_callback(options)
35
38
  if options.has_key?("chart_type")
36
- @chart_type[@current_name] = options['chart_type']
39
+ @metadata[@current_name]['chart_type'] = options['chart_type']
40
+ end
41
+ if options.has_key?('histogram')
42
+ if options['histogram']
43
+ @metadata[@current_name]['chart_type'] = 'Histogram'
44
+ end
45
+ end
46
+ if options.has_key?('bincount')
47
+ @metadata[@current_name]['bincount'] = options['bincount']
48
+ end
49
+ if options.has_key?('ymin')
50
+ @metadata[@current_name]['ymin'] = options['ymin']
51
+ end
52
+ if options.has_key?('ymax')
53
+ @metadata[@current_name]['ymax'] = options['ymax']
37
54
  end
38
55
  end
39
56
 
@@ -120,9 +137,43 @@ class SimpleChartkick < SimpleOutput::SimpleOutputPlugin
120
137
  @js_block = ""
121
138
 
122
139
  self.getMultiSeriesHashes.each_pair do |(chart_name, chart_series)|
123
- type = @chart_type.has_key?(chart_name) ? @chart_type[chart_name] : "LineChart"
140
+ if !@metadata.has_key?(chart_name)
141
+ @metadata[chart_name] = {'chart_type' => 'LineChart', 'bincount' => 10}
142
+ end
143
+ type = @metadata[chart_name].has_key?('chart_type') ? @metadata[chart_name]['chart_type'] : 'LineChart'
124
144
  if type == "PieChart"
125
145
  chart_series = chart_series[0]['data']
146
+ elsif type == "Histogram"
147
+ type = 'ColumnChart'
148
+ bins = @metadata[chart_name]['bincount']
149
+ #Reorder data
150
+ chart_series.each do |series|
151
+ name = series['name']
152
+ series_data = series['data']
153
+
154
+ hist_data = {}
155
+ ypoints = []
156
+
157
+ series_data.each_pair do |(x, y)|
158
+ ypoints << y
159
+ end
160
+ min = @metadata[chart_name].has_key?('ymin') ? @metadata[chart_name]['ymin'] : ypoints.min
161
+ max = @metadata[chart_name].has_key?('ymax') ? @metadata[chart_name]['ymax'] : ypoints.max
162
+ width = (max.to_f-min.to_f)/bins.to_f
163
+ bins.times do |i|
164
+ index = (width*i).round(2)
165
+ hist_data[index] = 0
166
+ ypoints.delete_if do |value|
167
+ if value >= width*i && value < width*(i+1)
168
+ hist_data[index] += 1
169
+ true
170
+ else
171
+ false
172
+ end
173
+ end
174
+ end
175
+ series['data'] = hist_data
176
+ end
126
177
  end
127
178
  self.chart_div(chart_series, type, chart_name)
128
179
  if @annotations.has_key?(chart_name)
data/lib/simplelog.rb ADDED
@@ -0,0 +1,169 @@
1
+ =begin
2
+ SimpleCSV
3
+ Copyright 2014 Austen Higgins-Cassidy
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ =end
17
+ require 'time'
18
+ class SimpleLog < SimpleOutput::SimpleOutputPlugin
19
+ #Only supports annotation
20
+ def initialize(name = "log", format="txt")
21
+ filename = name + self.getTimestamp() + "." + format
22
+ @file = File.new(filename, "w")
23
+ @series_names = {}
24
+ @data_id = 0
25
+ @annotations = {}
26
+ @current_name = ""
27
+ @series_id = 0
28
+ end
29
+
30
+ def translate_name(name)
31
+ if name == nil
32
+ name = @current_name
33
+ end
34
+
35
+ return name
36
+ end
37
+
38
+
39
+ def setXData(data, name, options={})
40
+
41
+ end
42
+
43
+ def setYData(data, name, options={})
44
+
45
+ end
46
+
47
+ def newData( x=[], y=[],name=nil, options={})
48
+
49
+ end
50
+
51
+ #Interface Functions ===================================
52
+ def appendXY( x=[], y=[],name=nil, options={})
53
+ log_name(name)
54
+ log_var(x, "Appending X Data")
55
+ log_var(y, "Appending Y Data")
56
+ end
57
+
58
+ def setXY(x=[], y=[], name=nil, options={})
59
+ log_name(name)
60
+ log_var(x, "Setting X Data")
61
+ log_var(y, "Setting Y Data")
62
+ end
63
+
64
+ def appendPoints(points =[], name=nil, options={})
65
+ log_name(name)
66
+ log_var(points, "Appending (points)")
67
+ end
68
+
69
+ def setPoints(points = [], name=nil, options={})
70
+ log_name(name)
71
+ log_var(points, "Setting (points)")
72
+ end
73
+
74
+ def appendHash(hash = {}, name=nil, options={})
75
+ log_name(name)
76
+ log_var(hash, "Appending (hash)")
77
+ end
78
+
79
+ def setHash(hash ={}, name=nil, options={})
80
+ log_name(name)
81
+ log_var(hash, "Setting (hash)")
82
+ end
83
+
84
+
85
+
86
+ def setOptions(name=nil, options = {})
87
+ log_var(option, "Options")
88
+ end
89
+
90
+ def annotate(annotation, name=nil, options = {})
91
+ name = translate_name(name)
92
+ log(annotation, name)
93
+ self.options_callback(options)
94
+ end
95
+
96
+ def log(content, name = nil)
97
+ if name != nil
98
+ logtext = self.getTimestamp() + " #{name}: #{content}"
99
+ else
100
+ logtext = self.getTimestamp() + " #{content}"
101
+ end
102
+ puts logtext
103
+ @file.syswrite("#{logtext}\n")
104
+ end
105
+
106
+ def log_name(name = nil)
107
+ name = translate_name(name)
108
+ log("<For #{name}>:")
109
+ end
110
+
111
+ def log_var(var, name=nil)
112
+ log("value:", name)
113
+ str = parse_var(var,1)
114
+ puts str
115
+ @file.syswrite("#{str}\n")
116
+ end
117
+
118
+ def parse_var(var, indent)
119
+ string = ""
120
+ case var
121
+ when Hash
122
+ string += self.put_at_indent("Hash:", indent)
123
+ var.each_pair do |(key, value)|
124
+ string += self.put_at_indent(key.to_s, indent+1)
125
+ string += self.parse_var(value, indent+1)
126
+ end
127
+ when Array
128
+ string += self.put_at_indent("Array:", indent)
129
+ var.each do |value|
130
+ string += self.parse_var(value, indent+1)
131
+ end
132
+ when Numeric
133
+ string += self.put_at_indent(var.to_s, indent)
134
+ when String
135
+ string += self.put_at_indent(var, indent)
136
+ else
137
+ string += self.put_at_indent(var.to_s, indent)
138
+ end
139
+ string
140
+ end
141
+
142
+ def put_at_indent(content, indent)
143
+ string = ""
144
+ indent.times { string += " "}
145
+ string += content + "\n"
146
+ end
147
+
148
+
149
+
150
+ def getTimestamp()
151
+ Time.now.strftime("%Y-%m-%d-%H%M%S")
152
+ end
153
+
154
+ def getDataAsPoints
155
+ [[0,0]]
156
+ end
157
+
158
+ def getDataAsXY
159
+ [[0],[0]]
160
+ end
161
+
162
+ def getSeriesHashes
163
+ {0 => 0}
164
+ end
165
+
166
+ def save()
167
+ @file.close
168
+ end
169
+ end
data/lib/simpleoutput.rb CHANGED
@@ -182,6 +182,10 @@ module SimpleOutput
182
182
  self.options_callback(options)
183
183
  end
184
184
 
185
+ def setOptions(name=nil, options = {})
186
+ self.options_callback(options)
187
+ end
188
+
185
189
  #Internal Helpers
186
190
  def getDataAsPoints
187
191
  series_data = {}
data/lib/simpleplot.rb CHANGED
@@ -35,6 +35,27 @@ class SimplePlot < SimpleOutput::SimpleOutputPlugin
35
35
  if options.has_key?('ylabel')
36
36
  @metadata[@current_name]['ylabel'] = options['ylabel']
37
37
  end
38
+ if options.has_key?('histogram')
39
+ @metadata[@current_name]['histogram'] = options['histogram']
40
+ end
41
+ if options.has_key?('xmin')
42
+ @metadata[@current_name]['xmin'] = options['xmin']
43
+ end
44
+ if options.has_key?('xmax')
45
+ @metadata[@current_name]['xmax'] = options['xmax']
46
+ end
47
+ if options.has_key?('ymin')
48
+ @metadata[@current_name]['ymin'] = options['ymin']
49
+ end
50
+ if options.has_key?('ymax')
51
+ @metadata[@current_name]['ymax'] = options['ymax']
52
+ end
53
+ if options.has_key?('bincount')
54
+ @metadata[@current_name]['bincount'] = options['binscount']
55
+ end
56
+ if options.has_key?('normalized')
57
+ @metadata[@current_name]['normalized'] = options['normalized']
58
+ end
38
59
  end
39
60
 
40
61
  def check_title(name, options)
@@ -47,7 +68,7 @@ class SimplePlot < SimpleOutput::SimpleOutputPlugin
47
68
  end
48
69
 
49
70
  def new_data_callback(name)
50
- @metadata[name] = {'xlabel' => 'x', 'ylabel' => 'y', 'xmin' => 0 , 'xmax' => 10, 'ymin' => 0, 'ymax' => 10, 'series_titles' => []}
71
+ @metadata[name] = {'length' => 0, 'xlabel' => 'x', 'ylabel' => 'y', 'xmin' => 0 , 'xmax' => 10, 'ymin' => 0, 'ymax' => 10, 'series_titles' => [], 'histogram' => false, 'bincount' => 10, 'normalized' => false}
51
72
  end
52
73
 
53
74
  def set_x_callback(data, name, options)
@@ -55,6 +76,7 @@ class SimplePlot < SimpleOutput::SimpleOutputPlugin
55
76
  xmax = data.max
56
77
  @metadata[name]['xmin'] = xmin
57
78
  @metadata[name]['xmax'] = xmax
79
+ @metadata[name]['length'] = (@metadata[name]['length'] < data.size) ? data.size : @metadata[name]['length']
58
80
  check_title(name, options)
59
81
  end
60
82
 
@@ -71,8 +93,9 @@ class SimplePlot < SimpleOutput::SimpleOutputPlugin
71
93
  ymin = y.min
72
94
  ymax = y.max
73
95
  if !@metadata.has_key?(name)
74
- new_series_callback(name)
96
+ new_data_callback(name)
75
97
  end
98
+ @metadata[name]['length'] = @metadata[name]['length'] < x.size ? x.size : @metadata[name]['length']
76
99
  @metadata[name]['xmin'] = xmin < @metadata[name]['xmin'] ? xmin : @metadata[name]['xmin']
77
100
  @metadata[name]['xmax'] = xmax > @metadata[name]['xmax'] ? xmax : @metadata[name]['xmax']
78
101
  @metadata[name]['ymin'] = ymin < @metadata[name]['ymin'] ? ymin : @metadata[name]['ymin']
@@ -94,14 +117,39 @@ class SimplePlot < SimpleOutput::SimpleOutputPlugin
94
117
 
95
118
  plot.xlabel @metadata[set_name]['xlabel']
96
119
  plot.ylabel @metadata[set_name]['ylabel']
97
- plot.xrange "[#{@metadata[set_name]['xmin']}:#{@metadata[set_name]['xmax']}]"
98
- plot.yrange "[#{@metadata[set_name]['ymin']}:#{@metadata[set_name]['ymax']}]"
99
120
  plot.data = []
121
+ if @metadata[set_name]['histogram']
122
+ size = @metadata[set_name]['length']
123
+ bins = @metadata[set_name]['bincount']
124
+ max = @metadata[set_name]['ymax']
125
+ min = @metadata[set_name]['ymin']
126
+ width = (max-min).to_f/bins.to_f
127
+ #bins = size.to_f/width.to_f
128
+ plot.yrange '[0:]'
129
+ plot.xrange "[#{min}:#{max}]"
130
+ plot.set('boxwidth',width*0.9)
131
+ plot.set('offset', 'graph 0.05,0.05,0.05,0.0')
132
+ plot.set('xtics' " #{min}, #{width.to_f}, #{max}")
133
+ plot.set('tics', 'out nomirror')
134
+ plot.set('style', 'fill solid 0.5')
135
+ else
136
+ plot.xrange "[#{@metadata[set_name]['xmin']}:#{@metadata[set_name]['xmax']}]"
137
+ plot.yrange "[#{@metadata[set_name]['ymin']}:#{@metadata[set_name]['ymax']}]"
138
+ end
100
139
  series.each_with_index do |line, index|
140
+ if @metadata[set_name]['histogram']
141
+ line = line[1]
142
+ end
101
143
  d = Gnuplot::DataSet.new(line)
102
144
  d.title = @metadata[set_name]['series_titles'][index]
103
- d.with = "linespoints"
104
- d.linewidth = 2
145
+
146
+ if @metadata[set_name]['histogram']
147
+ d.using = "(#{width}*floor($1/#{width})+#{width}/2.0):(1.0) smooth freq w boxes lc rgb\"blue\""
148
+ else
149
+ d.with = "linespoints"
150
+ d.linewidth = 2
151
+ end
152
+
105
153
  plot.data << d
106
154
 
107
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SimpleOutput
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austen Higgins-Cassidy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A pluging based graphing and report rendering system with multiple simultanous
14
14
  output systems supported
@@ -20,6 +20,7 @@ files:
20
20
  - LICENSE
21
21
  - include/chartkick.js
22
22
  - lib/simplechartkick.rb
23
+ - lib/simplelog.rb
23
24
  - lib/simpleoutput.rb
24
25
  - lib/simpleplot.rb
25
26
  homepage: https://github.com/Plasmarobo/simpleoutput