diff --git a/app/controllers/api/statistics_controller.rb b/app/controllers/api/statistics_controller.rb index 6f4c7f452..3368308b7 100644 --- a/app/controllers/api/statistics_controller.rb +++ b/app/controllers/api/statistics_controller.rb @@ -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 diff --git a/app/models/statistic_custom_aggregation.rb b/app/models/statistic_custom_aggregation.rb new file mode 100644 index 000000000..8abc66704 --- /dev/null +++ b/app/models/statistic_custom_aggregation.rb @@ -0,0 +1,3 @@ +class StatisticCustomAggregation < ActiveRecord::Base + belongs_to :statistic_type +end diff --git a/app/models/statistic_type.rb b/app/models/statistic_type.rb index 1a348668b..47909d644 100644 --- a/app/models/statistic_type.rb +++ b/app/models/statistic_type.rb @@ -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 diff --git a/db/migrate/20160905141858_create_statistic_custom_aggregations.rb b/db/migrate/20160905141858_create_statistic_custom_aggregations.rb new file mode 100644 index 000000000..d1242f56a --- /dev/null +++ b/db/migrate/20160905141858_create_statistic_custom_aggregations.rb @@ -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 diff --git a/db/migrate/20160905142700_add_field_to_statistic_custom_aggregation.rb b/db/migrate/20160905142700_add_field_to_statistic_custom_aggregation.rb new file mode 100644 index 000000000..8b0da532c --- /dev/null +++ b/db/migrate/20160905142700_add_field_to_statistic_custom_aggregation.rb @@ -0,0 +1,5 @@ +class AddFieldToStatisticCustomAggregation < ActiveRecord::Migration + def change + add_column :statistic_custom_aggregations, :field, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ea18873e2..fcc573fa0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/test/fixtures/statistic_custom_aggregations.yml b/test/fixtures/statistic_custom_aggregations.yml new file mode 100644 index 000000000..40debb04d --- /dev/null +++ b/test/fixtures/statistic_custom_aggregations.yml @@ -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"