added 260907 version of worker toolkit

This commit is contained in:
2026-09-08 20:30:51 -04:00
parent cbd3f0f8ca
commit 97aca37663
1283 changed files with 142951 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
class CreateExtensions < ActiveRecord::Migration[5.1]
def change
enable_extension "pg_trgm"
end
end

View File

@@ -0,0 +1,42 @@
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, default: "", null: false
t.string :encrypted_password, default: "", null: false
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## API authentication token
t.string :authentication_token, null: false
## Invitable
t.string :invitation_token
t.datetime :invitation_created_at
t.datetime :invitation_sent_at
t.datetime :invitation_accepted_at
t.integer :invitation_limit
t.integer :invited_by_id
t.string :invited_by_type
t.timestamps null: false
end
add_index :users, :authentication_token, unique: true
add_index :users, :email, unique: true
add_index :users, :reset_password_token
add_index :users, :invitation_token, unique: true
end
end

View File

@@ -0,0 +1,13 @@
class CreateProfiles < ActiveRecord::Migration[5.1]
def change
create_table :profiles do |t|
t.belongs_to :user, index: true, foreign_key: true
t.string :country_id
t.date :birth_date
t.string :sex_id
t.string :onboarding_step_id
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateConditions < ActiveRecord::Migration[5.1]
def up
create_table :conditions do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Condition.create_translation_table! name: :string
end
def down
drop_table :conditions
Condition.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserConditions < ActiveRecord::Migration[5.1]
def change
create_table :user_conditions do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :condition, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateSymptoms < ActiveRecord::Migration[5.1]
def up
create_table :symptoms do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Symptom.create_translation_table! name: :string
end
def down
drop_table :symptoms
Symptom.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserSymptoms < ActiveRecord::Migration[5.1]
def change
create_table :user_symptoms do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :symptom, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,17 @@
class CreateTrackings < ActiveRecord::Migration[5.1]
def change
create_table :trackings do |t|
t.belongs_to :user, index: true, foreign_key: true
t.references :trackable, polymorphic: true, index: true
t.date :start_at
t.date :end_at
t.integer :color_id
t.timestamps null: false
end
add_index :trackings, :trackable_type
add_index(:trackings,
[:user_id, :trackable_id, :trackable_type, :start_at],
unique: true, name: "index_trackings_unique_trackable")
end
end

View File

@@ -0,0 +1,14 @@
class CreateTreatments < ActiveRecord::Migration[5.1]
def up
create_table :treatments do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Treatment.create_translation_table! name: :string
end
def down
drop_table :treatments
Treatment.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserTreatments < ActiveRecord::Migration[5.1]
def change
create_table :user_treatments do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :treatment, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,13 @@
class CreateTags < ActiveRecord::Migration[5.1]
def up
create_table :tags do |t|
t.timestamps null: false
end
Tag.create_translation_table! name: :string
end
def down
drop_table :tags
Tag.drop_translation_table!
end
end

View File

@@ -0,0 +1,8 @@
class AddDemographicsToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :ethnicity_ids_string, :string
add_column :profiles, :day_habit_id, :string
add_column :profiles, :education_level_id, :string
add_column :profiles, :day_walking_hours, :integer
end
end

View File

@@ -0,0 +1,5 @@
class EnableHstoreExtension < ActiveRecord::Migration[5.1]
def change
enable_extension "hstore"
end
end

View File

@@ -0,0 +1,5 @@
class AddMostRecentDosesToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :most_recent_doses, :hstore
end
end

View File

@@ -0,0 +1,12 @@
class CreateTrackableUsages < ActiveRecord::Migration[5.1]
def change
create_table :trackable_usages do |t|
t.belongs_to :user, index: true, foreign_key: true
t.references :trackable, polymorphic: true, index: true
t.integer :count, default: 1
t.timestamps null: false
end
add_index :trackable_usages, [:user_id, :trackable_type, :trackable_id], unique: true, name: "index_trackable_usages_on_unique_columns"
end
end

