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..b934ab2 --- /dev/null +++ b/app/models/uc_measurement.rb @@ -0,0 +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 new file mode 100644 index 0000000..b1a8121 --- /dev/null +++ b/app/models/uc_monitor.rb @@ -0,0 +1,9 @@ +class UcMonitor < ActiveRecord::Base + belongs_to :user + + has_many :uc_signals_monitors + has_many :uc_signals, through: :uc_signals_monitors + + validates :name, :kind, presence: true + validates_associated :uc_signals, :user +end diff --git a/app/models/uc_sensor.rb b/app/models/uc_sensor.rb new file mode 100644 index 0000000..228e3cc --- /dev/null +++ b/app/models/uc_sensor.rb @@ -0,0 +1,7 @@ +class UcSensor < ActiveRecord::Base + has_many :uc_signals + belongs_to :user + + validates :name, :kind, presence: true + validates_associated :user +end diff --git a/app/models/uc_signal.rb b/app/models/uc_signal.rb new file mode 100644 index 0000000..d4b1d4a --- /dev/null +++ b/app/models/uc_signal.rb @@ -0,0 +1,13 @@ +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 + + has_many :uc_conditions_signals + has_many :uc_conditions, through: :uc_conditions_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 new file mode 100644 index 0000000..33737b0 --- /dev/null +++ b/app/models/uc_signals_monitor.rb @@ -0,0 +1,5 @@ +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..7a14d26 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,12 +1,17 @@ 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 + 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..782255b --- /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..c9e8406 --- /dev/null +++ b/db/migrate/20160309210907_create_uc_monitors.rb @@ -0,0 +1,14 @@ +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..d15f261 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,120 +11,98 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160231233554) do +ActiveRecord::Schema.define(version: 20160310131412) do - create_table "measurements", force: :cascade do |t| - t.datetime "created_at" - t.datetime "updated_at" - t.decimal "value", precision: 3, scale: 10 + create_table "plans", force: :cascade do |t| + 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 end - 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" + 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_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 + 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 - 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" - t.string "stripe_id" - t.string "stripe_token" - t.string "card_last4" - t.date "card_expiration" - t.string "card_type" - t.text "error" - 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 + 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 "logic" + t.integer "uc_process_id" 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_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 "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_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 "payola_subscriptions", ["guid"], name: "index_payola_subscriptions_on_guid" + add_index "uc_measurements", ["uc_signal_id"], name: "index_uc_measurements_on_uc_signal_id" - create_table "plans", force: :cascade do |t| - t.string "name" - t.string "stripe_id" - t.string "interval" - t.integer "amount" + 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_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" + 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| 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 +