weather.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /** @var yii\web\View $this */
  3. use yii\helpers\Html;
  4. use yii\web\View;
  5. use app\modules\ldjson\jsonLD;
  6. $this->title = 'Барнаул погода';
  7. $url = '/weather';
  8. $this->params['breadcrumbs'] = [
  9. [
  10. "text"=>$this->title,
  11. "url"=>$url
  12. ]
  13. ];
  14. $addtpage = ' amic.ru';
  15. Yii::$app->og->title = $this->title.$addtpage;
  16. Yii::$app->og->description ='Погода в Алтайском крае - '.Yii::$app->og->description.$addtpage;
  17. Yii::$app->og->og_title = str_replace( '"',"&quot;", $this->title );
  18. Yii::$app->og->og_description = str_replace( '"',"&quot;",Yii::$app->og->description);
  19. Yii::$app->og->canonical = $url;
  20. Yii::$app->og->og_type = "website";
  21. jsonLD::addAmicORG();
  22. $i = 1;
  23. foreach($this->params['breadcrumbs'] as $el){
  24. jsonLD::addBreadcrumb($i, $el['url'], $el['text']);
  25. $i++;
  26. }
  27. $cat = '/home/admin/import/';
  28. $data = [
  29. '160.xml',
  30. '150.xml',
  31. '157.xml',
  32. '7591.xml',
  33. '7586.xml',
  34. '7306.xml'
  35. ];
  36. $precipitationi = [
  37. 1 => '',
  38. 2 => '',
  39. 3 => '', // снег дождь
  40. 4 => 'Cloud-Rain.svg',
  41. 5 => 'Cloud-Hail.svg',
  42. 6 => 'Cloud-Hail.svg', //снег
  43. 7 => 'Cloud-Hail-Alt.svg', //снег
  44. 8 => 'Cloud-Lightning.svg',
  45. 9 => '',
  46. 10 => ''
  47. ];
  48. $cloudsi = [
  49. -1 => '', // - туман
  50. 0 => 'Sun.svg',
  51. 1 => 'Cloud-Sun.svg', // 'Малооблачно',
  52. 2 => 'Cloud.svg', // 'Облачно',
  53. 3 => 'Cloud.svg', // 'Пасмурно'
  54. ];
  55. ?>
  56. <div class="site-weather">
  57. <div class="row">
  58. <div class="col-md-8 mt-3 bg-white">
  59. <h1>Погода в Алтайском крае</h1>
  60. <?
  61. if( file_exists( '/home/admin/temp/temperature' ) ){
  62. echo "<p><big>Сейчас в Барнауле ".file_get_contents( '/home/admin/temp/temperature' )."<sup>o</sup>C &nbsp;&nbsp;</big></p>";
  63. }
  64. $cd ='';
  65. if( file_exists( $cat.'solar3.json' ) ){
  66. $strn = @file_get_contents( $cat.'solar3.json' );
  67. // $date = filemtime( $cat.'solar3.json' );
  68. $solarnow = json_decode( $strn );
  69. foreach($solarnow as $c) {
  70. if( $c < 4 ){
  71. $cd .= '"#00ff00",';
  72. }elseif( $c > 5 ){
  73. $cd .= '"#ff0000",';
  74. }else{
  75. $cd .= '"#ffd810",';
  76. }
  77. }
  78. }
  79. $ss = '"6:00","10:00","14:00","18:00","22:00","00:00"';
  80. if( file_exists( $cat.'solar.json' ) ){
  81. $str = @file_get_contents( $cat.'solar.json' );
  82. $date = filemtime( $cat.'solar.json' );
  83. $solar = json_decode( $str );
  84. $s = '';
  85. for( $i = 1; $i < 27; $i++ ){
  86. $s .= date('"d M"',$date+$i*86400).',';
  87. }
  88. ?>
  89. <div class="row mb-4">
  90. <div class="col-sm ml-auto" style="box-shadow: 2px 2px 7px #888;">
  91. <canvas id="myChart0"></canvas>
  92. </div>
  93. <div class="col-sm" style="box-shadow: 2px 2px 7px #888;">
  94. <canvas id="myChart"></canvas>
  95. </div>
  96. </div>
  97. <?
  98. ?>
  99. <script src='/js/chart.js'></script>
  100. <script>
  101. const ctx = document.getElementById('myChart');
  102. const ctx0 = document.getElementById('myChart0');
  103. let width, height, gradient;
  104. function getGradient(ctx, chartArea) {
  105. const chartWidth = chartArea.right - chartArea.left;
  106. const chartHeight = chartArea.bottom - chartArea.top;
  107. if (!gradient || width !== chartWidth || height !== chartHeight) {
  108. // Create the gradient because this is either the first render
  109. // or the size of the chart has changed
  110. width = chartWidth;
  111. height = chartHeight;
  112. gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top);
  113. gradient.addColorStop(0, 'green');
  114. gradient.addColorStop(0.5, 'red');
  115. gradient.addColorStop(1, '#960018');
  116. }
  117. return gradient;
  118. }
  119. new Chart(ctx, {
  120. type: 'line',
  121. data: {
  122. labels: [<?=$s?>],
  123. datasets: [{
  124. label: 'Магнитные возмущения',
  125. data: <?=$str?>,
  126. borderWidth: 1,
  127. fill: true,
  128. tension: 0.5,
  129. pointRadius: 0,
  130. backgroundColor: function(context) {
  131. const chart = context.chart;
  132. const {ctx, chartArea} = chart;
  133. if (!chartArea) {
  134. // This case happens on initial chart load
  135. return;
  136. }
  137. return getGradient(ctx, chartArea);
  138. },
  139. }]
  140. },
  141. options: {
  142. scales: {
  143. y: {
  144. beginAtZero: true,
  145. min:0,
  146. max:10
  147. }
  148. }
  149. }
  150. });
  151. new Chart(ctx0, {
  152. type: 'bar',
  153. data: {
  154. labels: [<?=$ss?>],
  155. datasets: [{
  156. label: 'Магнитные возмущения сегодня',
  157. data: <?=$strn?>,
  158. borderWidth: 1,
  159. fill: true,
  160. backgroundColor: [<?=$cd?>]
  161. }]
  162. },
  163. options: {
  164. scales: {
  165. y: {
  166. beginAtZero: true,
  167. min:0,
  168. max:10
  169. }
  170. }
  171. }
  172. });
  173. </script>
  174. <?
  175. // $this->registerJs(
  176. // "myChart = new Chart(document.getElementById('js-chart-1').getContext( '2d' ),config); console.log(config)",
  177. // View::POS_END
  178. //);
  179. }
  180. foreach( $data as $file )
  181. {
  182. $str = @file_get_contents( $cat.$file );
  183. if( $str ){
  184. $xml = simplexml_load_string( $str );
  185. if( $xml ){
  186. $town = rawurldecode( $xml->REPORT->TOWN['sname'] );
  187. $town = ( $town == 'SLAVGOROD' )?'Славгород':$town;
  188. $town = ( $town == "KAMEN'-NA-OBI" )?'Камень-на-Оби':$town;
  189. $town = ( $town == "Заринск,+Алтайский+край,+Россия" )?'Заринск':$town;
  190. echo "<h2>$town</h2><div class=\"town row justify-content-md-center mb-5 bg-white\">";
  191. foreach( $xml->REPORT->TOWN->FORECAST as $w ){
  192. $t_max = $w->TEMPERATURE['max'];
  193. $t_min = $w->TEMPERATURE['min'];
  194. $p_min = $w->PRESSURE['min'];
  195. $p_max = $w->PRESSURE['max'];
  196. $w_min = $w->WIND['min'];
  197. $w_max = $w->WIND['max'];
  198. $day = $w['day'];
  199. $month = $w['month'];
  200. $hour = $w['hour'];
  201. $year = $w['year'];
  202. $cloudiness = $w->PHENOMENA['cloudiness'];
  203. $precipitation = $w->PHENOMENA['precipitation'];
  204. ?>
  205. <div class="hour col-md-3 p-2">
  206. <div class='date'>На <?=$hour?> час <?=$day?>.<?=$month?>.<?=$year?></div>
  207. <p><big><b><?=$t_min?><sup>o</sup>C до <?=$t_max?><sup>o</sup>C</b></big></p>
  208. Давление <?=$p_min?>, <?=$p_max?>мм рт.ст.<br/>
  209. <span style = 'padding-top:5px'>Ветер <?=$w_min?>, <?=$w_max?>м/с</span>
  210. <div class="sign fleft col-3">
  211. <? if( $precipitationi["$precipitation"] !='' )
  212. {
  213. ?>
  214. <img class="weathericon2" src="/img/weather/<?=($precipitationi["$precipitation"] !='' )?$precipitationi["$precipitation"]:'e.gif'?>" >
  215. <?
  216. }
  217. ?>
  218. <img class="weathericon2" src="/img/weather/<?=($cloudsi["$cloudiness"] != '')?$cloudsi["$cloudiness"]:'e.gif'?>" >
  219. </div>
  220. </div>
  221. <?
  222. }
  223. echo "</div>";
  224. }
  225. }
  226. }
  227. ?>
  228. <p><a href="https://www.meteoservice.ru/">«Предоставлено Meteoservice.ru»</a></p>
  229. </div>
  230. <div class="col-md-4">
  231. <?=$this->render("/layouts/lenta/temalenta", ['topic'=>89, 'items'=>20])?>
  232. </div>
  233. </div>
  234. </div>