From 3e293363f624a580703ffe07dff2b3d7f5a40676 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 25 Mar 2011 17:39:14 -0400 Subject: [PATCH] add groups and joins to createsim.php --- scripts/createsim.php | 93 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 14 deletions(-) diff --git a/scripts/createsim.php b/scripts/createsim.php index e0b5fc906b..d97ecc1c4d 100644 --- a/scripts/createsim.php +++ b/scripts/createsim.php @@ -20,8 +20,8 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -$shortoptions = 'u:n:b:t:x:'; -$longoptions = array('users=', 'notices=', 'subscriptions=', 'tags=', 'prefix='); +$shortoptions = 'u:n:b:g:j:t:x:z:'; +$longoptions = array('users=', 'notices=', 'subscriptions=', 'groups=', 'joins=', 'tags=', 'prefix='); $helptext = << sprintf('%s%d', $groupprefix, $i), + 'local' => true, + 'fullname' => sprintf('Test Group %d', $i))); + if (!empty($user)) { + $user->free(); + } +} + function newNotice($i, $tagmax) { global $userprefix; @@ -117,38 +131,89 @@ function newSub($i) $to->free(); } -function main($usercount, $noticeavg, $subsavg, $tagmax) +function newJoin($u, $g) +{ + global $userprefix; + global $groupprefix; + + $userNumber = rand(0, $u - 1); + + $userNick = sprintf('%s%d', $userprefix, $userNumber); + + $user = User::staticGet('nickname', $userNick); + + if (empty($user)) { + throw new Exception("Can't find user '$fromnick'."); + } + + $groupNumber = rand(0, $g - 1); + + $groupNick = sprintf('%s%d', $groupprefix, $groupNumber); + + $group = User_group::staticGet('nickname', $groupNick); + + if (empty($group)) { + throw new Exception("Can't find group '$groupNick'."); + } + + if (!$user->isMember($group)) { + $user->joinGroup($group); + } +} + +function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) { global $config; $config['site']['dupelimit'] = -1; $n = 1; + $g = 1; newUser(0); + newGroup(0); // # registrations + # notices + # subs - $events = $usercount + ($usercount * ($noticeavg + $subsavg)); + $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg)); + + $ut = $usercount; + $gt = $ut + $groupcount; + $nt = $gt + ($usercount * $noticeavg); + $st = $nt + ($usercount * $subsavg); + $jt = $st + ($usercount * $joinsavg); for ($i = 0; $i < $events; $i++) { - $e = rand(0, 1 + $noticeavg + $subsavg); + $e = rand(0, $events); - if ($e == 0) { + if ($e > 0 && $e <= $ut) { + printfv("Creating user $n\n"); newUser($n); $n++; - } else if ($e < $noticeavg + 1) { + } else if ($e > $ut && $e <= $gt) { + printfv("Creating group $g\n"); + newGroup($g); + $g++; + } else if ($e > $gt && $e <= $nt) { + printfv("Making a new notice\n"); newNotice($n, $tagmax); - } else { + } else if ($e > $nt && $e <= $st) { + printfv("Making a new subscription\n"); newSub($n); + } else if ($e > $st && $e <= $jt) { + printfv("Making a new group join\n"); + newJoin($n, $g); } } } -$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100; -$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100; -$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10); -$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000; -$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser'; +$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100; +$groupcount = (have_option('g', 'groups')) ? get_option_value('g', 'groups') : 20; +$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100; +$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10); +$joinsavg = (have_option('j', 'joins')) ? get_option_value('j', 'joins') : 5; +$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000; +$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser'; +$groupprefix = (have_option('z', 'groupprefix')) ? get_option_value('z', 'groupprefix') : 'testgroup'; -main($usercount, $noticeavg, $subsavg, $tagmax); +main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax); -- 2.39.5