chore: init commit

in worker.../repo/GITFOLDER.zip is the .git folder.
This commit is contained in:
2026-08-11 14:44:09 -04:00
parent 0012380fd3
commit 2854619bc9
782 changed files with 65944 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
grade = Grade.find_by!(level: 6)
classroom = Classroom.find_or_initialize_by(name: "Smith's Sixth Grade", school_year: SchoolYear.first)
classroom.trading_enabled = true
classroom.grades << grade unless classroom.grades.include?(grade)
classroom.save!

View File

@@ -0,0 +1,28 @@
# For each quarter, spin up a GradeBook for this classroom
school_years = SchoolYear.first
classroom = Classroom.first
Quarter
.where(school_year: school_years)
.order(:number)
.each do |quarter|
book = GradeBook.find_or_create_by!(
quarter: quarter,
classroom: classroom
)
puts "Seeded GradeBook for #{quarter.name}"
Rails.logger.info "Seeded GradeBook for #{quarter.name}"
# And for each student in that classroom, create a blank entry
classroom
.users
.where(type: "Student")
.find_each do |student|
GradeEntry.find_or_create_by!(
grade_book: book,
user: student
)
puts "Seeded GradeEntry for student #{student.username}"
Rails.logger.info "Seeded GradeEntry for student #{student.username}"
end
end

View File

@@ -0,0 +1,14 @@
# Create grade levels 5-8
Classroom::GRADE_RANGE.each do |level|
# Create the grade name with proper ordinal (5th, 6th, 7th, etc.)
grade_name = "#{level.ordinalize} Grade"
grade = Grade.find_or_create_by(level: level) do |g|
g.name = grade_name
end
# Update name if it's not following the convention
if grade.persisted? && grade.name != grade_name
grade.update!(name: grade_name)
end
end

View File

@@ -0,0 +1,129 @@
# frozen_string_literal: true
# Pending buy orders
student = User.find_by(email: "student@example.com")
mike = User.find_by(email: "mike@example.com")
students = [student, mike].compact
if students.any?
stocks = Stock.limit(5)
students.each do |student_user|
if student_user&.portfolio
portfolio_balance = student_user.portfolio.cash_balance || 0
if portfolio_balance > 100
2.times do |i|
stock = stocks[i]
if stock
next unless stock.price_cents
shares = 1
cost = stock.price_cents / 100.0
if cost * shares <= portfolio_balance
existing_order = Order.find_by(
user: student_user,
stock: stock,
shares: shares,
status: :pending,
action: :buy
)
unless existing_order
Order.create!(
user: student_user,
stock: stock,
shares: shares,
status: :pending,
action: :buy
)
puts "Created pending buy order: #{student_user.email} - #{shares} shares of #{stock.ticker}"
Rails.logger.info "Seeded pending buy order for #{student_user.email}: #{shares} shares of #{stock.ticker}"
else
puts "Pending buy order already exists: #{student_user.email} - #{shares} shares of #{stock.ticker}"
end
end
end
end
end
end
end
end
# Pending sell orders
students.each do |student_user|
if student_user&.portfolio
existing_portfolio_stock = PortfolioStock.joins(:portfolio)
.where(portfolio: { user: student_user })
.first
if existing_portfolio_stock && existing_portfolio_stock.shares > 0
safe_shares = [existing_portfolio_stock.shares.to_i, 1].min
if safe_shares > 0
existing_order = Order.find_by(
user: student_user,
stock: existing_portfolio_stock.stock,
shares: safe_shares,
status: :pending,
action: :sell
)
unless existing_order
Order.create!(
user: student_user,
stock: existing_portfolio_stock.stock,
shares: safe_shares,
status: :pending,
action: :sell
)
puts "Created pending sell order: #{student_user.email} - #{safe_shares} shares of #{existing_portfolio_stock.stock.ticker}"
Rails.logger.info "Seeded pending sell order for #{student_user.email}: #{safe_shares} shares of #{existing_portfolio_stock.stock.ticker}"
else
puts "Pending sell order already exists: #{student_user.email} - #{safe_shares} shares of #{existing_portfolio_stock.stock.ticker}"
end
end
end
end
end
# Canceled orders
if students.any?
stocks = Stock.limit(5)
students.each do |student_user|
if student_user&.portfolio
[1, 2].sample.times do |i|
stock = stocks[i + 2]
if stock
shares = [1, 2].sample
existing_order = Order.find_by(
user: student_user,
stock: stock,
shares: shares,
status: :canceled,
action: :sell
)
unless existing_order
order = Order.new(
user: student_user,
stock: stock,
shares: shares,
action: :sell
)
order.status = :canceled
order.save!(validate: false)
puts "Created canceled order: #{student_user.email} - #{shares} shares of #{stock.ticker}"
Rails.logger.info "Seeded canceled order for #{student_user.email}: #{shares} shares of #{stock.ticker}"
else
puts "Canceled order already exists: #{student_user.email} - #{shares} shares of #{stock.ticker}"
end
end
end
end
end
else
puts "No student users found. Skipping orders seeding."
Rails.logger.warn "No student users found. Skipping orders seeding."
end

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
mike = User.find_by(email: "mike@example.com")
if mike
portfolio = Portfolio.find_by(user: mike)
if portfolio
# Create 6 months of historical snapshots with realistic value progression
# Starting 5 months ago and ending with current month
base_value = 150_00 # $150.00 starting value
snapshots_data = [
{ months_ago: 5, worth_cents: base_value },
{ months_ago: 4, worth_cents: base_value + 50_00 }, # +$50
{ months_ago: 3, worth_cents: base_value + 120_00 }, # +$70
{ months_ago: 2, worth_cents: base_value + 80_00 }, # -$40 (dip)
{ months_ago: 1, worth_cents: base_value + 180_00 }, # +$100 (recovery)
{ months_ago: 0, worth_cents: base_value + 250_00 } # +$70 (growth)
]
snapshots_data.each do |data|
snapshot_date = data[:months_ago].months.ago.beginning_of_month.to_date
PortfolioSnapshot.find_or_create_by!(
portfolio: portfolio,
date: snapshot_date
) do |snapshot|
snapshot.worth_cents = data[:worth_cents]
end
end
puts "Seeded #{snapshots_data.length} portfolio snapshots for Mike's portfolio"
Rails.logger.info "Seeded #{snapshots_data.length} portfolio snapshots for Mike's portfolio"
else
puts "Portfolio not found for Mike. Skipping portfolio snapshots seeding."
Rails.logger.warn "Portfolio not found for Mike. Skipping portfolio snapshots seeding."
end
else
puts "Student user 'Mike' not found. Skipping portfolio snapshots seeding."
Rails.logger.warn "Student user 'Mike' not found. Skipping portfolio snapshots seeding."
end

