Skip to content

Commit f75f335

Browse files
author
Lennart Koopmann
committed
more work on graph comparison
1 parent 060b192 commit f75f335

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

app/controllers/visuals_controller.rb

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def fetch
1414
when "totalgraph" then
1515
r["data"] = calculate_totalgraph(params[:hours])
1616
when "streamgraph" then
17-
r["data"] = calculate_streamgraph(params[:stream_id], params[:hours])
17+
r["data"] = calculate_streamgraph(params[:stream_ids], params[:hours])
1818
end
1919
end
2020

@@ -130,36 +130,49 @@ def calculate_totalgraph(hours = 12)
130130
end
131131
end
132132

133-
def calculate_streamgraph(stream_id, hours=12)
134-
stream = Stream.find(stream_id)
133+
def calculate_streamgraph(stream_ids, hours=12)
134+
streams = Array.new
135+
stream_ids.split(',').each do |id|
136+
stream = Stream.find(id)
137+
next if stream.streamrules.blank?
138+
139+
streams << stream
140+
end
135141

136-
return Array.new if stream.streamrules.blank?
142+
return Array.new if streams.blank?
137143

138-
data = Array.new
139-
data2 = Array.new
140-
Message.stream_counts_of_last_minutes(stream.id, hours.to_i*60).collect do |c|
141-
data << [ (c[:minute].to_i+Time.now.utc_offset)*1000, c[:count] ]
142-
data2 << [ (c[:minute].to_i+Time.now.utc_offset)*1000, c[:count]+rand(50) ]
144+
rows = Array.new
145+
streams.each do |stream|
146+
data = Array.new
147+
Message.stream_counts_of_last_minutes(stream.id, hours.to_i*60).collect do |c|
148+
data << [ (c[:minute].to_i+Time.now.utc_offset)*1000, c[:count] ]
149+
end
150+
rows << data
143151
end
144152

145153
ret = Array.new
146154

147-
ret << {
148-
"color" => "#000",
149-
"shadowSize" => 0,
150-
"data" => data2,
151-
"points" => { "show" => false },
152-
"lines" => { "show" => true, "fill" => false }
153-
}
155+
i = 0
156+
rows.each do |row|
157+
if i == 0
158+
color = "#fd0c99"
159+
filling = true
160+
shadow = true
161+
else
162+
color = "#000"
163+
filling = false
164+
shadow = false
165+
end
166+
ret << {
167+
"color" => color,
168+
"shadowSize" => shadow,
169+
"data" => row,
170+
"points" => { "show" => false },
171+
"lines" => { "show" => true, "fill" => filling }
172+
}
173+
i += 1
174+
end
154175

155-
ret << {
156-
"color" => "#fd0c99",
157-
"shadowSize" => 10,
158-
"data" => data,
159-
"points" => { "show" => false },
160-
"lines" => { "show" => true, "fill" => false }
161-
}
162-
163176
return ret
164177
end
165178

app/helpers/application_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def build_controller_action_uri append_params = nil
7272
end
7373

7474
def flot_graph_loader(options)
75-
if options[:stream_id].blank?
75+
if options[:stream_ids].blank?
7676
url = visuals_path("totalgraph", :hours => options[:hours])
7777
else
78-
url = visuals_path("streamgraph", :stream_id => options[:stream_id], :hours => options[:hours])
78+
url = visuals_path("streamgraph", :stream_ids => options[:stream_ids], :hours => options[:hours])
7979
end
8080

8181
"<script type='text/javascript'>

app/views/streams/analytics.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<%=raw flot_graph_loader(
2626
:inject => "#streams-analytics-new-messages",
27-
:stream_id => @stream.id,
27+
:stream_ids => params[:compare_with].blank? ? @stream.id : @stream.id.to_s + ",#{params[:compare_with]}",
2828
:hours => 12
2929
)
3030
%>

0 commit comments

Comments
 (0)