Changeset 146 for shepherd

Show
Ignore:
Timestamp:
10/25/06 19:53:05 (7 years ago)
Author:
lincoln
Message:

minor policy changes, cosmetic cleanup of how we tell the user about missing data

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • shepherd

    r145 r146  
    8989#  if there is more than this, we will continue asking grabbers for more 
    9090#  programming on this channel 
    91 $policy{peak_max_missing} = 10*60;              # up to 10 mins max allowed missing 
     91$policy{peak_max_missing} = 15*60;              # up to 15 mins max allowed missing 
    9292$policy{peak_start} = (16*(60*60))+(30*60);     # 4.30pm 
    9393$policy{peak_stop} = (23*(60*60))+(30*60);      # 11.30pm 
     
    103103# all other timeslots - 
    104104#  allow up to 45 minutes maximum missing programming 
    105 $policy{other_max_missing} = 45*60;             # up to 45 mins max allowed missing 
     105$policy{other_max_missing} = 60*60;             # up to 60 mins max allowed missing 
    106106 
    107107# if a postprocessor failed 5 times in a row, automatically disable it 
     
    10071007 
    10081008        my $data; 
     1009        my $lastpol = ""; 
    10091010        $data->{data_ok} = 1; # unless proven otherwise 
    10101011        $data->{have} = 0; 
    10111012        $data->{missing} = 0; 
    1012  
    1013         my $already_missing = ""; 
    1014         my $already_missing_last = ""; 
    10151013 
    10161014        for my $slotnum (0..($policy{num_timeslots}-1)) { 
     
    10341032 
    10351033                # day changed, dump any 'already_missing' data 
    1036                 if ($already_missing ne "") { 
    1037                     $already_missing .= sprintf "-%02d:%02d", 
    1038                       int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
    1039                       if ($already_missing_last ne ""); 
    1040                     push(@{($data->{missing_all})}, $already_missing); 
    1041                     $already_missing = ""; 
    1042                     $already_missing_last = ""; 
    1043                 } 
     1034                &dump_already_missing($data); 
    10441035            } 
    10451036 
     
    10491040 
    10501041                # if we have missing data queued up, push it now 
    1051                 if ($already_missing ne "") { 
    1052                     $already_missing .= sprintf "-%02d:%02d", 
    1053                       int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
    1054                       if ($already_missing_last ne ""); 
    1055                     push(@{($data->{missing_all})}, $already_missing); 
    1056                     $already_missing = ""; 
    1057                     $already_missing_last = ""; 
    1058                 } 
     1042                &dump_already_missing($data); 
     1043 
     1044                &dump_already_missing_period($data->{day}->[$day],$lastpol) 
     1045                  if ($lastpol ne ""); 
    10591046 
    10601047                $data->{day}->[$day]->{have} += $policy{timeslot_size}; 
     
    10731060 
    10741061            # store details of where we are missing data 
    1075             if ($already_missing eq "") { 
    1076                 $already_missing = sprintf "#%d/%02d:%02d", $day, 
    1077                       int($bucket_seconds_offset/3600),int(($bucket_seconds_offset%3600)/60); 
    1078                 $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
    1079             } else { 
    1080                 $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
     1062            if (!defined $data->{already_missing}) { 
     1063                $data->{already_missing} = sprintf "#%d/%02d:%02d", 
     1064                  $day, 
     1065                  int($bucket_seconds_offset / 3600), 
     1066                  int(($bucket_seconds_offset % 3600) / 60); 
    10811067            } 
     1068            $data->{already_missing_last} = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
    10821069 
    10831070            $data->{day}->[$day]->{missing} += $policy{timeslot_size}; 
     
    10851072 
    10861073            # work out what policy missing data for this bucket fits into 
     1074            my $pol; 
    10871075            if (($bucket_seconds_offset >= $policy{peak_start}) && 
    1088                 ($bucket_seconds_offset < $policy{peak_stop})) { 
    1089                 $data->{day}->[$day]->{missing_peak} += $policy{timeslot_size}; 
    1090                 push(@{($data->{day}->[$day]->{missing_peak_table})}, $bucket_seconds_offset); 
     1076                (($bucket_seconds_offset+$policy{timeslot_size}) <= $policy{peak_stop})) { 
     1077                $pol = "peak"; 
    10911078            } elsif (($bucket_seconds_offset >= $policy{nonpeak_start}) && 
    1092                      ($bucket_seconds_offset < $policy{nonpeak_stop})) { 
    1093                 $data->{day}->[$day]->{missing_nonpeak} += $policy{timeslot_size}; 
    1094                 push(@{($data->{day}->[$day]->{missing_nonpeak_table})}, $bucket_seconds_offset); 
     1079                     (($bucket_seconds_offset+$policy{timeslot_size}) <= $policy{nonpeak_stop})) { 
     1080                $pol = "nonpeak"; 
    10951081            } else { 
    1096                 $data->{day}->[$day]->{missing_other} += $policy{timeslot_size}; 
    1097                 push(@{($data->{day}->[$day]->{missing_other_table})}, $bucket_seconds_offset); 
     1082                $pol = "other"; 
    10981083            } 
     1084 
     1085            &dump_already_missing_period($data->{day}->[$day],$lastpol) 
     1086              if (($lastpol ne $pol) && ($lastpol ne "")); 
     1087 
     1088            $lastpol = $pol; 
     1089 
     1090            $data->{day}->[$day]->{"missing_".$pol} += $policy{timeslot_size}; 
     1091 
     1092            $data->{day}->[$day]->{"already_missing_".$pol."_start"} = $bucket_seconds_offset 
     1093              if (!defined $data->{day}->[$day]->{"already_missing_".$pol."_start"}); 
     1094            $data->{day}->[$day]->{"already_missing_".$pol."_stop"} = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
    10991095 
    11001096            $data->{day}->[$day]->{day_ok} = 0 if ($data->{day}->[$day]->{missing_peak} > $policy{peak_max_missing}); 
     
    11051101        } 
    11061102 
     1103        # finished all timeslots in this channel. 
    11071104        # if we have missing data queued up, push it now 
    1108         if ($already_missing ne "") { 
    1109             $already_missing .= sprintf "-%02d:%02d", 
    1110               int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
    1111               if ($already_missing_last ne ""); 
    1112             push(@{($data->{missing_all})}, $already_missing); 
    1113             $already_missing = ""; 
    1114             $already_missing_last = ""; 
    1115         } 
    1116  
    1117         my $statusstring = sprintf "ch %s: %s (%s)%s",  
    1118           $ch, pretty_duration($data->{have}), $data->{data_ok} ? "pass" : "fail", 
    1119           ($data->{missing} ? " missing" : ""); 
     1105        &dump_already_missing($data); 
     1106 
     1107        # fill in any last missing period data 
     1108        foreach my $day (@{($data->{day})}) { 
     1109            &dump_already_missing_period($day,"peak"); 
     1110            &dump_already_missing_period($day,"nonpeak"); 
     1111            &dump_already_missing_period($day,"other"); 
     1112        } 
     1113 
     1114        my $statusstring = sprintf " > ch %s: %s programming: %s\n",  
     1115          $ch, pretty_duration($data->{have}), 
     1116          $data->{data_ok} ? "PASS (within thresholds)" : "FAIL, missing data over policy threshold:"; 
    11201117 
    11211118        # display per-day missing data statistics 
    11221119        foreach my $day (@{($data->{day})}) { 
    1123             if ($day->{missing} > 0) { 
    1124                 $statusstring .= sprintf " #%d(",$day->{num}; 
     1120            unless ($day->{day_ok}) { 
     1121                $statusstring .= sprintf "\t".(strftime("%a %e %b",localtime($policy{starttime}+($day->{num}*86400)))).": "; 
    11251122 
    11261123                # do we have any data for this day? 
    1127                 if ($day->{have}) { 
    1128                     $statusstring .= sprintf "%s peak",pretty_duration($day->{missing_peak}) 
    1129                       if ($day->{missing_peak}); 
    1130  
    1131                     $statusstring .= sprintf "%s%s non-peak", 
    1132                       ($day->{missing_peak} ? ", " : ""), 
    1133                       pretty_duration($day->{missing_nonpeak},$policy{nonpeak_max_missing}) 
    1134                       if ($day->{missing_nonpeak}); 
    1135  
    1136                     $statusstring .= sprintf "%s%s other", 
    1137                       (($day->{missing_peak} + $day->{missing_nonpeak}) > 0 ? ", " : ""), 
    1138                       pretty_duration($day->{missing_other},$policy{other_max_missing}) 
    1139                       if ($day->{missing_other} > 0); 
    1140                 } else { 
    1141                     $statusstring .= "all[!]"; 
    1142                 } 
    1143  
    1144                 $statusstring .= ")"; 
     1124                $statusstring .= "peak ".join(", ",(@{($day->{missing_peak_table})})) 
     1125                  if (($day->{missing_peak}) && ($day->{missing_peak} > $policy{peak_max_missing})); 
     1126 
     1127                $statusstring .= sprintf "%snon-peak %s", 
     1128                  ($day->{missing_peak} ? " / " : ""), 
     1129                  join(", ",(@{($day->{missing_nonpeak_table})})) 
     1130                  if (($day->{missing_nonpeak}) && ($day->{missing_nonpeak} > $policy{nonpeak_max_missing})); 
     1131 
     1132                $statusstring .= sprintf "%sother %s", 
     1133                  (($day->{missing_peak} + $day->{missing_nonpeak}) > 0 ? " / " : ""), 
     1134                  join(", ",(@{($day->{missing_other_table})})) 
     1135                  if (($day->{missing_other}) && ($day->{missing_other} > $policy{other_max_missing})); 
     1136 
     1137                $statusstring .= "\n"; 
    11451138            } 
    11461139        } 
    1147         &log(" > $statusstring\n") unless $quiet; 
    1148  
    1149         &log("[debug] Missing the following bucket slots for this $ch: ". 
    1150           join(" ",(@{($data->{missing_all})}))."\n") 
    1151           if ($data->{missing} > 0); 
     1140        &log($statusstring) unless $quiet; 
    11521141 
    11531142        delete $channel_data->{$ch}->{analysis} if (defined $channel_data->{$ch}->{analysis}); 
     
    11561145 
    11571146    &log((sprintf " > OVERALL: %s\n", ($overall_data_ok ? "PASS" : "FAIL"))) unless $quiet; 
     1147 
    11581148    return $overall_data_ok; # return 1 for good, 0 for need more 
    11591149} 
    11601150 
     1151# helper routine for filling in 'missing_all' array 
     1152sub dump_already_missing 
     1153{ 
     1154    my $d = shift; 
     1155    if (defined $d->{already_missing}) { 
     1156        $d->{already_missing} .= sprintf "-%02d:%02d", 
     1157          int($d->{already_missing_last} / 3600), 
     1158          int(($d->{already_missing_last} % 3600) / 60) 
     1159          if (defined $d->{already_missing_last}); 
     1160        push(@{($d->{missing_all})}, $d->{already_missing}); 
     1161        delete $d->{already_missing}; 
     1162        delete $d->{already_missing_last}; 
     1163    } 
     1164} 
     1165 
     1166# helper routine for filling in per-day missing data 
     1167# specific to peak/nonpeak/other 
     1168sub dump_already_missing_period 
     1169{ 
     1170    my ($d,$p) = @_; 
     1171    my $startvar = "already_missing_".$p."_start"; 
     1172    my $stopvar = "already_missing_".$p."_stop"; 
     1173 
     1174    if (defined $d->{$startvar}) { 
     1175        push(@{($d->{"missing_".$p."_table"})}, 
     1176          sprintf "%02d:%02d-%02d:%02d", 
     1177            int($d->{$startvar} / 3600), 
     1178            int(($d->{$startvar} % 3600) / 60), 
     1179            int($d->{$stopvar} / 3600), 
     1180            int(($d->{$stopvar} % 3600) / 60)); 
     1181        delete $d->{$startvar}; 
     1182        delete $d->{$stopvar}; 
     1183    } 
     1184} 
    11611185 
    11621186# given a duration (seconds), return it in a pretty "{days}d{hr}h{min}m" string 
     
    11661190    my ($d,$crit) = @_; 
    11671191    my $s = ""; 
    1168     $s .= sprintf "%dd",int($d / (60*60*24)) if ($d > (60*60*24)); 
    1169     $s .= sprintf "%dh",int(($d % (60*60*24)) / (60*60)) if (($d % (60*60*24)) > (60*60)); 
    1170     $s .= sprintf "%dm",int(($d % (60*60)) / 60) if (($d % (60*60)) > 60); 
    1171     $s .= "no data[!]" if ($s eq ""); 
     1192    $s .= sprintf "%dd",int($d / (60*60*24)) if ($d >= (60*60*24)); 
     1193    $s .= sprintf "%dh",int(($d % (60*60*24)) / (60*60)) if (($d % (60*60*24)) >= (60*60)); 
     1194    $s .= sprintf "%dm",int(($d % (60*60)) / 60) if (($d % (60*60)) >= 60); 
     1195    $s .= "no" if ($s eq ""); 
    11721196 
    11731197    if (defined $crit) { 
     
    17761800    printf "Logging to $log_file.\n"; 
    17771801    open(LOG_FILE,">$log_file") || die "can't open log file $log_file for writing: $!\n"; 
     1802 
     1803    my $now = localtime(time); 
     1804    printf LOG_FILE "$progname version $version started at $now\n\n"; 
    17781805} 
    17791806