View File

@@ -0,0 +1,142 @@
# frozen_string_literal: true
# Create transactions for Student user
student = User.find_by(email: "student@example.com")
if student
portfolio = Portfolio.find_or_create_by(user: student)
# Initial deposit to give student starting balance
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 10_000_00
)
# Add earnings transactions with reasons for testing
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 500_00,
reason: :attendance_earnings
)
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 500_00,
reason: :reading_earnings
)
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 100_00,
reason: :math_earnings
)
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 50_00,
reason: :awards
)
PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 25_00,
reason: :transaction_fees
)
puts "Seeded portfolio transactions for Student user"
Rails.logger.info "Seeded portfolio transactions for Student user"
else
puts "Student user not found. Skipping Student portfolio transactions seeding."
Rails.logger.warn "Student user not found. Skipping Student portfolio transactions seeding."
end
# Create transactions for Mike user
mike = User.find_by(email: "mike@example.com")
if mike
portfolio = Portfolio.find_or_create_by(user: mike)
pt = PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 15_000_00
)
stocks = Stock.limit(3)
shares = 2
stocks.each do |stock|
next unless stock.price_cents
total_price_cents = (stock.price_cents * shares)
order = Order.create!(
user: mike,
stock: stock,
shares: shares,
status: :pending,
portfolio_transaction: pt,
action: :buy
)
ExecuteOrder.execute(order)
end
shares = 1
stocks.each do |stock|
next unless stock.price_cents
total_price_cents = (stock.price_cents * shares)
order = Order.create!(
user: mike,
stock: stock,
shares: shares,
status: :pending,
portfolio_transaction: pt,
action: :sell
)
ExecuteOrder.execute(order)
end
pt = PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :withdrawal,
amount_cents: 100_00
)
pt = PortfolioTransaction.create(
portfolio: portfolio,
transaction_type: :deposit,
amount_cents: 10_000_00
)
existing_stock_ids = Order.where(user: mike, action: :buy).pluck(:stock_id).uniq
stocks = Stock.where.not(id: existing_stock_ids).limit(1)
stocks.each do |stock|
next unless stock.price_cents
shares = 1
total_price_cents = (stock.price_cents * shares)
order = Order.create!(
user: mike,
stock: stock,
shares: shares,
status: :pending,
portfolio_transaction: pt,
action: :buy
)
ExecuteOrder.execute(order)
end
puts "Seeded three completed orders and transactions for the Student user 'Mike'"
Rails.logger.info "Seeded three completed orders and transactions for the Student user 'Mike"
else
puts "Student user 'Mike' not found. Skipping portfolio transactions seeding."
Rails.logger.warn "Student user 'Mike' not found. Skipping portfolio transactions seeding."
end

