summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-06-23 14:49:05 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-06-23 14:49:05 (GMT)
commite4624ce9f82e49fff037088999c45e92f37208ec (patch)
tree720005d9d0385abdbe163d8e4cac8cfab781507d /lib
parent3eeabde070d9a5823f78b8d9b997a22e21653fb6 (diff)
added feature to export schedules list0.10.0rel-0.10.0
Diffstat (limited to 'lib')
-rwxr-xr-xlib/RHRD/rddb.pm107
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 62146b5..99b4128 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -26,6 +26,7 @@ use strict;
use Config::IniFiles;
use DBI;
use RHRD::utils;
+use DateTime;
use Date::Calc;
########################### constants ###########################
@@ -1034,6 +1035,58 @@ sub create_or_update_schedule_log
return (1, 'OK', 'success');
}
+sub get_schedule_log
+{
+ my $ctx = shift;
+ my $year = shift;
+ my $month = shift;
+ my $day = shift;
+
+ my $logname = sprintf("%04d_%02d_%02d", $year, $month, $day);
+ my ($log_exists, $status, $errorstring) = check_log_exists($ctx, $logname);
+ unless (defined $log_exists) {
+ return (undef, $status, $errorstring);
+ }
+ if(!$log_exists) {
+ return (undef, 'ERROR', "Log does not exist");
+ }
+
+ $logname = get_log_table_name_escaped($ctx, $logname);
+ my $sql = qq{select START_TIME,CART_NUMBER from $logname order by COUNT};
+
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute()
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my @show_dbs;
+ while(my ($start_time, $cart_number) = $sth->fetchrow_array()) {
+ my $entry = {};
+ $entry->{'ID'} = $cart_number;
+ my ($title, $len, $status, $errorstring) = get_show_title_and_len($ctx, $cart_number);
+ unless (defined $title && defined $len) {
+ $sth->finish();
+ return (undef, $status, $errorstring);
+ }
+
+ $start_time = $start_time / 1000;
+ my $hour = int($start_time / 3600);
+ my $min = int(($start_time % 3600) / 60);
+ my $sec = int(($start_time % 60));
+ my $start = DateTime->new(year => $year, month => $month, day => $day, hour => $hour, minute => $min, second => $sec, time_zone => 'Europe/Vienna');
+
+ $entry->{'TITLE'} = $title;
+ $entry->{'START'} = $start;
+ $entry->{'LEN'} = $len;
+
+ push @show_dbs, $entry;
+ }
+ $sth->finish();
+
+ return @show_dbs;
+}
+
########################### SHOW handling ###########################
sub get_shows_cart_range
@@ -1390,6 +1443,60 @@ sub get_show_carts
return @carts;
}
+sub get_show_title_and_len
+{
+ my ($ctx, $showid) = @_;
+
+ my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_cart_range($ctx, $showid);
+ unless (defined $group_low_cart && defined $group_high_cart) {
+ return (undef, undef, $status, $errorstring);
+ }
+
+ (my $title, my $log, $status, $errorstring) = get_show_title_and_log($ctx, $showid);
+ unless (defined $title && defined $log) {
+ return (undef, undef, $status, $errorstring);
+ }
+
+ (my $log_exists, $status, $errorstring) = check_log_exists($ctx, $log);
+ unless (defined $log_exists) {
+ return (undef, undef, $status, $errorstring);
+ }
+ unless($log_exists) {
+ return (undef, undef, 'ERROR', "Log with name '$log' does not exist")
+ }
+
+ $log = get_log_table_name_escaped($ctx, $log);
+ my $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;};
+
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute()
+ or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my @carts;
+ while(my ($count, $cart) = $sth->fetchrow_array()) {
+ if($cart >= $group_low_cart && $cart <= $group_high_cart) {
+ push @carts, $cart;
+ }
+ }
+ $sth->finish();
+
+ $sql = qq{select SUM(AVERAGE_LENGTH) from CART where NUMBER in (} . join(',', @carts) . ")";
+
+ $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute()
+ or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($len) = $sth->fetchrow_array;
+ $sth->finish();
+ $len = 0 unless (defined $len);
+
+ return ($title, $len, 'OK', 'success');
+}
+
sub create_show_log
{
my ($ctx, $logname, $low_cart, $high_cart) = @_;