]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
- added top3 irctextcounter stats
[infobot.git] / src / Modules / Factoids.pl
index 46cbf8d0370e24b14650e2c4c1f6f77e99e900b1..3285dd9dfad26a2701ae0f26b17463a27745879e 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";
            }
@@ -143,7 +143,7 @@ sub CmdFactStats {
     my ($type) = @_;
 
     if ($type =~ /^author$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key","created_by");
+       my %hash = &dbGetCol("factoids", "factoid_key,created_by", "created_by IS NOT NULL");
        my %author;
 
        foreach (keys %hash) {
@@ -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");
        }
 
@@ -177,7 +177,7 @@ sub CmdFactStats {
     } elsif ($type =~ /^broken$/i) {
         &status("factstats(broken): starting...");
        my $start_time  = &timeget();
-       my %data        = &dbGetCol("factoids", "factoid_key","factoid_value");
+       my %data        = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
        my @list;
 
        my $delta_time  = &timedelta($start_time);
@@ -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 ");
@@ -240,17 +304,17 @@ sub CmdFactStats {
     } elsif ($type =~ /^dup(licate|e)$/i) {
         &status("factstats(dupe): starting...");
        my $start_time  = &timeget();
-       my %hash        = &dbGetCol("factoids", "factoid_key", "factoid_value", 1);
+       my %hash        = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL", 1);
        my $refs        = 0;
        my @list;
        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;
@@ -356,7 +420,7 @@ sub CmdFactStats {
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^locked$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key","locked_by");
+       my %hash = &dbGetCol("factoids", "factoid_key,locked_by", "locked_by IS NOT NULL");
        my @list = keys %hash;
 
        for (@list) {
@@ -367,7 +431,7 @@ sub CmdFactStats {
        return &formListReply(0, $prefix, @list);
 
     } elsif ($type =~ /^new$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key","created_time");
+       my %hash = &dbGetCol("factoids", "factoid_key,created_time", "created_time IS NOT NULL");
        my %age;
 
        foreach (keys %hash) {
@@ -384,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 ";
@@ -421,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;
@@ -445,7 +509,7 @@ sub CmdFactStats {
        return &formListReply(1, $prefix, @list);
 
     } elsif ($type =~ /^profanity$/i) {
-       my %data = &dbGetCol("factoids", "factoid_key","factoid_value");
+       my %data = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
        my @list;
 
        foreach (keys %data) {
@@ -478,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;
            }
@@ -491,7 +555,7 @@ sub CmdFactStats {
        return &formListReply(1, $prefix, @newlist);
 
     } elsif ($type =~ /^request(ed)?$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key", "requested_count",1);
+       my %hash = &dbGetCol("factoids", "factoid_key,requested_count", "requested_count IS NOT NULL", 1);
 
        if (!scalar keys %hash) {
            return 'sorry, no factoids have been questioned.';
@@ -515,8 +579,25 @@ sub CmdFactStats {
        my $prefix = "factoid statistics on $type ";
        return &formListReply(0, $prefix, @list);
 
+    } elsif ($type =~ /^reqrate$/i) {
+       my %hash = &dbGetCol("factoids",
+               "factoid_key,(unix_timestamp() - created_time)/requested_count as rate",
+               "requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1);
+
+       my $rate;
+       my @list;
+       my $total       = 0;
+       my $users       = 0;
+       foreach $rate (sort { $b <=> $a } keys %hash) {
+           my $f       = join(", ", sort keys %{ $hash{$rate} });
+           push(@list, "$f - ".&Time2String($rate));
+       }
+
+       my $prefix = "Rank of top factoid rate (time/req): ";
+       return &formListReply(0, $prefix, @list);
+
     } elsif ($type =~ /^requesters?$/i) {
-       my %hash = &dbGetCol("factoids", "factoid_key","requested_by");
+       my %hash = &dbGetCol("factoids", "factoid_key,requested_by", "requested_by IS NOT NULL");
        my %requester;
 
        foreach (keys %hash) {
@@ -533,7 +614,7 @@ sub CmdFactStats {
        # work-around.
        my %count;
        foreach (keys %requester) {
-           $count{$requester{$_}}{$_} = 1;
+           $count{ $requester{$_} }{$_} = 1;
        }
        undef %requester;