end
snapshots = nil
- if metric.numeric?
- snapshots_conditions = ["snapshots.scope = 'FIL'", "project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL"]
- snapshots_values = {}
- snapshots_conditions << "snapshots.path LIKE :path"
- snapshots_values[:path] = "#{@snapshot.path}#{@snapshot.id}.%"
- snapshots_conditions << "project_measures.metric_id = :m_id"
- snapshots_values[:m_id] = metric.id
- snapshots_conditions << "snapshots.root_project_id = :root_id"
- snapshots_values[:root_id] = @snapshot.root_project_id
-
- snapshots=Snapshot.find(:all,
- :conditions => [snapshots_conditions.join(' AND '), snapshots_values],
- :include => ['project', 'measures'],
- :order => "project_measures.value #{'DESC' if metric.direction<0}",
- :limit => limit)
+ if metric.numeric?
+ snapshots_conditions=["snapshots.scope = 'FIL'", "snapshots.islast=:islast"]
+ snapshots_values={:islast => true}
+ snapshots_conditions << '(snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
+ snapshots_values[:sid]=@snapshot.id
+ snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
+ snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
+
+ measures_conditions = ["project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL"]
+ measures_values = {}
+ measures_conditions << "project_measures.metric_id = :m_id"
+ measures_values[:m_id] = metric.id
+
+ measures=ProjectMeasure.find(:all,
+ :joins => :snapshot,
+ :conditions => [ (snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
+ :order => "project_measures.value #{'DESC' if metric.direction<0}",
+ :limit => limit)
+
+ snapshots=Snapshot.find(measures.map {|m| m.snapshot_id}, :include => 'project')
+ snapshots_by_id = {}
+ snapshots.each do |s|
+ snapshots_by_id[s.id]=s
+ end
end
%>
else
metric_max_value = snapshots.first.measure(metric).value
end
- snapshots.each do |s|
- measure = s.measure(metric)
- resource = s.resource
+ measures.each do |measure|
+ resource = snapshots_by_id[measure.snapshot_id].resource
%>
<tr class="<%= cycle 'even','odd', :name => ('hotspot_metric' + widget.id.to_s) -%>">
<td>
metric = Metric.find(:first, :conditions => "name = 'weighted_violations'")
- snapshots_conditions = ["snapshots.scope = 'FIL'"]
- snapshots_values = {}
+ snapshots_conditions=["snapshots.scope = 'FIL'", "snapshots.islast=:islast"]
+ snapshots_values={:islast => true}
snapshots_conditions << "(snapshots.qualifier = 'CLA' OR snapshots.qualifier = 'FIL' OR snapshots.qualifier = 'TRK')"
- snapshots_conditions << "project_measures.rule_id IS NULL"
- snapshots_conditions << "project_measures.characteristic_id IS NULL"
- snapshots_conditions << "snapshots.path LIKE :path"
- snapshots_values[:path] = "#{@snapshot.path}#{@snapshot.id}.%"
- snapshots_conditions << "project_measures.metric_id = :m_id"
- snapshots_values[:m_id] = metric.id
- snapshots_conditions << "snapshots.root_project_id = :root_id"
- snapshots_values[:root_id] = @snapshot.root_project_id
-
- snapshots=Snapshot.find(:all,
- :conditions => [snapshots_conditions.join(' AND '), snapshots_values],
- :include => ['project', 'measures'],
- :order => "project_measures.value DESC",
- :limit => limit)
+ snapshots_conditions << '(snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
+ snapshots_values[:sid]=@snapshot.id
+ snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
+ snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
+
+ measures_conditions = ["project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL"]
+ measures_values = {}
+ measures_conditions << "project_measures.metric_id = :m_id"
+ measures_values[:m_id] = metric.id
+
+ measures=ProjectMeasure.find(:all,
+ :joins => :snapshot,
+ :conditions => [ (snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
+ :order => "project_measures.value #{'DESC' if metric.direction<0}",
+ :limit => limit)
+
+ snapshots=Snapshot.find(measures.map {|m| m.snapshot_id}, :include => 'project')
+ snapshots_by_id = {}
+ snapshots.each do |s|
+ snapshots_by_id[s.id]=s
+ end
%>
<div class="line-block">
<thead><tr><th colspan="11"/></tr></thead>
<tbody>
<%
- snapshots.each do |s|
- resource = s.resource
+ measures.each do |measure|
+ resource = snapshots_by_id[measure.snapshot_id].resource
violations_per_severity={}
- s.measure(metric).text_value.split(';').each do |part|
+ measure.text_value.split(';').each do |part|
fields=part.split('=')
violations_per_severity[fields[0]]=fields[1]
end