View File

@@ -0,0 +1,7 @@
class AddTrackableUsagesCounts < ActiveRecord::Migration[5.1]
def change
add_column :conditions, :trackable_usages_count, :integer, default: 0
add_column :symptoms, :trackable_usages_count, :integer, default: 0
add_column :treatments, :trackable_usages_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddScreenNameToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :screen_name, :string
end
end

View File

@@ -0,0 +1,7 @@
class AddMostRecentPositionsToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :most_recent_conditions_positions, :hstore
add_column :profiles, :most_recent_symptoms_positions, :hstore
add_column :profiles, :most_recent_treatments_positions, :hstore
end
end

View File

@@ -0,0 +1,26 @@
class CreateFoods < ActiveRecord::Migration[5.1]
def change
create_table :foods do |t|
t.string :ndb_no
t.timestamps null: false
end
reversible do |dir|
dir.up do
Food.create_translation_table!(
long_desc: {type: :string, null: false},
shrt_desc: :string,
comname: :string,
sciname: :string
)
end
dir.down do
Food.drop_translation_table!
end
end
add_index :foods, :ndb_no
end
end

View File

@@ -0,0 +1,27 @@
class AddLongDescVectorIndexOnFoodTranslations < ActiveRecord::Migration[5.1]
disable_ddl_transaction!
def up
Food::LANG_MAP.each do |short_lang, long_lang|
drop_index(short_lang)
execute <<-SQL.strip_heredoc
CREATE INDEX CONCURRENTLY idx_fts_food_translations_#{short_lang} ON food_translations
USING gin(to_tsvector('#{long_lang}', long_desc))
WHERE locale = '#{short_lang}';
SQL
end
end
def down
Food::LANG_MAP.each do |short_lang, long_lang|
drop_index(short_lang)
end
end
private
def drop_index(short_lang)
execute "DROP INDEX CONCURRENTLY IF EXISTS idx_fts_food_translations_#{short_lang}"
end
end

View File

@@ -0,0 +1,19 @@
class CreateWeathers < ActiveRecord::Migration[5.1]
def change
create_table :weathers do |t|
t.date :date
t.string :postal_code
t.string :icon
t.string :summary
t.float :temperature_min
t.float :temperature_max
t.float :precip_intensity
t.float :pressure
t.float :humidity
t.timestamps null: false
end
add_index :weathers, %i[date postal_code], unique: true
end
end

View File

@@ -0,0 +1,6 @@
class AddPressureAndTemperatureSettingsToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :pressure_units, :integer, default: 0
add_column :profiles, :temperature_units, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddBetaTesterToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :beta_tester, :boolean, default: false
end
end

View File

@@ -0,0 +1,16 @@
class CreateCronoJobs < ActiveRecord::Migration[5.1]
def self.up
create_table :crono_jobs do |t|
t.string :job_id, null: false
t.text :log, limit: 1073741823 # LONGTEXT for MySQL
t.datetime :last_performed_at
t.boolean :healthy
t.timestamps null: false
end
add_index :crono_jobs, [:job_id], unique: true
end
def self.down
drop_table :crono_jobs
end
end

View File

@@ -0,0 +1,5 @@
class AddNotifyToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :notify, :boolean, default: true
end
end

View File

@@ -0,0 +1,13 @@
class AddNotifyTokenToProfiles < ActiveRecord::Migration[5.1]
def up
add_column :profiles, :notify_token, :string
Profile.find_each(batch_size: 500) do |profile|
profile.send(:generate_notify_token)
profile.save
end
end
def down
remove_column :profiles, :notify_token
end
end

View File

@@ -0,0 +1,16 @@
class AddSlugNameToProfiles < ActiveRecord::Migration[5.1]
def up
add_column :profiles, :slug_name, :string
add_index :profiles, :slug_name
Profile.find_each(batch_size: 500) do |profile|
profile.send(:ensure_slug_name)
profile.save
end
end
def down
remove_column :profiles, :slug_name
remove_index :profiles, :slug_name
end
end

