chore: make sure CSV and File objects are properly namespaced

main
Nelson Jovel 2 years ago
parent a99ed183a1
commit ed1310f93c

@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
dashboard (0.1.11) dashboard (0.1.13)
bcrypt_pbkdf bcrypt_pbkdf
cssbundling-rails cssbundling-rails
ed25519 ed25519

@ -12,7 +12,7 @@ module Dashboard
def seed_districts_and_schools(csv_file) def seed_districts_and_schools(csv_file)
dese_ids = [] dese_ids = []
schools = [] schools = []
CSV.parse(File.read(csv_file), headers: true) do |row| ::CSV.parse(::File.read(csv_file), headers: true) do |row|
district_name = row["District"].strip district_name = row["District"].strip
district_code = row["District Code"].try(:strip) district_code = row["District Code"].try(:strip)
@ -39,7 +39,7 @@ module Dashboard
def seed_sqm_framework(csv_file) def seed_sqm_framework(csv_file)
admin_data_item_ids = [] admin_data_item_ids = []
CSV.parse(File.read(csv_file), headers: true) do |row| ::CSV.parse(::File.read(csv_file), headers: true) do |row|
category_id = row["Category ID"].strip category_id = row["Category ID"].strip
category_name = row["Category"].strip category_name = row["Category"].strip
category = Category.find_or_create_by!(category_id:) category = Category.find_or_create_by!(category_id:)

@ -13,7 +13,7 @@ module Dashboard
def clean def clean
Dir.glob(Rails.root.join(input_filepath, "*.csv")).each do |filepath| Dir.glob(Rails.root.join(input_filepath, "*.csv")).each do |filepath|
puts filepath puts filepath
File.open(filepath) do |file| ::File.open(filepath) do |file|
puts "opening file" puts "opening file"
processed_data = process_raw_file(file:) processed_data = process_raw_file(file:)
processed_data in [headers, clean_csv, log_csv, data] processed_data in [headers, clean_csv, log_csv, data]
@ -67,7 +67,7 @@ module Dashboard
clean_csv = [] clean_csv = []
log_csv = [] log_csv = []
data = [] data = []
headers = CSV.parse(file.first).first headers = ::CSV.parse(file.first).first
duplicate_header = headers.detect { |header| headers.count(header) > 1 } duplicate_header = headers.detect { |header| headers.count(header) > 1 }
unless duplicate_header.nil? unless duplicate_header.nil?
puts "\n>>>>>>>>>>>>>>>>>> Duplicate header found. This will misalign column headings. Please delete or rename the duplicate column: #{duplicate_header} \n>>>>>>>>>>>>>> \n" puts "\n>>>>>>>>>>>>>>>>>> Duplicate header found. This will misalign column headings. Please delete or rename the duplicate column: #{duplicate_header} \n>>>>>>>>>>>>>> \n"
@ -85,7 +85,7 @@ module Dashboard
all_survey_items = survey_items(headers:) all_survey_items = survey_items(headers:)
file.lazy.each_slice(1000) do |lines| file.lazy.each_slice(1000) do |lines|
CSV.parse(lines.join, headers:).map do |row| ::CSV.parse(lines.join, headers:).map do |row|
values = SurveyItemValues.new(row:, headers:, values = SurveyItemValues.new(row:, headers:,
survey_items: all_survey_items, schools:) survey_items: all_survey_items, schools:)
next unless values.valid_school? next unless values.valid_school?
@ -121,12 +121,12 @@ module Dashboard
end end
def write_csv(data:, output_filepath:, filename:, prefix: "") def write_csv(data:, output_filepath:, filename:, prefix: "")
csv = CSV.generate do |csv| csv = ::CSV.generate do |csv|
data.each do |row| data.each do |row|
csv << row csv << row
end end
end end
File.write(output_filepath.join(prefix + filename), csv) ::File.write(output_filepath.join(prefix + filename), csv)
end end
def schools def schools
@ -145,11 +145,11 @@ module Dashboard
end end
def create_ouput_directory def create_ouput_directory
FileUtils.mkdir_p output_filepath ::FileUtils.mkdir_p output_filepath
end end
def create_log_directory def create_log_directory
FileUtils.mkdir_p log_filepath ::FileUtils.mkdir_p log_filepath
end end
end end
end end

