Skip to content

Commit

Permalink
Merge pull request #40 from jpty/patch-1
Browse files Browse the repository at this point in the history
Corrections
  • Loading branch information
lunarok authored Oct 14, 2024
2 parents 0f8ba40 + ae5833c commit ad455a7
Showing 1 changed file with 64 additions and 77 deletions.
141 changes: 64 additions & 77 deletions core/class/heliotrope.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class heliotrope extends eqLogic {

public static function pull() {
foreach (eqLogic::byType(__CLASS__, true) as $heliotrope) {
log::add(__CLASS__, 'debug', 'info daily ' . __FUNCTION__);
log::add(__CLASS__, 'debug', __FUNCTION__ .' ' .$heliotrope->getName());
$heliotrope->getInformations();
}
}

public static function cronHourly() {
if (date('G') == 3) {
foreach (eqLogic::byType(__CLASS__, true) as $heliotrope) {
log::add(__CLASS__, 'debug', 'info daily ' . __FUNCTION__);
log::add(__CLASS__, 'debug', __FUNCTION__ .' ' .$heliotrope->getName());
$heliotrope->getDaily();
$heliotrope->getInformations();
}
Expand All @@ -39,15 +39,15 @@ public static function cronHourly() {

public static function start() {
foreach (eqLogic::byType(__CLASS__, true) as $heliotrope) {
log::add(__CLASS__, 'debug', 'info daily ' . __FUNCTION__);
log::add(__CLASS__, 'debug', __FUNCTION__ .' ' .$heliotrope->getName());
$heliotrope->getDaily();
$heliotrope->getInformations();
}
}

public function postUpdate() {
if (is_object($this)) {
// dimensionnement mini des graphiques suivant dimension des tuiles
// dimensionnement mini des graphiques suivant dimension des tuiles
$array = $this->getDisplay('parameters');
if (!is_array($array)) $array = array();
if (!isset($array['elevationWidth'])) $w1 = 0;
Expand All @@ -62,13 +62,9 @@ public function postUpdate() {
$h = intval($this->getDisplay('height'));
log::add(__CLASS__, 'debug', __FUNCTION__ . " [$name] W=$w H=$h\nW1=$w1 H1=$h1 S1=$s1");
if ($h > 400) { // alt on azt
$s1 = 120;
$w1 = $w;
$h1 = $h - 120 - 30;
$s1 = 120; $w1 = $w; $h1 = $h -120 - 30;
} else { // azt to the right of alt
$s1 = 100;
$w1 = $w - 110;
$h1 = $h - 30;
$s1 = 100; $w1 = $w - 110; $h1 = $h - 30;
}
if ($w1 < 100) $w1 = 250;
if ($h1 < 100) $h1 = 200;
Expand All @@ -79,7 +75,7 @@ public function postUpdate() {
$this->setDisplay('parameters', $array);
$this->save();
}
// creation/maj des commandes
// creation/maj des commandes
$eqLogicId = $this->getId();
$heliotropeCmd = heliotropeCmd::byEqLogicIdAndLogicalId($eqLogicId, 'azimuth360');
if (!is_object($heliotropeCmd)) {
Expand Down Expand Up @@ -277,15 +273,15 @@ public function postUpdate() {
}
}

// Return altitude correction for altitude due to atmospheric refraction.
// http://en.wikipedia.org/wiki/Atmospheric_refraction
// Return altitude correction for altitude due to atmospheric refraction.
// http://en.wikipedia.org/wiki/Atmospheric_refraction
public static function correctForRefraction($d) {
if (!($d > -0.5)) $d = -0.5; // Function goes ballistic when negative.
return (0.017 / tan(deg2rad($d + 10.3 / ($d + 5.11))));
}

// Return the right ascension of the sun at Unix epoch t.
// http://bodmas.org/kepler/sun.html
// Return the right ascension of the sun at Unix epoch t.
// http://bodmas.org/kepler/sun.html
public static function sunAbsolutePositionDeg($t) {
$dSec = $t - 946728000;
$meanLongitudeDeg = fmod((280.461 + 0.9856474 * $dSec / 86400), 360);
Expand All @@ -299,9 +295,9 @@ public static function sunAbsolutePositionDeg($t) {
return array(rad2deg($rightAscensionRad), rad2deg($declinationRad));
}

// Convert an object's RA/Dec to altazimuth coordinates.
// http://answers.yahoo.com/question/index?qid=20070830185150AAoNT4i
// http://www.jgiesen.de/astro/astroJS/siderealClock/
// Convert an object's RA/Dec to altazimuth coordinates.
// http://answers.yahoo.com/question/index?qid=20070830185150AAoNT4i
// http://www.jgiesen.de/astro/astroJS/siderealClock/
public static function absoluteToRelativeDeg($t, $rightAscensionDeg, $declinationDeg, $latitude, $longitude) {
$longitude = (float) $longitude;
$latitude = (float) $latitude;
Expand All @@ -321,35 +317,35 @@ public function getLatitudeLongitude(&$latitude, &$longitude) {
if ($this->getConfiguration('geoloc') == 'jeedom') {
$latitude = config::byKey('info::latitude');
$longitude = config::byKey('info::longitude');
return (0);
return(0);
} else {
$geotrav = eqLogic::byId($this->getConfiguration('geoloc'));
if (!(is_object($geotrav) && $geotrav->getEqType_name() == 'geotrav')) {
log::add(__CLASS__, 'error', 'Localisation invalide, veuillez sélectionner un équipement geotrav valide');
return (1);
return(1);
}
$geolocval = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'), 'location:coordinate')->execCmd();
$geoloctab = explode(',', trim($geolocval));
$latitude = trim($geoloctab[0]);
$longitude = trim($geoloctab[1]);
return (0);
return(0);
}
}

public function getInformations() {
if ($this->getLatitudeLongitude($latitude, $longitude)) {
log::add(__CLASS__, 'error', __FUNCTION__ . " Latitude et longitude non connues.");
log::add(__CLASS__, 'error', __FUNCTION__ ." Latitude et longitude non connues.");
return;
} else {
log::add(__CLASS__, 'debug', __FUNCTION__ . " Latitude: $latitude Longitude: $longitude");
log::add(__CLASS__, 'debug', __FUNCTION__ ." Latitude: $latitude Longitude: $longitude");
}

// MAJ position actuelle du soleil
// MAJ position actuelle du soleil
self::getAltAzt(time(), $latitude, $longitude, $altitude, $azimuth360);
$this->checkAndUpdateCmd('azimuth360', round($azimuth360));
$this->checkAndUpdateCmd('altitude', round($altitude, 1));

// calcul jour, nuit, aubes crepuscules pour MAJ daystatus et daytext
// calcul jour, nuit, aubes crepuscules pour MAJ daystatus et daytext
$cmd = heliotropeCmd::byEqLogicIdAndLogicalId($this->getId(), 'aubeast');
if (is_object($cmd)) $aubeast = $cmd->execCmd();
else return;
Expand Down Expand Up @@ -409,13 +405,13 @@ public function getInformations() {

public function getDaily() {
if ($this->getLatitudeLongitude($latitude, $longitude)) {
log::add(__CLASS__, 'error', __FUNCTION__ . " Latitude et longitude non connues.");
log::add(__CLASS__, 'error', __FUNCTION__ ." Latitude et longitude non connues.");
return;
} else {
log::add(__CLASS__, 'debug', __FUNCTION__ . " Latitude: $latitude Longitude: $longitude");
log::add(__CLASS__, 'debug', __FUNCTION__ ." Latitude: $latitude Longitude: $longitude");
}

// Calcul lever, coucher, durée jour
// Calcul lever, coucher, durée jour
$sun_info = date_sun_info(time(), $latitude, $longitude);
$sunrise = date('Gi', $sun_info['sunrise']);
$this->checkAndUpdateCmd('sunrise', $sunrise);
Expand All @@ -424,7 +420,7 @@ public function getDaily() {
log::add(__CLASS__, 'debug', __FUNCTION__, "Lat: $latitude Sunrise True");
} else if ($sun_info['sunrise'] === false) { // nuit toute la journée
$daylen = 0;
log::add(__CLASS__, 'debug', __FUNCTION__, "Lat: $latitude Sunrise False");
log::add(__CLASS__, 'debug', __FUNCTION__ ." Lat: $latitude Sunrise False");
} else {
$daylen = round(($sun_info['sunset'] - $sun_info['sunrise']) / 60);
}
Expand All @@ -433,7 +429,7 @@ public function getDaily() {
$this->checkAndUpdateCmd('zenith', $zenith);
$sunset = date('Gi', $sun_info['sunset']);
$this->checkAndUpdateCmd('sunset', $sunset);
// Calcul aubes et crepsucules civil nautique, astronomique
// Calcul aubes et crepsucules civil nautique, astronomique
$aubeciv = date('Gi', $sun_info['civil_twilight_begin']);
$this->checkAndUpdateCmd('aubeciv', $aubeciv);
$crepciv = date('Gi', $sun_info['civil_twilight_end']);
Expand Down Expand Up @@ -475,7 +471,7 @@ public static function setupCron() {
if ($setting == '60') {
$cron->setSchedule('0 * * * *');
} else {
$cron->setSchedule('*/' . $setting . ' * * * *');
$cron->setSchedule('*/' .$setting .' * * * *');
}
$cron->save();
return true;
Expand All @@ -495,16 +491,13 @@ public function toHtml($_version = 'dashboard') {
}

if ($this->getLatitudeLongitude($latitude, $longitude)) {
log::add(__CLASS__, 'warning', __FUNCTION__ . " Latitude et longitude non connues.");
log::add(__CLASS__, 'warning', __FUNCTION__ ." Latitude et longitude non connues.");
return;
} else {
log::add(__CLASS__, 'debug', __FUNCTION__ . " Latitude: $latitude Longitude: $longitude");
log::add(__CLASS__, 'debug', __FUNCTION__ ." Latitude: $latitude Longitude: $longitude");
}

$id = array();
$value = array();
$display = array();
$history = array();
$id = array(); $value = array(); $display = array(); $history = array();
foreach ($this->getCmd('info') as $cmd) {
$type_cmd = $cmd->getLogicalId();
$id[$type_cmd] = $cmd->getId();
Expand All @@ -516,11 +509,11 @@ public function toHtml($_version = 'dashboard') {
if (!isset($replace['#elevationHeight#'])) $replace['#elevationHeight#'] = 220;
if (!isset($replace['#azimuthSize#'])) $replace['#azimuthSize#'] = 120;

// latitude longitude dans le titre de la tuile
// latitude longitude dans le titre de la tuile
$lat = round($latitude, 1);
$replace['#latitude#'] = $lat . (($lat >= 0) ? "°N" : "°S");
$replace['#latitude#'] = $lat .(($lat >= 0) ? "°N" : "°S");
$lon = round($longitude, 1);
$replace['#longitude#'] = $lon . (($lon >= 0) ? "°E" : "°W");
$replace['#longitude#'] = $lon .(($lon >= 0) ? "°E" : "°W");
/*
https://suncalc.org/#/lat,lon,zoom/date/time/objectlevel/maptype
Format voir:
Expand Down Expand Up @@ -548,10 +541,10 @@ public function toHtml($_version = 'dashboard') {
$replace['#zenith#'] = substr_replace($value['zenith'], ':', -2, 0);
if ($display['daylen'] == "none") $replace['#daylenTxt#'] = '';
else {
$h = floor($value['daylen'] / 60);
$mn = $value['daylen'] % 60;
$daylen = (($h) ? "{$h}h " : '') . (($mn) ? "{$mn}min " : '');
// Calcul variation durée jour
$valueDaylen = isset($value['daylen'])? intval($value['daylen']) : 0;
$h = floor($valueDaylen / 60); $mn = $valueDaylen % 60;
$daylen = (($h) ? "{$h}h " : '') .(($mn)? "{$mn}min " : '');
// Calcul variation durée jour
$sunInfo = date_sun_info(strtotime('today noon'), $latitude, $longitude);
$sunInfoHier = date_sun_info(strtotime('yesterday noon'), $latitude, $longitude);
$daylenToday = $sunInfo['sunset'] - $sunInfo['sunrise'];
Expand All @@ -567,13 +560,13 @@ public function toHtml($_version = 'dashboard') {
$inclin = 23 + 26 / 60;
$replace['#paneStart#'] = -180; // -180-$inclin+$latitude;
$replace['#paneEnd#'] = 0; // $inclin-$latitude;
// log::add(__CLASS__,'error',"AltMinYear: ". $replace['#paneStart#']." AltMaxYear: ". $replace['#paneEnd#']);
$minElev = max(-90 - $inclin + $latitude, 90);
// log::add(__CLASS__, 'error',"AltMinYear: ". $replace['#paneStart#']." AltMaxYear: ". $replace['#paneEnd#']);
$minElev = max(-90 -$inclin +$latitude, 90);
if ($minElev < -90) $minElev += 360;
if ($minElev > 90) $minElev -= 360;

$replace['#minElev#'] = round(max(-90 - $inclin + $latitude, -90), 2);
$replace['#maxElev#'] = round(min(90 + $inclin - $latitude, 90), 2);
$replace['#minElev#'] = round(max(-90 -$inclin +$latitude, -90), 2);
$replace['#maxElev#'] = round(min(90 +$inclin -$latitude, 90), 2);

if (array_key_exists('daystatus', $value) && $value['daystatus'] == "1") {
$replace['#heliosun#'] = "opacity : 1";
Expand All @@ -583,20 +576,20 @@ public function toHtml($_version = 'dashboard') {
$replace['#heliomoon#'] = "opacity : 1";
}

// Courbe élévation du soleil. Azimut dans les tooltips
// Courbe élévation du soleil. Azimut dans les tooltips
$serie = $serie2 = array();
$date = strtotime('today midnight');
$now = time();
// $date = strtotime('2022-06-21 00:00:00'); $now = strtotime('2022-06-21 12:00:00');
// message::add(__CLASS__, "Sunrise: " .date('H:i:s',$sunrise) ." Zenith: " .date('H:i:s',$transit) ." Sunset: " .date('H:i:s',$sunset));
// message::add(__CLASS__, "Sunrise: " .date('H:i:s', $sunrise) ." Zenith: " .date('H:i:s', $transit) ." Sunset: " .date('H:i:s', $sunset));
for ($i = 0; $i < 49; $i++) {
$t = $date + $i * 1800;
$t = $date +$i * 1800;
self::getAltAzt($t, $latitude, $longitude, $alt, $azt);
$msg = '{ "x":' . $t * 1000 . ',"y": ' . $alt . ',"z":' . $azt . ',"msg":"' . date('G:i', $t) . '"}';
$msg = '{ "x":' .$t * 1000 .',"y": ' .$alt .',"z":' .$azt .',"msg":"' .date('G:i', $t) .'"}';
if ($t < $now) $serie[] = $msg;
else $serie2[] = $msg;
}
// Ajout Lever, Zenith, Coucher ... sur la courbe
// Ajout Lever, Zenith, Coucher ... sur la courbe
$types = array();
$types[] = array("sunI" => 'sunrise', "txtDsp" => 'Lever', "cmdJ" => 'sunrise');
$types[] = array("sunI" => 'transit', "txtDsp" => 'Zénith', "cmdJ" => 'zenith');
Expand All @@ -609,9 +602,7 @@ public function toHtml($_version = 'dashboard') {
$types[] = array("sunI" => 'astronomical_twilight_end', "txtDsp" => 'Fin crépuscule astronomique', "cmdJ" => 'crepast');
$sun_info = date_sun_info($now, $latitude, $longitude);
$nb = count($types);
$sunriseTxt = '';
$sunsetTxt = '';
$zenithTxt = '';
$sunriseTxt = ''; $sunsetTxt = ''; $zenithTxt = '';
for ($i = 0; $i < $nb; $i++) {
$type = $types[$i]['sunI'];
$t = $sun_info[$type];
Expand All @@ -621,47 +612,43 @@ public function toHtml($_version = 'dashboard') {
if ($type == 'sunrise') {
$aztsunrise = $azt;
if ($display[$types[$i]['cmdJ']] != "none")
$sunriseTxt = $texte . ': ' . date('G:i:s', $t) . '<br/>';
$sunriseTxt = $texte .': ' .date('G:i:s', $t) .'<br/>';
} else if ($type == 'sunset') {
$aztsunset = $azt;
if ($display[$types[$i]['cmdJ']] != "none")
$sunsetTxt = $texte . ': ' . date('G:i:s', $t) . '<br/>';
$sunsetTxt = $texte .': ' .date('G:i:s', $t) .'<br/>';
} else if ($type == 'transit') {
if ($display[$types[$i]['cmdJ']] != "none")
$zenithTxt = $texte . ': ' . date('G:i:s', $t) . '<br/>';
$zenithTxt = $texte .': ' .date('G:i:s', $t) .'<br/>';
}
// if($display[$types[$i]['cmdJ']] == "none") continue;
$msg = '{ "x":' . $t * 1000 . ',"y":' . $alt . ',"z":' . $azt . ',"id":"' . $type . '","msg":"' . $texte . ': ' . date('G:i:s', $t) . '"}';
// if ($display[$types[$i]['cmdJ']] == "none") continue;
$msg = '{ "x":' .$t*1000 .',"y":' .$alt .',"z":' .$azt .',"id":"' .$type .'","msg":"' .$texte .': ' .date('G:i:s', $t) .'"}';
if ($t > $now) $serie2[] = $msg;
else $serie[] = $msg;
}
if ($sun_info['sunrise'] === true) { // jour toute la journée
$aztsunrise = 0;
$aztsunset = 360;
$aztsunrise = 0; $aztsunset = 360;
} else if ($sun_info['sunrise'] === false) { // nuit toute la journée
$aztsunrise = 180;
$aztsunset = 180;
$aztsunrise = 180; $aztsunset = 180;
}
$replace['#sunriseTxt#'] = $sunriseTxt;
$replace['#sunsetTxt#'] = $sunsetTxt;
$replace['#zenithTxt#'] = $zenithTxt;
$replace['#aztsunrise#'] = round($aztsunrise, 3);
if ($aztsunset < $aztsunrise) $aztsunset += 360;
if ($aztsunset < $aztsunrise) $aztsunset += 360;
$replace['#aztsunset#'] = round($aztsunset, 3);
log::add(__CLASS__, 'debug', "AztSunrise: $aztsunrise AztSunset: $aztsunset");

// Heure actuelle dans les 2 courbes
self::getAltAzt($now, $latitude, $longitude, $alt, $azt);
$msg = '{ "x":' . $now * 1000 . ',"y":' . $alt . ',"z":' . $azt . ',"msg":"Maintenant ' . date('G:i', $now) . '"}';
$msg2 = '{ "x":' . $now * 1000 . ',"y":' . $alt . ',"marker": { "symbol": \'url(plugins/' . __CLASS__ . '/core/template/sun.png)\'},"z":' . $azt . ',"msg":"Maintenant ' . date('G:i', $now) . '"}';
$serie[] = $msg;
$serie2[] = $msg2;
sort($serie);
sort($serie2);
$msg = '{ "x":' .$now * 1000 .',"y":' .$alt .',"z":' .$azt .',"msg":"Maintenant ' .date('G:i', $now) .'"}';
$msg2 = '{ "x":' .$now * 1000 .',"y":' .$alt .',"marker": { "symbol": \'url(plugins/' .__CLASS__ .'/core/template/sun.png)\'},"z":' .$azt .',"msg":"Maintenant ' .date('G:i', $now) .'"}';
$serie[] = $msg; $serie2[] = $msg2;
sort($serie); sort($serie2);
$replace['#altSerie#'] = implode(',', $serie);
$replace['#altSerie2#'] = implode(',', $serie2);

// inversion couleurs jour/nuit suivant hemisphere
// inversion couleurs jour/nuit suivant hemisphere
if ($latitude > 0) {
$replace['#bandColor1#'] = '#3C73A5';
$replace['#bandColor2#'] = '#8EBEEB';
Expand All @@ -675,17 +662,17 @@ public function toHtml($_version = 'dashboard') {

$t1 = microtime(true);
$duration = round($t1 - $t0, 3);
log::add(__CLASS__, 'debug', "END OF toHtml Duration: {$duration}s. Memory_usage: " . memory_get_usage());
if (file_exists(__DIR__ . "/../template/$_version/custom." . __CLASS__ . ".html"))
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, 'custom.' . __CLASS__, __CLASS__)));
log::add(__CLASS__, 'debug', "END OF toHtml Duration: {$duration}s. Memory_usage: " .memory_get_usage());
if (file_exists(__DIR__ . "/../template/$_version/custom." .__CLASS__ .".html"))
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, 'custom.' .__CLASS__, __CLASS__)));
else
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, __CLASS__, __CLASS__)));
}

public static function getAltAzt($time, $lat, $lon, &$alt, &$azt) {
list($ra, $dec) = self::sunAbsolutePositionDeg($time);
list($az, $alt) = self::absoluteToRelativeDeg($time, $ra, $dec, $lat, $lon);
$alt = $alt + self::correctForRefraction($alt);
$alt = $alt +self::correctForRefraction($alt);
if (0 > $az) $az += 360;
$azt = $az;
}
Expand Down

0 comments on commit ad455a7

Please sign in to comment.