View File

@@ -0,0 +1,5 @@
class AddNotifyTopPostsToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :notify_top_posts, :boolean, default: true
end
end

View File

@@ -0,0 +1,6 @@
class AddGlobalToFoodsAndTags < ActiveRecord::Migration[5.1]
def change
add_column :foods, :global, :boolean, default: true
add_column :tags, :global, :boolean, default: true
end
end

View File

@@ -0,0 +1,5 @@
class AddTrackableUsageCountToTags < ActiveRecord::Migration[5.1]
def change
add_column :tags, :trackable_usages_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserTags < ActiveRecord::Migration[5.1]
def change
create_table :user_tags do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :tag, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,12 @@
class AddTrackableAbilityToFoods < ActiveRecord::Migration[5.1]
def change
add_column :foods, :trackable_usages_count, :integer, default: 0
create_table :user_foods do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :food, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,10 @@
class CreatePositions < ActiveRecord::Migration[5.1]
def change
create_table :positions do |t|
t.string :postal_code, null: false
t.string :location_name, null: false
t.decimal :latitude, {precision: 10, scale: 7}
t.decimal :longitude, {precision: 10, scale: 7}
end
end
end

View File

@@ -0,0 +1,5 @@
class AddPositionReferenceToWeather < ActiveRecord::Migration[5.1]
def change
add_reference :weathers, :position, foreign_key: true
end
end

View File

@@ -0,0 +1,8 @@
class AddCheckinReminderToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :checkin_reminder, :boolean, default: false
add_column :profiles, :checkin_reminder_at, :datetime
add_column :profiles, :time_zone_name, :string
add_column :profiles, :reminder_job_id, :string
end
end

View File

@@ -0,0 +1,5 @@
class AddRejectedTypeToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :rejected_type, :string
end
end

View File