@ -5,7 +5,7 @@ require "csv"
module Dashboard module Dashboard
class DemographicLoader class DemographicLoader
def self.load_data(filepath:) def self.load_data(filepath:)
CSV.parse(File.read(filepath), headers: true) do |row| ::CSV.parse(::File.read(filepath), headers: true) do |row|
process_race(row:) process_race(row:)
process_gender(row:) process_gender(row:)
create_from_column(column: "Income", row:, model: Income) create_from_column(column: "Income", row:, model: Income)

@ -26,7 +26,7 @@ module Dashboard
def student_count(filepath:, dese_id:, year:) def student_count(filepath:, dese_id:, year:)
@students ||= {} @students ||= {}
if @students.count == 0 if @students.count == 0
CSV.parse(File.read(filepath), headers: true).map do |row| ::CSV.parse(::File.read(filepath), headers: true).map do |row|
academic_year = row["Academic Year"] academic_year = row["Academic Year"]
school_id = row["DESE ID"].to_i school_id = row["DESE ID"].to_i
total = row["Total"].gsub(",", "").to_i total = row["Total"].gsub(",", "").to_i

@ -5,7 +5,7 @@ module Dashboard
class Loader class Loader
def self.load_data(filepath:) def self.load_data(filepath:)
admin_data_values = [] admin_data_values = []
CSV.parse(File.read(filepath), headers: true) do |row| ::CSV.parse(::File.read(filepath), headers: true) do |row|
score = likert_score(row:) score = likert_score(row:)
next unless valid_likert_score(likert_score: score) next unless valid_likert_score(likert_score: score)

@ -76,7 +76,7 @@ module Dashboard
@teachers ||= {} @teachers ||= {}
@years_with_data ||= Set.new @years_with_data ||= Set.new
if @teachers.count == 0 if @teachers.count == 0
CSV.parse(File.read(filepath), headers: true).map do |row| ::CSV.parse(::File.read(filepath), headers: true).map do |row|
academic_year = row["Academic Year"] academic_year = row["Academic Year"]
@years_with_data << academic_year @years_with_data << academic_year
school_id = row["DESE ID"].to_i school_id = row["DESE ID"].to_i

@ -6,7 +6,7 @@ module Dashboard
class EnrollmentLoader class EnrollmentLoader
def load_data(filepath:) def load_data(filepath:)
enrollments = [] enrollments = []
CSV.parse(File.read(filepath), headers: true) do |row| ::CSV.parse(::File.read(filepath), headers: true) do |row|
row = EnrollmentRowValues.new(row:, schools: school_hash, academic_years: academic_year_hash) row = EnrollmentRowValues.new(row:, schools: school_hash, academic_years: academic_year_hash)
next unless row.school.present? && row.academic_year.present? next unless row.school.present? && row.academic_year.present?

@ -7,7 +7,7 @@ module Dashboard
def self.load_data(filepath:) def self.load_data(filepath:)
schools = [] schools = []
respondents = [] respondents = []
CSV.parse(File.read(filepath), headers: true) do |row| ::CSV.parse(::File.read(filepath), headers: true) do |row|
row = StaffingRowValues.new(row:) row = StaffingRowValues.new(row:)
next unless row.school.present? && row.academic_year.present? next unless row.school.present? && row.academic_year.present?

