Changeset 35 for stat_functions.php


Ignore:
Timestamp:
Nov 8, 2008, 10:13:48 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Malé změny ve funkci pro přidávání záznamů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • stat_functions.php

    r28 r35  
    2424function TruncateDigits($Value, $Digits = 4)
    2525{
    26   for($II = 2; $II > -1; $II--)
     26  for($II = 2; $II > -6; $II--)
    2727  {
    2828    if($Value >= pow(10, $II))
     
    105105}
    106106
    107 function AddValue($Measure, $Value)
     107function AddValue($Measure, $Value = 0, $Time = 0)
    108108{
    109109  global $LevelReducing, $MaxLevel, $Database;
    110  
    111   $Time = time();
     110
     111  if($Time == 0) $Time = time();
    112112  //$Value = round($Measure['divider'] * $Value);
    113113
     114  echo(TimeToMysqlDateTime($Time)."\n");
     115 
    114116  $Result = $Database->select($Measure['DataTable'], '*', 'measure='.$Measure['Id'].' AND level=0 ORDER BY time DESC LIMIT 2');
     117  echo($Database->LastQuery."\n");
    115118  if($Result->num_rows == 0) $Database->insert($Measure['DataTable'], array('min' => $Value, 'avg' => $Value, 'max' => $Value, 'level' => 0, 'measure' => $Measure['Id'], 'time' => TimeToMysqlDateTime($Time),
    116119    'continuity' => 0));
     
    120123    $LastValue = $Result->fetch_array();
    121124    $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');
    124129    }
    125130    else
    126131    {
    127       if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1; 
     132      if(($Time - MysqlDateTimeToTime($LastValue['time'])) < 1.25 * $Measure['Period']) $Continuity = 1;
    128133        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      {
    133139        $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
    135142      {
    136143        $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");
    138146      }
    139147    }
    140   } 
    141    
     148  }
     149
    142150    // Update levels
    143151    //echo($Time."<br>\n");
     
    149157      //if($EndTime < $Time) $EndTime = $EndTime + $TimeSegment;
    150158      $StartTime = $EndTime - $TimeSegment;
    151      
     159
    152160      //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n");
    153161      //flush();
    154  
     162
    155163      // Load values in time range
    156164      $Values = array();
     
    170178      $Point = ComputeOneValue($StartTime, $EndTime, $Values, $Measure, $Level);
    171179      //print_r($Point);
    172      
     180
    173181      $Database->delete($Measure['DataTable'], '(time > "'.TimeToMysqlDateTime($StartTime).'") AND
    174182        (time < "'.TimeToMysqlDateTime($EndTime).'") AND measure='.$Measure['Id'].' AND level='.$Level);
Note: See TracChangeset for help on using the changeset viewer.