@@ -0,0 +1,305 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171011142928) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_trgm"
enable_extension "hstore"
create_table "condition_translations", force: :cascade do |t|
t.integer "condition_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
end
add_index "condition_translations", ["condition_id"], name: "index_condition_translations_on_condition_id", using: :btree
add_index "condition_translations", ["locale"], name: "index_condition_translations_on_locale", using: :btree
create_table "conditions", force: :cascade do |t|
t.boolean "global", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "trackable_usages_count", default: 0
end
create_table "crono_jobs", force: :cascade do |t|
t.string "job_id", null: false
t.text "log"
t.datetime "last_performed_at"
t.boolean "healthy"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "crono_jobs", ["job_id"], name: "index_crono_jobs_on_job_id", unique: true, using: :btree
create_table "food_translations", force: :cascade do |t|
t.integer "food_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "long_desc", null: false
t.string "shrt_desc"
t.string "comname"
t.string "sciname"
end
add_index "food_translations", ["food_id"], name: "index_food_translations_on_food_id", using: :btree
add_index "food_translations", ["locale"], name: "index_food_translations_on_locale", using: :btree
create_table "foods", force: :cascade do |t|
t.string "ndb_no"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "global", default: true
t.integer "trackable_usages_count", default: 0
end
add_index "foods", ["ndb_no"], name: "index_foods_on_ndb_no", using: :btree
create_table "positions", force: :cascade do |t|
t.string "postal_code", null: false
t.string "location_name", null: false
t.decimal "latitude", precision: 10, scale: 7
t.decimal "longitude", precision: 10, scale: 7
end
create_table "profiles", force: :cascade do |t|
t.integer "user_id"
t.string "country_id"
t.date "birth_date"
t.string "sex_id"
t.string "onboarding_step_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "ethnicity_ids_string"
t.string "day_habit_id"
t.string "education_level_id"
t.integer "day_walking_hours"
t.hstore "most_recent_doses"
t.string "screen_name"
t.hstore "most_recent_conditions_positions"
t.hstore "most_recent_symptoms_positions"
t.hstore "most_recent_treatments_positions"
t.integer "pressure_units", default: 0
t.integer "temperature_units", default: 0
t.boolean "beta_tester", default: false
t.boolean "notify", default: true
t.string "notify_token"
t.string "slug_name"
t.boolean "notify_top_posts", default: true
t.boolean "checkin_reminder", default: false
t.datetime "checkin_reminder_at"
t.string "time_zone_name"
t.string "reminder_job_id"
t.string "rejected_type"
end
add_index "profiles", ["slug_name"], name: "index_profiles_on_slug_name", using: :btree
add_index "profiles", ["user_id"], name: "index_profiles_on_user_id", using: :btree
create_table "symptom_translations", force: :cascade do |t|
t.integer "symptom_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
end
add_index "symptom_translations", ["locale"], name: "index_symptom_translations_on_locale", using: :btree
add_index "symptom_translations", ["symptom_id"], name: "index_symptom_translations_on_symptom_id", using: :btree
create_table "symptoms", force: :cascade do |t|
t.boolean "global", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "trackable_usages_count", default: 0
end
create_table "tag_translations", force: :cascade do |t|
t.integer "tag_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
end
add_index "tag_translations", ["locale"], name: "index_tag_translations_on_locale", using: :btree
add_index "tag_translations", ["tag_id"], name: "index_tag_translations_on_tag_id", using: :btree
create_table "tags", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "global", default: true
t.integer "trackable_usages_count", default: 0
end
create_table "trackable_usages", force: :cascade do |t|
t.integer "user_id"
t.integer "trackable_id"
t.string "trackable_type"
t.integer "count", default: 1
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "trackable_usages", ["trackable_type", "trackable_id"], name: "index_trackable_usages_on_trackable_type_and_trackable_id", using: :btree
add_index "trackable_usages", ["user_id", "trackable_type", "trackable_id"], name: "index_trackable_usages_on_unique_columns", unique: true, using: :btree
add_index "trackable_usages", ["user_id"], name: "index_trackable_usages_on_user_id", using: :btree
create_table "trackings", force: :cascade do |t|
t.integer "user_id"
t.integer "trackable_id"
t.string "trackable_type"
t.date "start_at"
t.date "end_at"
t.integer "color_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "trackings", ["trackable_type", "trackable_id"], name: "index_trackings_on_trackable_type_and_trackable_id", using: :btree
add_index "trackings", ["trackable_type"], name: "index_trackings_on_trackable_type", using: :btree
add_index "trackings", ["user_id", "trackable_id", "trackable_type", "start_at"], name: "index_trackings_unique_trackable", unique: true, using: :btree
add_index "trackings", ["user_id"], name: "index_trackings_on_user_id", using: :btree
create_table "treatment_translations", force: :cascade do |t|
t.integer "treatment_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
end
add_index "treatment_translations", ["locale"], name: "index_treatment_translations_on_locale", using: :btree
add_index "treatment_translations", ["treatment_id"], name: "index_treatment_translations_on_treatment_id", using: :btree
create_table "treatments", force: :cascade do |t|
t.boolean "global", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "trackable_usages_count", default: 0
end
create_table "user_conditions", force: :cascade do |t|
t.integer "user_id"
t.integer "condition_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_conditions", ["condition_id"], name: "index_user_conditions_on_condition_id", using: :btree
add_index "user_conditions", ["user_id"], name: "index_user_conditions_on_user_id", using: :btree
create_table "user_foods", force: :cascade do |t|
t.integer "user_id"
t.integer "food_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_foods", ["food_id"], name: "index_user_foods_on_food_id", using: :btree
add_index "user_foods", ["user_id"], name: "index_user_foods_on_user_id", using: :btree
create_table "user_symptoms", force: :cascade do |t|
t.integer "user_id"
t.integer "symptom_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_symptoms", ["symptom_id"], name: "index_user_symptoms_on_symptom_id", using: :btree
add_index "user_symptoms", ["user_id"], name: "index_user_symptoms_on_user_id", using: :btree
create_table "user_tags", force: :cascade do |t|
t.integer "user_id"
t.integer "tag_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_tags", ["tag_id"], name: "index_user_tags_on_tag_id", using: :btree
add_index "user_tags", ["user_id"], name: "index_user_tags_on_user_id", using: :btree
create_table "user_treatments", force: :cascade do |t|
t.integer "user_id"
t.integer "treatment_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "user_treatments", ["treatment_id"], name: "index_user_treatments_on_treatment_id", using: :btree
add_index "user_treatments", ["user_id"], name: "index_user_treatments_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "authentication_token", null: false
t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
t.datetime "invitation_accepted_at"
t.integer "invitation_limit"
t.integer "invited_by_id"
t.string "invited_by_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", using: :btree
create_table "weathers", force: :cascade do |t|
t.date "date"
t.string "postal_code"
t.string "icon"
t.string "summary"
t.float "temperature_min"
t.float "temperature_max"
t.float "precip_intensity"
t.float "pressure"
t.float "humidity"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "position_id"
end
add_index "weathers", ["date", "postal_code"], name: "index_weathers_on_date_and_postal_code", unique: true, using: :btree
add_foreign_key "profiles", "users"
add_foreign_key "trackable_usages", "users"
add_foreign_key "trackings", "users"
add_foreign_key "user_conditions", "conditions"
add_foreign_key "user_conditions", "users"
add_foreign_key "user_foods", "foods"
add_foreign_key "user_foods", "users"
add_foreign_key "user_symptoms", "symptoms"
add_foreign_key "user_symptoms", "users"
add_foreign_key "user_tags", "tags"
add_foreign_key "user_tags", "users"
add_foreign_key "user_treatments", "treatments"
add_foreign_key "user_treatments", "users"
add_foreign_key "weathers", "positions"
end