@ -3,13 +3,13 @@
module Dashboard module Dashboard
class SurveyResponsesDataLoader class SurveyResponsesDataLoader
def load_data(filepath:) def load_data(filepath:)
File.open(filepath) do |file| ::File.open(filepath) do |file|
headers = file.first headers = file.first
headers_array = CSV.parse(headers).first headers_array = ::CSV.parse(headers).first
all_survey_items = survey_items(headers:) all_survey_items = survey_items(headers:)
file.lazy.each_slice(500) do |lines| file.lazy.each_slice(500) do |lines|
survey_item_responses = CSV.parse(lines.join, headers:).map do |row| survey_item_responses = ::CSV.parse(lines.join, headers:).map do |row|
process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items, process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items,
schools:)) schools:))
end end
@ -22,7 +22,7 @@ module Dashboard
def from_file(file:) def from_file(file:)
headers = file.gets headers = file.gets
headers_array = CSV.parse(headers).first headers_array = ::CSV.parse(headers).first
all_survey_items = survey_items(headers:) all_survey_items = survey_items(headers:)
survey_item_responses = [] survey_item_responses = []
@ -31,7 +31,7 @@ module Dashboard
line = file.gets line = file.gets
next unless line.present? next unless line.present?
CSV.parse(line, headers:).map do |row| ::CSV.parse(line, headers:).map do |row|
values = process_row(row: SurveyItemValues.new(row:, headers: headers_array, values = process_row(row: SurveyItemValues.new(row:, headers: headers_array,
survey_items: all_survey_items, schools:)) survey_items: all_survey_items, schools:))
survey_item_responses << values if values.present? survey_item_responses << values if values.present?
@ -132,9 +132,9 @@ module Dashboard
end end
def get_survey_item_ids_from_headers(headers:) def get_survey_item_ids_from_headers(headers:)
CSV.parse(headers).first ::CSV.parse(headers).first
.filter(&:present?) .filter(&:present?)
.filter { |header| header.start_with? "t-", "s-" } .filter { |header| header.start_with? "t-", "s-" }
end end
end end
end end

@ -1,3 +1,3 @@
module Dashboard module Dashboard
VERSION = "0.1.12" VERSION = "0.1.13"
end end

@ -7,7 +7,7 @@ namespace :dashboard do
qualtrics_schools = {} qualtrics_schools = {}
csv_file = Rails.root.join("data", "master_list_of_schools_and_districts.csv") csv_file = Rails.root.join("data", "master_list_of_schools_and_districts.csv")
CSV.parse(File.read(csv_file), headers: true) do |row| ::CSV.parse(::File.read(csv_file), headers: true) do |row|
district_id = row["District Code"].to_i district_id = row["District Code"].to_i
school_id = row["School Code"].to_i school_id = row["School Code"].to_i

@ -0,0 +1,12 @@
# This migration comes from dashboard (originally 20240103232412)
class CreateDashboardAcademicYears < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_academic_years do |t|
t.string :range
t.timestamps
end
add_index :dashboard_academic_years, :range, unique: true
end
end

@ -0,0 +1,14 @@
# This migration comes from dashboard (originally 20240103233517)
class CreateDashboardCategories < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_categories do |t|
t.string :name
t.text :description
t.string :slug
t.string :category_id
t.string :short_description
t.timestamps
end
end
end

@ -0,0 +1,13 @@
# This migration comes from dashboard (originally 20240104005325)
class CreateDashboardSubcategories < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_subcategories do |t|
t.string :name
t.text :description
t.string :subcategory_id
t.references :dashboard_categories, null: false, foreign_key: true
t.timestamps
end
end
end

@ -0,0 +1,13 @@
# This migration comes from dashboard (originally 20240104170806)
class CreateDashboardMeasures < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_measures do |t|
t.string :measure_id
t.string :name
t.references :dashboard_subcategory, null: false, foreign_key: true
t.text :description
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104170957)
class CreateDashboardScales < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_scales do |t|
t.string :scale_id
t.references :dashboard_measure, null: false, foreign_key: true
t.timestamps
end
end
end

@ -0,0 +1,17 @@
# This migration comes from dashboard (originally 20240104172921)
class CreateDashboardSurveyItems < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_survey_items do |t|
t.string :survey_item_id
t.string :prompt
t.float :watch_low_benchmark
t.float :growth_low_benchmark
t.float :approval_low_benchmark
t.float :ideal_low_benchmark
t.references :dashboard_scale, null: false, foreign_key: true
t.boolean :on_short_form
t.timestamps
end
end
end

@ -0,0 +1,17 @@
# This migration comes from dashboard (originally 20240104173424)
class CreateDashboardAdminDataItems < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_admin_data_items do |t|
t.string :admin_data_item_id
t.string :description
t.float :watch_low_benchmark
t.float :growth_low_benchmark
t.float :approval_low_benchmark
t.float :ideal_low_benchmark
t.boolean :hs_only_item
t.references :dashboard_scale, null: false, foreign_key: true
t.timestamps
end
end
end

@ -0,0 +1,12 @@
# This migration comes from dashboard (originally 20240104173931)
class CreateDashboardDistricts < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_districts do |t|
t.string :name
t.string :slug
t.integer :qualtrics_code
t.timestamps
end
end
end

