<commit_before>namespace :db do
	desc "Clear the database and fill with test data"
	task :populate => :environment do
		require 'populator'
		require 'faker'
		require '<PASSWORD>'

		subjects = ["Introduction To Programming",
					"Object-Oriented Programming",
					"Games Programming",
					"AI For Games"]

		days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

		# Clear the database
		[Project, ProjectMembership, ProjectStatus, Task, TaskInstance, TaskStatus, Team, TeamMembership, User].each(&:delete_all)
	
		# Create 4 users
		User.populate(4) do |user|
			user.email = Faker::Internet.email
			user.encrypted_password = <PASSWORD>("password")
			user.first_name = Faker::Name.first_name
			user.last_name = Faker::Name.last_name
			user.sign_in_count = 0
		end

		# Create 2 tutors
		tutor_num = 1
		User.populate(2) do |tutor|
			tutor.email = "<EMAIL>"
			tutor.encrypted_password = <PASSWORD>("password")
			tutor.first_name = "Tutor"
			tutor.last_name =  "#{tutor_num}"
			tutor.sign_in_count = 0
			tutor_num += 1
		end

		# Populate project/task statuses
		ProjectStatus.create(:health => 100)
		TaskStatus.create(:name => "Not complete", :description => "This task has not been signed off by your tutor.")
		TaskStatus.create(:name => "Needs fixing", :description => "This task must be resubmitted after fixing some issues.")
		TaskStatus.create(:name => "Complete", :description => "This task has been signed off by your tutor.")

		# Create 4 projects (subjects)
		subjects.each do |subject|
			Project.populate(1) do |project|
				project.name = subject
				project.description = Populator.words(10..15)
				project.start_date = Date.today
				project.end_date = 13.weeks.from_now

				# Create 6-12 tasks per project
				num_tasks = 6 + rand(6)
				assignment_num = 0
				Task.populate(num_tasks) do |task|
					assignment_num += 1
					task.name = "Assignment #{assignment_num}"
					task.project_id = project.id
					task.description = Populator.words(5..10)
					task.weighting = 1/num_tasks
					task.required = rand < 0.9 	# 10% chance of being false
					task.recommended_completion_date = assignment_num.weeks.from_now	# Assignment 6 due week 6, etc.
				end

				# Create 2 teams per project
				team_num = 1
				Team.populate(2) do |team|
					team.project_id = project.id
					team.meeting_time = "#{days.sample} #{rand(8..19)}:#{['00', '30'].sample}"				# Mon-Fri 8am-7:30pm
					team.meeting_location = "#{['EN', 'BA'].sample}#{rand(1..7)}#{rand(0..1)}#{rand(1..9)}" # EN###/BA###
					
					if team_num == 1
						team.user_id = 5	# Tutor 1
					else
						team.user_id = 6	# Tutor 2
					end
					
					team_num += 1
				end
			end
		end

		# Put each user in each project, in one team or the other
		User.all[0..3].each_with_index do |user, i|
			current_project = 1
			TeamMembership.populate(Project.count) do |team_membership|<commit_msg>Fixed populate task where trying to get a random number in a range was making the script fail (no such method exists)<commit_after>namespace :db do
	desc "Clear the database and fill with test data"
	task :populate => :environment do
		require 'populator'
		require 'faker'
		require '<PASSWORD>'

		subjects = ["Introduction To Programming",
					"Object-Oriented Programming",
					"Games Programming",
					"AI For Games"]

		days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

		# Clear the database
		[Project, ProjectMembership, ProjectStatus, Task, TaskInstance, TaskStatus, Team, TeamMembership, User].each(&:delete_all)
	
		# Create 4 users
		User.populate(4) do |user|
			user.email = Faker::Internet.email
			user.encrypted_password = <PASSWORD>("password")
			user.first_name = Faker::Name.first_name
			user.last_name = Faker::Name.last_name
			user.sign_in_count = 0
		end

		# Create 2 tutors
		tutor_num = 1
		User.populate(2) do |tutor|
			tutor.email = "<EMAIL>"
			tutor.encrypted_password = <PASSWORD>("password")
			tutor.first_name = "Tutor"
			tutor.last_name =  "#{tutor_num}"
			tutor.sign_in_count = 0
			tutor_num += 1
		end

		# Populate project/task statuses
		ProjectStatus.create(:health => 100)
		TaskStatus.create(:name => "Not complete", :description => "This task has not been signed off by your tutor.")
		TaskStatus.create(:name => "Needs fixing", :description => "This task must be resubmitted after fixing some issues.")
		TaskStatus.create(:name => "Complete", :description => "This task has been signed off by your tutor.")

		# Create 4 projects (subjects)
		subjects.each do |subject|
			Project.populate(1) do |project|
				project.name = subject
				project.description = Populator.words(10..15)
				project.start_date = Date.today
				project.end_date = 13.weeks.from_now

				# Create 6-12 tasks per project
				num_tasks = 6 + rand(6)
				assignment_num = 0
				Task.populate(num_tasks) do |task|
					assignment_num += 1
					task.name = "Assignment #{assignment_num}"
					task.project_id = project.id
					task.description = Populator.words(5..10)
					task.weighting = 1/num_tasks
					task.required = rand < 0.9 	# 10% chance of being false
					task.recommended_completion_date = assignment_num.weeks.from_now	# Assignment 6 due week 6, etc.
				end

				# Create 2 teams per project
				team_num = 1
				Team.populate(2) do |team|
					team.project_id = project.id
					team.meeting_time = "#{days.sample} #{8 + rand(12)}:#{['00', '30'].sample}"				# Mon-Fri 8am-7:30pm
					team.meeting_location = "#{['EN', 'BA'].sample}#{rand(7)}#{rand(1)}#{rand(9)}" # EN###/BA###
					
					if team_num == 1
						team.user_id = 5	# Tutor 1
					else
						team.user_id = 6	# Tutor 2
					end
					
					team_num += 1
				end
			end
		end

		# Put each user in each project, in one team or the other
		User.all[0..3].each_with_index do |user, i|
			current_project = 1
			TeamMembership.populate(Project.count) do |team_membership|
{'fraction_non_alphanumeric': 0.12606328683225587, 'fraction_numerical': 0.021605988431439266, 'mean_word_length': 3.3677563150074294, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1271731', 'n_tokens_mistral': 2447, 'n_tokens_neox': 1933, 'n_words': 527}