diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2015-02-18 10:13:26 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2015-02-18 10:13:26 +0000 |
commit | 9f57cbc905a1c0358142595163121b78a7881330 (patch) | |
tree | 20aeeb91d39531b505894d23888dc06656d2f68d | |
parent | abb4adc9ddcc53aa0180b7cbc78d0fc7a86b9603 (diff) |
Moved script to Frikanalen github repo.
-rwxr-xr-x | frikanalen/bin/frikanalen-tonostats | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/frikanalen/bin/frikanalen-tonostats b/frikanalen/bin/frikanalen-tonostats deleted file mode 100755 index 20185fe..0000000 --- a/frikanalen/bin/frikanalen-tonostats +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use vars qw(%opts %orgs %orgsecs); -use Data::Dumper; - -use Getopt::Std; - -use JSON; -use LWP::Simple; -use Frikanalen; - -sub get_tono_stats_page { - my $url = shift; - my $jsonstr = get($url); - my $json = decode_json( $jsonstr ); -# print Dumper($json); - unless ($json->{'results'}) { - return; - } - my $tono = 0; - my $notono = 0; - my $tonosec = 0; - my $notonosec = 0; - foreach my $video (@{$json->{'results'}}) { - my $durationsec = Frikanalen::parse_duration($video->{'duration'}); - if (exists $video->{'has_tono_records'} - && $video->{'has_tono_records'}) { - $tono++; - $tonosec += $durationsec; - $orgs{$video->{'organization'}}{tono}++; - $orgsecs{$video->{'organization'}}{tono} += $durationsec; - push(@{$orgs{$video->{'organization'}}{tonoids}}, - $video->{id}); -# print Dumper($video); -# exit 0; - } else { - $notono++; - $notonosec += $durationsec; - $orgs{$video->{'organization'} || ""}{notono}++; - $orgsecs{$video->{'organization'} || ""}{notono} += $durationsec; - } - } - if (defined $json->{'next'}) { - my ($newtono, $newnotono, $newtonosec, $newnotonosec) = - get_tono_stats_page($json->{'next'}); - $tono += $newtono; - $notono += $newnotono; - $tonosec += $newtonosec; - $notonosec += $newnotonosec; - } - return ($tono, $notono, $tonosec, $notonosec); -} - -sub get_tono_stats { - my $url = 'http://beta.frikanalen.tv/api/videos/'; - return get_tono_stats_page($url); -} -sub print_tono_stats { - my ($with, $without, $withsec, $withoutsec) = get_tono_stats(); - printf("Innslag med tono-musikk: %d (%.1f%%) %dt (%.1f%%)\n", - $with, 100 * $with / ($with+$without), - $withsec / (60*60), 100 * $withsec / ($withsec+$withoutsec)); - printf("Innslag uten tono-musikk: %d (%.1f%%) %dt (%.1f%%) \n", - $without, 100 *$without/($with+$without), - $withoutsec/ (60*60), 100 * $withoutsec / ($withsec+$withoutsec)); - print "Andel\tmed\t\tuten\t\tnavn\n"; - for my $org (sort tonoorder keys %orgs) { - my $tono = $orgs{$org}{tono} || 0; - my $notono = $orgs{$org}{notono} || 0; - my $tonosec = $orgsecs{$org}{tono} || 0; - my $notonosec = $orgsecs{$org}{notono} || 0; - my $frac = 0; - $frac = 100 * $tono / $with if $with; - printf("%5.1f\t%4d (%4dt)\t%4d (%4dt)\t%s\n", - $frac, - $tono, $tonosec / (60*60), - $notono, $notonosec / (60*60), - $org); - print(join(" ", " ", @{$orgs{$org}{tonoids}}), "\n") - if $opts{'i'} && exists $orgs{$org}{tonoids}; - } -} - -sub tonoorder { - my $order = ($orgs{$b}{tono} || 0) <=> ($orgs{$a}{tono} || 0); - if (0 == $order) { - $order = ($orgs{$b}{notono} || 0) <=> ($orgs{$a}{notono} || 0); - } - return $order; -} - -sub munin_plugin { - my @ARGV = @_; - if (defined $ARGV[0] && "config" eq $ARGV[0]) { - print <<EOF; -graph_title Fraction of events with Tono-related music -graph_category Frikanalen -tono_frac.label fraction -EOF - } else { - my ($with, $without) = get_tono_stats(); - printf "tono_frac.value %.3f\n", ($with / ($with + $without)); - } -} - -getopts("im", \%opts); - -if ($opts{'m'}) { - munin_plugin(@ARGV); -} else { - print_tono_stats(); -} |