Changeset 35
- Timestamp:
- Nov 8, 2008, 10:13:48 PM (16 years ago)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
database.php
r5 r35 7 7 { 8 8 var $Prefix = ''; 9 var $LastQuery = ''; 9 10 11 function query($Query) 12 { 13 $this->LastQuery = $Query; 14 return(parent::query($Query)); 15 } 16 10 17 function select($Table, $What = '*', $Condition = 1) 11 18 { 12 $Query = "SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition; 13 return($this->query($Query)); 19 return($this->query("SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition)); 14 20 } 15 21 -
stat_functions.php
r28 r35 24 24 function TruncateDigits($Value, $Digits = 4) 25 25 { 26 for($II = 2; $II > - 1; $II--)26 for($II = 2; $II > -6; $II--) 27 27 { 28 28 if($Value >= pow(10, $II)) … … 105 105 } 106 106 107 function AddValue($Measure, $Value )107 function AddValue($Measure, $Value = 0, $Time = 0) 108 108 { 109 109 global $LevelReducing, $MaxLevel, $Database; 110 111 $Time = time();110 111 if($Time == 0) $Time = time(); 112 112 //$Value = round($Measure['divider'] * $Value); 113 113 114 echo(TimeToMysqlDateTime($Time)."\n"); 115 114 116 $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 2'); 117 echo($Database->LastQuery."\n"); 115 118 if($Result->num_rows == 0) $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 116 119 'continuity' => 0)); … … 120 123 $LastValue = $Result->fetch_array(); 121 124 $NextToLastValue = $Result->fetch_array(); 122 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 0.75 * $Measure['Period']) 123 { 125 echo($Time.' - '.MysqlDateTimeToTime($LastValue['time']).' '.($Time - MysqlDateTimeToTime($LastValue['time'])).' = '.$Measure['Period']); 126 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 0.75 * $Measure['Period']) 127 { 128 echo('Too short period'); 124 129 } 125 130 else 126 131 { 127 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1; 132 if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1; 128 133 else $Continuity = 0; 129 if(($LastValue['avg'] == $NextToLastValue['avg']) and ($LastValue['avg'] == $Value) and 130 ($LastValue['continuity'] == 1) and ($Continuity == 1)) 131 { 132 //echo('s'); 134 //echo('('.$LastValue['avg'].'=='.$NextToLastValue['avg'].') and ('.$LastValue['avg'].' == '.$Value.') and 135 //('.$LastValue['continuity'].' == 1) and ('.$Continuity.' == 1))'."\n"); 136 if(($LastValue['avg'] == $NextToLastValue['avg']) and ($LastValue['avg'] == $Value) and 137 ($LastValue['continuity'] == 1) and ($Continuity == 1)) 138 { 133 139 $Database->update($Measure['DataTable'], 'time="'.$LastValue['time'].'" AND level=0 AND measure='.$Measure['Id'], array('time' => 'NOW()')); 134 } else 140 echo($Database->LastQuery."\n"); 141 } else 135 142 { 136 143 $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time), 137 'continuity' => $Continuity)); 144 'continuity' => $Continuity)); 145 echo($Database->LastQuery."\n"); 138 146 } 139 147 } 140 } 141 148 } 149 142 150 // Update levels 143 151 //echo($Time."<br>\n"); … … 149 157 //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment; 150 158 $StartTime = $EndTime - $TimeSegment; 151 159 152 160 //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n"); 153 161 //flush(); 154 162 155 163 // Load values in time range 156 164 $Values = array(); … … 170 178 $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level); 171 179 //print_r($Point); 172 180 173 181 $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND 174 182 (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level);
Note:
See TracChangeset
for help on using the changeset viewer.