View File

@@ -0,0 +1 @@
Rake::Task["usda:load"].invoke

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,101 @@
DAYS = 60
email = ENV["CHECKINS_FOR"]
if email.present?
puts "email=#{email}"
user = User.find_or_create_by(email: email)
# Delete all Tracking, Checkin and Tag
Tracking.destroy_all
Checkin.destroy_all
Checkin::Tag.destroy_all
# Set locale to default
I18n.locale = I18n.default_locale
# Create some trackables (both global and personal)
conditions = FactoryBot.create_list(:user_condition, 2, user: user).map(&:condition)
conditions += FactoryBot.create_list(:condition, 3)
symptoms = FactoryBot.create_list(:user_symptom, 2, user: user).map(&:symptom)
symptoms += FactoryBot.create_list(:symptom, 5)
treatments = FactoryBot.create_list(:user_treatment, 3, user: user).map(&:treatment)
treatments += FactoryBot.create_list(:treatment, 6)
# Create some tags
tags = FactoryBot.create_list(:tag, 10)
# Setup time frame
end_at = Date.today
day = end_at - (DAYS - 1).days
# Start tracking some trackable
2.times do
condition = conditions.pop
Tracking.create!(user: user, trackable: condition, start_at: day)
puts "Start tracking #{condition.name}"
end
3.times do
symptom = symptoms.pop
Tracking.create!(user: user, trackable: symptom, start_at: day)
puts "Start tracking #{symptom.name}"
end
4.times do
treatment = treatments.pop
Tracking.create!(user: user, trackable: treatment, start_at: day)
puts "Start tracking #{treatment.name}"
end
# Iterate on days
i = 1
divisors_range_start = DAYS / 4 + 2
divisors_range = (divisors_range_start..divisors_range_start + 2)
while day <= end_at
puts "\n\n=== Day: #{day} ==="
active_trackings = user.trackings.active_at(day).to_a
# Stop tracking something at some random iteration
if i % divisors_range.to_a.sample == 0
tracking = active_trackings.sample
tracking.update!(end_at: day)
puts "Stop tracking #{tracking.trackable.name}"
end
# Start tracking something at some random iteration
# (either something new, or something tracked earlier)
if i % divisors_range.to_a.sample == 0
tracked_earlier = (user.trackings.to_a - active_trackings.to_a).map(&:trackable)
trackables_matrix = [conditions, treatments, tracked_earlier, symptoms]
trackables = []
trackables = trackables_matrix.pop while trackables.empty?
trackable = trackables.pop
Tracking.create!(user: user, trackable: trackable, start_at: day)
puts "Start tracking #{trackable.name}"
end
# Checkin
checkin = FactoryBot.create(:checkin,
user_id: user.id, date: day, tag_ids: tags.sample(3).map(&:id))
active_trackings = user.trackings.reload.active_at(day)
active_trackings.map(&:trackable).each do |trackable|
if trackable.is_a? Condition
condition_checkin = FactoryBot.create(
:checkin_condition, checkin: checkin, condition_id: trackable.id
)
puts "Checked-in #{trackable.name}, value: #{condition_checkin.value}"
elsif trackable.is_a? Symptom
symptom_checkin = FactoryBot.create(
:checkin_symptom, checkin: checkin, symptom_id: trackable.id
)
puts "Checked-in #{trackable.name}, value: #{symptom_checkin.value}"
elsif trackable.is_a? Treatment
treatment_checkin = FactoryBot.create(
:checkin_treatment, checkin: checkin, treatment_id: trackable.id
)
puts "Checked-in #{trackable.name}, value: #{treatment_checkin.value}"
end
end
day += 1.day
i += 1
end
end

