hawk-eye 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/README.md +2 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/javascripts/hawk-eye.js.coffee +2 -0
  6. data/app/assets/javascripts/hawk-eye/base.js.coffee +17 -0
  7. data/app/assets/javascripts/hawk-eye/date-bin-variable.js.coffee +256 -0
  8. data/app/assets/javascripts/hawk-eye/test.js.coffee +256 -0
  9. data/app/assets/stylesheets/hawk-eye/graphs/_variable_bin.sass +18 -0
  10. data/app/assets/stylesheets/hawk-eye/hawk-eye.sass +2 -0
  11. data/app/assets/stylesheets/hawk-eye/test.sass +40 -0
  12. data/app/assets/stylesheets/hawk_eye/application.css +15 -0
  13. data/app/controllers/hawk_eye/application_controller.rb +14 -0
  14. data/app/helpers/hawk_eye/application_helper.rb +4 -0
  15. data/app/services/hawk_eye/graph/date_bin_helpers.rb +7 -0
  16. data/app/services/hawk_eye/graph/date_bin_variable.rb +89 -0
  17. data/app/views/hawk_eye/application/home.html.slim +15 -0
  18. data/app/views/layouts/hawk_eye/application.html.erb +14 -0
  19. data/config/routes.rb +3 -0
  20. data/lib/hawk-eye.rb +1 -0
  21. data/lib/hawk_eye.rb +7 -0
  22. data/lib/hawk_eye/engine.rb +5 -0
  23. data/lib/hawk_eye/version.rb +3 -0
  24. data/lib/tasks/hawk_eye_tasks.rake +4 -0
  25. data/spec/dummy/README.rdoc +28 -0
  26. data/spec/dummy/Rakefile +6 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/spec/dummy/bin/bundle +3 -0
  33. data/spec/dummy/bin/rails +4 -0
  34. data/spec/dummy/bin/rake +4 -0
  35. data/spec/dummy/bin/setup +29 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/config/application.rb +32 -0
  38. data/spec/dummy/config/boot.rb +5 -0
  39. data/spec/dummy/config/database.yml +25 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +41 -0
  42. data/spec/dummy/config/environments/production.rb +79 -0
  43. data/spec/dummy/config/environments/test.rb +42 -0
  44. data/spec/dummy/config/initializers/assets.rb +11 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/spec/dummy/config/initializers/inflections.rb +16 -0
  49. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  50. data/spec/dummy/config/initializers/session_store.rb +3 -0
  51. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/spec/dummy/config/locales/en.yml +23 -0
  53. data/spec/dummy/config/routes.rb +4 -0
  54. data/spec/dummy/config/secrets.yml +22 -0
  55. data/spec/dummy/public/404.html +67 -0
  56. data/spec/dummy/public/422.html +67 -0
  57. data/spec/dummy/public/500.html +66 -0
  58. data/spec/dummy/public/favicon.ico +0 -0
  59. metadata +247 -0