View File

@@ -0,0 +1,17 @@
# Create 4 quarters for the first school year
school_year = SchoolYear.find_by(school: School.first, year: Year.first)
if school_year
(1..4).each do |n|
Quarter.find_or_create_by!(
school_year: school_year,
number: n
) do |q|
q.update(name: "Quarter #{n}")
end
end
puts "Quarters created for school year: #{school_year.year.name} at #{school_year.school.name}."
Rails.logger.info "Created 4 quarters for school year: #{school_year.year.name} at #{school_year.school.name}."
else
puts "No current school year found. Skipping quarter creation."
end

View File

@@ -0,0 +1 @@
SchoolYear.find_or_create_by!(school: School.first, year: Year.first)

View File

@@ -0,0 +1 @@
School.find_or_create_by(name: "Test School")

View File

@@ -0,0 +1,35 @@
# frozen_string_literal: true
active_seed_stocks = [
{ ticker: "BAC", stock_exchange: "NYSE", company_name: "Bank of America Corporation", company_website: "https://www.bankofamerica.com", description: "Bank of America Corporation operates as a bank holding company for Bank of America, N.A., which provides various banking and financial products and services.", industry: "Banks", management: "Brian Moynihan (CEO), Alastair Borthwick (CFO)", employees: 216_823, competitor_names: "JPMorgan Chase, Wells Fargo, Citigroup, Goldman Sachs", sales_growth: 2.5, industry_avg_sales_growth: 4.1, debt_to_equity: 1.15, industry_avg_debt_to_equity: 1.25, profit_margin: 32.1, industry_avg_profit_margin: 28.5, cash_flow: 31_200_000_000.00, debt: 294_000_000_000.00, price_cents: 4_512 },
{ ticker: "CCL", stock_exchange: "NYSE", company_name: "Carnival Corporation & plc", company_website: "https://www.carnival.com", description: "Carnival Corporation & plc operates as a leisure travel company providing cruise vacations and complementary vacation services.", industry: "Travel Services", management: "Josh Weinstein (CEO), David Bernstein (CFO)", employees: 120_000, competitor_names: "Royal Caribbean, Norwegian Cruise Line, MSC Cruises", sales_growth: 15.2, industry_avg_sales_growth: 8.7, debt_to_equity: 3.45, industry_avg_debt_to_equity: 1.85, profit_margin: -2.1, industry_avg_profit_margin: 5.8, cash_flow: 3_800_000_000.00, debt: 28_500_000_000.00, price_cents: 2_185 },
{ ticker: "F", stock_exchange: "NYSE", company_name: "Ford Motor Company", company_website: "https://www.ford.com", description: "Ford Motor Company designs, manufactures, markets, and services a full line of Ford trucks, utility vehicles, and cars worldwide.", industry: "Automobiles", management: "Jim Farley (CEO), John Lawler (CFO)", employees: 190_000, competitor_names: "General Motors, Tesla, Toyota, Stellantis", sales_growth: 11.8, industry_avg_sales_growth: 6.4, debt_to_equity: 1.85, industry_avg_debt_to_equity: 0.95, profit_margin: 3.7, industry_avg_profit_margin: 7.2, cash_flow: 11_500_000_000.00, debt: 96_000_000_000.00, price_cents: 1_177 },
{ ticker: "IBIT", stock_exchange: "NASDAQ", company_name: "iShares Bitcoin Trust ETF", company_website: "https://www.ishares.com", description: "iShares Bitcoin Trust provides exposure to bitcoin by holding bitcoin and seeks to reflect the performance of bitcoin.", industry: "Exchange Traded Funds", management: "BlackRock Fund Advisors (Sponsor), Samara Cohen (Chief Investment Officer)", employees: 0, competitor_names: "Grayscale Bitcoin Trust, Fidelity Wise Origin Bitcoin Fund, ARK 21Shares Bitcoin ETF", sales_growth: 0.0, industry_avg_sales_growth: 0.0, debt_to_equity: 0.0, industry_avg_debt_to_equity: 0.0, profit_margin: 0.0, industry_avg_profit_margin: 0.0, cash_flow: 0.00, debt: 0.00, price_cents: 4_125 },
{ ticker: "KO", stock_exchange: "NYSE", company_name: "The Coca-Cola Company", company_website: "https://www.coca-colacompany.com", description: "The Coca-Cola Company manufactures, retails, and markets nonalcoholic beverage concentrates and syrups worldwide.", industry: "Beverages", management: "James Quincey (CEO), John Murphy (CFO)", employees: 86_200, competitor_names: "PepsiCo, Dr Pepper Snapple Group, Monster Beverage", sales_growth: 11.2, industry_avg_sales_growth: 5.50, debt_to_equity: 1.65, industry_avg_debt_to_equity: 0.85, profit_margin: 25.4, industry_avg_profit_margin: 12.50, cash_flow: 10_800_000_000.00, debt: 37_000_000_000.00, price_cents: 6_899 },
{ ticker: "KHC", stock_exchange: "NASDAQ", company_name: "The Kraft Heinz Company", company_website: "https://www.kraftheinzcompany.com", description: "The Kraft Heinz Company manufactures and markets food and beverage products in the United States and internationally.", industry: "Food Products", management: "Carlos Abrams-Rivera (CEO), Andre Maciel (CFO)", employees: 38_000, competitor_names: "Unilever, Nestle, General Mills, Campbell Soup", sales_growth: -1.2, industry_avg_sales_growth: 3.8, debt_to_equity: 0.87, industry_avg_debt_to_equity: 0.65, profit_margin: 8.9, industry_avg_profit_margin: 11.2, cash_flow: 4_200_000_000.00, debt: 27_800_000_000.00, price_cents: 3_654 },
{ ticker: "NKE", stock_exchange: "NYSE", company_name: "Nike, Inc.", company_website: "https://www.nike.com", description: "Nike, Inc. designs, develops, markets, and sells athletic footwear, apparel, equipment, and accessories worldwide.", industry: "Footwear & Accessories", management: "John Donahoe (CEO), Matthew Friend (CFO)", employees: 83_700, competitor_names: "Adidas, Under Armour, Puma, New Balance", sales_growth: 0.3, industry_avg_sales_growth: 4.2, debt_to_equity: 0.68, industry_avg_debt_to_equity: 0.55, profit_margin: 12.9, industry_avg_profit_margin: 9.8, cash_flow: 6_900_000_000.00, debt: 9_600_000_000.00, price_cents: 7_521 },
{ ticker: "MAT", stock_exchange: "NASDAQ", company_name: "Mattel, Inc.", company_website: "https://www.mattel.com", description: "Mattel, Inc. designs, manufactures, and markets various toy products worldwide under the Mattel, Fisher-Price, American Girl, Thomas & Friends, UNO, and Hot Wheels brands.", industry: "Leisure Products", management: "Ynon Kreiz (CEO), Anthony DiSilvestro (CFO)", employees: 33_000, competitor_names: "Hasbro, LEGO, Spin Master, MGA Entertainment", sales_growth: -1.5, industry_avg_sales_growth: 2.8, debt_to_equity: 2.85, industry_avg_debt_to_equity: 1.25, profit_margin: 17.2, industry_avg_profit_margin: 8.9, cash_flow: 1_100_000_000.00, debt: 2_900_000_000.00, price_cents: 1_892 },
{ ticker: "SONY", stock_exchange: "NYSE", company_name: "Sony Group Corporation", company_website: "https://www.sony.com", description: "Sony Group Corporation operates as a technology and media company that develops, produces, manufactures, and sells various products worldwide.", industry: "Consumer Electronics", management: "Kenichiro Yoshida (CEO), Hiroki Totoki (CFO)", employees: 108_900, competitor_names: "Samsung, Apple, Nintendo, Microsoft", sales_growth: 4.8, industry_avg_sales_growth: 6.2, debt_to_equity: 0.35, industry_avg_debt_to_equity: 0.45, profit_margin: 13.2, industry_avg_profit_margin: 8.9, cash_flow: 8_500_000_000.00, debt: 15_200_000_000.00, price_cents: 2_752 },
{ ticker: "VZ", stock_exchange: "NYSE", company_name: "Verizon Communications Inc.", company_website: "https://www.verizon.com", description: "Verizon Communications Inc., through its subsidiaries, offers communications, technology, information, and entertainment products and services to consumers, businesses, and governmental entities worldwide.", industry: "Telecommunications Services", management: "Hans Vestberg (CEO), Matt Ellis (CFO)", employees: 117_100, competitor_names: "AT&T, T-Mobile, Comcast, Charter Communications", sales_growth: 2.1, industry_avg_sales_growth: 3.8, debt_to_equity: 1.8, industry_avg_debt_to_equity: 1.5, profit_margin: 17.2, industry_avg_profit_margin: 12.4, cash_flow: 23_700_000_000.00, debt: 176_200_000_000.00, price_cents: 4_423 },
]
active_seed_stocks.each do |stock_data|
stock = Stock.find_or_create_by(ticker: stock_data[:ticker])
stock.update!(stock_data)
end
archived_seed_stocks = [
{ ticker: "DIS", company_name: "Disney" },
{ ticker: "EA", company_name: "Electronic Arts" },
{ ticker: "GAP", company_name: "Gap" },
{ ticker: "LUV", company_name: "Southwest Airlines" },
{ ticker: "META", company_name: "Facebook" },
{ ticker: "SIRI", company_name: "SiriusXM" },
{ ticker: "TWX", company_name: "Time Warner" },
{ ticker: "UA", company_name: "Under Armour" },
]
archived_seed_stocks.each do |stock_data|
stock = Stock.find_or_create_by(ticker: stock_data[:ticker])
stock.update!(stock_data.merge(archived: true))
end

