На основе предыдущих наработок сделал универсальную функцию, которой можно передавать имя свойства в виде параметра
Пример вызова из сценария:
include_once(DIR_MODULES . 'charts/charts.class.php');
$charts = new charts();
$chartPNG = $charts->getImagefrom_obj('gismeteo.temp','white','area',60,350, 1000);
print('<br>Путь к файлу: ' . $chartPNG . '<br><br>');
print('<img src="' . $chartPNG . '">');
где вместо gismeteo.temp -имя.своство вашего объекта,
white - стиль графика, может быть любой из вариантов (avocado,dark-blue,dark-green,dark-unica,gray,grid-light,grid,high-contrast-dark,high-contrast-light,sand-signika,skies,sunset) https://github.com/highcharts/highcharts/tree/mast...)
area - тип графика, может быть spinline, area....
60 - количество дней, за которое нужно строить график
350 - высота графика, пиксели
1000 - ширина графика, пиксели
Т.о. в телеграмм создаем команды:
//white - стиль графика, может быть любой из вариантов (avocado,dark-blue,dark-green,dark-unica,gray,grid-light,grid,high-contrast-dark,high-contrast-light,sand-signika,skies,sunset) https://github.com/highcharts/highcharts/tree/mast...)
//area - тип графика, может быть spinline, area....
//60 - количество дней, за которое нужно строить график
//350 - высота графика, пиксели
//1000 - ширина графика, пиксели
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$objects=getObjectsByClass("SHumSensors");
foreach($objects as $obj) {
$objj=getObject('Sensor_temphum04');
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
if (gg($obj['TITLE'].".value") ){
// if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
//$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F92A7').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:curve:grid");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F92A7').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:area:green");
}
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
$objects=getObjectsByClass("STempSensors");
//print_r($objects);
foreach($objects as $obj) {
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
// if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
// $option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8CA1').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:curve:green");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F8CA1').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:area:grid");
}
$objects=getObjectsByClass("STempHumSensors");
//print_r($objects);
foreach($objects as $obj) {
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
if (gg($obj['TITLE'].".value") )
//$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8CA1').gg($obj['TITLE'].".value")."°;".hex2bin('F09F92A7').gg($obj['TITLE'].".valueHumidity")."%".$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:curve:green");
$option[] = $telegram_module->buildInlineKeyboardButton(hex2bin('F09F8CA1').gg($obj['TITLE'].".value")."°;".hex2bin('F09F92A7').gg($obj['TITLE'].".valueHumidity")."%".$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:area:sunset");
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
$objects=getObjectsByClass("SGeneralSensors");
//print_r($objects);
foreach($objects as $obj) {
//if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
if (gg($obj['TITLE'].".value") )
// $option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F92A2').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":31:curve:orange");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F92A2').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":31:area:orange");
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
$objects=getObjectsByClass("SCounters");
//print_r($objects);
foreach($objects as $obj) {
//if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
if (gg($obj['TITLE'].".value") )
//$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F939B').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":365:bar:orange");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F939B').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":365:area:orange");
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
$objects=getObjectsByClass("SPressureSensors");
//print_r($objects);
foreach($objects as $obj) {
// if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
if (gg($obj['TITLE'].".value") )
// $option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F90A3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":31:curve:orange");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F90A3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":31:area:orange");
}
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
$objects=getObjectsByClass("SLeak");
//print_r($objects);
foreach($objects as $obj) {
$objj=getObject($obj['TITLE']);
$lr=$objj->description;
if (strlen($lr)>2) {$lr=" (".$lr.")";} else {$lr="";}
// if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
// $option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8EA3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:curve:green");
$option[] = $telegram_module->buildInlineKeyboardButton($text=hex2bin('F09F8EA3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7:area:green");
}
$count_row = 1;
$option = array_chunk($option, $count_row);
$keyb = $telegram_module->buildInlineKeyBoard($option);
$content = array('chat_id' => $chat_id, 'text' => "Датчики: ", 'reply_markup' => $keyb, 'parse_mode' => 'HTML');
$telegram_module->sendContent($content);
И добавляем callback
include_once(DIR_MODULES . 'telegram/telegram.class.php');
if (substr($callback,9,13)== 'sensorhistory')
{
$obj=explode(':',substr($callback,23))[0];
$days=explode(':',substr($callback,23))[1];
$gtype=explode(':',substr($callback,23))[2];
$color=explode(':',substr($callback,23))[3];
if ($days==365) {$px=37; $int= 2592000;}
if ($days==31) {$px=6; $int= 604800;}
//$telegram_module->sendMessageToAll($obj);
$text=$obj.':'.chr(10);
$ar=getHistoryAvgDay($obj, time()-$days*86400, time());
foreach ($ar as $key=>$val)
{
$diff=round($val['VALUE']-$last,2);
if ($last) $difftxt=' ('.$diff.')';
$text.=$val['VALUE']." : ".$val['ADDED'].$difftxt.chr(10);
$last=$val['VALUE'];
}
$telegram_module->sendMessageToAll($text);
include_once(DIR_MODULES . 'charts/charts.class.php');
$charts = new charts();
$chartPNG = $charts->getImageFromObj($obj,'white','area',$d,350, 1000);
$telegram_module->sendImageToAll('.'.$chartPNG);
}
Теперь при запросе параметра в ответе будет прилетать набор данных и график hightcharts.
Основано на предыдущем посте https://connect.smartliving.ru/profile/1502/blog28...
И наработках skysilver https://connect.smartliving.ru/profile/461/blog/ek...
Внимание: данный скрипт будет работать после одобрения https://github.com/sergejey/majordomo-charts/pull/...
Екатеринбург, Россия
На форуме: directman66