science-ation/scripts/judges_fake.php

174 lines
6.4 KiB
PHP

<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
?>
<?
echo "To run this script, edit it and comment out the 'exit' (and this message) at the beginning";
exit;
include '../common.inc.php';
$numjudges = 200;
$stmt = $pdo->prepare('TRUNCATE TABLE judges');
$stmt->execute();
$stmt = $pdo->prepare('TRUNCATE TABLE judges_catpref');
$stmt->execute();
$stmt = $pdo->prepare('TRUNCATE TABLE judges_expertise');
$stmt->execute();
$stmt = $pdo->prepare('TRUNCATE TABLE judges_years');
$stmt->execute();
$stmt = $pdo->prepare('TRUNCATE TABLE judges_languages');
$stmt->execute();
function getrand($ar)
{
return $ar[rand(0, count($ar) - 1)];
}
$firstnames = array('James', 'Bob', 'Ali', 'Erin', 'Julia', 'Dave', 'Steve', 'Bryan', 'Jane', 'Elizabeth', 'Norm', 'Sue', 'Eric', 'Terry', 'Arthur', 'Angel', 'Allison', 'Jeremy', 'Jacqueline', 'Derek', 'Kristen', 'Greg', 'Cheryl', 'Debbie', 'Heather', 'Donald', 'Linda', 'George', 'Patrica', 'Carmel', 'Dawn', 'Scott', 'Brad', 'Bruce', 'Paul', 'Guillaume');
$lastnames = array('Grant', 'Browning', 'Mehdi', 'Borque', 'Temple', 'Culhane', 'Sargent', 'Sing', 'Belanger', 'Desjardin', 'Jones', 'Smith', 'Brown', 'Johnson', 'Williams', 'White', 'Thompson', 'Baker');
$domains = array('lightbox.org', 'microsoft.com', 'yahoo.com', 'msn.com', 'gmail.com', 'reach.net', 'slicer.ca', 'cwsf.ca', 'sfiab.ca');
for ($x = 0; $x < $numjudges; $x++) {
$firstname = getrand($firstnames);
$lastname = getrand($lastnames);
$email = strtolower($firstname . '@' . getrand($domains));
// set their judging experience (school)
$num = rand(0, 100);
// 50% chance they have 0-2 years of experience
// 30% chance they hvae 3-5 years of experience
// 15% chance they have 6-9 years of experience
// 5% chance they have 10-20 years of experience
if ($num < 50)
$years_school = rand(0, 2);
else if ($num < 80)
$years_school = rand(3, 5);
else if ($num < 95)
$years_school = rand(6, 9);
else
$years_school = rand(10, 20);
// set their judging experience (regional)
$num = rand(0, 100);
// 60% chance they have 0-2 years of experience
// 30% chance they hvae 3-5 years of experience
// 6% chance they have 6-9 years of experience
// 4% chance they have 10-15 years of experience
if ($num < 60)
$years_regional = rand(0, 2);
else if ($num < 90)
$years_regional = rand(3, 5);
else if ($num < 96)
$years_regional = rand(6, 9);
else
$years_regional = rand(10, 15);
// set their judging experience (national)
$num = rand(0, 100);
// 70% chance they have 0-2 years of experience
// 20% chance they hvae 3-5 years of experience
// 7% chance they have 6-9 years of experience
// 3% chance they have 10-13 years of experience
if ($num < 70)
$years_national = rand(0, 2);
else if ($num < 90)
$years_national = rand(3, 5);
else if ($num < 97)
$years_national = rand(6, 9);
else
$years_national = rand(10, 13);
$willing_chair = 'no';
// if more than 10 years combined experience, than there's a 80% chance they'll be a willing chair
if ($years_national + $years_regional + $years_regional > 10) {
$num = rand(0, 100);
if ($num < 80)
$willing_chair = 'yes';
} else if ($years_national + $years_regional + $years_regional > 6) {
// if more than 6 years combined experience, than there's a 40% chance they'll be a willing chair
$num = rand(0, 100);
if ($num < 40)
$willing_chair = 'yes';
}
echo "Creating $firstname $lastname ($email) s=$years_school r=$years_regional n=$years_national wc=$willing_chair <br />\n";
// there's a 1 in 20 chance that this judge is not yet completed their info
$compnum = rand(0, 20);
if ($compnum == 1)
$complete = 'no';
else
$complete = 'yes';
$q = $pdo->prepare("INSERT INTO judges (firstname,lastname,email,years_school,years_regional,years_national,willing_chair,complete) VALUES (?,?,?,?,?,?,?,?)");
$q->execute([$firstname,$lastname,$email,$years_school,$years_regional,$years_national,$willing_chair,$complete]);
$id = $pdo->lastInsertId();
// for both these, the annealer expects -2 to 2 , but since expertise was done waaaaaay before as 1-5 we'll add it as 1-5 and the annealer will subtract 3
// to compensate
// preference is ranked -2 to 2
for ($a = 1; $a <= 3; $a++) {
$catrank = rand(-2, 2);
$stmt = $pdo->prepare("INSERT INTO judges_catpref (judges_id,projectcategories_id,rank,year) VALUES (?,?,?,'2007')");
$stmt->execute([$id,$a,$catrank]);
}
// expertise is ranked 1-5
for ($a = 1; $a <= 6; $a++) {
$divrank = rand(1, 5);
$stmt = $pdo->prepare("INSERT INTO judges_expertise (judges_id,projectdivisions_id,val,year) VALUES (?,?,?,'2007')");
$stmt->execute([$id,$a,$divrank]);
}
// and add the record to the judges_years table so they will be 'active' for this year
$stmt = $pdo->prepare("INSERT INTO judges_years (judges_id,year) VALUES (?,'2007')");
$stmt->execute([$id]);
// 60% chance they only speak english
// 20% chance they only speak french
// 20% chance they are bilingual
$num = rand(0, 100);
if ($num < 60) {
$stmt = $pdo->prepare("INSERT INTO judges_languages (judges_id,languages_lang) VALUES (?,'en')");
$stmt->execute([$id]);
} else if ($num < 80) {
$stmt = $pdo->prepare("INSERT INTO judges_languages (judges_id,languages_lang) VALUES (?,'fr')");
$stmt->execute([$id]);
} else {
$stmt = $pdo->prepare("INSERT INTO judges_languages (judges_id,languages_lang) VALUES (?,'en')");
$stmt->execute([$id]);
$stmt = $pdo->prepare("INSERT INTO judges_languages (judges_id,languages_lang) VALUES (?,'fr')");
$stmt->execute([$id]);
}
}
?>