View File

@@ -0,0 +1,72 @@
# Teacher
teacher = User.find_or_initialize_by(email: "teacher@example.com")
unless teacher.persisted?
teacher.attributes = {
name: "Teacher Name",
password: "password",
password_confirmation: "password",
admin: false,
type: "Teacher",
classroom: Classroom.first
}
teacher.save
puts "Created Teacher user: #{teacher.email}"
Rails.logger.info "Seeded Teacher user: #{teacher.email}"
else
puts "Teacher user already exists: #{teacher.email}"
end
# Student
student = User.find_or_initialize_by(email: "student@example.com")
unless student.persisted?
student.attributes = {
username: "Student",
password: "password",
password_confirmation: "password",
admin: false,
type: "Student",
classroom: Classroom.first
}
student.save
puts "Created Student user: #{student.email}"
Rails.logger.info "Seeded Student user: #{student.email}"
else
puts "Student user already exists: #{student.email}"
end
# Admin
admin = User.find_or_initialize_by(email: "admin@example.com")
unless admin.persisted?
admin.attributes = {
username: "Admin",
password: "password",
password_confirmation: "password",
admin: true,
type: "User",
classroom: Classroom.first
}
admin.save
puts "Created Admin user: #{admin.email}"
Rails.logger.info "Seeded Admin user: #{admin.email}"
else
puts "Admin user already exists: #{admin.email}"
end
# Student "mike" to who the portfolio transactions will belong
mike = User.find_or_initialize_by(email: "mike@example.com")
unless mike.persisted?
mike.attributes = {
username: "mike",
email: "mike@example.com",
password: "password",
password_confirmation: "password",
admin: false,
type: "Student",
classroom: Classroom.first
}
mike.save
puts "Created portfolio transactions user: #{mike.email}"
Rails.logger.info "Seeded user: #{mike.email}"
else
puts "Mike already exists: #{mike.email}"
end

View File

@@ -0,0 +1,8 @@
current_year = Date.current.year
start_year = current_year - 3
end_year = current_year + 10
(start_year..end_year).each do |i|
year = Year.find_or_create_by(name: "#{i} - #{i + 1}")
year.save!
end