Skip to content

Commit 962ab1b

Browse files
committed
Merge branch 'feature/coursedummydata' into courseflow
2 parents 0a26e86 + e2085da commit 962ab1b

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

lib/tasks/courseflow_testing.rake

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
namespace :db do
2+
3+
desc "check courseflow data"
4+
task check_courseflow_data: :environment do
5+
# Check that the unit definitions have been populated
6+
unit_definitions = UnitDefinition.all
7+
puts "Unit Definitions: #{unit_definitions.count}"
8+
unit_definitions.each do |unit_definition|
9+
puts "Unit Definition: #{unit_definition.name}"
10+
puts "Description: #{unit_definition.description}"
11+
puts "Code: #{unit_definition.code}"
12+
puts "Version: #{unit_definition.version}"
13+
puts "Units: #{unit_definition.units.count}"
14+
end
15+
end
16+
17+
desc "clear courseflow data"
18+
task clear_courseflow_data: :environment do
19+
# Clear existing data from database
20+
old_units = Unit.where.not(unit_definition_id: nil)
21+
puts "Deleting #{old_units.count} units"
22+
old_units.destroy_all
23+
puts "Deleting #{UnitDefinition.count} unit definitions"
24+
UnitDefinition.destroy_all
25+
end
26+
27+
desc "Populate the courseflow databases with dummy data"
28+
task populate_courseflow_data: :environment do
29+
require 'faker'
30+
31+
# Clear existing data from database
32+
old_units = Unit.where.not(unit_definition_id: nil)
33+
puts "Deleting #{old_units.count} units"
34+
old_units.destroy_all
35+
puts "Deleting #{UnitDefinition.count} unit definitions"
36+
UnitDefinition.destroy_all
37+
38+
unit_names = [
39+
"Information Technology", "Programming", "Web Development", "Data Science", "Cyber Security"
40+
]
41+
42+
unit_descriptions = [
43+
"Introduction to Information Technology", "Introduction to Programming", "Introduction to Web Development", "Introduction to Data Science", "Introduction to Cyber Security"
44+
]
45+
46+
course_codes = [
47+
"SIT101", "SIT102", "SIT103", "SIT104", "SIT105"
48+
]
49+
50+
course_versions = [
51+
"1.0", "1.1", "1.2", "1.3", "1.4"
52+
]
53+
54+
# Use factorybot to create new unit definitions
55+
# unit_definitions = FactoryBot.create_list(:unit_definition, 5)
56+
5.times do
57+
puts "Creating new unit definitions"
58+
unit_definition = UnitDefinition.create(
59+
name: unit_names.sample,
60+
description: unit_descriptions.sample,
61+
code: course_codes.sample,
62+
version: course_versions.sample
63+
)
64+
65+
if unit_definition.persisted?
66+
puts "Unit Definition: #{unit_definition.name}"
67+
puts "Description: #{unit_definition.description}"
68+
puts "Code: #{unit_definition.code}"
69+
puts "Version: #{unit_definition.version}"
70+
puts "Unit definition #{unit_definition.id} created successfully"
71+
72+
# Use factory bot to create the associated units
73+
FactoryBot.create_list(:unit, 3, name: unit_definition.name, description: unit_definition.description, unit_definition_id: unit_definition.id)
74+
else
75+
puts "Unit definition not created"
76+
end
77+
end
78+
79+
puts "Database filled with courseflow data"
80+
puts "Unit Definitions: #{UnitDefinition.count}"
81+
end
82+
83+
desc "Populate the courseflow db with fixed unit definitions"
84+
task populate_fixed_courseflow_data: :environment do
85+
require 'faker'
86+
87+
# Clear existing data from database
88+
old_units = Unit.where.not(unit_definition_id: nil)
89+
puts "Deleting #{old_units.count} units"
90+
old_units.destroy_all
91+
puts "Deleting #{UnitDefinition.count} unit definitions"
92+
UnitDefinition.destroy_all
93+
94+
# Create new unit definitions
95+
unit_definitions = [
96+
{ name: "Computer Systems", code: "SIT111", version: "1.0" },
97+
{ name: "Discrete Mathematics", code: "SIT192", version: "1.0" },
98+
{ name: "Data Science Concepts", code: "SIT112", version: "1.0" },
99+
{ name: "Introduction to Programming", code: "SIT102", version: "1.0" },
100+
101+
{ name: "Object-Oriented Development", code: "SIT232", version: "1.0" },
102+
{ name: "Database Fundamentals", code: "SIT103", version: "1.0" },
103+
{ name: "Linear Algebra for Data Analysis", code: "SIT292", version: "1.0" },
104+
{ name: "Computer Networks and Communication", code: "SIT202", version: "1.0" },
105+
106+
{ name: "Computer Intelligence", code: "SIT215", version: "1.0" },
107+
{ name: "Data Structures and Algorithms", code: "SIT221", version: "1.0" },
108+
{ name: "Gamified Media", code: "ALM201", version: "1.0" },
109+
{ name: "Global Media", code: "ALM215", version: "1.0" },
110+
111+
{ name: "Professional Practice", code: "SIT344", version: "1.0" },
112+
{ name: "Team Project (A) - Project Management and Practices", code: "SIT374", version: "1.0" },
113+
{ name: "Team Project (B) - Execution and Delivery", code: "SIT378", version: "1.0" },
114+
{ name: "Concurrent and Distributed Programming", code: "SIT315", version: "1.0" },
115+
116+
{ name: "Computer Networks and Communication", code: "SIT202", version: "1.0" },
117+
{ name: "Cyber Security Management", code: "SIT284", version: "1.0" },
118+
{ name: "Machine Learning", code: "SIT307", version: "1.0" },
119+
{ name: "Full Stack Development: Secure Backend Services", code: "SIT331", version: "1.0" }
120+
]
121+
122+
unit_definitions.each do |unit_definition|
123+
new_unit_definition = UnitDefinition.create(
124+
name: unit_definition[:name],
125+
description: Faker::Lorem.paragraph(sentence_count: 1), # Generates a random description for the definitions
126+
code: unit_definition[:code],
127+
version: unit_definition[:version]
128+
)
129+
puts "Created Unit Definition: #{new_unit_definition.name}"
130+
end
131+
end
132+
end

0 commit comments

Comments
 (0)