metric_admin 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ module MetricsHelper
2
+ def summary_headers(summary)
3
+ if summary.action == "count"
4
+ [summary.group_by_key, summary.action]
5
+ else
6
+ [summary.group_by_key, summary.action, 'Amount']
7
+ end
8
+ end
9
+
10
+ def summary_results(summary, results)
11
+ response = []
12
+ headers = results[0]
13
+ summary_key = summary.group_by_key.capitalize.gsub("_"," ")
14
+ summary_index = headers.index(summary_key)
15
+
16
+ if summary.action_on.present?
17
+ summary_action_on = summary.action_on.capitalize.gsub("_"," ")
18
+ summary_action_on_index = headers.index(summary_action_on)
19
+ end
20
+
21
+ summary_results = results.map{|x| x[summary_index]}.uniq.sort - [summary_key]
22
+
23
+ case summary.action
24
+ when 'count'
25
+ summary_results.each do |s|
26
+ response << {:key => s, :count => results.count{|x| x[summary_index] == s }}
27
+ end
28
+ when 'sum'
29
+ summary_results.each do |s|
30
+ response << {:key => s, :count => results.count{|x| x[summary_index] == s }, :sum => results.select{|x| x[summary_index] == s }.sum{|x| x[summary_action_on_index].to_f }}
31
+ end
32
+ when 'average'
33
+ summary_results.each do |s|
34
+ response << {:key => s, :count => results.count{|x| x[summary_index] == s }, :average => results.select{|x| x[summary_index] == s }.sum{|x| x[summary_action_on_index].to_f } / results.count{|x| x[summary_index] == s }}
35
+ end
36
+ when 'median'
37
+ summary_results.each do |s|
38
+ response << {:key => s, :count => results.count{|x| x[summary_index] == s }, :median => median(results.select{|x| x[summary_index] == s }.map{|x| x[summary_action_on_index].to_f })}
39
+ end
40
+ else
41
+ raise "#{summary.action.capitalize} is not defined, please define it in metrics_helper.rb"
42
+ end
43
+
44
+ return response
45
+ end
46
+ end
@@ -1,19 +1,27 @@
1
1
  - f.fields_for :metric_summaries do |ms|
2
2
  %div.summary
3
- = ms.label "Metric summary title"
4
- = ms.text_field :title
5
- = ms.label "Group by"
6
- = ms.select :group_by_key, eval(@metric.logic.match(/\['(.*?)'\]/)[0]), :prompt => 'select one...'
7
- and
8
- = ms.label "Action"
9
- = ms.select :action, %w( count sum average median), {}, { :class => "action-to-take" }
10
- on
11
- %div.acton
12
- = ms.label "Act on"
13
- = ms.select :action_on, eval(@metric.logic.match(/\['(.*?)'\]/)[0]), :include_blank => true
14
- = link_to "Add summary", "#", :class => "add_fields", :'data-id' => @metric.id
15
- - if ms.object.new_record?
16
- = link_to "Remove", "#", :class => "remove_fields"
17
- - else
18
- = link_to "Remove", admin_metric_metric_summary_path(@metric, ms.object), :method => :delete, :remote => true, :class => "remove_fields"
19
- = ms.hidden_field :id
3
+ %div.summary-row
4
+ %div.form-field
5
+ = ms.label "Summary Title"
6
+ = ms.text_field :title
7
+ %div.form-field
8
+ = ms.label "Group By"
9
+ = ms.select :group_by_key, eval(@metric.logic.match(/\['(.*?)'\]/)[0]), :prompt => 'select one...'
10
+ and
11
+ %div.form-field
12
+ = ms.label "Action to Take"
13
+ = ms.select :action, %w( count sum average median), {}, { :class => "action-to-take" }
14
+ on
15
+ %div.form-field
16
+ %div.acton
17
+ %div.form-field
18
+ = ms.label "Acting On"
19
+ = ms.select :action_on, eval(@metric.logic.match(/\['(.*?)'\]/)[0]), :include_blank => true
20
+ %div.form-field
21
+ = link_to "Add", "#", :style=> "position: relative; top: -5px;", :class => "btn btn-default add_fields", :'data-id' => @metric.id
22
+ or
23
+ - if ms.object.new_record?
24
+ = link_to "Remove", "#", :style=> "position: relative; top: -5px;",:class => "btn btn-default remove_fields"
25
+ - else
26
+ = link_to "Remove", admin_metric_metric_summary_path(@metric, ms.object), :method => :delete, :remote => true, :style=> "position: relative; top: -5px;",:class => "btn btn-default remove_fields"
27
+ = ms.hidden_field :id
@@ -83,14 +83,15 @@
83
83
  .controls
84
84
  %label.control-label{:for => "staff_evaluation"} Staff: (for purposes of metric evaluation)
85
85
  = collection_select :metric, :staff_evaluation, @metric.resource_type.resources, :code, :name
86
+ %button.btn.run_logic{"aria-hidden" => "true", "data-dismiss" => "modal"}
87
+ Run
88
+ %i.icon-play
86
89
  %br
87
- %label.control-label{:for => "description"} Configure Summaries:
90
+ %hr
91
+ %h4 Configure Summaries
88
92
  .controls
89
93
  = render :partial => "metric_summaries", :locals => { :f => f } if @metric.logic.match(/\['(.*?)'\]/).present?
90
94
  %br
91
- %button.btn.run_logic{"aria-hidden" => "true", "data-dismiss" => "modal"}
92
- Run
93
- %i.icon-play
94
95
  .loaderImage{:style=>"display:none;"}
95
96
  Loading...
