Changeset 655 for trunk/Modules/TimeMeasure/Measure.php
- Timestamp:
- May 11, 2014, 4:28:01 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/TimeMeasure/Measure.php
r569 r655 11 11 var $DivisionCount = 500; 12 12 var $ValueTypes = array('Min', 'Avg', 'Max'); 13 13 14 14 function Load($Id) 15 15 { … … 22 22 } else throw new Exception('Measure not found'); 23 23 } 24 24 25 25 function TimeSegment($Base, $Level) 26 26 { … … 48 48 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2'); 49 49 //echo($Database->LastQuery."\n"); 50 if($Result->num_rows == 0) 51 { 52 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0)); 50 if($Result->num_rows == 0) 51 { 52 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => 0)); 53 53 //echo($Database->LastQuery."\n"); 54 54 } else if($Result->num_rows == 1) … … 61 61 $NextToLastValue = $Result->fetch_assoc(); 62 62 //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['Time']).' '.($Time - MysqlDateTimeToTime($LastValue['Time'])).' = '.$Measure['Period']."\n"); 63 if((($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))64 { 63 if((($Time - MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0)) 64 { 65 65 echo('Too short period\n'); 66 66 } else 67 67 { 68 if(($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1;68 if(($Time - MysqlDateTimeToTime($LastValue['Time'])) < 1.25 * $this->Data['Period']) $Continuity = 1; 69 69 else $Continuity = 0; 70 70 echo('('.$LastValue['Avg'].'=='.$NextToLastValue['Avg'].') and ('.$LastValue['Avg'].' == '.$Value.') and ('.$LastValue['Continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); 71 71 if(($LastValue['Min'] == $NextToLastValue['Min']) and ($LastValue['Min'] == $Value['Min']) and ($LastValue['Avg'] == $NextToLastValue['Avg']) and ($LastValue['Avg'] == $Value['Avg']) and ($LastValue['Max'] == $NextToLastValue['Max']) and ($LastValue['Max'] == $Value['Max']) and ($LastValue['Continuity'] == 1) and ($Continuity == 1)) 72 72 { 73 $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$ Measure['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));73 $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time))); 74 74 //echo($this->Database->LastQuery."\n"); 75 75 } else … … 77 77 $this->Database->insert($this->Data['DataTable'], array('Min' => $Value['Min'], 'Avg' => $Value['Avg'], 'Max' => $Value['Max'], 'Level' => $Level, 'Measure' => $this->Data['Id'], 'Time' => $this->Database->TimeToMysqlDateTime($Time), 'Continuity' => $Continuity)); 78 78 } 79 } 79 } 80 80 81 81 // Update next level … … 95 95 $Values = array(); 96 96 //.'" AND Time < "'.TimeToMysqlDateTime($EndTime).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time'); 97 $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'. $this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time');97 $Result = $this->Database->select($this->Data['DataTable'], '*', '(Time > "'.TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND (Measure='.$this->Data['Id'].') AND (Level='.($Level - 1).') ORDER BY Time'); 98 98 while($Row = $Result->fetch_assoc()) 99 99 { 100 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);100 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 101 101 $Values[] = $Row; 102 102 } … … 108 108 // Load subsidary values 109 109 print_r($Values); 110 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime)); 110 $Values = array_merge($this->LoadLeftSideValue($Level - 1, $this->Data, 111 $StartTime), $Values, $this->LoadRightSideValue($Level - 1, $EndTime)); 111 112 print_r($Values); 112 113 … … 114 115 //print_r($Point); 115 116 116 $this->Database->delete($this->Data['DataTable'], '(Time > "'.$this->Database->TimeToMysqlDateTime($StartTime).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level); 117 $this->Database->delete($this->Data['DataTable'], '(Time > "'.TimeToMysqlDateTime($StartTime). 118 '") AND (Time < "'.TimeToMysqlDateTime($EndTime).'") AND Measure='.$this->Data['Id'].' AND Level='.$Level); 117 119 $this->Data['Period'] = $TimeSegment; 118 $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'], 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2); 120 $this->AddValue(array('Min' => $Point['Min'], 'Avg' => $Point['Avg'], 121 'Max' => $Point['Max']), $Level, $StartTime + ($EndTime - $StartTime) / 2); 119 122 } 120 123 } … … 180 183 } 181 184 } 182 } 183 else if($ValueType == 'Min') 184 { 185 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 185 } 186 else if($ValueType == 'Min') 187 { 188 //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>'); 186 189 if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled']) 187 190 { … … 201 204 $NewValue[$ValueType] = $NewValue[$ValueType]; 202 205 } 203 //if(($RightTime - $LeftTime) > 0) 204 if($this->Data['Cumulative'] == 0) 206 //if(($RightTime - $LeftTime) > 0) 207 if($this->Data['Cumulative'] == 0) 205 208 { 206 209 $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime); … … 214 217 { 215 218 // Get first and last time 216 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 219 //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 217 220 $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1'); 218 221 if($Result->num_rows > 0) … … 229 232 } else $AbsoluteRightTime = 0; 230 233 231 if($this->Debug) 232 { 233 echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('. $this->Database->TimeToMysqlDateTime($AbsoluteLeftTime).')<br>');234 echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('. $this->Database->TimeToMysqlDateTime($AbsoluteRightTime).')<br>');234 if($this->Debug) 235 { 236 echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.TimeToMysqlDateTime($AbsoluteLeftTime).')<br>'); 237 echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.TimeToMysqlDateTime($AbsoluteRightTime).')<br>'); 235 238 } 236 239 return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime)); … … 238 241 239 242 function LoadRightSideValue($Level, $Time) 240 { 243 { 241 244 $Result = array(); 242 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');245 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 243 246 if($DbResult->num_rows > 0) 244 247 { 245 248 $Row = $DbResult->fetch_assoc(); 246 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);249 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 247 250 return(array($Row)); 248 251 } else … … 251 254 //array_push($Values, array('Time' => $Time, 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 252 255 $Result[] = array('Time' => ($Time + $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 253 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.$this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 256 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'. 257 TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 254 258 if($DbResult->num_rows > 0) 255 259 { 256 260 $Row = $DbResult->fetch_assoc(); 257 array_unshift($Result, array('Time' => ( $this->Database->MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));261 array_unshift($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) + 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 258 262 } 259 263 // if($Debug) print_r($Result); … … 266 270 $Result = array(); 267 271 //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'Time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY Time DESC LIMIT 1'."<br>\n"); 268 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1');272 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time < "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 1'); 269 273 if($DbResult->num_rows > 0) 270 274 { 271 275 $Row = $DbResult->fetch_assoc(); 272 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);276 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 273 277 return(array($Row)); 274 278 } else … … 279 283 $Result[] = array('Time' => ($Time - $this->TimeSegment($this->Data['Period'], $Level)), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0); 280 284 281 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'. $this->Database->TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1');285 $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.TimeToMysqlDateTime($Time).'" AND Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time ASC LIMIT 1'); 282 286 if($DbResult->num_rows > 0) 283 287 { 284 288 $Row = $DbResult->fetch_assoc(); 285 array_push($Result, array('Time' => ( $this->Database->MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0));289 array_push($Result, array('Time' => (MysqlDateTimeToTime($Row['Time']) - 10), 'Min' => 0, 'Avg' => 0, 'Max' => 0, 'Continuity' => 0)); 286 290 } 287 291 // if($Debug) print_r($Result); … … 292 296 function GetValues($TimeFrom, $TimeTo, $Level) 293 297 { 294 if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('. $this->Database->TimeToMysqlDateTime($TimeFrom).')<br>');295 if($this->Debug) echo('TimeTo: '.$TimeTo.'('. $this->Database->TimeToMysqlDateTime($TimeTo).')<br>');298 if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.TimeToMysqlDateTime($TimeFrom).')<br>'); 299 if($this->Debug) echo('TimeTo: '.$TimeTo.'('.TimeToMysqlDateTime($TimeTo).')<br>'); 296 300 297 301 //$AbsoluteTime = GetTimeRange($MeasureId); 298 302 299 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 303 // if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 300 304 // ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime)) 301 305 // { 302 306 303 307 // Load values in time range 304 $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'.$this->Database->TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'.$this->Database->TimeToMysqlDateTime($TimeTo).'") AND (Measure='.$this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time'); 308 $Result = $this->Database->select($this->Data['DataTable'], 'Time, Min, Avg, Max, Continuity', '(Time > "'. 309 TimeToMysqlDateTime($TimeFrom).'") AND (Time < "'. 310 TimeToMysqlDateTime($TimeTo).'") AND (Measure='. 311 $this->Data['Id'].') AND (Level='.$Level.') ORDER BY Time'); 305 312 // echo($Level.' '.TimeToMysqlDateTime($TimeFrom).' '.TimeToMysqlDateTime($TimeTo)); 306 313 $Values = array(); … … 311 318 // echo($III.' '.$Row['Time'].' '.memory_get_usage().','); 312 319 // $III++; 313 $Values[] = array('Time' => $this->Database->MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'], 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']); 320 $Values[] = array('Time' => MysqlDateTimeToTime($Row['Time']), 'Min' => $Row['Min'], 321 'Avg' => $Row['Avg'], 'Max' => $Row['Max'], 'Continuity' => $Row['Continuity']); 314 322 } 315 323 // array_pop($Values); … … 317 325 // die(); 318 326 if($this->Debug) echo('Item count: '.count($Values)); 319 327 320 328 $Points = array(); 321 329 if(count($Values) > 0) … … 385 393 while($Row = $DbResult->fetch_assoc()) 386 394 { 387 $Row['Time'] = $this->Database->MysqlDateTimeToTime($Row['Time']);395 $Row['Time'] = MysqlDateTimeToTime($Row['Time']); 388 396 $Values[] = $Row; 389 397 } … … 416 424 // Load values in time range 417 425 //array_pop($NextValues); 418 } 426 } 419 427 echo("Uroven dokoncena<br>\n"); 420 428 $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', 'Level='.$Level.' AND Measure='.$this->Data['Id']);
Note:
See TracChangeset
for help on using the changeset viewer.