-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSensor.php
More file actions
53 lines (44 loc) · 1.6 KB
/
Sensor.php
File metadata and controls
53 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @author BreathLess
* @type Library
* @description: Sensor class, ported from OX!
* @package Evil
* @subpackage Sensor
* @version 0.1
* @date 28.11.10
* @time 16:19
*/
class Evil_Sensor
{
public static function track ($type, $source)
{
$sensor = Evil_Structure::getObject('sensor');
// Получить из конфигов частоту трекинга
// Проверить время последнего съема значений
// Снять значение
$sourceClass = Evil_Factory::make('Evil_Sensor_'.$type);
$value = $sourceClass->track($source, array());
// Поместить в БД
$sensor->create('',
array('src'=> $source,
'type'=> $type,
'value'=> $value,
'time'=>time())
);
return $value;
}
public static function get ($type, $source)
{
$sensors = Evil_Structure::getComposite('sensor');
$sensors->where('src','=',$source);
$srcFiltered = $sensors->data('id');
$sensors->where('type','=',$type);
$typeFiltered = $sensors->data('id');
$sensors->load(array_intersect($srcFiltered, $typeFiltered));
$Output = array();
foreach($sensors->_items as $item)
$Output[] = array((int)$item->getValue('time')*1000, (float)$item->getValue('value'));
return $Output;
}
}