Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- ob_start();
- function x($str) { return mysql_real_escape_string($str); }
- $db = mysql_connect('localhost', 'user', 'pass');
- mysql_select_db('db');
- // Truncate the existing users table.
- mysql_query("TRUNCATE users");
- // Truncate the existing logs table.
- mysql_query("TRUNCATE logs_access");
- // Set auto_increment to default.
- mysql_query("ALTER TABLE users AUTO_INCREMENT=1");
- mysql_query("ALTER TABLE logs_access AUTO_INCREMENT=1");
- // Grab dummy data.
- $names = explode("\n", file_get_contents("names.txt"));
- // How many do we want to have?
- $count = 100; // initial population of 100 students
- // Separate the name parts.
- for($x = 0; $x < $count; $x++) {
- $names[$x] = explode(" ", $names[$x]);
- }
- for($x = 0; $x < $count; $x++) {
- $name = Array(trim($names[$x][0]), trim($names[$x][1]));
- $username = strtolower($name[0]) . "." . strtolower($name[1]);
- mysql_query(sprintf("INSERT INTO users VALUES (NULL, '%s', SHA1('%s'), 'demo.hh-login.com', 1, '%s', '%s');", x($username), x($username), x($name[0], x($name[1])));
- $users[] = Array("id" => mysql_insert_id(), "username" => $username, "firstName" => $name[0], "lastName" => $name[1]);
- }
- echo "<h1>Created $count users.</h1>"; ob_flush();
- // create logins and logouts
- for($i = 0; $i < 40; $i++) {
- echo "<h1>Week #$i</h1>"; ob_flush();
- // First 100 users will have four logins per week
- // length of login will be between 2.5 and 4 hours
- // start time is between 3pm and 6pm.
- $k = 0;
- foreach($users as $user) {
- $k++;
- if($k < $count/3) {
- for($j = 0; $j < 7; $j++) {
- if(rand(1, 7) <= 3) continue; // take three days off on average
- $randomHour = rand(15, 18);
- $randomMinute = rand(1, 59);
- $randomSecond = rand(1, 59);
- $durationHour = rand(2, 4);
- $durationMinute = rand($durationHour == 2 ? 30 : 1, 59);
- $durationSecond = rand(1, 59);
- $randomDay = date("Y-m-d h:i:s", strtotime(sprintf("%s +$j days +$i weeks", date("Y-m-d h:i:s", mktime($randomHour, $randomMinute, $randomSecond, 9, 3, 2000)))));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'login', '%s')", $user['id'], $randomDay));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'logout', '%s')", $user['id'], date("Y-m-d h:i:s", strtotime("$randomDay +$durationHour hours +$durationMinute minutes +$durationSecond seconds"))));
- echo "(Group 1) User " . $user['firstName'] . " " . $user['lastName'] . " logged in at $randomDay. They logged out $durationHour hours $durationMinute minutes $durationSecond seconds later.<br>";
- }
- ob_flush();
- } else if($k < 2*$count/3) {
- for($j = 1; $j < 6; $j++) {
- if(rand(1, 7) <= 2) continue; // take four days off on average
- $randomHour = rand(20, 22);
- $randomMinute = rand(1, 59);
- $randomSecond = rand(1, 59);
- $durationHour = rand(1, 3);
- $durationMinute = rand(1, 59);
- $durationSecond = rand(1, 59);
- $randomDay = date("Y-m-d h:i:s", strtotime(sprintf("%s +$j days $i weeks", date("Y-m-d h:i:s", mktime($randomHour, $randomMinute, $randomSecond, 9, 3, 2000)))));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'login', '%s')", $user['id'], $randomDay));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'logout', '%s')", $user['id'], date("Y-m-d h:i:s", strtotime("$randomDay +$durationHour hours +$durationMinute minutes +$durationSecond seconds"))));
- echo "(Group 2) User " . $user['firstName'] . " " . $user['lastName'] . " logged in at $randomDay. They logged out $durationHour hours $durationMinute minutes $durationSecond seconds later.<br>";
- }
- ob_flush();
- } else {
- for($j = 1; $j < 6; $j++) {
- if(rand(1, 7) <= 2) continue; // take four days off on average
- $randomHour = rand(20, 22);
- $randomMinute = rand(1, 59);
- $randomSecond = rand(1, 59);
- $durationHour = rand(1, 3);
- $durationMinute = rand(1, 59);
- $durationSecond = rand(1, 59);
- $randomDay = date("Y-m-d h:i:s", strtotime(sprintf("%s +$j days $i weeks", date("Y-m-d h:i:s", mktime($randomHour, $randomMinute, $randomSecond, 9, 3, 2000)))));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'login', '%s')", $user['id'], $randomDay));
- mysql_query(sprintf("INSERT INTO logs_access VALUES (NULL, %d, 'logout', '%s')", $user['id'], date("Y-m-d h:i:s", strtotime("$randomDay +$durationHour hours +$durationMinute minutes +$durationSecond seconds"))));
- echo "(Group 3) User " . $user['firstName'] . " " . $user['lastName'] . " logged in at $randomDay. They logged out $durationHour hours $durationMinute minutes $durationSecond seconds later.<br>";
- }
- ob_flush();
- }
- }
- }
- echo "<h1>DONE</h1>";
- ob_flush();
- exit;
- ?>
Add Comment
Please, Sign In to add comment