From 54befe0ab8397c046e10590aa484b87a24ff4d31 Mon Sep 17 00:00:00 2001 From: Diego Araos Date: Wed, 9 Mar 2016 23:15:42 +0100 Subject: [PATCH 1/5] Add first bunch of models for platform --- .gitignore | 3 ++ Gemfile | 1 + Gemfile.lock | 8 +++ app/models/measurement.rb | 3 -- app/models/uc_measurement.rb | 3 ++ app/models/uc_monitor.rb | 6 +++ app/models/uc_sensor.rb | 4 ++ app/models/uc_signal.rb | 7 +++ app/models/uc_signals_monitor.rb | 4 ++ app/models/user.rb | 9 ++-- .../20160231233554_create_measurements.rb | 8 --- .../20160231233554_create_uc_measurements.rb | 13 +++++ .../20160309195325_create_uc_sensors.rb | 13 +++++ .../20160309200556_create_uc_signals.rb | 13 +++++ ...160309210843_create_uc_signals_monitors.rb | 10 ++++ .../20160309210907_create_uc_monitors.rb | 12 +++++ db/schema.rb | 50 ++++++++++++++++--- 17 files changed, 146 insertions(+), 21 deletions(-) delete mode 100644 app/models/measurement.rb create mode 100644 app/models/uc_measurement.rb create mode 100644 app/models/uc_monitor.rb create mode 100644 app/models/uc_sensor.rb create mode 100644 app/models/uc_signal.rb create mode 100644 app/models/uc_signals_monitor.rb delete mode 100644 db/migrate/20160231233554_create_measurements.rb create mode 100644 db/migrate/20160231233554_create_uc_measurements.rb create mode 100644 db/migrate/20160309195325_create_uc_sensors.rb create mode 100644 db/migrate/20160309200556_create_uc_signals.rb create mode 100644 db/migrate/20160309210843_create_uc_signals_monitors.rb create mode 100644 db/migrate/20160309210907_create_uc_monitors.rb diff --git a/.gitignore b/.gitignore index adc49d2..a9e752b 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,6 @@ pickle-email-*.html # tilde files are usually backup files from a text editor *~ + +# ERD file +erd.pdf \ No newline at end of file diff --git a/Gemfile b/Gemfile index 57aed8a..8836887 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ group :development, :test do gem 'byebug' end group :development do + gem 'rails-erd' gem 'web-console', '~> 2.0' gem 'spring' end diff --git a/Gemfile.lock b/Gemfile.lock index 5862d5a..08a166e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,7 @@ GEM chartkick (1.4.1) childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) + choice (0.2.0) coderay (1.1.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) @@ -175,6 +176,11 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.4.6) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) rails_12factor (0.0.3) @@ -219,6 +225,7 @@ GEM rspec-mocks (~> 3.4.0) rspec-support (~> 3.4.0) rspec-support (3.4.1) + ruby-graphviz (1.2.2) rubyzip (1.1.7) sass (3.4.21) sass-rails (5.0.4) @@ -314,6 +321,7 @@ DEPENDENCIES pusher (~> 0.16) quiet_assets rails (= 4.2.5.1) + rails-erd rails_12factor rails_layout rspec-rails diff --git a/app/models/measurement.rb b/app/models/measurement.rb deleted file mode 100644 index 88cbe3c..0000000 --- a/app/models/measurement.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Measurement < ActiveRecord::Base - -end diff --git a/app/models/uc_measurement.rb b/app/models/uc_measurement.rb new file mode 100644 index 0000000..70d2182 --- /dev/null +++ b/app/models/uc_measurement.rb @@ -0,0 +1,3 @@ +class UcMeasurement < ActiveRecord::Base + belongs_to :uc_signal +end diff --git a/app/models/uc_monitor.rb b/app/models/uc_monitor.rb new file mode 100644 index 0000000..9b605eb --- /dev/null +++ b/app/models/uc_monitor.rb @@ -0,0 +1,6 @@ +class UcMonitor < ActiveRecord::Base + belongs_to :user + + has_many :uc_signals_monitors + has_many :uc_signals, through: :uc_signals_monitors +end diff --git a/app/models/uc_sensor.rb b/app/models/uc_sensor.rb new file mode 100644 index 0000000..6ef027e --- /dev/null +++ b/app/models/uc_sensor.rb @@ -0,0 +1,4 @@ +class UcSensor < ActiveRecord::Base + has_many :uc_signals + belongs_to :user +end diff --git a/app/models/uc_signal.rb b/app/models/uc_signal.rb new file mode 100644 index 0000000..3519a18 --- /dev/null +++ b/app/models/uc_signal.rb @@ -0,0 +1,7 @@ +class UcSignal < ActiveRecord::Base + belongs_to :uc_sensor + has_many :uc_measurements + + has_many :uc_signals_monitors + has_many :uc_monitors, through: :uc_signals_monitors +end diff --git a/app/models/uc_signals_monitor.rb b/app/models/uc_signals_monitor.rb new file mode 100644 index 0000000..da0250d --- /dev/null +++ b/app/models/uc_signals_monitor.rb @@ -0,0 +1,4 @@ +class UcSignalsMonitor < ActiveRecord::Base + belongs_to :uc_signal + belongs_to :uc_monitor +end diff --git a/app/models/user.rb b/app/models/user.rb index 5da4d21..8a924a9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,15 @@ class User < ActiveRecord::Base + has_many :uc_monitors + has_many :uc_sensors + + belongs_to :plan + validates_associated :plan + enum role: [:user, :admin, :silver, :gold, :platinum] after_initialize :set_default_role, :if => :new_record? after_initialize :set_default_plan, :if => :new_record? # after_create :sign_up_for_mailing_list - belongs_to :plan - validates_associated :plan - def set_default_role self.role ||= :user end diff --git a/db/migrate/20160231233554_create_measurements.rb b/db/migrate/20160231233554_create_measurements.rb deleted file mode 100644 index 3616cca..0000000 --- a/db/migrate/20160231233554_create_measurements.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateMeasurements < ActiveRecord::Migration - def change - create_table :measurements do |t| - t.timestamps - t.decimal :value, precision: 12, scale: 3 - end - end -end diff --git a/db/migrate/20160231233554_create_uc_measurements.rb b/db/migrate/20160231233554_create_uc_measurements.rb new file mode 100644 index 0000000..9e5d0d1 --- /dev/null +++ b/db/migrate/20160231233554_create_uc_measurements.rb @@ -0,0 +1,13 @@ +class CreateUcMeasurements < ActiveRecord::Migration + def change + create_table :uc_measurements do |t| + t.timestamps null: false + + t.decimal :value, precision: 12, scale: 3 + + t.integer :uc_signal_id + + t.index :uc_signal_id + end + end +end diff --git a/db/migrate/20160309195325_create_uc_sensors.rb b/db/migrate/20160309195325_create_uc_sensors.rb new file mode 100644 index 0000000..d3f1502 --- /dev/null +++ b/db/migrate/20160309195325_create_uc_sensors.rb @@ -0,0 +1,13 @@ +class CreateUcSensors < ActiveRecord::Migration + def change + create_table :uc_sensors do |t| + t.string :name + t.string :description + t.string :kind + + t.integer :user_id + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160309200556_create_uc_signals.rb b/db/migrate/20160309200556_create_uc_signals.rb new file mode 100644 index 0000000..c7e0567 --- /dev/null +++ b/db/migrate/20160309200556_create_uc_signals.rb @@ -0,0 +1,13 @@ +class CreateUcSignals < ActiveRecord::Migration + def change + create_table :uc_signals do |t| + t.timestamps null: false + + t.string :unit + + t.integer :uc_sensor_id + + t.index :uc_sensor_id + end + end +end diff --git a/db/migrate/20160309210843_create_uc_signals_monitors.rb b/db/migrate/20160309210843_create_uc_signals_monitors.rb new file mode 100644 index 0000000..1b17739 --- /dev/null +++ b/db/migrate/20160309210843_create_uc_signals_monitors.rb @@ -0,0 +1,10 @@ +class CreateUcSignalsMonitors < ActiveRecord::Migration + def change + create_table :uc_signals_monitors do |t| + t.timestamps null: false + + t.integer :uc_signal_id + t.integer :uc_monitor_id + end + end +end diff --git a/db/migrate/20160309210907_create_uc_monitors.rb b/db/migrate/20160309210907_create_uc_monitors.rb new file mode 100644 index 0000000..61f8e84 --- /dev/null +++ b/db/migrate/20160309210907_create_uc_monitors.rb @@ -0,0 +1,12 @@ +class CreateUcMonitors < ActiveRecord::Migration + def change + create_table :uc_monitors do |t| + t.timestamps null: false + + t.integer :user_id + + t.string :name + t.string :kind + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8ec5c9b..52f450c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,13 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160231233554) do - - create_table "measurements", force: :cascade do |t| - t.datetime "created_at" - t.datetime "updated_at" - t.decimal "value", precision: 3, scale: 10 - end +ActiveRecord::Schema.define(version: 20160309210907) do create_table "payola_affiliates", force: :cascade do |t| t.string "code" @@ -127,6 +121,48 @@ t.datetime "updated_at", null: false end + create_table "uc_measurements", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.decimal "value", precision: 12, scale: 3 + t.integer "uc_signal_id" + end + + add_index "uc_measurements", ["uc_signal_id"], name: "index_uc_measurements_on_uc_signal_id" + + create_table "uc_monitors", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id" + t.string "name" + t.string "kind" + end + + create_table "uc_sensors", force: :cascade do |t| + t.string "name" + t.string "description" + t.string "kind" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "uc_signals", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "unit" + t.integer "uc_sensor_id" + end + + add_index "uc_signals", ["uc_sensor_id"], name: "index_uc_signals_on_uc_sensor_id" + + create_table "uc_signals_monitors", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uc_signal_id" + t.integer "uc_monitor_id" + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false From 9f092019f7d64bceabbbf7b8bbd74be54e01f31b Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Thu, 10 Mar 2016 16:05:47 +0100 Subject: [PATCH 2/5] Complete model --- app/models/uc_signal.rb | 3 + app/models/user.rb | 2 + .../20160309200556_create_uc_signals.rb | 4 +- .../20160309210907_create_uc_monitors.rb | 2 + db/schema.rb | 144 ++++++------------ 5 files changed, 54 insertions(+), 101 deletions(-) diff --git a/app/models/uc_signal.rb b/app/models/uc_signal.rb index 3519a18..e081a0c 100644 --- a/app/models/uc_signal.rb +++ b/app/models/uc_signal.rb @@ -4,4 +4,7 @@ class UcSignal < ActiveRecord::Base has_many :uc_signals_monitors has_many :uc_monitors, through: :uc_signals_monitors + + has_many :uc_conditions_signals + has_many :uc_conditions, through: :uc_conditions_signals end diff --git a/app/models/user.rb b/app/models/user.rb index 8a924a9..7a14d26 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,8 @@ class User < ActiveRecord::Base has_many :uc_monitors has_many :uc_sensors + has_many :uc_actuators + has_many :uc_processes belongs_to :plan validates_associated :plan diff --git a/db/migrate/20160309200556_create_uc_signals.rb b/db/migrate/20160309200556_create_uc_signals.rb index c7e0567..96a968d 100644 --- a/db/migrate/20160309200556_create_uc_signals.rb +++ b/db/migrate/20160309200556_create_uc_signals.rb @@ -6,8 +6,10 @@ def change t.string :unit t.integer :uc_sensor_id - t.index :uc_sensor_id + + t.integer :uc_condition_id + t.index :uc_condition_id end end end diff --git a/db/migrate/20160309210907_create_uc_monitors.rb b/db/migrate/20160309210907_create_uc_monitors.rb index 61f8e84..c9e8406 100644 --- a/db/migrate/20160309210907_create_uc_monitors.rb +++ b/db/migrate/20160309210907_create_uc_monitors.rb @@ -7,6 +7,8 @@ def change t.string :name t.string :kind + + end end end diff --git a/db/schema.rb b/db/schema.rb index 52f450c..488f03c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,114 +11,48 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160309210907) do - - create_table "payola_affiliates", force: :cascade do |t| - t.string "code" - t.string "email" - t.integer "percent" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "payola_coupons", force: :cascade do |t| - t.string "code" - t.integer "percent_off" - t.datetime "created_at" - t.datetime "updated_at" - t.boolean "active", default: true - end +ActiveRecord::Schema.define(version: 20160310131412) do - create_table "payola_sales", force: :cascade do |t| - t.string "email", limit: 191 - t.string "guid", limit: 191 - t.integer "product_id" - t.string "product_type", limit: 100 - t.datetime "created_at" - t.datetime "updated_at" - t.string "state" + create_table "plans", force: :cascade do |t| + t.string "name" t.string "stripe_id" - t.string "stripe_token" - t.string "card_last4" - t.date "card_expiration" - t.string "card_type" - t.text "error" + t.string "interval" t.integer "amount" - t.integer "fee_amount" - t.integer "coupon_id" - t.boolean "opt_in" - t.integer "download_count" - t.integer "affiliate_id" - t.text "customer_address" - t.text "business_address" - t.string "stripe_customer_id", limit: 191 - t.string "currency" - t.text "signed_custom_fields" - t.integer "owner_id" - t.string "owner_type", limit: 100 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "payola_sales", ["coupon_id"], name: "index_payola_sales_on_coupon_id" - add_index "payola_sales", ["email"], name: "index_payola_sales_on_email" - add_index "payola_sales", ["guid"], name: "index_payola_sales_on_guid" - add_index "payola_sales", ["owner_id", "owner_type"], name: "index_payola_sales_on_owner_id_and_owner_type" - add_index "payola_sales", ["product_id", "product_type"], name: "index_payola_sales_on_product" - add_index "payola_sales", ["stripe_customer_id"], name: "index_payola_sales_on_stripe_customer_id" - - create_table "payola_stripe_webhooks", force: :cascade do |t| - t.string "stripe_id" - t.datetime "created_at" - t.datetime "updated_at" + create_table "uc_actions", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "kind" + t.string "value" + t.integer "uc_process_id" end - create_table "payola_subscriptions", force: :cascade do |t| - t.string "plan_type" - t.integer "plan_id" - t.datetime "start" - t.string "status" - t.string "owner_type" - t.integer "owner_id" - t.string "stripe_customer_id" - t.boolean "cancel_at_period_end" - t.datetime "current_period_start" - t.datetime "current_period_end" - t.datetime "ended_at" - t.datetime "trial_start" - t.datetime "trial_end" - t.datetime "canceled_at" - t.integer "quantity" - t.string "stripe_id" - t.string "stripe_token" - t.string "card_last4" - t.date "card_expiration" - t.string "card_type" - t.text "error" - t.string "state" - t.string "email" - t.datetime "created_at" - t.datetime "updated_at" - t.string "currency" - t.integer "amount" - t.string "guid", limit: 191 - t.string "stripe_status" - t.integer "affiliate_id" - t.string "coupon" - t.text "signed_custom_fields" - t.text "customer_address" - t.text "business_address" - t.integer "setup_fee" - t.integer "tax_percent" + create_table "uc_actuators", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id" + t.string "name" + t.string "description" + t.string "kind" end - add_index "payola_subscriptions", ["guid"], name: "index_payola_subscriptions_on_guid" - - create_table "plans", force: :cascade do |t| + create_table "uc_conditions", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "name" - t.string "stripe_id" - t.string "interval" - t.integer "amount" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "logic" + t.integer "uc_process_id" + end + + create_table "uc_conditions_signals", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uc_signal_id" + t.integer "uc_condition_id" end create_table "uc_measurements", force: :cascade do |t| @@ -138,6 +72,14 @@ t.string "kind" end + create_table "uc_processes", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "user_id" + t.string "name" + t.string "description" + end + create_table "uc_sensors", force: :cascade do |t| t.string "name" t.string "description" @@ -148,12 +90,14 @@ end create_table "uc_signals", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "unit" t.integer "uc_sensor_id" + t.integer "uc_condition_id" end + add_index "uc_signals", ["uc_condition_id"], name: "index_uc_signals_on_uc_condition_id" add_index "uc_signals", ["uc_sensor_id"], name: "index_uc_signals_on_uc_sensor_id" create_table "uc_signals_monitors", force: :cascade do |t| From c28088bae46c5cadd8f3e2fd6c04777e83e0d6d7 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Thu, 10 Mar 2016 16:27:22 +0100 Subject: [PATCH 3/5] Added validations --- app/models/uc_measurement.rb | 1 + app/models/uc_monitor.rb | 3 +++ app/models/uc_sensor.rb | 3 +++ app/models/uc_signal.rb | 3 +++ 4 files changed, 10 insertions(+) diff --git a/app/models/uc_measurement.rb b/app/models/uc_measurement.rb index 70d2182..b934ab2 100644 --- a/app/models/uc_measurement.rb +++ b/app/models/uc_measurement.rb @@ -1,3 +1,4 @@ class UcMeasurement < ActiveRecord::Base belongs_to :uc_signal + validates_associated :uc_signal end diff --git a/app/models/uc_monitor.rb b/app/models/uc_monitor.rb index 9b605eb..bfbb99c 100644 --- a/app/models/uc_monitor.rb +++ b/app/models/uc_monitor.rb @@ -3,4 +3,7 @@ class UcMonitor < ActiveRecord::Base has_many :uc_signals_monitors has_many :uc_signals, through: :uc_signals_monitors + + validates :name, :kind, presence: true + validates_associated :uc_signals, :users end diff --git a/app/models/uc_sensor.rb b/app/models/uc_sensor.rb index 6ef027e..dd701b8 100644 --- a/app/models/uc_sensor.rb +++ b/app/models/uc_sensor.rb @@ -1,4 +1,7 @@ class UcSensor < ActiveRecord::Base has_many :uc_signals belongs_to :user + + validates :name, :kind, presence: true + validates_associated :users end diff --git a/app/models/uc_signal.rb b/app/models/uc_signal.rb index e081a0c..a197ea4 100644 --- a/app/models/uc_signal.rb +++ b/app/models/uc_signal.rb @@ -7,4 +7,7 @@ class UcSignal < ActiveRecord::Base has_many :uc_conditions_signals has_many :uc_conditions, through: :uc_conditions_signals + + validates :unit, :kind, presence: true + validates_associated :uc_signals end From a5cb625c7a7aa17de55c4f0d1febf153a7b9d647 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Thu, 10 Mar 2016 16:51:14 +0100 Subject: [PATCH 4/5] Fix small mistake --- app/models/uc_monitor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/uc_monitor.rb b/app/models/uc_monitor.rb index bfbb99c..b1a8121 100644 --- a/app/models/uc_monitor.rb +++ b/app/models/uc_monitor.rb @@ -5,5 +5,5 @@ class UcMonitor < ActiveRecord::Base has_many :uc_signals, through: :uc_signals_monitors validates :name, :kind, presence: true - validates_associated :uc_signals, :users + validates_associated :uc_signals, :user end From 9617e732f443d2c93ead1dc77bc56c4c7b90f5c3 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Thu, 10 Mar 2016 19:31:31 +0100 Subject: [PATCH 5/5] Seeds added --- app/models/uc_sensor.rb | 2 +- app/models/uc_signal.rb | 4 +-- app/models/uc_signals_monitor.rb | 1 + .../20160309200556_create_uc_signals.rb | 2 -- db/schema.rb | 6 ++-- db/seeds.rb | 30 +++++++++++++++++-- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/models/uc_sensor.rb b/app/models/uc_sensor.rb index dd701b8..228e3cc 100644 --- a/app/models/uc_sensor.rb +++ b/app/models/uc_sensor.rb @@ -3,5 +3,5 @@ class UcSensor < ActiveRecord::Base belongs_to :user validates :name, :kind, presence: true - validates_associated :users + validates_associated :user end diff --git a/app/models/uc_signal.rb b/app/models/uc_signal.rb index a197ea4..d4b1d4a 100644 --- a/app/models/uc_signal.rb +++ b/app/models/uc_signal.rb @@ -8,6 +8,6 @@ class UcSignal < ActiveRecord::Base has_many :uc_conditions_signals has_many :uc_conditions, through: :uc_conditions_signals - validates :unit, :kind, presence: true - validates_associated :uc_signals + validates :unit, presence: true + validates_associated :uc_sensor end diff --git a/app/models/uc_signals_monitor.rb b/app/models/uc_signals_monitor.rb index da0250d..33737b0 100644 --- a/app/models/uc_signals_monitor.rb +++ b/app/models/uc_signals_monitor.rb @@ -2,3 +2,4 @@ class UcSignalsMonitor < ActiveRecord::Base belongs_to :uc_signal belongs_to :uc_monitor end + diff --git a/db/migrate/20160309200556_create_uc_signals.rb b/db/migrate/20160309200556_create_uc_signals.rb index 96a968d..782255b 100644 --- a/db/migrate/20160309200556_create_uc_signals.rb +++ b/db/migrate/20160309200556_create_uc_signals.rb @@ -8,8 +8,6 @@ def change t.integer :uc_sensor_id t.index :uc_sensor_id - t.integer :uc_condition_id - t.index :uc_condition_id end end end diff --git a/db/schema.rb b/db/schema.rb index 488f03c..d15f261 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -90,14 +90,12 @@ end create_table "uc_signals", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "unit" t.integer "uc_sensor_id" - t.integer "uc_condition_id" end - add_index "uc_signals", ["uc_condition_id"], name: "index_uc_signals_on_uc_condition_id" add_index "uc_signals", ["uc_sensor_id"], name: "index_uc_signals_on_uc_sensor_id" create_table "uc_signals_monitors", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index b3c8672..a3f9fcb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,5 +7,31 @@ # Mayor.create(name: 'Emanuel', city: cities.first) user = CreateAdminService.new.call puts 'CREATED ADMIN USER: ' << user.email -CreatePlanService.new.call -puts 'CREATED PLANS' +#CreatePlanService.new.call +#puts 'CREATED PLANS' + + +##Create Sensors + +sensorKind=['Thermometer', 'Accelerometer', 'Claps', 'Light', 'Speed'] +signalUnit=['Celsius', 'm/s^2', 'Claps', 'lumens', 'km/hr'] +actuatorKind=['Relay', 'RGB Light', 'Heater', 'Speaker', 'Water Tap'] +actionKind=['Set Value', 'Set State', 'Switch State', 'Increase Value', 'Decrease Value'] + +userId = 1 + +for i in 1..5 + sensor = UcSensor.create(:name => "Sensor #{i}", :kind => sensorKind[i-1], :user_id => userId) + signal = UcSignal.create(:uc_sensor_id => "#{i}", :unit => signalUnit[i-1]) + actuator = UcActuator.create(:name => "Actuator #{i}", :kind => actuatorKind[i-1], :user_id => userId) + process = UcProcess.create(:name => "Process #{i}", :user_id => userId) + action = UcAction.create(:name => "Action #{i}", :kind => actionKind[i-1], :uc_process_id => "#{i}", ) + condition = UcCondition.create(:logic => "{}", :uc_process_id => "#{i}") +end + +for i in 1..5 + for j in 1..200 + measurement = UcMeasurement.create(:uc_signal_id => "#{i}", :value => rand(20..40)) + end +end +