1 | <?php |
||
10 | class Sensor extends Model |
||
11 | { |
||
12 | use LogsActivity; |
||
13 | |||
14 | protected $table = 'sensors'; |
||
15 | |||
16 | /** |
||
17 | * Update the updated_at and created_at timestamps? |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | public $timestamps = false; |
||
22 | |||
23 | /** |
||
24 | * The attributes that are mass assignable. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $fillable = array('device_id', 'name', 'type'); |
||
29 | |||
30 | /** |
||
31 | * The attributes that are visible. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $visible = array('id', 'device_id', 'name', 'type'); |
||
36 | |||
37 | /** |
||
38 | * The attributes to log in the Activity Log |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected static $logAttributes = array('id', 'device_id', 'name', 'type'); |
||
43 | |||
44 | /** |
||
45 | * Only log those that have actually changed after the update. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected static $logOnlyDirty = true; |
||
50 | |||
51 | /** |
||
52 | * Get the device associated with the sensor. |
||
53 | */ |
||
54 | public function device() |
||
58 | |||
59 | /** |
||
60 | * Get the sensor data associated with the sensor. |
||
61 | */ |
||
62 | public function data() |
||
66 | |||
67 | /** |
||
68 | * Get the latest sensor data entry associated with the sensor. |
||
69 | */ |
||
70 | public function getLatestDataAttribute() |
||
74 | |||
75 | /** |
||
76 | * Get the last hour's sensor data averaged by the minute for the sensor. |
||
77 | */ |
||
78 | public function getLastHourMinutelyAvgDataAttribute() |
||
86 | |||
87 | /** |
||
88 | * Get the last day's sensor data averaged hourly for the sensor. |
||
89 | */ |
||
90 | public function getLastDayHourlyAvgDataAttribute() |
||
98 | |||
99 | /** |
||
100 | * Get the last weeks's sensor data averaged daily for the sensor. |
||
101 | */ |
||
102 | public function getLastWeekDailyAvgDataAttribute() |
||
110 | |||
111 | /** |
||
112 | * Get the last months's sensor data averaged daily for the sensor. |
||
113 | */ |
||
114 | public function getLastMonthDailyAvgDataAttribute() |
||
122 | |||
123 | /** |
||
124 | * Get the last year's sensor data averaged monthly for the sensor. |
||
125 | */ |
||
126 | public function getLastYearMonthlyAvgDataAttribute() |
||
134 | } |