diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2013-03-04 10:51:26 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2013-03-04 10:51:26 +0000 |
commit | 13175f321bb9d981053dfe9ef5a328095527961a (patch) | |
tree | cea46af39921899a9de002cc2123bf99d2df58ca | |
parent | c10a03af153b25c404ca8f3f3bf512020cc23409 (diff) |
Improve stats.
-rw-r--r-- | frikanalen/bin/Frikanalen.pm | 29 | ||||
-rwxr-xr-x | frikanalen/bin/frikanalen-filler-playlist | 15 | ||||
-rwxr-xr-x | frikanalen/bin/frikanalen-tonostats | 40 | ||||
-rwxr-xr-x | frikanalen/bin/scheduler | 21 | ||||
-rw-r--r-- | frikanalen/bin/tonostats.txt | 2 |
5 files changed, 63 insertions, 44 deletions
diff --git a/frikanalen/bin/Frikanalen.pm b/frikanalen/bin/Frikanalen.pm index cdc0c97..fe663a0 100644 --- a/frikanalen/bin/Frikanalen.pm +++ b/frikanalen/bin/Frikanalen.pm @@ -1,7 +1,5 @@ # -# Support library for script parsing the getfiled/filelog files. -# -# $Id: FileLog.pm 18293 2010-09-17 08:39:47Z pre $ +# Support library for script talking to the Frikanalen API # package Frikanalen; @@ -13,23 +11,20 @@ use SOAP::Lite on_action => sub {sprintf '%s/%s', @_}, ; our $VERSION = 0.01; our @ISA = qw(Exporter); our @EXPORT = qw( - getEpgUrls + parse_duration ); -sub getEpgUrls { - my $soap = new SOAP::Lite - -> uri('http://tempuri.org') - -> proxy('http://communitysite1.frikanalen.tv/CommunitySite/EpgWebService.asmx'); - my $res; - my $obj = $soap->GetEpgUrls; - unless ($obj->fault) { - return $obj->result->{string}; - } else { -# print Dumper($obj); - print $obj->fault->{faultstring}, "\n"; - return undef; +# Convert "04:05.12" to 4 * 60 + 5.12 +sub parse_duration { + my $durationstr = shift; + my @parts = split(/:/, $durationstr); + my $duration = 0; + while (my $part = shift @parts) { + $duration *= 60; + $duration += int($part); } +# print "$durationstr = $duration\n"; + return $duration; } - 1; diff --git a/frikanalen/bin/frikanalen-filler-playlist b/frikanalen/bin/frikanalen-filler-playlist index 6a14c4c..b730d42 100755 --- a/frikanalen/bin/frikanalen-filler-playlist +++ b/frikanalen/bin/frikanalen-filler-playlist @@ -9,6 +9,7 @@ use vars qw(%opts); use Data::Dumper; use JSON; use LWP::Simple; +use Frikanalen; my $starturl = "http://beta.frikanalen.tv/ws/videos/"; my @videos = get_relevant_videos($starturl); @@ -31,6 +32,7 @@ sub get_relevant_videos { # Skip stuff triggering TONO fee next if ($video->{'has_tono_records'}); +# next unless ($durationsec >= 45 * 60); # print Dumper($video); my $entry = join(";", $video->{id}, @@ -45,16 +47,3 @@ sub get_relevant_videos { } return @videos; } - -# Convert "04:05.12" to 4 * 60 + 5.12 -sub parse_duration { - my $durationstr = shift; - my @parts = split(/:/, $durationstr); - my $duration = 0; - while (my $part = shift @parts) { - $duration *= 60; - $duration += int($part); - } -# print "$durationstr = $duration\n"; - return $duration; -} diff --git a/frikanalen/bin/frikanalen-tonostats b/frikanalen/bin/frikanalen-tonostats index 1acdcef..e74f2e3 100755 --- a/frikanalen/bin/frikanalen-tonostats +++ b/frikanalen/bin/frikanalen-tonostats @@ -2,13 +2,14 @@ use strict; use warnings; -use vars qw(%opts %orgs); +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; @@ -20,26 +21,36 @@ sub get_tono_stats_page { } 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) = get_tono_stats_page($json->{'next'}); + my ($newtono, $newnotono, $newtonosec, $newnotonosec) = + get_tono_stats_page($json->{'next'}); $tono += $newtono; $notono += $newnotono; + $tonosec += $newtonosec; + $notonosec += $newnotonosec; } - return ($tono, $notono); + return ($tono, $notono, $tonosec, $notonosec); } sub get_tono_stats { @@ -47,18 +58,27 @@ sub get_tono_stats { return get_tono_stats_page($url); } sub print_tono_stats { - my ($with, $without) = get_tono_stats(); - printf("Innslag med tono-musikk: %d (%.1f%%)\n", $with, 100 * $with / ($with+$without)); - printf("Innslag uten tono-musikk: %d (%.1f%%)\n",$without, 100 *$without/($with+$without)); - - print "Andel\tmed\tuten\tnavn\n"; + 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 "%4.1f\t%d\t%d\t%s\n", $frac, $tono, $notono, $org; - print join(" ", " ", @{$orgs{$org}{tonoids}}), "\n" + 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}; } } diff --git a/frikanalen/bin/scheduler b/frikanalen/bin/scheduler index 51b4e2a..56022db 100755 --- a/frikanalen/bin/scheduler +++ b/frikanalen/bin/scheduler @@ -46,7 +46,6 @@ use GD; use POSIX; use Event; use File::Temp; -use Frikanalen; # SOAP:Lite må modifiseres til å gjøre ting på MS måten :-/ use SOAP::Lite on_action => sub {sprintf '%s/%s', @_}, ; @@ -158,8 +157,8 @@ EOF } sub ezstream_stop { - if ( $ezpid ) { - kill SIGTERM => "$ezpid"; + if ( $ezpid ) { + kill SIGTERM => "$ezpid"; `pkill -P $ezpid ffmpeg`; } if ( -f $ezcfgname ) { unlink $ezcfgname } ; @@ -187,7 +186,7 @@ sub tidy { my @events = (); -my $listref = Frikanalen::getEpgUrls(); +my $listref = getEpgUrls(); for my $url (@{$listref}) { # print "Loading '$url'\n"; my $ua = new LWP::UserAgent; @@ -809,3 +808,17 @@ sub get_video_meta { return $video; } } +sub getEpgUrls { + my $soap = new SOAP::Lite + -> uri('http://tempuri.org') + -> proxy('http://communitysite1.frikanalen.tv/CommunitySite/EpgWebService.asmx'); + my $res; + my $obj = $soap->GetEpgUrls; + unless ($obj->fault) { + return $obj->result->{string}; + } else { +# print Dumper($obj); + print $obj->fault->{faultstring}, "\n"; + return undef; + } +} diff --git a/frikanalen/bin/tonostats.txt b/frikanalen/bin/tonostats.txt index 5dda1c0..3ccbf43 100644 --- a/frikanalen/bin/tonostats.txt +++ b/frikanalen/bin/tonostats.txt @@ -1,4 +1,6 @@ tono no-tono totalt nye innslag pr. dag + + 2013-03-04 795 (31.7%) 1713 (68.3%) 2013-02-24 795 (31.7%) 1711 (68.3%) 2013-02-19 795 (31.7%) 1710 (68.3%) 2505 2012-06-28 735 (31.9%) 1571 (68.1%) 2306 |