source: custom/convert_data.php

Last change on this file was 6, checked in by george, 17 years ago

Přepracovaná vývojová verze s oddělenými datovými tabulkami a různými datovými typy.

File size: 1.4 KB
Line 
1<?php
2
3include('../global.php');
4
5$Database->select_db('measure');
6$Result = $Database->select('measure', '*', 'DataTable != "data"');
7while($Measure = $Result->fetch_array())
8{
9 echo($Measure['Description'].'<br>');
10
11 $Database->query("
12CREATE TABLE IF NOT EXISTS `".$Measure['DataTable']."` (
13 `time` datetime NOT NULL default '0000-00-00 00:00:00',
14 `measure` smallint(11) NOT NULL default '0',
15 `min` ".$Measure['DataType']." NOT NULL default '0',
16 `avg` ".$Measure['DataType']." NOT NULL default '0',
17 `max` ".$Measure['DataType']." NOT NULL default '0',
18 `continuity` tinyint(1) NOT NULL default '0',
19 `level` tinyint(4) NOT NULL default '0',
20 KEY `time` (`time`)
21) ENGINE=MyISAM DEFAULT CHARSET=latin2;
22");
23 $Database->query('TRUNCATE TABLE `'.$Measure['DataTable'].'`');
24
25 $Database->query('INSERT INTO '.$Measure['DataTable'].' SELECT * FROM data WHERE measure='.$Measure['Id']);
26 $Database->query('INSERT INTO '.$Measure['DataTable'].' SELECT * FROM data_cache WHERE measure='.$Measure['Id']);
27 if($Measure['Divider'] == 100)
28 {
29 $Database->query('UPDATE '.$Measure['DataTable'].' SET min=min / '.$Measure['Divider'].', avg=avg /'.$Measure['Divider'].', max=max /'.$Measure['Divider']);
30 }
31 if($Measure['Divider'] == 1000000000)
32 {
33 $Database->query('UPDATE '.$Measure['DataTable'].' SET min=min * 1000000, avg=avg *1000000, max=max * 1000000');
34 }
35}
36
37?>
Note: See TracBrowser for help on using the repository browser.