]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
- moved scripts/setup_sql.pl to src/db_mysql as &createTables()
[infobot.git] / src / Modules / Factoids.pl
index d6c20b4a1e382f1480e3c04136099435186303b6..64bc303aedbbc237b7b77d57a524b4b3f7ed2eed 100644 (file)
@@ -22,7 +22,7 @@ sub CmdFactInfo {
     my $i = 0;
     my %factinfo;
     my @factinfo = &getFactInfo($faqtoid,"*");
-    foreach ( &dbGetRowInfo("factoids") ) {
+    foreach ( &dbGetColInfo("factoids") ) {
        $factinfo{$_} = $factinfo[$i] || '';
        $i++;
     }
@@ -56,7 +56,7 @@ sub CmdFactInfo {
            if (time() - $time > 60*60*24*7) {
                my $days = int( (time() - $time)/60/60/24 );
                $string .= " at \037". scalar(localtime $time). "\037" .
-                               " ($days days) ";
+                               " ($days days)";
            } else {
                $string .= " ".&Time2String(time() - $time)." ago";
            }
@@ -167,7 +167,7 @@ sub CmdFactStats {
        my $count;
        my @list;
        foreach $count (sort { $b <=> $a } keys %count) {
-           my $author = join(", ", sort keys %{$count{$count}});
+           my $author = join(", ", sort keys %{ $count{$count} });
            push(@list, "$count by $author");
        }
 
@@ -204,6 +204,70 @@ sub CmdFactStats {
        my $prefix = "broken factoid ";
        return &formListReply(1, $prefix, @list);
 
+    } elsif ($type =~ /^total$/i) {
+        &status("factstats(total): starting...");
+       my $start_time  = &timeget();
+       my @list;
+       my $str;
+       my($i,$j);
+       my %hash;
+
+       ### lets do it.
+       # total factoids requests.
+       $i = &sumKey("factoids", "requested_count");
+       push(@list, "total requests - $i");
+
+       # total factoids modified.
+       $str = &countKeys("factoids", "modified_by");
+       push(@list, "total modified - $str");
+
+       # total factoids modified.
+       $j      = &countKeys("factoids", "requested_count");
+       $str    = &countKeys("factoids", "factoid_key");
+       push(@list, "total non-requested - ".($str - $i));
+
+       # average request/factoid.
+       # i/j == total(requested_count)/count(requested_count)
+       $str = sprintf("%.01f", $i/$j);
+       push(@list, "average requested per factoid - $str");
+
+       # total prepared for deletion.
+       $str    = scalar( &searchTable("factoids", "factoid_key", "factoid_value", " #DEL") );
+       push(@list, "total prepared for deletion - $str");
+
+       # total unique authors.
+       foreach ( &dbRawReturn("SELECT created_by FROM factoids WHERE created_by IS NOT NULL") ) {
+           /^(\S+)!/;
+           my $nick = lc $1;
+           $hash{$nick}++;
+       }
+       push(@list, "total unique authors - ".(scalar keys %hash) );
+       undef %hash;
+
+       # total unique requesters.
+       foreach ( &dbRawReturn("SELECT requested_by FROM factoids WHERE requested_by IS NOT NULL") ) {
+           /^(\S+)!/;
+           my $nick = lc $1;
+           $hash{$nick}++;
+       }
+       push(@list, "total unique requesters - ".(scalar keys %hash) );
+       undef %hash;
+
+       ### end of "job".
+
+       my $delta_time  = &timedelta($start_time);
+        &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
+       $start_time     = &timeget();
+
+       # bail out on no results.
+       if (scalar @list == 0) {
+           return 'no broken factoids... wooohoo.';
+       }
+
+       # parse the results.
+       my $prefix = "General factoid stiatistics ";
+       return &formListReply(1, $prefix, @list);
+
     } elsif ($type =~ /^deadredir$/i) {
        my @list = &searchTable("factoids", "factoid_key",
                        "factoid_value", "^<REPLY> see ");
@@ -246,11 +310,11 @@ sub CmdFactStats {
        my $v;
 
        foreach $v (keys %hash) {
-           my $count = scalar(keys %{$hash{$v}});
+           my $count = scalar(keys %{ $hash{$v} });
            next if ($count == 1);
 
            my @sublist;
-           foreach (keys %{$hash{$v}}) {
+           foreach (keys %{ $hash{$v} }) {
                if ($v =~ /^<REPLY> see /i) {
                    $refs++;
                    next;
@@ -316,6 +380,11 @@ sub CmdFactStats {
            $match++ if ($val =~ /\s{3,}/);
            next unless ($match);
 
+           my $v = &getFactoid($val);
+           if (defined $v) {
+               &DEBUG("key $key => $val => $v");
+           }
+
            $key =~ s/\,/\037\,\037/g;
            push(@list, $key);
        }
@@ -379,7 +448,7 @@ sub CmdFactStats {
 
        my @list;
        foreach (sort {$a <=> $b} keys %age) {
-           push(@list, join(",", keys %{$age{$_}}));
+           push(@list, join(",", keys %{ $age{$_} }));
        }
 
        my $prefix = "new factoids in the last 24hours ";
@@ -416,7 +485,7 @@ sub CmdFactStats {
            my @sublist;
            my $length;
            foreach $length (@length) {
-               foreach (keys %{$length{$length}}) {
+               foreach (keys %{ $length{$length} }) {
                    if ($key{$_} =~ /^$val/i) {
                        s/([\,\;]+)/\037$1\037/g;
                        s/( and|and )/\037$1\037/g;
@@ -473,7 +542,7 @@ sub CmdFactStats {
 
        my @newlist;
        foreach $f (keys %redir) {
-           my @sublist = keys %{$redir{$f}};
+           my @sublist = keys %{ $redir{$f} };
            for (@sublist) {
                s/([\,\;]+)/\037$1\037/g;
            }
@@ -528,7 +597,7 @@ sub CmdFactStats {
        # work-around.
        my %count;
        foreach (keys %requester) {
-           $count{$requester{$_}}{$_} = 1;
+           $count{ $requester{$_} }{$_} = 1;
        }
        undef %requester;