@@ -0,0 +1,18 @@
1
+ .facet-container
2
+ float: left
3
+ margin-right: 14px
4
+ tr
5
+ &.facet-active
6
+ background-color: #ca4
7
+ .facet-graph
8
+ width: 320px
9
+ display: inline-block
10
+ .facet-legend
11
+ width: 320px
12
+ display: inline-block
13
+ vertical-align: top
14
+ .c3-chart-arc
15
+ &.facet-active
16
+ font-weight: bold
17
+ &.facet-inactive
18
+ opacity: 0.2
@@ -0,0 +1,2 @@
1
+ //= require c3
2
+ @import ./graphs/*
@@ -0,0 +1,40 @@
1
+ path
2
+ stroke: #fff
3
+
4
+ &:hover
5
+ opacity: 0.9
6
+
7
+ rect:hover
8
+ fill: blue
9
+
10
+ .axis
11
+ font: 10px sans-serif
12
+
13
+ .legend tr
14
+ border-bottom: 1px solid grey
15
+
16
+ &:first-child
17
+ border-top: 1px solid grey
18
+
19
+ .axis
20
+ path, line
21
+ fill: none
22
+ stroke: #000
23
+ shape-rendering: crispEdges
24
+
25
+ .x.axis path
26
+ display: none
27
+
28
+ .legend
29
+ margin-bottom: 76px
30
+ display: inline-block
31
+ border-collapse: collapse
32
+ border-spacing: 0px
33
+
34
+ td
35
+ padding: 4px 5px
36
+ vertical-align: bottom
37
+
38
+ .legendFreq, .legendPerc
39
+ align: right
40
+ width: 50px
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,14 @@
1
+ module HawkEye
2
+ class ApplicationController < ::ApplicationController
3
+ layout 'application'
4
+ def home
5
+ respond_to do |format|
6
+ format.html
7
+ format.json do
8
+ @graph = HawkEye::Graph::DateBinVariable.new(variables: %w[homes_passed length_hvd_kvd1], facets: %w[cu_state state], bin_type: params[:bin_type] || 'month')
9
+ render json: @graph.data_for_client
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module HawkEye
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module HawkEye::Graph::DateBinHelpers
2
+ extend ActiveSupport::Concern
3
+
4
+ def bin_type
5
+ options[:bin_type] || 'month'
6
+ end
7
+ end
@@ -0,0 +1,89 @@
1
+ class HawkEye::Graph::DateBinVariable
2
+ include HawkEye::Graph::DateBinHelpers
3
+ attr_reader :options
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def facets
10
+ @facets ||= options[:facets] || []
11
+ end
12
+
13
+ def date_boundaries
14
+ 3.years.ago.to_date..1.year.from_now.to_date
15
+ Time.now.beginning_of_year.to_date..Time.now.end_of_year.to_date
16
+ nil
17
+ end
18
+
19
+ def date_column
20
+ :plan_date
21
+ end
22
+
23
+ def variables
24
+ @variables ||= Array.wrap(options[:variables])
25
+ end
26
+
27
+ def aggregation_method
28
+ :sum # sum, count, ...
29
+ end
30
+
31
+ def data_for_client
32
+ found_facets = {}
33
+ facets.each{|f| found_facets[f] = Set.new } # my guess is that this is more efficient than a complex default 1 vs N issue
34
+ result = {
35
+ variables: variables.map{|variable| {name: variable, label: WorkflowInstance.human_attribute_name(variable)} },
36
+ payload: {},
37
+ bin_type: bin_type,
38
+ date_column: {
39
+ name: date_column,
40
+ label: WorkflowInstance.human_attribute_name(date_column)
41
+ },
42
+ aggregation_method: aggregation_method
43
+ }
44
+
45
+ base_stats = WorkflowInstance.group(date_column).group(*facets)
46
+ base_stats = base_stats.where(date_column => date_boundaries) if date_boundaries
47
+ base_stats = base_stats.where(baan_number: 222)
48
+
49
+ variables.each do |variable|
50
+ variable_stats = base_stats.public_send(aggregation_method, variable)
51
+
52
+ grouped_by_bin = variable_stats.group_by do |(date, _facet_values), stat|
53
+ if date
54
+ date = date.public_send("beginning_of_#{bin_type}")
55
+ if result[:min_date]
56
+ result[:min_date] = date if date < result[:min_date]
57
+ else
58
+ result[:min_date] = date
59
+ end
60
+ if result[:max_date]
61
+ result[:max_date] = date if date > result[:max_date]
62
+ else
63
+ result[:max_date] = date
64
+ end
65
+ date
66
+ else
67
+ 'no_date'
68
+ end
69
+ end
70
+
71
+ grouped_by_bin.each do |bin, group_result|
72
+ result[:payload][bin] ||= []
73
+ group_result.each do |facet_values, stat|
74
+ facet_values.shift # first argument is the unprocessed date
75
+ facet_values.each.with_index{|fv, i| found_facets[facets[i]] << fv} # add to found results
76
+ if existing_data = result[:payload][bin].find{|p| p[:facets] == facet_values }
77
+ existing_data[variable] = stat
78
+ else
79
+ result[:payload][bin] << {facets: facet_values, variable => stat}
80
+ end
81
+ end
82
+ end
83
+ result[:facets] = found_facets.map{|facet_name, facet_values| {name: facet_name, label: WorkflowInstance.human_attribute_name(facet_name), values: facet_values}}
84
+ end
85
+ #result[:min_date] = result[:min_date].beginning_of_year
86
+ #result[:max_date] = result[:max_date].end_of_year.beginning_of_month
87
+ result
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ = page_title t('hawk_eye.title')
2
+ form#graph-settings-form
3
+ = select_tag 'bin_type', options_for_select(%w[week month quarter], params[:bin_type])
4
+ #dashboard2
5
+ javascript:
6
+ $(function(){
7
+ var f = $('#graph-settings-form');
8
+ f.change(function(){
9
+ $.getJSON(Routes.hawk_eye_root_path() + '?' + $(this).serialize()).then(function(data){
10
+ data.target = '#dashboard2';
11
+ HawkEye.DateBinVariable.setup(data);
12
+ })
13
+ }).change()
14
+ });
15
+
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HawkEye</title>
5
+ <%= stylesheet_link_tag "hawk_eye/application", media: "all" %>
6
+ <%= javascript_include_tag "hawk_eye/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ HawkEye::Engine.routes.draw do
2
+ root to: 'hawk_eye/application#home'
3
+ end
@@ -0,0 +1 @@
1
+ require 'hawk_eye'
@@ -0,0 +1,7 @@
1
+ Gem.loaded_specs['hawk-eye'].runtime_dependencies.each do |d|
2
+ require d.name
3
+ end
4
+ require "hawk_eye/engine"
5
+
6
+ module HawkEye
7
+ end
@@ -0,0 +1,5 @@
1
+ module HawkEye
2
+ class Engine < ::Rails::Engine
3
+ #isolate_namespace HawkEye
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module HawkEye
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hawk_eye do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "action_view/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require(*Rails.groups)
12
+ require "hawk_eye"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+
28
+ # Do not swallow errors in after_commit/after_rollback callbacks.
29
+ config.active_record.raise_in_transactional_callbacks = true
30
+ end
31
+ end
32
+