if from_date
options[:from] = from_date
end
+ metric_count_per_snapshot_id = {}
TrendsChart.time_machine_measures(@resource, metric_data_map.keys, options).each() do |trend_item|
+ sid = trend_item["sid"]
+ if metric_count_per_snapshot_id[sid]
+ metric_count_per_snapshot_id[sid] += 1
+ else
+ metric_count_per_snapshot_id[sid] = 1
+ end
metric_data_map[trend_item["metric_id"].to_i] << {:date => trend_item["created_at"], :value => trend_item["value"], :sid => trend_item["sid"]}
end
js_data = "["
js_snapshots = "["
js_metrics = "["
+ total_number_of_metrics = metric_name_map.keys.size()
metric_data_map.keys.each_with_index() do |metric_id, index|
unless metric_data_map[metric_id].empty?
js_metrics += "\"" + metric_name_map[metric_id] + "\","
js_data += "["
metric_data_map[metric_id].each() do |metric_data|
- m_date = Time.parse(metric_data[:date])
- js_data += "{x:d("
- js_data += m_date.year.to_s
- js_data += ","
- # Need to decrease by 1 the month as the JS Date object start months at 0 (= January)
- js_data += (m_date.month - 1).to_s
- js_data += ","
- js_data += m_date.day.to_s
- js_data += ","
- js_data += m_date.hour.to_s
- js_data += ","
- js_data += m_date.min.to_s
- js_data += ","
- js_data += m_date.sec.to_s
- js_data += "),y:"
- js_data += sprintf( "%0.02f", metric_data[:value])
- js_data += "},"
- if index == 0
- # we fill the js_snapshots array (no need to do this more than once)
- js_snapshots += "{sid:"
- js_snapshots += metric_data[:sid].to_s
- js_snapshots += ",d:\""
- js_snapshots += l m_date, :format => :long
- js_snapshots += "\"},"
+ # for every metric value, we need to check that the corresponding snapshot has values for each metric (if not, Protovis won't be able to display)
+ if metric_count_per_snapshot_id[metric_data[:sid]]==total_number_of_metrics
+ m_date = Time.parse(metric_data[:date])
+ js_data += "{x:d("
+ js_data += m_date.year.to_s
+ js_data += ","
+ # Need to decrease by 1 the month as the JS Date object start months at 0 (= January)
+ js_data += (m_date.month - 1).to_s
+ js_data += ","
+ js_data += m_date.day.to_s
+ js_data += ","
+ js_data += m_date.hour.to_s
+ js_data += ","
+ js_data += m_date.min.to_s
+ js_data += ","
+ js_data += m_date.sec.to_s
+ js_data += "),y:"
+ js_data += sprintf( "%0.02f", metric_data[:value])
+ js_data += "},"
+ if index == 0
+ # we fill the js_snapshots array (no need to do this more than once)
+ js_snapshots += "{sid:"
+ js_snapshots += metric_data[:sid].to_s
+ js_snapshots += ",d:\""
+ js_snapshots += human_short_date m_date
+ js_snapshots += "\"},"
+ end
end
end
js_data = js_data.chomp(',') + "],"