Class: Gricer::BaseController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Gricer::BaseController
- Defined in:
- app/controllers/gricer/base_controller.rb
Overview
This is the base controller which is used by Gricer’s basic statistics controllers
You can use this to make your own statistics controllers from a scaffold.
Direct Known Subclasses
Instance Method Summary collapse
-
#process_stats ⇒ Object
This action generates a JSON for a process statistics.
-
#spread_stats ⇒ Object
This action generates a JSON for a spread statistics.
Instance Method Details
#process_stats ⇒ Object
This action generates a JSON for a process statistics.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/gricer/base_controller.rb', line 12 def process_stats @items = basic_collection handle_special_fields data = { alternatives: [ { type: 'spread', uri: url_for(action: "spread_stats", field: params[:field], filters: params[:filters], only_path: true) }, { type: 'process' } ], from: @stat_from.to_time.utc.to_i * 1000, thru: @stat_thru.to_time.utc.to_i * 1000, step: @stat_step.to_i * 1000, data: @items.stat(params[:field], @stat_from, @stat_thru, @stat_step) } if further_details.keys.include? params[:field] filters = (params[:filters] || {}) filters[params[:field]] = '%{self}' data[:detail_uri] = url_for(action: "process_stats", field: further_details[params[:field]], filters: filters, only_path: true) end render json: data end |
#spread_stats ⇒ Object
This action generates a JSON for a spread statistics.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/gricer/base_controller.rb', line 44 def spread_stats @items = basic_collection.between_dates(@stat_from, @stat_thru) handle_special_fields data = { alternatives: [ { type: 'spread' }, { type: 'process', uri: url_for(action: "process_stats", field: params[:field], filters: params[:filters], only_path: true) } ], from: @stat_from.to_time.utc.to_i * 1000, thru: @stat_thru.to_time.utc.to_i * 1000, total: @items.count(:id), data: @items.count_by(params[:field]) } if further_details.keys.include? params[:field] filters = (params[:filters] || {}) filters[params[:field]] = '%{self}' data[:detail_uri] = url_for(action: "spread_stats", field: further_details[params[:field]], filters: filters, only_path: true) end render json: data end |