1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

database structure for custom aggregations in statistics

This commit is contained in:
Sylvain 2016-09-05 17:16:23 +02:00
parent d0837706b6
commit ea671d03a4
7 changed files with 41 additions and 1 deletions

View File

@ -12,6 +12,7 @@ class API::StatisticsController < API::ApiController
authorize :statistic, :#{path}?
query = MultiJson.load(request.body.read)
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
# TODO
render json: results
end

View File

@ -0,0 +1,3 @@
class StatisticCustomAggregation < ActiveRecord::Base
belongs_to :statistic_type
end

View File

@ -2,4 +2,5 @@ class StatisticType < ActiveRecord::Base
has_one :statistic_index
has_many :statistic_type_sub_types
has_many :statistic_sub_types, through: :statistic_type_sub_types
has_many :statistic_custom_aggregations
end

View File

@ -0,0 +1,11 @@
class CreateStatisticCustomAggregations < ActiveRecord::Migration
def change
create_table :statistic_custom_aggregations do |t|
t.text :query
t.string :path
t.belongs_to :statistic_type, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@ -0,0 +1,5 @@
class AddFieldToStatisticCustomAggregation < ActiveRecord::Migration
def change
add_column :statistic_custom_aggregations, :field, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160831084519) do
ActiveRecord::Schema.define(version: 20160905142700) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -541,6 +541,17 @@ ActiveRecord::Schema.define(version: 20160831084519) do
add_index "slots", ["availability_id"], name: "index_slots_on_availability_id", using: :btree
add_index "slots", ["reservation_id"], name: "index_slots_on_reservation_id", using: :btree
create_table "statistic_custom_aggregations", force: :cascade do |t|
t.text "query"
t.string "path"
t.integer "statistic_type_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "field"
end
add_index "statistic_custom_aggregations", ["statistic_type_id"], name: "index_statistic_custom_aggregations_on_statistic_type_id", using: :btree
create_table "statistic_fields", force: :cascade do |t|
t.integer "statistic_index_id"
t.string "key", limit: 255
@ -805,6 +816,7 @@ ActiveRecord::Schema.define(version: 20160831084519) do
add_foreign_key "organizations", "profiles"
add_foreign_key "prices", "groups"
add_foreign_key "prices", "plans"
add_foreign_key "statistic_custom_aggregations", "statistic_types"
add_foreign_key "tickets", "event_price_categories"
add_foreign_key "tickets", "reservations"
add_foreign_key "user_tags", "tags"

View File

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
query: '{query:{bool:{must:[range:{start_at:{gte:"2016-08-01T02:00:00+02:00", lte:"2016-09-01T02:00:00+02:00"}, match:{available_type: "machines"}}]}}}'
path: "/fablab/availabilities"
statistic_type_id: 2
field: "available_hours"