Changeset 46 for trunk/Application/Model


Ignore:
Timestamp:
Jul 27, 2014, 9:05:14 PM (10 years ago)
Author:
chronos
Message:
  • Opraveno: SQL aktualizace 40 plus chybějící tabulka MeasureMethod.
  • Opraveno: Neplatné ukázkové konfigurační soubory.
Location:
trunk/Application/Model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Model/Measure.php

    r45 r46  
    1313  var $DivisionCount = 500;
    1414  var $ValueTypes = array('Min', 'Avg', 'Max');
    15  
     15
    1616  function Load($Id)
    1717  {
     
    2424    } else throw new Exception('Measure not found');
    2525  }
    26  
     26
    2727  function TimeSegment($Base, $Level)
    2828  {
     
    5050    $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time DESC LIMIT 2');
    5151    //echo($Database->LastQuery."\n");
    52     if($Result->num_rows == 0) 
    53     {
    54        $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)); 
     52    if($Result->num_rows == 0)
     53    {
     54       $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));
    5555       //echo($Database->LastQuery."\n");
    5656    } else if($Result->num_rows == 1)
     
    6464      //echo($Level.': '.$Time.' - '.MysqlDateTimeToTime($LastValue['Time']).' '.($Time - MysqlDateTimeToTime($LastValue['Time'])).' = '.$Measure['Period']."\n");
    6565      if((($Time - $this->Database->MysqlDateTimeToTime($LastValue['Time'])) < 0.75 * $this->Data['Period']) and ($Level == 0))
    66       { 
     66      {
    6767        echo('Too short period\n');
    6868      } else
     
    7373        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))
    7474        {
    75           $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$Measure['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
     75          $this->Database->update($this->Data['DataTable'], '(Time="'.$LastValue['Time'].'") AND (Level='.$Level.') AND (Measure='.$this->Data['Id'].')', array('Time' => $this->Database->TimeToMysqlDateTime($Time)));
    7676          //echo($this->Database->LastQuery."\n");
    7777        } else
     
    7979          $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));
    8080        }
    81       } 
     81      }
    8282
    8383      // Update next level
     
    8585      {
    8686        $Level = $Level + 1;
    87         //echo('Level '.$Level."<br>\n");
     87        //echo('Level '.$Level."<br/>\n");
    8888        $TimeSegment = $this->TimeSegment($this->Data['Period'], 1);
    8989        $EndTime = $this->AlignTime($Time, $TimeSegment);
     
    9191        $StartTime = $EndTime - $TimeSegment;
    9292
    93         //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br>\n");
     93        //echo(" ".$TimeSegment." ".$StartTime.'-'.$EndTime."<br/>\n");
    9494        //flush();
    9595
     
    127127  {
    128128    $Y = ($Y2 - $Y1) / ($X2 - $X1) * ($X - $X1) + $Y1;
    129     //echo($Y1.'-'.$Y.'-'.$Y2.' '.$X1.'-'.$X.'-'.$X2.'<br>');
     129    //echo($Y1.'-'.$Y.'-'.$Y2.' '.$X1.'-'.$X.'-'.$X2.'<br/>');
    130130    return($Y);
    131131  }
     
    182182            }
    183183          }
    184         } 
    185         else if($ValueType == 'Min') 
    186         {
    187           //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br>');
     184        }
     185        else if($ValueType == 'Min')
     186        {
     187          //echo($Values[$I+1]['continuity'].'=='.$Measure['ContinuityEnabled'].'<br/>');
    188188          if($Values[$I + 1]['Continuity'] == $this->Data['ContinuityEnabled'])
    189189          {
     
    203203      $NewValue[$ValueType] = $NewValue[$ValueType];
    204204    }
    205     //if(($RightTime - $LeftTime) > 0) 
    206     if($this->Data['Cumulative'] == 0) 
     205    //if(($RightTime - $LeftTime) > 0)
     206    if($this->Data['Cumulative'] == 0)
    207207    {
    208208      $NewValue['Avg'] = $NewValue['Avg'] / ($RightTime - $LeftTime);
    209209    }
    210210    return($NewValue);
    211     //echo($NewValue['avg'].'<br>');
     211    //echo($NewValue['avg'].'<br/>');
    212212    //return(array('min' => rand(0,1), 'avg' => $NewValue['avg'], 'max' => rand(0,1)));
    213213  }
     
    216216  {
    217217    // Get first and last time
    218     //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n"); 
     218    //echo($Measure['Id'].','.$Level.','.StatTableName($Level)."\n");
    219219    $Result = $this->Database->select($this->Data['DataTable'], '*', 'Measure='.$this->Data['Id'].' AND Level='.$Level.' ORDER BY Time LIMIT 1');
    220220    if($Result->num_rows > 0)
     
    231231    } else $AbsoluteRightTime = 0;
    232232
    233     if($this->Debug) 
    234     {
    235       echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteLeftTime).')<br>');
    236       echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteRightTime).')<br>');
     233    if($this->Debug)
     234    {
     235      echo('AbsoluteLeftTime: '.$AbsoluteLeftTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteLeftTime).')<br/>');
     236      echo('AbsoluteRightTime: '.$AbsoluteRightTime.'('.$this->Database->TimeToMysqlDateTime($AbsoluteRightTime).')<br/>');
    237237    }
    238238    return(array('Left' => $AbsoluteLeftTime, 'Right' => $AbsoluteRightTime));
     
    240240
    241241  function LoadRightSideValue($Level, $Time)
    242   { 
     242  {
    243243    $Result = array();
    244244    $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');
     
    267267  {
    268268    $Result = array();
    269     //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'Time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY Time DESC LIMIT 1'."<br>\n");
     269    //echo('SELECT * FROM '.StatTableName($Level). ' WHERE '. 'Time < "'.TimeToMysqlDateTime($Time).'" AND measure='.$Measure['Id'].' AND level='.$Level.' ORDER BY Time DESC LIMIT 1'."<br/>\n");
    270270    $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');
    271271    if($DbResult->num_rows > 0)
     
    294294  function GetValues($TimeFrom, $TimeTo, $Level)
    295295  {
    296     if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.$this->Database->TimeToMysqlDateTime($TimeFrom).')<br>');
    297     if($this->Debug) echo('TimeTo: '.$TimeTo.'('.$this->Database->TimeToMysqlDateTime($TimeTo).')<br>');
     296    if($this->Debug) echo('TimeFrom: '.$TimeFrom.'('.$this->Database->TimeToMysqlDateTime($TimeFrom).')<br/>');
     297    if($this->Debug) echo('TimeTo: '.$TimeTo.'('.$this->Database->TimeToMysqlDateTime($TimeTo).')<br/>');
    298298
    299299    //$AbsoluteTime = GetTimeRange($MeasureId);
    300300
    301     //  if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and 
     301    //  if(($TimeFrom > $AbsoluteLeftTime) and ($TimeStart < $AbsoluteRightTime) and
    302302    //    ($TimeTo > $AbsoluteLeftTime) and ($TimeTo < $AbsoluteRightTime))
    303303    //  {
     
    319319    //  die();
    320320    if($this->Debug) echo('Item count: '.count($Values));
    321  
     321
    322322    $Points = array();
    323323    if(count($Values) > 0)
    324324    {
    325325      $Values = array_merge($this->LoadLeftSideValue($Level, $TimeFrom), $Values, $this->LoadRightSideValue($Level, $TimeTo));
    326       //echo(count($Values).'<br>');
    327       //echo($TimeFrom.','.$TimeTo.'<br>');
    328       //echo($Values[0]['Time'].'<br>');
     326      //echo(count($Values).'<br/>');
     327      //echo($TimeFrom.','.$TimeTo.'<br/>');
     328      //echo($Values[0]['Time'].'<br/>');
    329329      $StartIndex = 0;
    330330      $Points = array();
    331       //echo($DivisionCount.'<br>');
     331      //echo($DivisionCount.'<br/>');
    332332      if($this->Debug) print_r($Values);
    333333      //die();
     
    335335      {
    336336        $TimeStart = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * $I;
    337         //if($Debug) echo('TimeStart '.$I.': '.$TimeStart.'('.TimeToMysqlDateTime($TimeStart).')<br>');
     337        //if($Debug) echo('TimeStart '.$I.': '.$TimeStart.'('.TimeToMysqlDateTime($TimeStart).')<br/>');
    338338        $TimeEnd = $TimeFrom + (($TimeTo - $TimeFrom) / $this->DivisionCount) * ($I + 1);
    339         if($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.$this->Database->TimeToMysqlDateTime($TimeEnd).')<br>');
    340         //echo($TimeStart.','.$TimeEnd.'<br>');
     339        if($this->Debug) echo('TimeEnd '.$I.': '.$TimeEnd.'('.$this->Database->TimeToMysqlDateTime($TimeEnd).')<br/>');
     340        //echo($TimeStart.','.$TimeEnd.'<br/>');
    341341
    342342        $EndIndex = $StartIndex;
     
    344344        //while(($Values[$EndIndex]['Time'] < $TimeEnd)) $EndIndex = $EndIndex + 1;
    345345        $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    346         //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
     346        //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br/>');
    347347        //print_r($SubValues);
    348348        $Points[] = $this->ComputeOneValue($TimeStart, $TimeEnd, $SubValues, $Level);
     
    356356  function RebuildMeasureCache()
    357357  {
    358     echo('Velicina '.$this->Data['Name']."<br>\n");
     358    echo('Velicina '.$this->Data['Name']."<br/>\n");
    359359    if($this->Data['Continuity'] == 0) $this->Data['ContinuityEnabled'] = 0;  // non continuous
    360360      else $this->Data['ContinuityEnabled'] = 2;    // continuous graph
     
    365365    echo("Mazu starou cache (".$Row[0]." polozek)...");
    366366    $this->Database->delete($this->Data['DataTable'], 'Level > 0 AND Measure='.$this->Data['Id']);
    367     echo("<br>\n");
     367    echo("<br/>\n");
    368368
    369369    for($Level = 1; $Level <= $this->MaxLevel; $Level++)
    370370    {
    371       echo('Uroven '.$Level."<br>\n");
     371      echo('Uroven '.$Level."<br/>\n");
    372372      $TimeRange = $this->GetTimeRange($Level - 1);
    373373      //echo($Measure['Id'].','.($Level-1)."\n");
     
    377377      $EndTime = $this->AlignTime($TimeRange['Right'], $TimeSegment);
    378378      $BurstCount = 500;
    379       echo('For 0 to '.round(($EndTime - $StartTime) / $TimeSegment / $BurstCount)."<br>\n");
     379      echo('For 0 to '.round(($EndTime - $StartTime) / $TimeSegment / $BurstCount)."<br/>\n");
    380380      for($I = 0; $I <= round(($EndTime - $StartTime) / $TimeSegment / $BurstCount); $I++)
    381381      {
     
    384384        $EndTime2 = $StartTime + ($I + 1) * $BurstCount * $TimeSegment;
    385385        $Values = array();
    386         $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.$this->Database->TimeToMysqlDateTime($StartTime2).'" AND Time < "'.$this->Database->TimeToMysqlDateTime($EndTime2).'" AND Measure='.$Measure['Id'].' AND Level='.($Level - 1).' ORDER BY Time');
     386        $DbResult = $this->Database->select($this->Data['DataTable'], '*', 'Time > "'.
     387          $this->Database->TimeToMysqlDateTime($StartTime2).'" AND Time < "'.
     388          $this->Database->TimeToMysqlDateTime($EndTime2).'" AND Measure='.$this->Data['Id'].
     389          ' AND Level='.($Level - 1).' ORDER BY Time');
    387390        while($Row = $DbResult->fetch_assoc())
    388391        {
     
    393396        if(count($Values) > 0)
    394397        {
    395           $Values = array_merge($this->LoadLeftSideValue($Level - 1, $StartTime2), $Values, $this->LoadRightSideValue($Level - 1, $Measure, $EndTime2));
     398          $Values = array_merge($this->LoadLeftSideValue($Level - 1, $StartTime2),
     399            $Values, $this->LoadRightSideValue($Level - 1, $EndTime2));
    396400
    397401          $StartIndex = 0;
     
    405409            while($Values[$EndIndex]['Time'] < $EndTime3) $EndIndex = $EndIndex + 1;
    406410            $SubValues = array_slice($Values, $StartIndex, $EndIndex - $StartIndex + 1);
    407             //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br>');
     411            //echo($StartIndex.','.$EndIndex.' '.count($SubValues).'<br/>');
    408412            //print_r($SubValues);
    409413            if(count($SubValues) > 2)
     
    418422        // Load values in time range
    419423        //array_pop($NextValues);
    420       } 
    421       echo("Uroven dokoncena<br>\n");
     424      }
     425      echo("Uroven dokoncena<br/>\n");
    422426      $DbResult = $this->Database->select($this->Data['DataTable'], 'COUNT(*)', 'Level='.$Level.' AND Measure='.$this->Data['Id']);
    423427      $Row = $DbResult->fetch_row();
    424       echo("Vloženo ".$Row[0]." položek.<br>\n");
     428      echo("Vloženo ".$Row[0]." položek.<br/>\n");
    425429    }
    426430  }
     
    441445    {
    442446      $Measure->RebuildMeasureCache();
    443       echo('Velicina dokoncena<br>');
     447      echo('Velicina dokoncena<br/>');
    444448    }
    445449  }
  • trunk/Application/Model/User.php

    r42 r46  
    3838    $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
    3939    $Row = $Query->fetch_assoc();
    40     if($Row['User'] != $this->AnonymousUserId) 
     40    if($Row['User'] != $this->AnonymousUserId)
    4141    {
    4242      $Query = $this->Database->select('User', '*', 'Id='.$Row['User']);
    4343      $this->Data = $Query->fetch_assoc();
    4444      $Result = $this->System->Translate('UserLogged');
    45     } else 
     45    } else
    4646    {
    4747      $Query = $this->Database->select('User', '*', 'Id='.$this->AnonymousUserId);
     
    7575        if($Query->num_rows > 0) $Result = $this->System->Translate('NameUsed');
    7676        else
    77         { 
     77        {
    7878          $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"');
    7979          if($Query->num_rows > 0) $Result = $this->System->Translate('EmailUsed');
     
    8282            $this->Database->insert('User', array('Name' => $Name, 'Login' => $Login, 'Password' => $this->PasswordHash($Login, $Password), 'Email' => $Email, 'RegistrationTime' => 'NOW()', 'Locked' => 1, 'Role' => 2));
    8383            $UserId = $this->Database->insert_id;
    84            
     84
    8585            $Subject = FromUTF8('Registrace nového účtu', 'iso2');
    86             $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/">http://'.$Config['System']['Host'].$Config['System']['RootFolder']."/</a>.<br>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br><br>\n\nVáš účet je: ".$Login."\n<br>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'">http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'</a>.'."\n<br> \n\n<br><br>Na tento email neodpovídejte.";
     86            $Message = 'Provedli jste registraci nového účtu na serveru <a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/">http://'.$Config['System']['Host'].$Config['System']['RootFolder']."/</a>.<br/>\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br/><br/>\n\nVáš účet je: ".$Login."\n<br/>Pro dokončení registrace klikněte na tento odkaz: ".'<a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'">http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=UserRegisterConfirm&User='.$UserId.'&H='.$this->PasswordHash($Login, $Password).'</a>.'."\n<br/> \n\n<br/><br/>Na tento email neodpovídejte.";
    8787            $AdditionalHeaders = "To: ".$Name." <".$Email.">\n"."From: ".FromUTF8($Config['System']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    8888            mail($Email, $Subject, $Message, $AdditionalHeaders);
     
    121121      if($Row['Password'] != $this->PasswordHash($Login, $Password)) $Result = $this->System->Translate('BadPassword');
    122122      else if($Row['Locked'] == 1) $Result = $this->System->Translate('AccountLocked');
    123       else 
    124       {
    125         $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress()));     
     123      else
     124      {
     125        $this->Database->update('User', 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()', 'LastIpAddress' => GetRemoteAddress()));
    126126        $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => $Row['Id']));
    127127        // načtení stavu stromu
     
    185185    // Check group-operation relation
    186186    $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
    187     if($DbResult->num_rows > 0) return(true); 
     187    if($DbResult->num_rows > 0) return(true);
    188188    return(false);
    189189  }
     
    222222
    223223      $Subject = 'Obnova hesla';
    224       $Message = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'">http://'.$Config['System']['Host'].$Config['System']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Login']." je: ".$NewPassword."\n<br>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br><br>Na tento email neodpovídejte.";
     224      $Message = 'Požádali jste o zaslání nového hesla na serveru <a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'">http://'.$Config['System']['Host'].$Config['System']['RootFolder']."</a>.<br />\nPokud jste tak neučinili, měli by jste tento email ignorovat.<br /><br />\n\nVaše nové heslo k účtu ".$Row['Login']." je: ".$NewPassword."\n<br/>Pro aktivaci tohoto hesla klikněte na ".'<a href="http://'.$Config['System']['Host'].$Config['System']['RootFolder'].'/?Action=PasswordRecoveryConfirm&User='.$Row['Id'].'&H='.$Row['Password'].'&P='.$NewPassword.'">tento odkaz</a>.'."\n<br /> Po přihlášení si prosím změňte heslo na nové.\n\n<br/><br/>Na tento email neodpovídejte.";
    225225      $AdditionalHeaders = "To: ".$Row['Name']." <".$Row['Email'].">\n"."From: ".FromUTF8($Config['System']['Title'], 'iso2')." <noreplay@zdechov.net>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=utf-8";
    226226      mail($Row['Email'], $Subject, $Message, $AdditionalHeaders);
     
    247247    return($Output);
    248248  }
    249  
     249
    250250  function ServerCount()
    251251  {
     
    264264      $Total += $Server->RealmCount();
    265265    }
    266     return($Total);   
     266    return($Total);
    267267  }
    268268}
Note: See TracChangeset for help on using the changeset viewer.