Skip to content

Instantly share code, notes, and snippets.

@Llewellynvdm
Created December 5, 2021 02:40
Show Gist options
  • Save Llewellynvdm/3b0a1aa29ec82671ecd156618b5c7a1e to your computer and use it in GitHub Desktop.
Save Llewellynvdm/3b0a1aa29ec82671ecd156618b5c7a1e to your computer and use it in GitHub Desktop.
Generate Transportation SQL data
<?php
function randomLetter($size)
{
$bag = "A BC DEF G HIJKLL MNOP QRS TUV W XUZ ";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
function randomNumber($size)
{
$bag = "0987654321877";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
function randomL($size)
{
$bag = "111110111111000";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
function randomOne($size)
{
$bag = "221111111";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
function randomTwo($size)
{
$bag = "222222211";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
$truck_driver = array();
$Surnames = array(
"SMITH",
"JOHNSON",
"WILLIAMS",
"BROWN",
"JONES",
"GARCIA",
"MILLER",
"DAVIS",
"RODRIGUEZ",
"MARTINEZ",
"HERNANDEZ",
"LOPEZ",
"GONZALEZ",
"WILSON",
"ANDERSON",
"THOMAS",
"TAYLOR",
"MOORE",
"JACKSON",
"MARTIN",
"LEE",
"PEREZ",
"THOMPSON",
"WHITE",
"HARRIS",
"SANCHEZ",
"CLARK",
"RAMIREZ",
"LEWIS",
"ROBINSON",
"WALKER",
"YOUNG",
"ALLEN",
"KING",
"WRIGHT",
"SCOTT",
"TORRES",
"NGUYEN",
"HILL",
"FLORES",
"GREEN",
"ADAMS",
"NELSON",
"BAKER",
"HALL",
"RIVERA",
"CAMPBELL",
"MITCHELL",
"CARTER",
"ROBERTS",
"GOMEZ",
"PHILLIPS",
"EVANS",
"TURNER",
"DIAZ",
"PARKER",
"CRUZ",
"EDWARDS",
"COLLINS",
"REYES",
"STEWART",
"MORRIS",
"MORALES",
"MURPHY",
"COOK",
"ROGERS",
"GUTIERREZ",
"ORTIZ",
"MORGAN",
"COOPER",
"PETERSON",
"BAILEY",
"REED",
"KELLY",
"HOWARD",
"RAMOS",
"KIM",
"COX",
"WARD",
"RICHARDSON",
"WATSON",
"BROOKS",
"CHAVEZ",
"WOOD",
"JAMES",
"BENNETT",
"GRAY",
"MENDOZA",
"RUIZ",
"HUGHES",
"PRICE",
"ALVAREZ",
"CASTILLO",
"SANDERS",
"PATEL",
"MYERS",
"LONG",
"ROSS",
"FOSTER",
"JIMENEZ",
"POWELL",
"JENKINS",
"PERRY",
"RUSSELL",
"SULLIVAN",
"BELL",
"COLEMAN",
"BUTLER",
"HENDERSON",
"BARNES",
"GONZALES",
"FISHER",
"VASQUEZ",
"SIMMONS",
"ROMERO",
"JORDAN",
"PATTERSON",
"ALEXANDER",
"HAMILTON",
"GRAHAM",
"REYNOLDS",
"GRIFFIN",
"WALLACE",
"MORENO",
"WEST",
"COLE",
"HAYES",
"BRYANT",
"HERRERA",
"GIBSON",
"ELLIS",
"TRAN",
"MEDINA",
"AGUILAR",
"STEVENS",
"MURRAY",
"FORD",
"CASTRO",
"MARSHALL",
"OWENS",
"HARRISON",
"FERNANDEZ",
"MCDONALD",
"WOODS",
"WASHINGTON",
"KENNEDY",
"WELLS",
"VARGAS",
"HENRY",
"CHEN",
"FREEMAN",
"WEBB",
"TUCKER",
"GUZMAN",
"BURNS",
"CRAWFORD",
"OLSON",
"SIMPSON",
"PORTER",
"HUNTER",
"GORDON",
"MENDEZ",
"SILVA",
"SHAW",
"SNYDER",
"MASON",
"DIXON",
"MUNOZ",
"HUNT",
"HICKS",
"HOLMES",
"PALMER",
"WAGNER",
"BLACK",
"ROBERTSON",
"BOYD",
"ROSE",
"STONE",
"SALAZAR",
"FOX",
"WARREN",
"MILLS",
"MEYER",
"RICE",
"SCHMIDT",
"GARZA",
"DANIELS",
"FERGUSON",
"NICHOLS",
"STEPHENS",
"SOTO",
"WEAVER",
"RYAN"
);
$Names = array(
"JAMES",
"JOHN",
"ROBERT",
"MICHAEL",
"WILLIAM",
"DAVID",
"RICHARD",
"CHARLES",
"JOSEPH",
"THOMAS",
"CHRISTOPHER",
"DANIEL",
"PAUL",
"MARK",
"DONALD",
"GEORGE",
"KENNETH",
"STEVEN",
"EDWARD",
"BRIAN",
"RONALD",
"ANTHONY",
"KEVIN",
"JASON",
"MATTHEW",
"GARY",
"TIMOTHY",
"JOSE",
"LARRY",
"JEFFREY",
"FRANK",
"SCOTT",
"ERIC",
"STEPHEN",
"ANDREW",
"RAYMOND",
"GREGORY",
"JOSHUA",
"JERRY",
"DENNIS",
"WALTER",
"PATRICK",
"PETER",
"HAROLD",
"DOUGLAS",
"HENRY",
"CARL",
"ARTHUR",
"RYAN",
"ROGER",
"JOE",
"JUAN",
"JACK",
"ALBERT",
"JONATHAN",
"JUSTIN",
"TERRY",
"GERALD",
"KEITH",
"SAMUEL",
"WILLIE",
"RALPH",
"LAWRENCE",
"NICHOLAS",
"MARY",
"PATRICIA",
"LINDA",
"BARBARA",
"ELIZABETH",
"JENNIFER",
"MARIA",
"SUSAN",
"MARGARET",
"DOROTHY",
"LISA",
"NANCY",
"KAREN",
"BETTY",
"HELEN",
"SANDRA",
"DONNA",
"CAROL",
"RUTH",
"SHARON",
"MICHELLE",
"LAURA",
"SARAH",
"KIMBERLY",
"DEBORAH",
"JESSICA",
"SHIRLEY",
"CYNTHIA",
"ANGELA",
"MELISSA",
"BRENDA",
"AMY",
"ANNA",
"REBECCA",
"VIRGINIA",
"KATHLEEN",
"PAMELA",
"MARTHA",
"DEBRA",
"AMANDA",
"STEPHANIE",
"CAROLYN",
"CHRISTINE",
"MARIE",
"JANET",
"CATHERINE",
"FRANCES",
"ANN"
);
// open the file
$Employee_file = fopen('CHAMPLAIN/Employee.sql', "w");
if (!is_resource($Employee_file))
{
echo 'CHAMPLAIN/Employee.sql could not open';
exit;
}
$ns = count($Names);
$ss = count($Surnames);
$ns--;
$ss--;
$keys = array();
for ($i = 0; $i < 1000; $i++)
{
$n = rand(0, $ns);
$s = rand(0, $ss);
$l = trim(randomLetter(1));
if (strlen($l))
{
$l = " " . $l . ". ";
}
else
{
$l = " ";
}
$randomNumber = randomNumber(6);
while (isset($keys[$randomNumber]))
{
$randomNumber = randomNumber(6);
}
$license = randomL(1);
$keys[$randomNumber] = $randomNumber;
fwrite(
$Employee_file,
"INSERT INTO [Employee] ([Number],[Name],[DateOfHire],[DateOfBirth],[CommercialDriverLicense])"
. PHP_EOL
);
fwrite(
$Employee_file, "VALUES (" . $randomNumber . ", '" .
ucfirst(strtolower($Names[$n])) . $l . ucfirst(
strtolower($Surnames[$s])
) .
"', '20" . rand(0, 1) . rand(0, 9) . "-" . rand(1, 12) . "-" . rand(
1, 26
) .
"', '19" . rand(74, 95) . "-" . rand(1, 12) . "-" . rand(1, 26) .
"', " . $license . ")" . PHP_EOL
);
$employee_id = $i + 1;
if ($license == 1)
{
$truck_driver[] = $employee_id;
}
}
// close file.
fclose($Employee_file);
$trailer_tracker = array();
$desc1 = array(
'Purchased in',
'Part of buy out from',
'From deal made in',
'A William Trailer'
);
$desc2 = array(
'2010',
'2000',
'2011',
'2013',
'2014',
'2002'
);
$cap = array(
1 => array(12000, 22000, 34000, 46400),
2 => array(21000, 20000, 17000, 14000, 9000, 60000),
3 => array(14000, 9000, 8160, 7300, 7000, 6500),
4 => array(7300, 7000, 6500),
5 => array(21000, 20000, 17000, 14000, 9000, 8160, 7300, 7000, 6500, 60000)
);
// open the file
$Trailer_file = fopen('CHAMPLAIN/Trailer.sql', "w");
if (!is_resource($Trailer_file))
{
echo 'CHAMPLAIN/Trailer.sql could not open';
exit;
}
for ($i = 0; $i < 1000; $i++)
{
$type = rand(1, 4);
$max = count($cap[$type]) - 1;
$capacity = $cap[$type][rand(0, $max)];
$d = rand(0, 10);
if (isset($desc1[$d]))
{
$description = array();
$description[] = $desc1[$d];
if ($d != 3)
{
$description[] = $desc2[rand(0, 5)];
}
$description = trim(implode(' ', $description));
}
else
{
$description = '';
}
$trailer_id = $i + 1;
$trailer_tracker[$trailer_id] = array('trailer' => $trailer_id,
'trailer_type' => $type,
'capacity' => $capacity);
fwrite(
$Trailer_file,
"INSERT INTO [Trailer] ([Type],[Mileage],[Capacity],[Description])"
. PHP_EOL
);
fwrite(
$Trailer_file, "VALUES (" . $type . ", " . rand(12412, 21212452) .
", " . $capacity . ", '" . $description . "')" . PHP_EOL
);
}
// close file.
fclose($Trailer_file);
$desc1 = array(
'Best',
'Worse',
'Average',
'Normal',
'',
'',
'Normal'
);
$desc2 = array(
'seating',
'steering',
'breaking',
'lighting',
'cooling',
'heating',
'tyre changing'
);
$desc3 = array(
'experience',
'report',
'turtle',
'',
'feedback',
'monkey',
'rates'
);
$desc4 = array(
'yearly',
'monthly',
'daily',
'',
'',
'weekly',
''
);
$keys = array('number' => array(), 'trailer' => array());
$truck_tracker = array();
// open the file
$Truck_file = fopen('CHAMPLAIN/Truck.sql', "w");
if (!is_resource($Truck_file))
{
echo 'CHAMPLAIN/Truck.sql could not open';
exit;
}
for ($tt = 0; $tt < 800; $tt++)
{
$number = randomNumber(5);
while (isset($keys['number'][$number]))
{
$number = randomNumber(5);
}
$keys['number'][$number] = true;
$d = rand(0, 100);
if (isset($desc1[$d]) && strlen($desc1[$d]))
{
$description = array();
$description[] = $desc1[$d];
$description[] = $desc2[rand(0, 6)];
$description[] = $desc3[rand(0, 6)];
$description[] = $desc4[rand(0, 6)];
$description = trim(implode(' ', $description));
}
else
{
$description = '';
}
$body_type = randomTwo(1);
$fuel_type = randomOne(1);
$engine_type = rand(1, 4);
$trailer = 1; // no trailer
// if body type two
if ($body_type == 2)
{
$trailer = rand(1, 1000);
while (isset($keys['trailer'][$trailer]))
{
$trailer = rand(1, 1000);
}
$keys['trailer'][$trailer] = true;
}
$licenseNumber = array();
$licenseNumber[] = randomLetter(3);
$licenseNumber[] = randomNumber(5);
$licenseNumber[] = randomLetter(2);
$licenseNumber = implode(' ', $licenseNumber);
$haul_type = rand(1, 2);
fwrite(
$Truck_file,
"INSERT INTO [Truck] ([Type],[Number],[Mileage],[BodyType],[Description],[EngineType],[FuelType], [LicenseNumber], [Trailer])"
. PHP_EOL
);
fwrite(
$Truck_file,
"VALUES (" . $haul_type . ", " . $number . ", " . rand(12412, 21212452)
. ", " . $body_type . ", '" . $description . "', " . $engine_type . ", "
.
$fuel_type . ", '" . trim($licenseNumber) . "', " . $trailer . ")"
. PHP_EOL
);
$truck_id = $tt + 1;
// truck maintenance
$do = randomTwo(1);
if ($do == 1)
{
$maintenance = rand(1, 2);
}
else
{
$maintenance = 0;
}
if (!isset($trailer_tracker[$trailer]))
{
$max = count($cap[5]) - 1;
$capacity = $cap[5][rand(0, $max)];
$truck_tracker[] = array(
'trailer_type' => 5,
'capacity' => $capacity,
'trailer' => $trailer,
'id' => $truck_id,
'haul' => $haul_type,
'maintenance' => $maintenance);
}
else
{
// update the trailer array to have the truck ID
$trailer_tracker[$trailer]['id'] = $truck_id;
$trailer_tracker[$trailer]['haul'] = $haul_type;
$trailer_tracker[$trailer]['maintenance'] = $maintenance;
// now link the trailer to the truck
$truck_tracker[] = $trailer_tracker[$trailer];
}
}
// close file.
fclose($Truck_file);
unset($trailer_tracker);
$items = array(
1 => array("name" => "TNT", "wpu" => array(6, 9)),
2 => array("name" => "dynamite", "wpu" => array(6, 9)),
3 => array("name" => "rocket propellant", "wpu" => array(25, 26)),
4 => array("name" => "display fireworks", "wpu" => array(6, 9)),
5 => array("name" => "consumer fireworks", "wpu" => array(2, 3, 4)),
6 => array("name" => "ammunition", "wpu" => array(3, 6, 9, 10)),
7 => array("name" => "acetylene", "wpu" => array(24)),
8 => array("name" => "hydrogen", "wpu" => array(24)),
9 => array("name" => "propane", "wpu" => array(24)),
10 => array("name" => "gasoline", "wpu" => array(25)),
11 => array("name" => "acetone", "wpu" => array(25)),
12 => array("name" => "diesel", "wpu" => array(25)),
13 => array("name" => "kerosene", "wpu" => array(25)),
14 => array("name" => "Oils", "wpu" => array(23, 24)),
15 => array("name" => "Fragrances", "wpu" => array(6)),
16 => array("name" => "Cleaning Compounds", "wpu" => array(25, 26)),
17 => array("name" => "Industrial Chemicals", "wpu" => array(25, 26)),
18 => array("name" => "Juice", "wpu" => array(2, 7, 9)),
19 => array("name" => "Milk", "wpu" => array(23)),
20 => array("name" => "Apricot", "wpu" => array(1, 2, 3)),
21 => array("name" => "Asparagus", "wpu" => array(1, 2, 3)),
22 => array("name" => "Avocado", "wpu" => array(1, 2, 3)),
23 => array("name" => "Banana", "wpu" => array(1, 2, 3)),
24 => array("name" => "Bean Sprouts", "wpu" => array(1, 2, 3)),
25 => array("name" => "Bell Peppers", "wpu" => array(1, 2, 3)),
26 => array("name" => "Melon", "wpu" => array(1, 2, 3)),
27 => array("name" => "Blackberries", "wpu" => array(1, 2, 3)),
28 => array("name" => "Blueberries", "wpu" => array(1, 2, 3)),
29 => array("name" => "Bok Choy", "wpu" => array(1, 2, 3)),
30 => array("name" => "Broccoli", "wpu" => array(1, 2, 3)),
31 => array("name" => "Brussels Sprouts", "wpu" => array(1, 2, 3)),
32 => array("name" => "Cauliflower", "wpu" => array(1, 2, 3)),
33 => array("name" => "Celery", "wpu" => array(1, 2, 3)),
34 => array("name" => "Cherries", "wpu" => array(1, 2, 3)),
35 => array("name" => "Collard Greens", "wpu" => array(1, 2, 3)),
36 => array("name" => "Cranberries", "wpu" => array(1, 2, 3)),
37 => array("name" => "Cucumber", "wpu" => array(1, 2, 3)),
38 => array("name" => "Eggplant", "wpu" => array(1, 2, 3)),
39 => array("name" => "Endive", "wpu" => array(1, 2, 3)),
40 => array("name" => "Fennel", "wpu" => array(1, 2, 3)),
41 => array("name" => "Figs", "wpu" => array(1, 2, 3)),
42 => array("name" => "Gooseberries", "wpu" => array(1, 2, 3)),
43 => array("name" => "Grapes", "wpu" => array(1, 2, 3)),
44 => array("name" => "Green Beans", "wpu" => array(1, 2, 3)),
45 => array("name" => "Green Onions", "wpu" => array(1, 2, 3)),
46 => array("name" => "Greens", "wpu" => array(1, 2, 3)),
47 => array("name" => "Guava", "wpu" => array(1, 2, 3)),
48 => array("name" => "Honeydew Melon", "wpu" => array(1, 2, 3)),
49 => array("name" => "Iceberg Lettuce", "wpu" => array(1, 2, 3)),
50 => array("name" => "Kale", "wpu" => array(1, 2, 3)),
51 => array("name" => "Kiwifruit", "wpu" => array(1, 2, 3)),
52 => array("name" => "Lettuce", "wpu" => array(1, 2, 3)),
53 => array("name" => "Limes", "wpu" => array(1, 2, 3)),
54 => array("name" => "Lychee", "wpu" => array(1, 2, 3)),
55 => array("name" => "Mandarins", "wpu" => array(1, 2, 3)),
56 => array("name" => "Mangoes", "wpu" => array(1, 2, 3)),
57 => array("name" => "Mulberries", "wpu" => array(1, 2, 3)),
58 => array("name" => "Mushrooms", "wpu" => array(1, 2, 3)),
59 => array("name" => "Nectarines", "wpu" => array(1, 2, 3)),
60 => array("name" => "Okra", "wpu" => array(1, 2, 3)),
61 => array("name" => "Passion Fruit", "wpu" => array(1, 2, 3)),
62 => array("name" => "Peaches", "wpu" => array(1, 2, 3)),
63 => array("name" => "Pears", "wpu" => array(1, 2, 3)),
64 => array("name" => "Peas", "wpu" => array(1, 2, 3)),
65 => array("name" => "Peppers", "wpu" => array(1, 2, 3)),
66 => array("name" => "Persimmons", "wpu" => array(1, 2, 3)),
67 => array("name" => "Plums", "wpu" => array(1, 2, 3)),
68 => array("name" => "Pomegranate", "wpu" => array(1, 2, 3)),
69 => array("name" => "Prickly Pear", "wpu" => array(1, 2, 3)),
70 => array("name" => "Prunes", "wpu" => array(1, 2, 3)),
71 => array("name" => "Quince", "wpu" => array(1, 2, 3)),
72 => array("name" => "Raspberries", "wpu" => array(1, 2, 3)),
73 => array("name" => "Rhubarb", "wpu" => array(1, 2, 3)),
74 => array("name" => "Romaine Lettuce", "wpu" => array(1, 2, 3)),
75 => array("name" => "Shallots", "wpu" => array(1, 2, 3)),
76 => array("name" => "Snow Peas", "wpu" => array(1, 2, 3)),
77 => array("name" => "Spinach", "wpu" => array(1, 2, 3)),
78 => array("name" => "Sprouts", "wpu" => array(1, 2, 3)),
79 => array("name" => "Strawberries", "wpu" => array(1, 2, 3)),
80 => array("name" => "String Beans", "wpu" => array(1, 2, 3)),
81 => array("name" => "Sweet Potato", "wpu" => array(1, 2, 3)),
82 => array("name" => "Tangerines", "wpu" => array(1, 2, 3)),
83 => array("name" => "Tomato", "wpu" => array(1, 2, 3)),
84 => array("name" => "Turnip", "wpu" => array(1, 2, 3)),
85 => array("name" => "Water Chestnuts", "wpu" => array(1, 2, 3)),
86 => array("name" => "Watercress", "wpu" => array(1, 2, 3)),
87 => array("name" => "Zucchini Squash", "wpu" => array(1, 2, 3)),
88 => array("name" => "Tissue Paper", "wpu" => array(1, 2, 3)),
89 => array("name" => "Toilet Paper", "wpu" => array(1, 2, 3)),
90 => array("name" => "Clothes", "wpu" => array(2, 3, 4, 5)),
91 => array("name" => "Foot ware", "wpu" => array(2, 3, 4, 5)),
92 => array("name" => "Air conditioning ", "wpu" => array(4, 6, 9)),
93 => array("name" => "Air fryer ", "wpu" => array(3, 6, 9)),
94 => array("name" => "Air ioniser ", "wpu" => array(3, 6, 9)),
95 => array("name" => "Blower ", "wpu" => array(3, 6, 9)),
96 => array("name" => "Blender ", "wpu" => array(3, 6, 9)),
97 => array("name" => "Immersion blender ", "wpu" => array(3, 6, 9)),
98 => array("name" => "Clothes dryer combo ", "wpu" => array(6, 7)),
99 => array("name" => "Clothes iron ", "wpu" => array(3, 6, 9)),
100 => array("name" => "Coffee maker ", "wpu" => array(3, 6, 9)),
101 => array("name" => "Dehumidifier ", "wpu" => array(3, 6, 9)),
102 => array("name" => "Dishwasher", "wpu" => array(6, 7)),
103 => array("name" => "Domestic robot", "wpu" => array(3, 6, 9)),
104 => array("name" => "Electric blanket ", "wpu" => array(2, 3, 4, 5)),
105 => array("name" => "Electric drill ", "wpu" => array(3, 6, 9)),
106 => array("name" => "Electric knife ", "wpu" => array(1, 2, 3)),
107 => array("name" => "Electric heater", "wpu" => array(3, 6, 9)),
108 => array("name" => "Evaporative cooler", "wpu" => array(6, 7)),
109 => array("name" => "Food processor", "wpu" => array(3, 6, 9)),
110 => array("name" => "Kitchen hood ", "wpu" => array(3, 6, 9)),
111 => array("name" => "Garbage disposer ", "wpu" => array(3, 6, 9)),
112 => array("name" => "Fan", "wpu" => array(3, 6, 9)),
113 => array("name" => "Hair dryer", "wpu" => array(3, 6, 9)),
114 => array("name" => "Hair iron ", "wpu" => array(3, 6, 9)),
115 => array("name" => "Mixer ", "wpu" => array(3, 6, 9)),
116 => array("name" => "Humidifier ", "wpu" => array(3, 6, 9)),
117 => array("name" => "Icemaker ", "wpu" => array(3, 6, 9)),
118 => array("name" => "Ice cream maker ", "wpu" => array(3, 6, 9)),
119 => array("name" => "Juicer ", "wpu" => array(3, 6, 9)),
120 => array("name" => "Lawn mower", "wpu" => array(3, 6, 9)),
121 => array("name" => "Convection oven", "wpu" => array(6, 7)),
122 => array("name" => "Microwave oven ", "wpu" => array(3, 6, 9)),
123 => array("name" => "Pie iron ", "wpu" => array(3, 6, 9)),
124 => array("name" => "Refrigerator", "wpu" => array(6, 7)),
125 => array("name" => "Sewing machine", "wpu" => array(3, 6, 9)),
126 => array("name" => "Television ", "wpu" => array(3, 6, 9)),
127 => array("name" => "Toaster ", "wpu" => array(1, 2, 3)),
128 => array("name" => "Vacuum cleaner", "wpu" => array(3, 6, 9)),
129 => array("name" => "Waffle iron ", "wpu" => array(3, 6, 9)),
130 => array("name" => "Water dispenser ", "wpu" => array(3, 6, 9)),
131 => array("name" => "Washing machine", "wpu" => array(6, 7)),
132 => array("name" => "Cattle", "wpu" => array(27)),
133 => array("name" => "Goats", "wpu" => array(5, 7)),
134 => array("name" => "Sheep", "wpu" => array(6, 7)),
135 => array("name" => "Hogs", "wpu" => array(9)),
136 => array("name" => "Chickens", "wpu" => array(28)),
137 => array("name" => "Ducks", "wpu" => array(28)),
138 => array("name" => "Geese", "wpu" => array(29)),
139 => array("name" => "Rabbits", "wpu" => array(28)),
140 => array("name" => "Lumber", "wpu" => array(4, 5, 6, 7, 8, 9)),
141 => array("name" => "Stone", "wpu" => array(4, 5, 6, 7, 8, 9)),
142 => array("name" => "Metal piping",
"wpu" => array(5, 6, 7, 8, 9, 10, 27)),
143 => array("name" => "I-Beams", "wpu" => array(5, 6, 7, 8, 9, 10, 27)),
144 => array("name" => "Steel frames",
"wpu" => array(5, 6, 7, 8, 9, 10, 27)),
145 => array("name" => "Backhoes", "wpu" => array(12, 13, 14)),
146 => array("name" => "Forklifts", "wpu" => array(14, 15)),
147 => array("name" => "Bobcats", "wpu" => array(12, 13, 14)),
148 => array("name" => "Bricks", "wpu" => array(30)),
149 => array("name" => "Scaffolding", "wpu" => array(4, 5, 6, 7, 8, 9)),
150 => array("name" => "Scrap metal", "wpu" => array(4, 5, 6, 7, 8, 9)),
151 => array("name" => "Baled Tires", "wpu" => array(4)),
152 => array("name" => "Airplane parts",
"wpu" => array(16, 17, 18, 19, 20)),
153 => array("name" => "Military tanks", "wpu" => array(20)),
154 => array("name" => "Turbine", "wpu" => array(20))
);
$cargotype = array(
1 => array(1, 2),
2 => array(5),
3 => array(1, 4, 5),
4 => array(2, 3),
5 => array(1, 2, 3, 4, 5)
);
$cargo = array(
1 => array(1 =>
array(3, 7, 8, 9, 10, 11, 12, 13),
2 =>
array(15, 16, 17, 19)),
2 => array(5 =>
array(140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151,
152, 153, 154)),
3 => array(1 =>
array(1, 2, 4, 5, 6, 15),
4 =>
array(88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
123, 124, 125, 126, 127, 128, 129, 130, 131),
5 =>
array(136, 137, 138, 139)),
4 => array(2 =>
array(18, 19),
3 =>
array(20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87)),
5 => array(1 =>
array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15),
2 =>
array(15, 16, 17, 18, 19),
3 =>
array(20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87),
4 =>
array(88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
123, 124, 125, 126, 127, 128, 129, 130, 131),
5 =>
array(136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147,
148, 149, 150, 151, 152, 153, 154))
);
$wpu = array(
1 => 0.5,
2 => 1,
3 => 10,
4 => 20,
5 => 30,
6 => 50,
7 => 70,
8 => 80,
9 => 100,
10 => 1000,
11 => 2000,
12 => 3000,
13 => 5000,
14 => 7000,
15 => 10000,
16 => 20000,
17 => 30000,
18 => 40000,
19 => 50000,
20 => 60000,
21 => 70000,
22 => 100000,
23 => 1,
24 => 2,
25 => 3,
26 => 4,
27 => 700,
28 => 2,
29 => 6,
30 => 500
);
$hauls = '';
$driver_max = count($truck_driver) - 1;
$day_counter = 10;
$day_number = 1;
$month_number = 02;
$keys = array();
for ($h = 0; $h < $driver_max; $h++)
{
// set the driver
$driver = rand(0, $driver_max);
while (isset($keys['driver'][$driver]))
{
$driver = rand(0, $driver_max);
}
$keys['driver'][$driver] = true;
$driver = $truck_driver[$driver];
// set the truck
$truck = rand(0, 799);
while (isset($keys['truck'][$truck]))
{
$truck = rand(0, 799);
}
// use a truck only once (for now)
$keys['truck'][$truck] = true;
// we get the truck details
$truck = $truck_tracker[$truck];
if ($day_counter <= 0)
{
$day_counter = rand(7, 10);
$day_number++;
}
if ($day_number > 29)
{
$month_number++;
$day_number = 1;
}
// set the began date
$began_time = strtotime("2020-" . $month_number . "-" . $day_number);
$began = date('Y-m-d', $began_time);
$maintenance_same = true;
// set hte mileage (haul length)
if ($truck['haul'] == 2)
{
// short haul
$mileage = rand(10, 449);
// add days to began date
$days = rand(0, 2);
$delivered = strtotime('+' . $days . 'days', $began_time);
$delivered = date('Y-m-d', $delivered);
// check if we have maintenance
if ($truck['maintenance'])
{
if ($days >= 1)
{
$startDate = strtotime('+1day', $began_time);
$startDate = date('Y-m-d', $startDate);
$endDate = $startDate;
}
else
{
$startDate = $began;
$endDate = $began;
}
}
}
else
{
// long haul
$mileage = rand(450, 3599);
// add days to began date
if ($mileage > 600)
{
$days = round($mileage / 400 + rand(4, 7));
}
else
{
$days = rand(2, 3);
}
$delivered = strtotime('+' . $days . 'days', $began_time);
$delivered = date('Y-m-d', $delivered);
// check if we have maintenance
if ($truck['maintenance'])
{
if ($days > 5)
{
$startDate = strtotime('+1day', $began_time);
$startDate = date('Y-m-d', $startDate);
$endDate = strtotime('+3day', $began_time);
$endDate = date('Y-m-d', $endDate);
$maintenance_same = false;
}
else
{
$startDate = $began;
$endDate = $began;
}
}
}
if ($maintenance_same)
{
// the note
switch ($truck['maintenance'])
{
case 1:
$maintenance_note = 'Routine Maintenance Scheduled on the '
. $startDate;
break;
case 2:
$maintenance_note = 'Unscheduled Maintenance on the ' . $startDate;
break;
default:
$maintenance_note = '';
}
}
else
{
// the note
switch ($truck['maintenance'])
{
case 1:
$maintenance_note = 'Routine Maintenance Scheduled from '
. $startDate . ' to ' . $endDate;
break;
case 2:
$maintenance_note = 'Unscheduled Maintenance from ' . $startDate
. ' to ' . $endDate;
break;
default:
$maintenance_note = '';
}
}
// get cargo type
$cargo_max = count($cargotype[$truck['trailer_type']]) - 1;
$cargo_type = $cargotype[$truck['trailer_type']][rand(0, $cargo_max)];
// add haul once
$print_haul = true;
// get item types
$item_map = $cargo[$truck['trailer_type']][$cargo_type];
$item_max = count($item_map) - 1;
// get haul ID
$haul_id = $h + 1;
$cargo_weight = $truck['capacity'];
$mix = ($cargo_type == 3 || $cargo_type == 4) ? 1 : 0;
// if can mix
if ($mix)
{
$mix = randomL(1);
}
$weight_mix = rand(0, 1);
// item array
$_item_id = 0;
$_item_code = '';
$_item_desc = '';
$_item_weight = 0;
// open the file
$Manifest_file = fopen('CHAMPLAIN/Manifest.sql', "a+");
if (!is_resource($Manifest_file))
{
echo 'CHAMPLAIN/Manifest.sql could not open';
exit;
}
// set manifest
while ($cargo_weight)
{
// get item ID
if (!$_item_id || $mix)
{
$_item_id = $item_map[rand(0, $item_max)];
// get the product name
$_item_desc = ucfirst(strtolower($items[$_item_id]['name']));
// get product CODE
$_item_code = strtoupper(substr($_item_desc, 0, 3)) . $_item_id;
}
// get Size ID
if (!$_item_weight || $weight_mix || $mix)
{
$_item_size_id = rand(0, count($items[$_item_id]['wpu']) - 1);
$_item_weight = $wpu[$items[$_item_id]['wpu'][$_item_size_id]];
}
// check if item will fit
if ($_item_weight > $cargo_weight)
{
// remove ITEM
$_item_id = 0;
$_item_weight = 0;
continue;
}
// we first get the full qty that can be loaded
$qty = floor($cargo_weight / $_item_weight);
// if we have no mix, and no size mix we have one entry so calculate full qty
if (!$mix)
{
// add only once
$cargo_weight = 0;
}
else
{
// how many should we add then
if ($qty != 1)
{
$d = rand(0, 1);
if ($d && $qty > 10000)
{
$div = floor(rand(200, 5000));
}
elseif ($d && $qty > 1000)
{
$div = floor(rand(10, 500));
}
else
{
if ($d && $qty > 100)
{
$div = floor(rand(2, 50));
}
else
{
if ($d && $qty > 10)
{
$div = floor(rand(2, 5));
}
else
{
$div = 2;
}
}
}
$qty = floor($qty / $div);
}
$load_weight = $qty * $_item_weight;
$cargo_weight = $cargo_weight - $load_weight;
if ($cargo_weight < 0 || $load_weight == 0)
{
$cargo_weight = 0;
continue;
}
}
// print haul only once if load works out
if ($print_haul)
{
if ($truck['maintenance'])
{
// open the file
$TruckMaintenance_file = fopen('CHAMPLAIN/TruckMaintenance.sql', "a+");
if (!is_resource($TruckMaintenance_file))
{
echo 'CHAMPLAIN/TruckMaintenance.sql could not open';
exit;
}
fwrite(
$TruckMaintenance_file,
"INSERT INTO [TruckMaintenance] ([Type],[TruckID],[StartDate],[EndDate],[Code])"
. PHP_EOL
);
fwrite(
$TruckMaintenance_file,
"VALUES (" . rand(1, 7) . ", " . $truck['id'] . ", '" .
$startDate . "', '" . $endDate . "', "
. $truck['maintenance'] . ")" . PHP_EOL
);
// close file.
fclose($TruckMaintenance_file);
}
// open the file
$Haul_file = fopen('CHAMPLAIN/Haul.sql', "a+");
if (!is_resource($Haul_file))
{
echo 'CHAMPLAIN/Haul.sql could not open';
exit;
}
fwrite(
$Haul_file,
"INSERT INTO [Haul] ([TruckID],[ClientID],[CargoType],[Began],[Delivered],[Mileage],[Notes],[Employee])"
. PHP_EOL
);
fwrite(
$Haul_file,
"VALUES (" . $truck['id'] . ", " . rand(1, 1799) . ", "
. $cargo_type . ", '" . $began . "', '" . $delivered . "', "
. $mileage . ", '" . $maintenance_note . "', " . $driver . ")" . PHP_EOL
);
$print_haul = false;
$day_counter--;
// close file.
fclose($Haul_file);
}
fwrite(
$Manifest_file,
"INSERT INTO [Manifest] ([HaulID],[Item],[Description],[Weight],[qty])"
. PHP_EOL
);
fwrite(
$Manifest_file,
"VALUES (" . $haul_id . ", '" . $_item_code . "', '" . $_item_desc
. "', " . $_item_weight . ", " . $qty . ")" . PHP_EOL
);
}
fclose($Manifest_file);
}
echo 'Done!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment