]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/createsim.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / scripts / createsim.php
old mode 100644 (file)
new mode 100755 (executable)
index 9de855e..e5b47df
@@ -31,7 +31,7 @@ $longoptions = array(
     'words=',
     'prefix=',
     'groupprefix=',
-    'faves='
+//    'faves=',
 );
 
 $helptext = <<<END_OF_CREATESIM_HELP
@@ -40,7 +40,6 @@ Creates a lot of test users and notices to (loosely) simulate a real server.
     -b --subscriptions Average subscriptions per user (default no. users/20)
     -g --groups        Number of groups (default 20)
     -j --joins         Number of groups per user (default 5)
-    -f --faves         Number of faves per user (default notices/10)
     -n --notices       Average notices per user (default 100)
     -t --tags          Number of distinct hash tags (default 10000)
     -u --users         Number of users (default 100)
@@ -50,7 +49,7 @@ Creates a lot of test users and notices to (loosely) simulate a real server.
 
 END_OF_CREATESIM_HELP;
 
-require_once INSTALLDIR.'/scripts/commandline.inc';
+require_once INSTALLDIR.'/scripts/commandline.inc.php';
 
 // XXX: make these command-line options
 
@@ -72,7 +71,7 @@ function newGroup($i, $j)
 
     // Pick a random user to be the admin
 
-    $n = rand(0, max($j - 1, 0));
+    $n = mt_rand(0, max($j - 1, 0));
     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n));
 
     $group = User_group::register(array('nickname' => sprintf('%s%d', $groupprefix, $i),
@@ -87,41 +86,41 @@ function newNotice($i, $tagmax)
 
     $options = array('scope' => Notice::defaultScope());
 
-    $n = rand(0, $i - 1);
+    $n = mt_rand(0, $i - 1);
     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n));
 
-    $is_reply = rand(0, 1);
+    $is_reply = mt_rand(0, 1);
 
     $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);
+            $nval = mt_rand(0, $notices->N - 1);
             $notices->fetch(); // go to 0th
             for ($i = 0; $i < $nval; $i++) {
                 $notices->fetch();
             }
             $options['reply_to'] = $notices->id;
-            $dont_use_nickname = rand(0, 2);
+            $dont_use_nickname = mt_rand(0, 2);
             if ($dont_use_nickname != 0) {
                 $rprofile = $notices->getProfile();
                 $content = "@".$rprofile->nickname." ".$content;
             }
-            $private_to_addressees = rand(0, 4);
+            $private_to_addressees = mt_rand(0, 4);
             if ($private_to_addressees == 0) {
                 $options['scope'] |= Notice::ADDRESSEE_SCOPE;
             }
         }
     } else {
-        $is_directed = rand(0, 4);
+        $is_directed = mt_rand(0, 4);
 
         if ($is_directed == 0) {
-            $subs = $user->getSubscriptions(0, 100)->fetchAll();
+            $subs = $user->getSubscribed(0, 100)->fetchAll();
             if (count($subs) > 0) {
                 $seen = array();
-                $f = rand(0, 9);
+                $f = mt_rand(0, 9);
                 if ($f <= 6) {
                     $addrs = 1;
                 } else if ($f <= 8) {
@@ -130,7 +129,7 @@ function newNotice($i, $tagmax)
                     $addrs = 3;
                 }
                 for ($m = 0; $m < $addrs; $m++) {
-                    $x = rand(0, count($subs) - 1);
+                    $x = mt_rand(0, count($subs) - 1);
                     if ($seen[$x]) {
                         continue;
                     }
@@ -141,7 +140,7 @@ function newNotice($i, $tagmax)
                     $rprofile = $subs[$x];
                     $content = "@".$rprofile->nickname." ".$content;
                 }
-                $private_to_addressees = rand(0, 4);
+                $private_to_addressees = mt_rand(0, 4);
                 if ($private_to_addressees == 0) {
                     $options['scope'] |= Notice::ADDRESSEE_SCOPE;
                 }
@@ -149,36 +148,36 @@ function newNotice($i, $tagmax)
         }
     }
 
-    $has_hash = rand(0, 2);
+    $has_hash = mt_rand(0, 2);
 
     if ($has_hash == 0) {
-        $hashcount = rand(0, 2);
+        $hashcount = mt_rand(0, 2);
         for ($j = 0; $j < $hashcount; $j++) {
-            $h = rand(0, $tagmax);
+            $h = mt_rand(0, $tagmax);
             $content .= " #tag{$h}";
         }
     }
 
-    $in_group = rand(0, 5);
+    $in_group = mt_rand(0, 5);
 
     if ($in_group == 0) {
         $groups = $user->getGroups();
-        if ($groups->N > 0) {
-            $gval = rand(0, $groups->N - 1);
+        if ($groups instanceof User_group) {
+            $gval = mt_rand(0, $groups->N - 1);
             $groups->fetch(); // go to 0th
             for ($i = 0; $i < $gval; $i++) {
                 $groups->fetch();
             }
             $options['groups'] = array($groups->id);
             $content = "!".$groups->nickname." ".$content;
-            $private_to_group = rand(0, 2);
+            $private_to_group = mt_rand(0, 2);
             if ($private_to_group == 0) {
                 $options['scope'] |= Notice::GROUP_SCOPE;
             }
         }
     }
 
-    $private_to_site = rand(0, 4);
+    $private_to_site = mt_rand(0, 4);
 
     if ($private_to_site == 0) {
         $options['scope'] |= Notice::SITE_SCOPE;
@@ -187,11 +186,12 @@ function newNotice($i, $tagmax)
     $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);
+    $n = mt_rand(0, $i - 1);
     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n));
 
     $content = testNoticeContent();
@@ -202,17 +202,17 @@ function newMessage($i)
         return;
     }
 
-    $j = rand(0, count($friends) - 1);
+    $j = mt_rand(0, count($friends) - 1);
     
     $other = $friends[$j];
 
     $message = Message::saveNew($user->id, $other->id, $content, 'createsim');
-}
+}*/
 
 function newSub($i)
 {
     global $userprefix;
-    $f = rand(0, $i - 1);
+    $f = mt_rand(0, $i - 1);
 
     $fromnick = sprintf('%s%d', $userprefix, $f);
 
@@ -222,7 +222,7 @@ function newSub($i)
         throw new Exception("Can't find user '$fromnick'.");
     }
 
-    $t = rand(0, $i - 1);
+    $t = mt_rand(0, $i - 1);
 
     if ($t == $f) {
         $t++;
@@ -235,11 +235,11 @@ function newSub($i)
 
     $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();
@@ -250,7 +250,7 @@ function newJoin($u, $g)
     global $userprefix;
     global $groupprefix;
 
-    $userNumber = rand(0, $u - 1);
+    $userNumber = mt_rand(0, $u - 1);
 
     $userNick = sprintf('%s%d', $userprefix, $userNumber);
 
@@ -260,7 +260,7 @@ function newJoin($u, $g)
         throw new Exception("Can't find user '$fromnick'.");
     }
 
-    $groupNumber = rand(0, $g - 1);
+    $groupNumber = mt_rand(0, $g - 1);
 
     $groupNick = sprintf('%s%d', $groupprefix, $groupNumber);
 
@@ -275,12 +275,13 @@ function newJoin($u, $g)
     }
 }
 
+/* Plugins should be part of the simulation too!
 function newFave($u)
 {
     global $userprefix;
     global $groupprefix;
 
-    $userNumber = rand(0, $u - 1);
+    $userNumber = mt_rand(0, $u - 1);
 
     $userNick = sprintf('%s%d', $userprefix, $userNumber);
 
@@ -292,7 +293,7 @@ function newFave($u)
 
     // NB: it's OK to like your own stuff!
 
-    $otherNumber = rand(0, $u - 1);
+    $otherNumber = mt_rand(0, $u - 1);
 
     $otherNick = sprintf('%s%d', $userprefix, $otherNumber);
 
@@ -308,7 +309,7 @@ function newFave($u)
         return;
     }
 
-    $idx = rand(0, count($notices) - 1);
+    $idx = mt_rand(0, count($notices) - 1);
 
     $notice = $notices[$idx];
 
@@ -317,7 +318,7 @@ function newFave($u)
     }
 
     Fave::addNew($user->getProfile(), $notice);
-}
+}*/
 
 function testNoticeContent()
 {
@@ -327,7 +328,7 @@ function testNoticeContent()
         return "test notice content";
     }
 
-    $cnt = rand(3, 8);
+    $cnt = mt_rand(3, 8);
 
     $ids = array_rand($words, $cnt);
 
@@ -344,7 +345,8 @@ function testNoticeContent()
     return $text;
 }
 
-function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax)
+//function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax)
+function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax)
 {
     global $config;
     $config['site']['dupelimit'] = -1;
@@ -372,7 +374,8 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesav
 
     // # registrations + # notices + # subs
 
-    $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg + $favesavg + $messageavg));
+    //$events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg + $favesavg + $messageavg));
+    $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg));
 
     $events -= $preuser;
     $events -= $pregroup;
@@ -382,14 +385,15 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesav
     $nt = $gt + ($usercount * $noticeavg);
     $st = $nt + ($usercount * $subsavg);
     $jt = $st + ($usercount * $joinsavg);
-    $ft = $jt + ($usercount * $favesavg);
-    $mt = $ft + ($usercount * $messageavg);
+//    $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, $ft, $mt)\n");
+    printfv("$events events ($ut, $gt, $nt, $st, $jt)\n");
 
     for ($i = 0; $i < $events; $i++)
     {
-        $e = rand(0, $events);
+        $e = mt_rand(0, $events);
 
         if ($e >= 0 && $e <= $ut) {
             printfv("$i Creating user $n\n");
@@ -408,12 +412,12 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesav
         } else if ($e > $st && $e <= $jt) {
             printfv("$i Making a new group join\n");
             newJoin($n, $g);
-        } else if ($e > $jt && $e <= $ft) {
+/*        } else if ($e > $jt && $e <= $ft) {
             printfv("$i Making a new fave\n");
-            newFave($n);
-        } else if ($e > $ft && $e <= $mt) {
+            newFave($n);*/
+/*        } else if ($e > $ft && $e <= $mt) {
             printfv("$i Making a new message\n");
-            newMessage($n);
+            newMessage($n);*/
         } else {
             printfv("No event for $i!");
         }
@@ -427,8 +431,8 @@ $groupcount  = (have_option('g', 'groups')) ? get_option_value('g', 'groups') :
 $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);
+//$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';
@@ -445,7 +449,8 @@ if (is_readable($wordsfile)) {
 }
 
 try {
-    main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax);
+    //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());
 }