Changeset 228
- Timestamp:
- 07/31/08 08:45:46
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
obskml/trunk/QAQC/CalcPlatformUptimePercentage.pl
r217 r228 1 1 ####################################################################################################### 2 2 #Revisions 3 #Rev: 1.2.0.0 4 #Author: DWR 5 #Changes: Added handling of time zones. The data is stamped in GMT in the database, so we want to be able to move the time 6 # frame to be EST for us east coasters. 7 # Added command line option -TimeZone to allow for compensation away from GMT. 8 # 9 #Sub: TabulatePlatformResults() 10 #Changes: Added a query URL to allow the ability to drill down on a sensor/platform to see the data for the time period. 11 # 3 12 #Rev: 1.1.0.0 4 13 #Author: DWR … … 30 39 #of shell commands. 31 40 32 use constant MICROSOFT_PLATFORM => 1;41 use constant MICROSOFT_PLATFORM => 0; 33 42 34 43 #1 enables the various debug print statements, 0 turns them off. 35 44 use constant USE_DEBUG_PRINTS => 0; 36 45 46 use constant SECONDS_PER_DAY => ( 24 * 60 * 60 ); 37 47 ###path config############################################# 38 48 my $strDBName = ''; … … 59 69 "TstProfFeed=s", 60 70 "UpdateDatabase:s", 61 "Date:s" ); 71 "Date:s", 72 "TimeZone:s" ); 62 73 63 74 my $strWorkingDir = $CommandLineOptions{"WorkingDir"}; … … 72 83 "--TstProfFeed provides the url where the test_profiles.xml file resides.\n". 73 84 "--UpdateDatabase specifies if the metrics table in the database is to be updated. Values are \"yes\" to update, or \"no\". This value is optional, default is \"no\" \n". 74 "--Date specifies the day, in YYYY-MM-DD format, to get the stats for, this is optional and if not provided the default is the last full day( date '1 day ago')\n" ); 85 "--Date specifies the day, in YYYY-MM-DD format, to get the stats for, this is optional and if not provided the default is the last full day( date '1 day ago')\n". 86 "--TimeZone optional timezone argument. The data dates in the DB are all in GMT. Options are EASTERN, CENTRAL, MOUNTAIN, PACIFIC. Default is EASTERN."); 87 75 88 } 76 89 #Optional command line arguments. … … 82 95 83 96 my $strDate = $CommandLineOptions{"Date"}; 97 #DWR v1.2.0.0 98 my $strEndDate; 84 99 if( !length( $strDate ) ) 85 100 { … … 88 103 $strDate = `date --d=\"1 days ago\" +%Y-%m-%d`; 89 104 chomp( $strDate ); 105 106 $strEndDate = `date +%Y-%m-%d`; 107 chomp( $strEndDate ); 90 108 } 91 109 else … … 93 111 $strDate = `\\UnixUtils\\usr\\local\\wbin\\date.exe --d=\"1 days ago\" +%Y-%m-%d`; 94 112 chomp( $strDate ); 113 114 $strEndDate = `\\UnixUtils\\usr\\local\\wbin\\date.exe +%Y-%m-%d`; 115 chomp( $strEndDate ); 95 116 } 96 117 } 97 118 my $strTimeZone = $CommandLineOptions{"TimeZone"}; 119 if( length( $strTimeZone ) == 0 ) 120 { 121 $strTimeZone = 'EASTERN'; 122 } 98 123 ########################################################### 99 124 … … 179 204 180 205 181 my $strBeginDateRange = $strDate.'T00:00:00'; 182 my $strEndDateRange = $strDate.'T24:00:00'; 206 ######################################################################################################### 207 #DWR v1.2.0.0 208 #Add support for time zone handling. 209 210 #if you want to reference other time zones, add them here 211 my %time_zone = ('GMT',0,'EST',-5,'EDT',-4,'CST',-6,'CDT',-5,'MST',-7,'MDT',-6,'PST',-8,'PDT',-7); 212 #print 'time_zone='.$time_zone{$strTimeZone}."\n"; 213 214 #daylight savings time consideration 215 my ($temp_sec,$temp_min,$temp_hour,$temp_mday,$temp_mon,$temp_year,$temp_wday,$temp_yday,$isdst) = localtime(time); 216 217 #correct $strTimeZone depending on whether $isdst is set for EASTERN,etc 218 if ($strTimeZone eq 'EASTERN') 219 { 220 if ($isdst) 221 { 222 $strTimeZone = 'EDT'; 223 } 224 else 225 { 226 $strTimeZone = 'EST'; 227 } 228 } 229 if ($strTimeZone eq 'CENTRAL') 230 { 231 if ($isdst) 232 { 233 $strTimeZone = 'CDT'; 234 } 235 else 236 { 237 $strTimeZone = 'CST'; 238 } 239 } 240 if ($strTimeZone eq 'MOUNTAIN') 241 { 242 if ($isdst) 243 { 244 $strTimeZone = 'MDT'; 245 } 246 else 247 { 248 $strTimeZone = 'MST'; 249 } 250 } 251 if ($strTimeZone eq 'PACIFIC') 252 { 253 if ($isdst) 254 { 255 $strTimeZone = 'PDT'; 256 } 257 else 258 { 259 $strTimeZone = 'PST'; 260 } 261 } 262 my $iTimeZoneShift = -1*$time_zone{$strTimeZone}; 263 264 ######################################################################################################### 183 265 184 266 my %PlatformIDs; … … 205 287 my $iUpdateInterval = sprintf( "%d", $obs->find('UpdateInterval') ); 206 288 207 my $strStart = $strDate."T00:00:00"; 208 my $strEnd = $strDate."T24:00:00"; 209 QueryPlatformSensorReportCount( $DB, $strPlatformID, $strStart, $strEnd, $strObsName, $iUpdateInterval, \%PlatformIDs ); 289 my $strStart = $strDate.'T00:00:00'; 290 my $strEnd = $strEndDate.'T00:00:00'; 291 #DWR v1.2.0.0 292 #Added $iTimeZoneShift to compensate for time zones. Measurements in the DB are all stored in GMT. 293 QueryPlatformSensorReportCount( $DB, $strPlatformID, $strStart, $strEnd, $strObsName, $iUpdateInterval, \%PlatformIDs, $iTimeZoneShift ); 210 294 }#obstypes 211 295 #PlotPlatformResults( $DB, $strPlatformID, \%PlatformIDs, $strWorkingDir ); … … 244 328 # 5. $SensorIDs is a reference to a hash which will be populated as: key=Sensor ID from sensor.m_type_id column, value=Sensor Name from sensor.short_name column. 245 329 ######################################################################################################################## 246 sub QueryReportingSensorsForPlatform #( $DB, $strPlatformID, $strStartDate, $strEndDate, \%SensorIDs ) 330 =comment 331 sub QueryReportingSensorsForPlatform #( $DB, $strPlatformID, $strStartDate, $strEndDate, \%SensorIDs, $iTimeZoneShift ) 247 332 { 248 333 my $DBI = shift @_; … … 251 336 my $strEndDate = shift @_; 252 337 my $SensorIDs = shift @_; 253 338 my $iTimeZoneShift= shift @_; 339 340 #m_date >= '$strStartDate' AND m_date < '$strEndDate' AND 341 254 342 my $strSQL = "SELECT DISTINCT(sensor.m_type_id), sensor.short_name 255 343 FROM multi_obs 256 344 LEFT JOIN sensor on sensor.row_id=multi_obs.sensor_id 257 WHERE m_date >= '$strStartDate' AND m_date < '$strEndDate' AND platform_handle = '$strPlatform' 345 WHERE 346 WHERE datetime(m_date) >= datetime('$strStartDate','-$iTimeZoneShift hours') AND 347 datetime(m_date) < datetime('$strEndDate','-$iTimeZoneShift hours') AND 348 platform_handle = '$strPlatform' 258 349 ORDER BY sensor.row_id ASC;"; 259 350 … … 277 368 return( $iCnt ); 278 369 } 279 370 =cut 280 371 ######################################################################################################################## 281 372 # QueryPlatformSensorReportCount … … 288 379 # 6. $PlatformInfo is a reference to a hash which will be populated with per platform/sensor information. 289 380 ######################################################################################################################## 290 sub QueryPlatformSensorReportCount #( $DB, $strPlatformID, $strStart, $strEnd, $strSensorName, $iUpdateInterval, \%PlatformIDs )291 { 292 my ( $DB, $strPlatformID, $strStart, $strEnd, $strSensorName, $iUpdateInterval, $PlatformIDs ) = @_;381 sub QueryPlatformSensorReportCount #( $DB, $strPlatformID, $strStart, $strEnd, $strSensorName, $iUpdateInterval, \%PlatformIDs, $iTimeZoneShift ) 382 { 383 my ( $DB, $strPlatformID, $strStart, $strEnd, $strSensorName, $iUpdateInterval, $PlatformIDs,$iTimeZoneShift ) = @_; 293 384 294 385 #This query will return the number of entries of the sensor type given for the given platform and date range. 295 386 #In other words how many times do we have an entry for that sensor for that platform during that date/time interval. 387 # m_date >= '$strStart' AND m_date < '$strEnd' AND 388 389 #DWR v1.2.0.0 390 #Added time zone adjustment into WHERE clause for start/end date range. 296 391 my $strSQL = "SELECT COUNT( sensor.m_type_id ) 297 392 FROM multi_obs 298 393 LEFT JOIN sensor on sensor.row_id=multi_obs.sensor_id 299 WHERE platform_handle = '$strPlatformID' AND m_date >= '$strStart' AND m_date < '$strEnd' AND sensor.short_name = '$strSensorName';"; 394 WHERE 395 platform_handle = '$strPlatformID' AND 396 sensor.short_name = '$strSensorName' AND 397 datetime(m_date) >= datetime('$strStart','$iTimeZoneShift hours') AND 398 datetime(m_date) < datetime('$strEnd','$iTimeZoneShift hours');"; 300 399 301 400 my $hSt = $DB->prepare( $strSQL ); … … 514 613 my $fSensorAvg = 0; 515 614 my $iMaxCnt = 0; 615 616 #DWR v1.2.0.0 617 #Build link to query data for sensor 618 my $strURL = 'http://nautilus.baruch.sc.edu/~dramage_prod/cgi-bin/DumpPlatformSensorReport.php?'; 619 516 620 if( $iRowCnt == 0 ) 517 621 { … … 552 656 #DWR v1.1.0.0 553 657 my $fAvg = $fSensorAvg / $iDayCnt; 658 if( $iUpdateInterval == 0 ) 659 { 660 $iUpdateInterval = 1; 661 } 554 662 $fSensorAvg = ($fAvg / $iUpdateInterval) * 100.0 ; 555 663 if( $iSensorCnt == 0 ) … … 561 669 $strRow = $strRow.','; 562 670 } 671 #DWR v1.2.0.0 672 #Build the url for our drill down into the database for this platform/sensor data. 673 my $iUpdatesInSeconds = SECONDS_PER_DAY / $iUpdateInterval; 674 $strURL .= "PLATFORMID=$strPlatformID&OBSERVATION=$Sensor&UPDATEINTERVAL=$iUpdatesInSeconds&STARTDATE=$strDate&ENDDATE=$strEndDate&TIMEZONE=EASTERN"; 563 675 my $strSensorAvg = sprintf( "%.2f",$fSensorAvg ); 564 $strRow = $strRow."$strSensorAvg($fAvg/$iUpdateInterval)"; 676 $strRow = $strRow."$strSensorAvg($fAvg/$iUpdateInterval);$strURL"; 677 565 678 if( $iUpdateDatabase ) 566 679 { 567 680 AddRecordToDatabase( $DB, $strPlatformID, $Sensor, $strSensorAvg, $strStartDate ); 568 681 } 682 569 683 $iSensorCnt++; 570 684 }#foreach sensor
