123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <?php
- /** @var yii\web\View $this */
- use yii\helpers\Html;
- use yii\web\View;
- use app\modules\ldjson\jsonLD;
- $this->title = 'Барнаул погода';
- $url = '/weather';
- $this->params['breadcrumbs'] = [
- [
- "text"=>$this->title,
- "url"=>$url
- ]
- ];
- $addtpage = ' amic.ru';
- Yii::$app->og->title = $this->title.$addtpage;
- Yii::$app->og->description ='Погода в Алтайском крае - '.Yii::$app->og->description.$addtpage;
- Yii::$app->og->og_title = str_replace( '"',""", $this->title );
- Yii::$app->og->og_description = str_replace( '"',""",Yii::$app->og->description);
- Yii::$app->og->canonical = $url;
- Yii::$app->og->og_type = "website";
- jsonLD::addAmicORG();
- $i = 1;
- foreach($this->params['breadcrumbs'] as $el){
- jsonLD::addBreadcrumb($i, $el['url'], $el['text']);
- $i++;
- }
- //
- $cat = '/home/admin/import/';
- $data = [
- '160.xml',
- '150.xml',
- '157.xml',
- '7591.xml',
- '7586.xml',
- '7306.xml'
- ];
- $data = [
- 'Barnaul.json',
- 'Biysk.json',
- 'Zarinsk.json',
- 'Kamen.json',
- 'Slavgorod.json',
- 'Rubcovsk.json',
- 'Zmeinogorsk.json',
- 'Belokuriha.json',
- 'Gornyi.json',
- 'Zaviyalovoi.json'
- ];
- $city = [
- 'Barnaul.json' => 'Барнаул',
- 'Biysk.json' => 'Бийск',
- 'Zarinsk.json' => 'Заринск',
- 'Kamen.json' => 'Камень на Оби',
- 'Slavgorod.json' => 'Славгород',
- 'Rubcovsk.json' => 'Рубцовск',
- 'Zmeinogorsk.json' => 'Змеиногорск',
- 'Belokuriha.json' => 'Белокуриха',
- 'Gornyi.json' => 'Горно-Алтайск',
- 'Zaviyalovoi.json' => 'Завьялово',
- ];
- $part_name = [
- 'night' => 'ночь',
- 'morning' => 'утро',
- 'day' => 'день',
- 'evening' => 'вечер',
- ];
- $precipitationi = [
- 0 => '',
- 1 => '',
- 2 => '',
- 3 => '', // снег дождь
- 4 => 'Cloud-Rain.svg',
- 5 => 'Cloud-Hail.svg',
- 6 => 'Cloud-Hail.svg', //снег
- 7 => 'Cloud-Hail-Alt.svg', //снег
- 8 => 'Cloud-Lightning.svg',
- 9 => '',
- 10 => ''
- ];
- $cloudsi = [
- 'clear' => '',
- -1 => '', // - туман
- 0 => 'Sun.svg',
- 1 => 'Cloud-Sun.svg', // 'Малооблачно',
- 2 => 'Cloud.svg', // 'Облачно',
- 3 => 'Cloud.svg', // 'Пасмурно'
- ];
- $cloudsiY = [
- 'clear' => 'Sun.svg',
- 'partly-cloudy' => 'Cloud-Sun.svg', // 'Малооблачно',
- 'cloudy' => 'Cloud.svg', // 'Облачно',
- 'overcast' => 'Cloud.svg', // 'Пасмурно'
- ]
- ?>
- <div class="site-weather">
- <div class="row">
- <div class="col-md-8 mt-3 bg-white">
- <h1>Погода в Алтайском крае</h1>
- <?
- if( file_exists( '/home/admin/temp/temperature' ) ){
- echo "<p><big>Сейчас в Барнауле ".file_get_contents( '/home/admin/temp/temperature' )."<sup>o</sup>C </big></p>";
- }
- $cd ='';
- if( file_exists( $cat.'solar3.json' ) ){
- $strn = @file_get_contents( $cat.'solar3.json' );
- // $date = filemtime( $cat.'solar3.json' );
- $solarnow = json_decode( $strn );
- foreach($solarnow as $c) {
- if( $c < 4 ){
- $cd .= '"#00ff00",';
- }elseif( $c > 5 ){
- $cd .= '"#ff0000",';
- }else{
- $cd .= '"#ffd810",';
- }
- }
- }
- $ss = '"6:00","10:00","14:00","18:00","22:00","00:00"';
- if( file_exists( $cat.'solar.json' ) ){
- $str = @file_get_contents( $cat.'solar.json' );
- $date = filemtime( $cat.'solar.json' );
- $solar = json_decode( $str );
- $s = '';
- for( $i = 1; $i < 27; $i++ ){
- $s .= date('"d M"',$date+$i*86400).',';
- }
- ?>
- <div class="row mb-4">
- <div class="col-sm ml-auto" style="box-shadow: 2px 2px 7px #888;">
- <canvas id="myChart0"></canvas>
- </div>
- <div class="col-sm" style="box-shadow: 2px 2px 7px #888;">
- <canvas id="myChart"></canvas>
- </div>
- </div>
- <p>Лаборатория солнечной астрономии и гелиофизического приборостроения
- (ИКИ РАН и ИСЗФ СО РАН)</p>
- <h3 class="text-center">Текущий прогноз погоды по Алтайскому краю</h3>
- <?
- ?>
- <script src='/js/chart.js'></script>
- <script>
- const ctx = document.getElementById('myChart');
- const ctx0 = document.getElementById('myChart0');
- let width, height, gradient;
- function getGradient(ctx, chartArea) {
- const chartWidth = chartArea.right - chartArea.left;
- const chartHeight = chartArea.bottom - chartArea.top;
- if (!gradient || width !== chartWidth || height !== chartHeight) {
- // Create the gradient because this is either the first render
- // or the size of the chart has changed
- width = chartWidth;
- height = chartHeight;
- gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top);
- gradient.addColorStop(0, 'green');
- gradient.addColorStop(0.5, 'red');
- gradient.addColorStop(1, '#960018');
- }
- return gradient;
- }
-
-
- new Chart(ctx, {
- type: 'line',
- data: {
- labels: [<?=$s?>],
- datasets: [{
- label: 'Магнитные возмущения',
- data: <?=$str?>,
- borderWidth: 1,
- fill: true,
- tension: 0.5,
- pointRadius: 0,
- backgroundColor: function(context) {
- const chart = context.chart;
- const {ctx, chartArea} = chart;
- if (!chartArea) {
- // This case happens on initial chart load
- return;
- }
- return getGradient(ctx, chartArea);
- },
- }]
- },
- options: {
- scales: {
- y: {
- beginAtZero: true,
- min:0,
- max:10
- }
- }
- }
- });
- new Chart(ctx0, {
- type: 'bar',
- data: {
- labels: [<?=$ss?>],
- datasets: [{
- label: 'Магнитные возмущения сегодня',
- data: <?=$strn?>,
- borderWidth: 1,
- fill: true,
- backgroundColor: [<?=$cd?>]
- }]
- },
- options: {
- scales: {
- y: {
- beginAtZero: true,
- min:0,
- max:10
- }
- }
- }
- });
- </script>
- <?
- // $this->registerJs(
- // "myChart = new Chart(document.getElementById('js-chart-1').getContext( '2d' ),config); console.log(config)",
- // View::POS_END
- //);
- }
- foreach( $data as $file )
- {
- $str = @file_get_contents( $cat.$file );
- if( $str ){
- $obj = json_decode($str);
- // echo "<pre>";
- // print_r($obj);
- // echo "</pre>";
- $cur_date = date( "d-m-Y H:i", $obj->fact->obs_time );
- echo "<h2>$city[$file]</h2><div class=\"town row justify-content-md-center mb-5 bg-white\">";
- foreach( $obj->forecast->parts as $w ){
- // echo $w->part_name;
- $t_max = $w->temp_max;
- $t_min = $w->temp_min;
- $p_min = $w->pressure_mm;
- $p_max = $w->pressure_mm;
- $w_min = $w->wind_speed;
- $w_max = $w->wind_gust;
- $day = date( "d", $obj->fact->obs_time );
- $month = date( "m", $obj->fact->obs_time );
- $hour = $part_name[$w->part_name];
- $year = date( "Y", $obj->fact->obs_time );
- $cloudiness = $w->condition;
- $precipitation = $w->prec_mm;
- $icon = $w->icon;
- ?>
- <div class="hour col-md-4 p-2 mx-3">
- <div class='date'>На <?=$hour?> <?=$day?>.<?=$month?>.<?=$year?></div>
- <div><big><b><?=$t_min?><sup>o</sup>C до <?=$t_max?><sup>o</sup>C</b></big></div>
- <div class="sign mx-auto col-3">
- <? if( $icon !='' )
- {
- ?>
- <img class="weathericon2" src="https://yastatic.net/weather/i/icons/funky/dark/<?=$icon?>.svg" >
- <?
- }
- ?>
- </div>
- Давление <?=$p_min?>мм рт.ст.<br/>
- <span style = 'padding-top:5px'>Ветер <?=$w_min?>, <?=$w_max?>м/с</span>
- </div>
- <?
- }
- echo "</div>";
- }
- if( 0 && $str ){
- $xml = simplexml_load_string( $str );
- if( $xml ){
- $town = rawurldecode( $xml->REPORT->TOWN['sname'] );
- $town = ( $town == 'SLAVGOROD' )?'Славгород':$town;
- $town = ( $town == "KAMEN'-NA-OBI" )?'Камень-на-Оби':$town;
- $town = ( $town == "Заринск,+Алтайский+край,+Россия" )?'Заринск':$town;
- echo "<h2>$town</h2><div class=\"town row justify-content-md-center mb-5 bg-white\">";
- foreach( $xml->REPORT->TOWN->FORECAST as $w ){
- $t_max = $w->TEMPERATURE['max'];
- $t_min = $w->TEMPERATURE['min'];
- $p_min = $w->PRESSURE['min'];
- $p_max = $w->PRESSURE['max'];
- $w_min = $w->WIND['min'];
- $w_max = $w->WIND['max'];
- $day = $w['day'];
- $month = $w['month'];
- $hour = $w['hour'];
- $year = $w['year'];
- $cloudiness = $w->PHENOMENA['cloudiness'];
- $precipitation = $w->PHENOMENA['precipitation'];
- ?>
- <div class="hour col-md-3 p-2">
- <div class='date'>На <?=$hour?> час <?=$day?>.<?=$month?>.<?=$year?></div>
- <p><big><b><?=$t_min?><sup>o</sup>C до <?=$t_max?><sup>o</sup>C</b></big></p>
- Давление <?=$p_min?>, <?=$p_max?>мм рт.ст.<br/>
- <span style = 'padding-top:5px'>Ветер <?=$w_min?>, <?=$w_max?>м/с</span>
- <div class="sign fleft col-3">
- <? if( $precipitationi["$precipitation"] !='' )
- {
- ?>
- <img class="weathericon2" src="/img/weather/<?=($precipitationi["$precipitation"] !='' )?$precipitationi["$precipitation"]:'e.gif'?>" >
- <?
- }
- ?>
- <img class="weathericon2" src="/img/weather/<?=($cloudsi["$cloudiness"] != '')?$cloudsi["$cloudiness"]:'e.gif'?>" >
- </div>
- </div>
-
- <?
- }
- echo "</div>";
- }
- }
- }
- ?>
- <p><center><a href="https://yandex.ru/pogoda/"><img src="/img/logo_weather_ru_indoor.svg" height="30px"><br><h5>По данным сервиса</h5></a></center></p>
- </div>
- <div class="col-md-4 overflow-hidden">
- <?=$this->render("/layouts/lenta/temalenta", ['topic'=>89, 'items'=>20])?>
- </div>
- </div>
- </div>
|