View File

@@ -0,0 +1,5 @@
[
"test@flaredown.com"
].each do |email|
FactoryBot.create(:user, email: email) unless User.exists?(email: email)
end

View File

@@ -0,0 +1,249 @@
SEED_SYMPTOMS = [
"Abdominal pain",
"Absence of speech",
"Allergy",
"Altered mental status",
"Anal itching",
"Anemia",
"Ankle pain",
"Anxiety",
"Aphasia",
"Arm pain",
"Attention deficit",
"Back pain",
"Bad breath",
"Bad taste in the mouth",
"Beau's lines",
"Behavior disorder",
"Bladder spasms",
"Bleeding gums",
"Blisters",
"Blood in semen",
"Blood in urine",
"Bloody nose",
"Bloody sputum",
"Blunted affect",
"Blurred vision",
"Bowel incontinence",
"Breast discharge",
"Breast lumps",
"Breast pain",
"Brittle nails",
"Bumps on skin",
"Burning urination",
"Buttock pain",
"Catatonia",
"Chest pain",
"Chills",
"Chronic pain",
"Cloudy urine",
"Coccydynia",
"Cold",
"Cold feet",
"Cold fingers",
"Cold hands",
"Confusion",
"Constipation",
"Cough",
"Cyanosis/turning blue",
"Dark circles under the eyes",
"Dark urine",
"Decreased appetite",
"Delirium",
"Delusions",
"Depigmentation of skin",
"Depression",
"Detrusor contraction",
"Diarrhea",
"Difficulty concentrating",
"Difficulty urinating",
"Difficulty with speech",
"Dilated pupils",
"Discharge from penis",
"Distended stomach",
"Dizziness",
"Double vision",
"Drainage of pus",
"Drooling",
"Dry eye",
"Dry mouth",
"Dry skin",
"Dysarthria",
"Dyspepsia",
"Dysphagia",
"Earache",
"Easy bruising",
"Elbow pain",
"Emotional disorder",
"Enlarged heart",
"Euphoria",
"Excessive sweating",
"Eye discharge",
"Eye pain",
"Eye twitch",
"Fainting",
"Fatigue and tiredness",
"Fecal incontinence",
"Fever",
"Finger pain",
"Flaky scalp",
"Flat affect",
"Fluctuating mood",
"Foot pain",
"Frequent urination",
"Gas",
"Hair loss",
"Hairy tongue",
"Hallucinations",
"Hand pain",
"Headache",
"Hearing loss",
"Heartburn",
"Heel pain",
"Hemolysis",
"Hemolytic anemia",
"Hip pain",
"Hoarseness",
"Hot flashes",
"Hyperactivity",
"Hyperventilation",
"Impotence",
"Impulsivity",
"Inability to regulate emotions",
"Inattention",
"Incontinence,
urine",
"Increased appetite",
"Infertility",
"Insomnia",
"Itch",
"Jaundice",
"Jaw pain",
"Joint cracking",
"Joint pain",
"Joint redness",
"Joint stiffness",
"Knee pain",
"Koilonychia",
"Labile mood",
"Leg pain",
"Leg sores",
"Leg swelling",
"Limping",
"Loss of appetite",
"Loss of speech",
"Loss of taste sensation",
"Loss of temperature sensation",
"Low libido",
"Low urine output",
"Lump or mass on gums",
"Memory loss",
"Menstrual cramps",
"Metallic taste in the mouth",
"Missed menstrual period",
"Mood swings",
"Mouth sores",
"Muscle cramps",
"Muscle pain",
"Mutism",
"Nail clubbing",
"Nail discoloration",
"Nail pitting",
"Nail separation",
"Nasal congestion",
"Nausea",
"Neck pain",
"Neglecting oneself",
"Numbness fingers",
"Numbness or tingling sensation in the tongue",
"Numbness toes",
"Onychorrhexis",
"Overactive bladder",
"Pain in the penis",
"Painful gums",
"Painful intercourse",
"Pale skin",
"Palpitations",
"Paralysis",
"Paranoia",
"Peeling skin",
"Pelvic pain",
"Penile discharge",
"Penile itching",
"Penile pain",
"Peripheral neuropathy",
"Photophobia",
"Pink eye",
"Pleurisy",
"Poor hygiene",
"Proteinuria",
"Ptosis",
"Rash",
"Rectal bleeding",
"Rectal incontinence",
"Rectal pain",
"Red spots on the skin",
"Red streaks on the skin",
"Restless leg syndrome",
"Ringing in ears",
"Runny nose",
"Seizures",
"Self-neglect",
"Shaking hands",
"Shortness of breath",
"Shoulder pain",
"Snoring",
"Sore throat",
"Sore tongue",
"Stiff neck",
"Stomach cramps",
"Stool color & texture changes",
"Strange behavior",
"Suicide",
"Swollen ankles and/or swollen feet",
"Swollen eyes",
"Swollen joints",
"Swollen lip",
"Swollen lymph nodes",
"Swollen testicles",
"Swollen tongue",
"Swollen tonsils",
"Tachycardia",
"Testicular pain",
"Thirst",
"Tingling in hands and feet",
"Toe pain",
"Toothache",
"Tremor",
"Tunnel vision",
"Unsteady gait",
"Unusual behavior",
"Urge incontinence",
"Urinary retention",
"Urinary urgency",
"Urine odor",
"Vaginal bleeding",
"Vaginal discharge",
"Vaginal dryness",
"Vaginal itching",
"Vaginal odor",
"Vaginal pain",
"Vertical ridges on the fingernails",
"Vertigo",
"Vision loss",
"Vocal outbursts",
"Vomiting",
"Vomiting blood",
"Watery eye",
"Weakness",
"Weight gain",
"Weight loss",
"Wheezing",
"White tongue",
"Wrist pain"
]
I18n.locale = :en
SEED_SYMPTOMS.each do |name|
Symptom.find_or_create_by!(name: name)
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff