weather.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. //
  28. $cat = '/home/admin/import/';
  29. $data = [
  30. '160.xml',
  31. '150.xml',
  32. '157.xml',
  33. '7591.xml',
  34. '7586.xml',
  35. '7306.xml'
  36. ];
  37. $data = [
  38. 'Barnaul.json',
  39. 'Biysk.json',
  40. 'Zarinsk.json',
  41. 'Kamen.json',
  42. 'Slavgorod.json',
  43. 'Rubcovsk.json',
  44. 'Zmeinogorsk.json',
  45. 'Belokuriha.json',
  46. 'Gornyi.json',
  47. 'Zaviyalovoi.json'
  48. ];
  49. $city = [
  50. 'Barnaul.json' => 'Барнаул',
  51. 'Biysk.json' => 'Бийск',
  52. 'Zarinsk.json' => 'Заринск',
  53. 'Kamen.json' => 'Камень на Оби',
  54. 'Slavgorod.json' => 'Славгород',
  55. 'Rubcovsk.json' => 'Рубцовск',
  56. 'Zmeinogorsk.json' => 'Змеиногорск',
  57. 'Belokuriha.json' => 'Белокуриха',
  58. 'Gornyi.json' => 'Горно-Алтайск',
  59. 'Zaviyalovoi.json' => 'Завьялово',
  60. ];
  61. $part_name = [
  62. 'night' => 'ночь',
  63. 'morning' => 'утро',
  64. 'day' => 'день',
  65. 'evening' => 'вечер',
  66. ];
  67. $precipitationi = [
  68. 0 => '',
  69. 1 => '',
  70. 2 => '',
  71. 3 => '', // снег дождь
  72. 4 => 'Cloud-Rain.svg',
  73. 5 => 'Cloud-Hail.svg',
  74. 6 => 'Cloud-Hail.svg', //снег
  75. 7 => 'Cloud-Hail-Alt.svg', //снег
  76. 8 => 'Cloud-Lightning.svg',
  77. 9 => '',
  78. 10 => ''
  79. ];
  80. $cloudsi = [
  81. 'clear' => '',
  82. -1 => '', // - туман
  83. 0 => 'Sun.svg',
  84. 1 => 'Cloud-Sun.svg', // 'Малооблачно',
  85. 2 => 'Cloud.svg', // 'Облачно',
  86. 3 => 'Cloud.svg', // 'Пасмурно'
  87. ];
  88. $cloudsiY = [
  89. 'clear' => 'Sun.svg',
  90. 'partly-cloudy' => 'Cloud-Sun.svg', // 'Малооблачно',
  91. 'cloudy' => 'Cloud.svg', // 'Облачно',
  92. 'overcast' => 'Cloud.svg', // 'Пасмурно'
  93. ]
  94. ?>
  95. <div class="site-weather">
  96. <div class="row">
  97. <div class="col-md-8 mt-3 bg-white">
  98. <h1>Погода в Алтайском крае</h1>
  99. <?
  100. if( file_exists( '/home/admin/temp/temperature' ) ){
  101. echo "<p><big>Сейчас в Барнауле ".file_get_contents( '/home/admin/temp/temperature' )."<sup>o</sup>C &nbsp;&nbsp;</big></p>";
  102. }
  103. $cd ='';
  104. if( file_exists( $cat.'solar3.json' ) ){
  105. $strn = @file_get_contents( $cat.'solar3.json' );
  106. // $date = filemtime( $cat.'solar3.json' );
  107. $solarnow = json_decode( $strn );
  108. foreach($solarnow as $c) {
  109. if( $c < 4 ){
  110. $cd .= '"#00ff00",';
  111. }elseif( $c > 5 ){
  112. $cd .= '"#ff0000",';
  113. }else{
  114. $cd .= '"#ffd810",';
  115. }
  116. }
  117. }
  118. $ss = '"6:00","10:00","14:00","18:00","22:00","00:00"';
  119. if( file_exists( $cat.'solar.json' ) ){
  120. $str = @file_get_contents( $cat.'solar.json' );
  121. $date = filemtime( $cat.'solar.json' );
  122. $solar = json_decode( $str );
  123. $s = '';
  124. for( $i = 1; $i < 27; $i++ ){
  125. $s .= date('"d M"',$date+$i*86400).',';
  126. }
  127. ?>
  128. <div class="row mb-4">
  129. <div class="col-sm ml-auto" style="box-shadow: 2px 2px 7px #888;">
  130. <canvas id="myChart0"></canvas>
  131. </div>
  132. <div class="col-sm" style="box-shadow: 2px 2px 7px #888;">
  133. <canvas id="myChart"></canvas>
  134. </div>
  135. </div>
  136. <p>Лаборатория солнечной астрономии и гелиофизического приборостроения
  137. (ИКИ РАН и ИСЗФ СО РАН)</p>
  138. <h3 class="text-center">Текущий прогноз погоды по Алтайскому краю</h3>
  139. <?
  140. ?>
  141. <script src='/js/chart.js'></script>
  142. <script>
  143. const ctx = document.getElementById('myChart');
  144. const ctx0 = document.getElementById('myChart0');
  145. let width, height, gradient;
  146. function getGradient(ctx, chartArea) {
  147. const chartWidth = chartArea.right - chartArea.left;
  148. const chartHeight = chartArea.bottom - chartArea.top;
  149. if (!gradient || width !== chartWidth || height !== chartHeight) {
  150. // Create the gradient because this is either the first render
  151. // or the size of the chart has changed
  152. width = chartWidth;
  153. height = chartHeight;
  154. gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top);
  155. gradient.addColorStop(0, 'green');
  156. gradient.addColorStop(0.5, 'red');
  157. gradient.addColorStop(1, '#960018');
  158. }
  159. return gradient;
  160. }
  161. new Chart(ctx, {
  162. type: 'line',
  163. data: {
  164. labels: [<?=$s?>],
  165. datasets: [{
  166. label: 'Магнитные возмущения',
  167. data: <?=$str?>,
  168. borderWidth: 1,
  169. fill: true,
  170. tension: 0.5,
  171. pointRadius: 0,
  172. backgroundColor: function(context) {
  173. const chart = context.chart;
  174. const {ctx, chartArea} = chart;
  175. if (!chartArea) {
  176. // This case happens on initial chart load
  177. return;
  178. }
  179. return getGradient(ctx, chartArea);
  180. },
  181. }]
  182. },
  183. options: {
  184. scales: {
  185. y: {
  186. beginAtZero: true,
  187. min:0,
  188. max:10
  189. }
  190. }
  191. }
  192. });
  193. new Chart(ctx0, {
  194. type: 'bar',
  195. data: {
  196. labels: [<?=$ss?>],
  197. datasets: [{
  198. label: 'Магнитные возмущения сегодня',
  199. data: <?=$strn?>,
  200. borderWidth: 1,
  201. fill: true,
  202. backgroundColor: [<?=$cd?>]
  203. }]
  204. },
  205. options: {
  206. scales: {
  207. y: {
  208. beginAtZero: true,
  209. min:0,
  210. max:10
  211. }
  212. }
  213. }
  214. });
  215. </script>
  216. <?
  217. // $this->registerJs(
  218. // "myChart = new Chart(document.getElementById('js-chart-1').getContext( '2d' ),config); console.log(config)",
  219. // View::POS_END
  220. //);
  221. }
  222. foreach( $data as $file )
  223. {
  224. $str = @file_get_contents( $cat.$file );
  225. if( $str ){
  226. $obj = json_decode($str);
  227. // echo "<pre>";
  228. // print_r($obj);
  229. // echo "</pre>";
  230. $cur_date = date( "d-m-Y H:i", $obj->fact->obs_time );
  231. echo "<h2>$city[$file]</h2><div class=\"town row justify-content-md-center mb-5 bg-white\">";
  232. foreach( $obj->forecast->parts as $w ){
  233. // echo $w->part_name;
  234. $t_max = $w->temp_max;
  235. $t_min = $w->temp_min;
  236. $p_min = $w->pressure_mm;
  237. $p_max = $w->pressure_mm;
  238. $w_min = $w->wind_speed;
  239. $w_max = $w->wind_gust;
  240. $day = date( "d", $obj->fact->obs_time );
  241. $month = date( "m", $obj->fact->obs_time );
  242. $hour = $part_name[$w->part_name];
  243. $year = date( "Y", $obj->fact->obs_time );
  244. $cloudiness = $w->condition;
  245. $precipitation = $w->prec_mm;
  246. $icon = $w->icon;
  247. ?>
  248. <div class="hour col-md-4 p-2 mx-3">
  249. <div class='date'>На <?=$hour?> <?=$day?>.<?=$month?>.<?=$year?></div>
  250. <div><big><b><?=$t_min?><sup>o</sup>C до <?=$t_max?><sup>o</sup>C</b></big></div>
  251. <div class="sign mx-auto col-3">
  252. <? if( $icon !='' )
  253. {
  254. ?>
  255. <img class="weathericon2" src="https://yastatic.net/weather/i/icons/funky/dark/<?=$icon?>.svg" >
  256. <?
  257. }
  258. ?>
  259. </div>
  260. Давление <?=$p_min?>мм рт.ст.<br/>
  261. <span style = 'padding-top:5px'>Ветер <?=$w_min?>, <?=$w_max?>м/с</span>
  262. </div>
  263. <?
  264. }
  265. echo "</div>";
  266. }
  267. if( 0 && $str ){
  268. $xml = simplexml_load_string( $str );
  269. if( $xml ){
  270. $town = rawurldecode( $xml->REPORT->TOWN['sname'] );
  271. $town = ( $town == 'SLAVGOROD' )?'Славгород':$town;
  272. $town = ( $town == "KAMEN'-NA-OBI" )?'Камень-на-Оби':$town;
  273. $town = ( $town == "Заринск,+Алтайский+край,+Россия" )?'Заринск':$town;
  274. echo "<h2>$town</h2><div class=\"town row justify-content-md-center mb-5 bg-white\">";
  275. foreach( $xml->REPORT->TOWN->FORECAST as $w ){
  276. $t_max = $w->TEMPERATURE['max'];
  277. $t_min = $w->TEMPERATURE['min'];
  278. $p_min = $w->PRESSURE['min'];
  279. $p_max = $w->PRESSURE['max'];
  280. $w_min = $w->WIND['min'];
  281. $w_max = $w->WIND['max'];
  282. $day = $w['day'];
  283. $month = $w['month'];
  284. $hour = $w['hour'];
  285. $year = $w['year'];
  286. $cloudiness = $w->PHENOMENA['cloudiness'];
  287. $precipitation = $w->PHENOMENA['precipitation'];
  288. ?>
  289. <div class="hour col-md-3 p-2">
  290. <div class='date'>На <?=$hour?> час <?=$day?>.<?=$month?>.<?=$year?></div>
  291. <p><big><b><?=$t_min?><sup>o</sup>C до <?=$t_max?><sup>o</sup>C</b></big></p>
  292. Давление <?=$p_min?>, <?=$p_max?>мм рт.ст.<br/>
  293. <span style = 'padding-top:5px'>Ветер <?=$w_min?>, <?=$w_max?>м/с</span>
  294. <div class="sign fleft col-3">
  295. <? if( $precipitationi["$precipitation"] !='' )
  296. {
  297. ?>
  298. <img class="weathericon2" src="/img/weather/<?=($precipitationi["$precipitation"] !='' )?$precipitationi["$precipitation"]:'e.gif'?>" >
  299. <?
  300. }
  301. ?>
  302. <img class="weathericon2" src="/img/weather/<?=($cloudsi["$cloudiness"] != '')?$cloudsi["$cloudiness"]:'e.gif'?>" >
  303. </div>
  304. </div>
  305. <?
  306. }
  307. echo "</div>";
  308. }
  309. }
  310. }
  311. ?>
  312. <p><center><a href="https://yandex.ru/pogoda/"><img src="/img/logo_weather_ru_indoor.svg" height="30px"><br><h5>По данным сервиса</h5></a></center></p>
  313. </div>
  314. <div class="col-md-4 overflow-hidden">
  315. <?=$this->render("/layouts/lenta/temalenta", ['topic'=>89, 'items'=>20])?>
  316. </div>
  317. </div>
  318. </div>