X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcreatesim.php;h=a4b7667310da8e6520b055bf533d2bffa39aba3f;hb=dc6f49ba0851d01b38719cc25f3d16f7b74dd4da;hp=bd32ac632456d116b1edd401d6ea1699237e78bd;hpb=5b9062a51837399ec9e132d8d706d9d91e1cb7de;p=quix0rs-gnu-social.git diff --git a/scripts/createsim.php b/scripts/createsim.php index bd32ac6324..a4b7667310 100644 --- a/scripts/createsim.php +++ b/scripts/createsim.php @@ -20,23 +20,36 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -$shortoptions = 'u:n:b:g:j:t:x:z:'; -$longoptions = array('users=', 'notices=', 'subscriptions=', 'groups=', 'joins=', 'tags=', 'prefix='); +$shortoptions = 'b:g:j:n:t:u:w:x:z:'; +$longoptions = array( + 'subscriptions=', + 'groups=', + 'joins=', + 'notices=', + 'tags=', + 'users=', + 'words=', + 'prefix=', + 'groupprefix=', +// 'faves=', +); $helptext = << sprintf('%s%d', $groupprefix, $i), 'local' => true, @@ -71,17 +84,17 @@ function newNotice($i, $tagmax) { global $userprefix; - $options = array('scope' => common_config('notice', 'defaultscope')); + $options = array('scope' => Notice::defaultScope()); $n = rand(0, $i - 1); - $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n)); + $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n)); $is_reply = rand(0, 1); - $content = 'Test notice content'; + $content = testNoticeContent(); if ($is_reply == 0) { - $stream = new InboxNoticeStream($user, $user->getProfile()); + $stream = new InboxNoticeStream($user->getProfile(), $user->getProfile()); $notices = $stream->getNotices(0, 20); if ($notices->N > 0) { $nval = rand(0, $notices->N - 1); @@ -100,6 +113,39 @@ function newNotice($i, $tagmax) $options['scope'] |= Notice::ADDRESSEE_SCOPE; } } + } else { + $is_directed = rand(0, 4); + + if ($is_directed == 0) { + $subs = $user->getSubscribed(0, 100)->fetchAll(); + if (count($subs) > 0) { + $seen = array(); + $f = rand(0, 9); + if ($f <= 6) { + $addrs = 1; + } else if ($f <= 8) { + $addrs = 2; + } else { + $addrs = 3; + } + for ($m = 0; $m < $addrs; $m++) { + $x = rand(0, count($subs) - 1); + if ($seen[$x]) { + continue; + } + if ($subs[$x]->id == $user->id) { + continue; + } + $seen[$x] = true; + $rprofile = $subs[$x]; + $content = "@".$rprofile->nickname." ".$content; + } + $private_to_addressees = rand(0, 4); + if ($private_to_addressees == 0) { + $options['scope'] |= Notice::ADDRESSEE_SCOPE; + } + } + } } $has_hash = rand(0, 2); @@ -116,8 +162,8 @@ function newNotice($i, $tagmax) if ($in_group == 0) { $groups = $user->getGroups(); - if ($groups->N > 0) { - $gval = rand(0, $group->N - 1); + if ($groups instanceof User_group) { + $gval = rand(0, $groups->N - 1); $groups->fetch(); // go to 0th for ($i = 0; $i < $gval; $i++) { $groups->fetch(); @@ -137,9 +183,32 @@ function newNotice($i, $tagmax) $options['scope'] |= Notice::SITE_SCOPE; } - $notice = Notice::saveNew($user->id, $content, 'system', $options); + $notice = Notice::saveNew($user->id, $content, 'createsim', $options); } +/* Plugins should be part of the simulation too! +function newMessage($i) +{ + global $userprefix; + + $n = rand(0, $i - 1); + $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n)); + + $content = testNoticeContent(); + + $friends = $user->mutuallySubscribedUsers()->fetchAll(); + + if (count($friends) == 0) { + return; + } + + $j = rand(0, count($friends) - 1); + + $other = $friends[$j]; + + $message = Message::saveNew($user->id, $other->id, $content, 'createsim'); +}*/ + function newSub($i) { global $userprefix; @@ -147,7 +216,7 @@ function newSub($i) $fromnick = sprintf('%s%d', $userprefix, $f); - $from = User::staticGet('nickname', $fromnick); + $from = User::getKV('nickname', $fromnick); if (empty($from)) { throw new Exception("Can't find user '$fromnick'."); @@ -164,13 +233,13 @@ function newSub($i) $tunic = sprintf('%s%d', $userprefix, $t); - $to = User::staticGet('nickname', $tunic); + $to = User::getKV('nickname', $tunic); - if (empty($to)) { + if (!($to instanceof User)) { throw new Exception("Can't find user '$tunic'."); } - subs_subscribe_to($from, $to); + Subscription::start($from->getProfile(), $to->getProfile()); $from->free(); $to->free(); @@ -185,7 +254,7 @@ function newJoin($u, $g) $userNick = sprintf('%s%d', $userprefix, $userNumber); - $user = User::staticGet('nickname', $userNick); + $user = User::getKV('nickname', $userNick); if (empty($user)) { throw new Exception("Can't find user '$fromnick'."); @@ -195,7 +264,7 @@ function newJoin($u, $g) $groupNick = sprintf('%s%d', $groupprefix, $groupNumber); - $group = User_group::staticGet('nickname', $groupNick); + $group = User_group::getKV('nickname', $groupNick); if (empty($group)) { throw new Exception("Can't find group '$groupNick'."); @@ -206,6 +275,77 @@ function newJoin($u, $g) } } +/* Plugins should be part of the simulation too! +function newFave($u) +{ + global $userprefix; + global $groupprefix; + + $userNumber = rand(0, $u - 1); + + $userNick = sprintf('%s%d', $userprefix, $userNumber); + + $user = User::getKV('nickname', $userNick); + + if (empty($user)) { + throw new Exception("Can't find user '$userNick'."); + } + + // NB: it's OK to like your own stuff! + + $otherNumber = rand(0, $u - 1); + + $otherNick = sprintf('%s%d', $userprefix, $otherNumber); + + $other = User::getKV('nickname', $otherNick); + + if (empty($other)) { + throw new Exception("Can't find user '$otherNick'."); + } + + $notices = $other->getNotices()->fetchAll(); + + if (count($notices) == 0) { + return; + } + + $idx = rand(0, count($notices) - 1); + + $notice = $notices[$idx]; + + if ($user->hasFave($notice)) { + return; + } + + Fave::addNew($user->getProfile(), $notice); +}*/ + +function testNoticeContent() +{ + global $words; + + if (is_null($words)) { + return "test notice content"; + } + + $cnt = rand(3, 8); + + $ids = array_rand($words, $cnt); + + foreach ($ids as $id) { + $parts[] = $words[$id]; + } + + $text = implode(' ', $parts); + + if (mb_strlen($text) > 80) { + $text = substr($text, 0, 77) . "..."; + } + + return $text; +} + +//function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax) function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) { global $config; @@ -234,6 +374,7 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) // # registrations + # notices + # subs + //$events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg + $favesavg + $messageavg)); $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg)); $events -= $preuser; @@ -244,7 +385,10 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) $nt = $gt + ($usercount * $noticeavg); $st = $nt + ($usercount * $subsavg); $jt = $st + ($usercount * $joinsavg); +// $ft = $jt + ($usercount * $favesavg); +// $mt = $ft + ($usercount * $messageavg); +// printfv("$events events ($ut, $gt, $nt, $st, $jt, $ft, $mt)\n"); printfv("$events events ($ut, $gt, $nt, $st, $jt)\n"); for ($i = 0; $i < $events; $i++) @@ -268,22 +412,44 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) } else if ($e > $st && $e <= $jt) { printfv("$i Making a new group join\n"); newJoin($n, $g); +/* } else if ($e > $jt && $e <= $ft) { + printfv("$i Making a new fave\n"); + newFave($n);*/ +/* } else if ($e > $ft && $e <= $mt) { + printfv("$i Making a new message\n"); + newMessage($n);*/ } else { printfv("No event for $i!"); } } } +$defaultWordsfile = '/usr/share/dict/words'; + $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; +//$favesavg = (have_option('f', 'faves')) ? get_option_value('f', 'faves') : max($noticeavg/10, 5); +//$messageavg = (have_option('m', 'messages')) ? get_option_value('m', 'messages') : max($noticeavg/10, 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'; +$wordsfile = (have_option('w', 'words')) ? get_option_value('w', 'words') : $defaultWordsfile; + +if (is_readable($wordsfile)) { + $words = file($wordsfile); +} else { + if ($wordsfile != $defaultWordsfile) { + // user specified words file couldn't be read + throw new Exception("Couldn't read words file: {$wordsfile}."); + } + $words = null; +} try { + //main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax); main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax); } catch (Exception $e) { printfv("Got an exception: ".$e->getMessage());