@ -0,0 +1,17 @@
# This migration comes from dashboard (originally 20240104174053)
class CreateDashboardSchools < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_schools do |t|
t.string :name
t.references :dashboard_district, null: false, foreign_key: true
t.string :slug
t.integer :qualtrics_code
t.integer :dese_id
t.boolean :is_hs
t.timestamps
end
add_index :dashboard_schools, :dese_id, unique: true
end
end

@ -0,0 +1,16 @@
# This migration comes from dashboard (originally 20240104174331)
class CreateDashboardAdminDataValues < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_admin_data_values do |t|
t.float :likert_score
t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_admin_data_item, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true
t.timestamps
end
add_index :dashboard_admin_data_values,
%i[dashboard_admin_data_item_id dashboard_school_id dashboard_academic_year_id], unique: true
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104174458)
class CreateDashboardElls < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_ells do |t|
t.string :designation
t.string :slug
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104174606)
class CreateDashboardGenders < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_genders do |t|
t.integer :qualtrics_code
t.string :designation
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104174649)
class CreateDashboardIncomes < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_incomes do |t|
t.string :designation
t.string :slug
t.timestamps
end
end
end

@ -0,0 +1,12 @@
# This migration comes from dashboard (originally 20240104181033)
class CreateDashboardRaces < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_races do |t|
t.string :designation
t.integer :qualtrics_code
t.string :slug
t.timestamps
end
end
end

@ -0,0 +1,29 @@
# This migration comes from dashboard (originally 20240104181617)
class CreateDashboardRespondents < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_respondents do |t|
t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true
t.integer :total_students
t.float :total_teachers
t.integer :pk
t.integer :k
t.integer :one
t.integer :two
t.integer :three
t.integer :four
t.integer :five
t.integer :six
t.integer :seven
t.integer :eight
t.integer :nine
t.integer :ten
t.integer :eleven
t.integer :twelve
t.timestamps
end
add_index :dashboard_respondents, %i[dashboard_school_id dashboard_academic_year_id], unique: true
end
end

@ -0,0 +1,14 @@
# This migration comes from dashboard (originally 20240104181856)
class CreateDashboardResponseRates < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_response_rates do |t|
t.references :dashboard_subcategory, null: false, foreign_key: true
t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true
t.float :student_response_rate
t.float :teacher_response_rate
t.timestamps
end
end
end

@ -0,0 +1,13 @@
# This migration comes from dashboard (originally 20240104183857)
class CreateDashboardScores < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_scores do |t|
t.float :average
t.boolean :meets_teacher_threshold
t.boolean :meets_student_threshold
t.boolean :meets_admin_data_threshold
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104183934)
class CreateDashboardSpeds < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_speds do |t|
t.string :designation
t.string :slug
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104184053)
class CreateDashboardStudents < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_students do |t|
t.string :lasid
t.string :response_id
t.timestamps
end
end
end

@ -0,0 +1,11 @@
# This migration comes from dashboard (originally 20240104190838)
class CreateDashboardStudentRaces < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_student_races do |t|
t.references :dashboard_student, null: false, foreign_key: true
t.references :dashboard_race, null: false, foreign_key: true
t.timestamps
end
end
end

@ -0,0 +1,24 @@
# This migration comes from dashboard (originally 20240104192128)
class CreateDashboardSurveyItemResponses < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_survey_item_responses do |t|
t.integer :likert_score
t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_survey_item, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true
t.references :dashboard_student, foreign_key: true
t.references :dashboard_gender, foreign_key: true
t.references :dashboard_income, foreign_key: true
t.references :dashboard_ell, foreign_key: true
t.references :dashboard_sped, foreign_key: true
t.string :response_id
t.integer :grade
t.datetime :recorded_date
t.timestamps
end
add_index :dashboard_survey_item_responses, %i[dashboard_school_id dashboard_academic_year_id]
add_index :dashboard_survey_item_responses,
%i[response_id dashboard_school_id dashboard_academic_year_id dashboard_survey_item_id], unique: true
end
end

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_01_04_192128) do ActiveRecord::Schema[7.1].define(version: 2024_02_07_230541) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"

Loading…
Cancel
Save