Bether Graph generation & covid version 2
This commit is contained in:
		@@ -23,6 +23,9 @@ class CronApi extends ApiController
 | 
			
		||||
		$pluginsFiles = array_diff(scandir($dir), ['..', '.']);
 | 
			
		||||
		foreach ($pluginsFiles as $key => $pluginFile) {
 | 
			
		||||
			$className = str_replace(".php", "", $pluginFile);
 | 
			
		||||
			if (strpos($pluginFile, '_') === true) {
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			if (!class_exists($className)) {
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,20 +19,27 @@ class RoomsApi extends ApiController
 | 
			
		||||
		$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
 | 
			
		||||
		foreach ($subDevicesData as $subDeviceKey => $subDevice) {
 | 
			
		||||
			foreach ($subDevice as $key => $value) {
 | 
			
		||||
				$type = null;
 | 
			
		||||
				if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
 | 
			
		||||
					$type = "";
 | 
			
		||||
					foreach (explode('-', $subDevicesData[$subDeviceKey][$key]['type']) as $word) {
 | 
			
		||||
						$type .= ucfirst($word);
 | 
			
		||||
					}
 | 
			
		||||
					if (!class_exists($type)) {
 | 
			
		||||
						continue;
 | 
			
		||||
					}
 | 
			
		||||
					$deviceClass = new $type;
 | 
			
		||||
					if (!method_exists($deviceClass, 'translate')) {
 | 
			
		||||
						continue;
 | 
			
		||||
					}
 | 
			
		||||
					$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
 | 
			
		||||
					$type = $subDevicesData[$subDeviceKey][$key]['type'];
 | 
			
		||||
				} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
 | 
			
		||||
					$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
 | 
			
		||||
				} else {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				$cammelCaseClass = "";
 | 
			
		||||
				foreach (explode('-', $type) as $word) {
 | 
			
		||||
					$cammelCaseClass .= ucfirst($word);
 | 
			
		||||
				}
 | 
			
		||||
				if (!class_exists($cammelCaseClass)) {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				$deviceClass = new $cammelCaseClass;
 | 
			
		||||
				if (!method_exists($deviceClass, 'translate')) {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -96,13 +96,7 @@ class WidgetApi extends ApiController
 | 
			
		||||
							'type' => 'time',
 | 
			
		||||
							'distribution' => 'linear',
 | 
			
		||||
						]],
 | 
			
		||||
						'yAxes' => [[
 | 
			
		||||
							'ticks' => [
 | 
			
		||||
								'min' => $this->getDeviceConfig($subDeviceData['type'])['min'],
 | 
			
		||||
								'max' => $this->getDeviceConfig($subDeviceData['type'])['max'],
 | 
			
		||||
								'steps' => $this->getDeviceConfig($subDeviceData['type'])['scale'],
 | 
			
		||||
							]
 | 
			
		||||
						]]
 | 
			
		||||
 | 
			
		||||
					],
 | 
			
		||||
					'legend' => [
 | 
			
		||||
						'display' => false
 | 
			
		||||
@@ -119,6 +113,17 @@ class WidgetApi extends ApiController
 | 
			
		||||
			'lastConnectionTime' => (empty($niceTime) ? "00:00" : $niceTime),
 | 
			
		||||
		];
 | 
			
		||||
 | 
			
		||||
		//TODO: Make Cleaner 
 | 
			
		||||
		if (isset(RANGES[$subDeviceData['type']])){
 | 
			
		||||
			$response['graph']['options']['options']['scales']['yAxes'] = [[
 | 
			
		||||
				'ticks' => [
 | 
			
		||||
					'min' => RANGES[$subDeviceData['type']]['min'],
 | 
			
		||||
					'max' => RANGES[$subDeviceData['type']]['max'],
 | 
			
		||||
					'steps' => RANGES[$subDeviceData['type']]['scale'],
 | 
			
		||||
				]
 | 
			
		||||
			]];
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		$this->response($response);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user