96
97
 
@@ -0,0 +1,82 @@
1
+ .row-fluid
2
+ .span9
3
+ %h1.page-title{:style=>"margin:20px;"}= @metric.title
4
+ .span3
5
+ - if current_user.role?(:administrator)
6
+ = link_to "View metric Logic", edit_admin_metric_path(@metric) , :class=>"btn btn-secondary pull-right", :style=>"margin:20px;"
7
+ .row-fluid
8
+ .span12
9
+ - if @metric.description.to_s != ""
10
+ .well
11
+ %strong Description:
12
+ %br
13
+ = @metric.description rescue nil
14
+
15
+ - @metric.metric_summaries.each do |summary|
16
+ .row-fluid
17
+ .span6
18
+ .well
19
+ %h5=summary.title
20
+ %table.table.table-striped.table-bordered
21
+ - headers = summary_headers(summary)
22
+ %thead
23
+ %tr
24
+ - headers.each_with_index do |x,i|
25
+ %th{:class=>i+1 == headers.count ? "tr" : "tl"}= x.capitalize.gsub("_"," ")
26
+ %tbody
27
+ - summary_results(summary, @result.detailed_results).each do |s|
28
+ %tr
29
+ %td= s[:key]
30
+ %td.tr= s[:count]
31
+ - if summary.action != "count" && ((summary.action_on.downcase["value"]) || (summary.action_on.downcase["amount"]) )
32
+ %td.tr= number_to_currency(s[summary.action.to_sym])
33
+ - elsif summary.action_on.downcase["date"]
34
+ %td.tr= display_date(s[summary.action.to_sym])
35
+ - else
36
+ %td.tr= s[summary.action.to_sym]
37
+
38
+
39
+
40
+ - if @result && @result.detailed_results
41
+ %table.table.tablesorter.table-striped.table-bordered
42
+ - headers = @result.detailed_results.first
43
+ %thead
44
+ %tr
45
+ - headers.each_with_index do |x,i|
46
+ %th{:class=> i+1 == headers.count ? "tr" : "tl"}= x
47
+ %tbody
48
+ - @result.detailed_results.shift
49
+ - @result.detailed_results.each do |x|
50
+ %tr
51
+ - x.each_with_index do |y, i|
52
+ %td{:class=> (i+1 == headers.count) || ((headers[i].downcase["value"]) || (headers[i].downcase["amount"]) ) ? "tr" : "tl", "data-sort-value"=>y.to_s.gsub(",","")}
53
+ - if headers[i].downcase["date"]
54
+ = display_date(y) rescue nil
55
+ - elsif ((headers[i].downcase["value"]) || (headers[i].downcase["amount"]) )
56
+ = number_to_currency(y)
57
+ - else
58
+ = y
59
+ %tfoot
60
+ - if @metric.data_type['average']
61
+
62
+ - if @metric.data_type == "averagecurrency" && (@metric.name.downcase['avg'] || @metric.name.downcase['average'])
63
+ %tr
64
+ %td{:style=>"border-top:2px solid #444;background:#fff;"} Average
65
+ - headers[1..-1].each_with_index do |col, i|
66
+ %td{:class=> (i+2 == headers.count) || ((col.downcase["value"]) || (col.downcase["amount"]) ) ? "tr" : "tl", :style=>"border-top:2px solid #444; background:#fff;"}
67
+ - if (i+2 == headers.count)
68
+ = number_to_currency(@result.result)
69
+ - if @metric.data_type == "average"
70
+ %tr
71
+ %td{:style=>"border-top:2px solid #444;background:#fff;"} Average
72
+ - headers[1..-1].each_with_index do |col, i|
73
+ %td{:class=> (i+2 == headers.count) || ((col.downcase["value"]) || (col.downcase["amount"]) ) ? "tr" : "tl", :style=>"border-top:2px solid #444; background:#fff;"}
74
+ - if (i+2 == headers.count)
75
+ = @result.result
76
+ - else
77
+ / %tr
78
+ / %td{:style=>"border-top:2px solid #444;background:#fff;"} Sum
79
+ / - headers[1..-1].each_with_index do |col, i|
80
+ / %td{:class=> (i+2 == headers.count) || ((col.downcase["value"]) || (col.downcase["amount"]) ) ? "tr" : "tl", :style=>"border-top:2px solid #444; background:#fff;"}
81
+ / - if ((col.downcase["value"]) || (col.downcase["amount"]) )
82
+ / = number_to_currency(@result.detailed_results.sum{|x| x[i+1].to_f })
@@ -1,3 +1,3 @@
1
1
  module MetricAdmin
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 15
9
- version: 0.0.15
8
+ - 16
9
+ version: 0.0.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - Analytics For Lawyers
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2016-09-30 00:00:00 -04:00
17
+ date: 2016-10-03 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -63,12 +63,14 @@ files:
63
63
  - Rakefile
64
64
  - app/controllers/admin/metric_summaries_controller.rb
65
65
  - app/controllers/admin/metrics_controller.rb
66
+ - app/helpers/metrics_helper.rb
66
67
  - app/views/admin/metrics/_metric_summaries.html.haml
67
68
  - app/views/admin/metrics/edit.haml
68
69
  - app/views/admin/metrics/evaluate.js.erb
69
70
  - app/views/admin/metrics/index.haml
70
71
  - app/views/admin/metrics/new.html.haml
71
72
  - app/views/admin/metrics/show.html.erb
73
+ - app/views/metrics/metric_detail.html.haml
72
74
  - config
73
75
  - hooks/ctags
74
76
  - hooks/post-checkout