Browse code

Save results to array

Cinan Rakosnik authored on 17/12/2012 at 01:42:14
Showing 1 changed files
... ...
@@ -15,13 +15,16 @@ module Rubysermon
15 15
 		def initialize
16 16
 			@config 		= { repeat: 60,
17 17
 								config_path: "#{LIB_PATH}/rubysermon/config.json",
18
-								db_path: "/tmp/rubysermon_history.db"
18
+								db_path: "/tmp/rubysermon_history.db",
19
+								history_size: 90
19 20
 			}
20 21
 
21 22
 			@running_mods	= []
22 23
 			@enabled_mods	= []
23 24
 			@db				= nil
24 25
 
26
+			@results		= []
27
+
25 28
 			check_args()
26 29
 		end
27 30
 
... ...
@@ -63,6 +66,7 @@ module Rubysermon
63 63
 
64 64
 		def load_mod(mod_name)
65 65
 			begin
66
+				#prekonvertovat na symbol
66 67
 				mod = ModLoader.load(mod_name)
67 68
 				@running_mods.push(mod)
68 69
 			rescue ModLoaderException => e
... ...
@@ -88,11 +92,32 @@ module Rubysermon
88 88
 			while true
89 89
 				current_time = DateTime.now()
90 90
 				@running_mods.each do |mod|
91
-					result = mod.results
92
-					notify = mod.notify?
91
+					save_results(mod, current_time, mod.results())
92
+					notify() if mod.notify?
93 93
 				end
94
+				make_output()
94 95
 				sleep @config[:repeat]
95 96
 			end
96 97
 		end
98
+
99
+		def save_results(mod, time, result)
100
+			mod_results = @results[mod]
101
+
102
+			if mod_results.size >= @config[:history_size]
103
+				mod_results.slice!(@config[:history_size], @results[mod].size)
104
+			end
105
+
106
+			#shift() and push() operations have O(1) complexity.
107
+			mod_results.shift()
108
+			mod_results.push([time: time, value: result])
109
+		end
110
+
111
+		def notify
112
+
113
+		end
114
+
115
+		def make_output
116
+
117
+		end
97 118
 	end
98 119
 end