/*$fechaFinal=date("Y-m-d")."T".date("H:i:s"); $ano=date("Y"); $mesTemp=date("m")-1; if ($mesTemp==0){ $mesTemp=12; $ano=$ano-1; } $mes=""; if(mesTemp<10) { $mes="0".$mesTemp; } else { $mes=$mesTemp; } $dia=date("d"); if($dia==31){ if($mes<>2){ $dia=30; } else { $dia=28; } }*/ $miFecha=new DateTime('Now'); $miFechaFinal=$miFecha->format('Y-m-d')."T".$miFecha->format("H:i:s"); $miFecha2=$miFecha; $miFecha2->modify('-1 month'); $miFechaInicial=$miFecha->format('Y-m-d')."T00:00:00"; //$fechaInicial=$ano."-".$mesTemp."-".$dia."T00:00:00"; //$strFI="datetime\'".$fechaInicial."\'"; //$strFF="datetime\'".$fechaFinal."\'"; $miFecha24h=new DateTime('Now'); $miFecha48h=new DateTime('Now'); $sieteDiasAntes=new DateTime('Now'); $catorceDiasAntes=new DateTime('Now'); $miFecha24h->modify('-1 day'); $miFecha48h->modify('-2 day'); $sieteDiasAntes->modify('-7 day'); $catorceDiasAntes->modify('-14 day'); $strFecha24h=$miFecha24h->format('Y-m-d'); $strFecha48h=$miFecha48h->format('Y-m-d'); $str7DiasAntes=$sieteDiasAntes->format('Y-m-d'); $str14DiasAntes=$catorceDiasAntes->format('Y-m-d'); $miFechaInicial=$str7DiasAntes."T00:00:00"; $miFechaInicial14=$str14DiasAntes."T00:00:00"; $strFI="datetime\'".$miFechaInicial."\'"; $strFI14="datetime\'".$miFechaInicial14."\'"; $strFF="datetime\'".$miFechaFinal."\'"; //datetime\'2020-10-31T00:00:00\' $dataBinarioLlanes7='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI.'"}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Municipio"}}],"Values":[[{"Literal":{"Value":"\'Llanes\'"}}]]}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1},"ExecutionMetricsKind":1}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $dataBinarioLlanes14='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI14.'"}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Municipio"}}],"Values":[[{"Literal":{"Value":"\'Llanes\'"}}]]}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1},"ExecutionMetricsKind":1}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $llanes=datosAsturias($dataBinarioLlanes7); $llanes7= $llanes["M0"]; $llanes=datosAsturias($dataBinarioLlanes14); $llanes14= $llanes["M0"]; $dataBinarioR7='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"And":{"Left":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI.'"}}}},"Right":{"Comparison":{"ComparisonKind":3,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFF.'"}}}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Latitud"}},{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Longitud"}}],"Values":[[{"Literal":{"Value":"43.37D"}},{"Literal":{"Value":"-4.57D"}}]]}}},{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"DateSpan":{"Expression":{"Literal":{"Value":"datetime\'2020-01-01T00:00:00\'"}},"TimeUnit":5}}}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1}}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $dataBinarioR14='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"And":{"Left":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI14.'"}}}},"Right":{"Comparison":{"ComparisonKind":3,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFF.'"}}}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Latitud"}},{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Longitud"}}],"Values":[[{"Literal":{"Value":"43.37D"}},{"Literal":{"Value":"-4.57D"}}]]}}},{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"DateSpan":{"Expression":{"Literal":{"Value":"datetime\'2020-01-01T00:00:00\'"}},"TimeUnit":5}}}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1}}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $ribadedeva= datosAsturias($dataBinarioR7); $ribadedeva7= $ribadedeva["M0"]; $ribadedeva= datosAsturias($dataBinarioR14); $ribadedeva14= $ribadedeva["M0"]; //Segundo Concejo $dataBinarioP7='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"And":{"Left":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI.'"}}}},"Right":{"Comparison":{"ComparisonKind":3,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFF.'"}}}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Latitud"}},{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Longitud"}}],"Values":[[{"Literal":{"Value":"43.31D"}},{"Literal":{"Value":"-4.59D"}}]]}}},{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"DateSpan":{"Expression":{"Literal":{"Value":"datetime\'2020-01-01T00:00:00\'"}},"TimeUnit":5}}}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1}}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $dataBinarioP14='{"version":"1.0.0","queries":[{"Query":{"Commands":[{"SemanticQueryDataShapeCommand":{"Query":{"Version":2,"From":[{"Name":"c","Entity":"Casos confirmados","Type":0},{"Name":"f","Entity":"Fechas","Type":0},{"Name":"m","Entity":"Municipios","Type":0}],"Select":[{"Measure":{"Expression":{"SourceRef":{"Source":"c"}},"Property":"Núm. casos confirmados"},"Name":"Casos confirmados.Núm. casos confirmados"}],"Where":[{"Condition":{"And":{"Left":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFI14.'"}}}},"Right":{"Comparison":{"ComparisonKind":3,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"Literal":{"Value":"'.$strFF.'"}}}}}}},{"Condition":{"In":{"Expressions":[{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Latitud"}},{"Column":{"Expression":{"SourceRef":{"Source":"m"}},"Property":"Longitud"}}],"Values":[[{"Literal":{"Value":"43.31D"}},{"Literal":{"Value":"-4.59D"}}]]}}},{"Condition":{"Comparison":{"ComparisonKind":2,"Left":{"Column":{"Expression":{"SourceRef":{"Source":"f"}},"Property":"Fecha"}},"Right":{"DateSpan":{"Expression":{"Literal":{"Value":"datetime\'2020-01-01T00:00:00\'"}},"TimeUnit":5}}}}}]},"Binding":{"Primary":{"Groupings":[{"Projections":[0]}]},"DataReduction":{"DataVolume":3,"Primary":{"Top":{}}},"Version":1}}}]},"QueryId":"","ApplicationContext":{"DatasetId":"f88d83cd-7b6e-4913-95b9-4be8d93e7208","Sources":[{"ReportId":"9fb0aec7-e0a5-4ca8-8d30-c817b27ac857"}]}}],"cancelQueries":[],"modelId":404258}'; $penamellera=datosAsturias($dataBinarioP7); $penamellera7=$penamellera["M0"]; $penamellera=datosAsturias($dataBinarioP14); $penamellera14=$penamellera["M0"]; $url="https://services3.arcgis.com/JW6jblFaBSUw9ROV/arcgis/rest/services/COVID19MunicipiosUpdate/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=NOMBRE%20asc&resultOffset=0&resultRecordCount=104&resultType=standard&cacheHint=true"; $arrayDatos []= dameDatos ($url); $datosVal[] = $arrayDatos[0][91]; $datosHerr[] = $arrayDatos[0][33]; $datosSVB[] = $arrayDatos[0][73]; $valorVSV14= calculaAfectados($datosVal[0]["attributes"]["Pob_Municipio"],$datosVal[0]["attributes"]["Tasa_100K_14dias"]); $valorVSV7= calculaAfectados($datosVal[0]["attributes"]["Pob_Municipio"],$datosVal[0]["attributes"]["Tasa_100K_7dias"]); $valorVSVAcum=$datosVal[0]["attributes"]["Positivos"]; $valorVSVTot=$datosVal[0]["attributes"]["Fallecidos"]; $valorTemporal=$datosVal[0]["attributes"]["Positivosx100K"]/1000; $valorVSVPos=$valorTemporal."%"; $valorVSVAct=$datosVal[0]["attributes"]["Activos"]; $valorSVB14= calculaAfectados($datosSVB[0]["attributes"]["Pob_Municipio"],$datosSVB[0]["attributes"]["Tasa_100K_14dias"]); $valorSVB7= calculaAfectados($datosSVB[0]["attributes"]["Pob_Municipio"],$datosSVB[0]["attributes"]["Tasa_100K_7dias"]); $valorSVBAcum=$datosSVB[0]["attributes"]["Positivos"]; $valorSVBTot=$datosSVB[0]["attributes"]["Fallecidos"]; $valorTemporal=$datosSVB[0]["attributes"]["Positivosx100K"]/1000; $valorSVBPos=$valorTemporal."%"; $valorSVBAct=$datosSVB[0]["attributes"]["Activos"]; $valorHERR14= calculaAfectados($datosHerr[0]["attributes"]["Pob_Municipio"],$datosHerr[0]["attributes"]["Tasa_100K_14dias"]); $valorHERR7= calculaAfectados($datosHerr[0]["attributes"]["Pob_Municipio"],$datosHerr[0]["attributes"]["Tasa_100K_7dias"]); $valorHERRAcum=$datosHerr[0]["attributes"]["Positivos"]; $valorHERRTot=$datosHerr[0]["attributes"]["Fallecidos"]; $valorTemporal=$datosHerr[0]["attributes"]["Positivosx100K"]/1000; $valorHERRPos=$valorTemporal."%"; $valorHERRAct=$datosHerr[0]["attributes"]["Activos"]; function dameDatos($miUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $miUrl); $result = curl_exec($ch); curl_close($ch); $obj = json_decode($result, true); $test []= $obj["features"]; $prueba= $test[0]; $res=$prueba[0]; return $prueba; } function calculaAfectados ($poblacion, $dato) { $resultado= round($dato*$poblacion/100000); return $resultado; } function dameDato($miUrl) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $miUrl); $result = curl_exec($ch); curl_close($ch); $obj = json_decode($result, true); $test []= $obj["features"]; $prueba= $test[0]; $res=$prueba[0]; $res2=$res["attributes"]; return $res2["value"]; } function datosAsturias($binariu){ $urlQ="https://wabi-west-europe-d-primary-api.analysis.windows.net/public/reports/querydata?synchronous=true"; $chW = curl_init(); // IMPORTANT: the below line is a security risk, read https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software // in most cases, you should set it to true curl_setopt($chW, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($chW, CURLOPT_RETURNTRANSFER, true); curl_setopt($chW,CURLOPT_ENCODING , ""); curl_setopt($chW, CURLOPT_POST, 1 ); curl_setopt($chW, CURLOPT_POSTFIELDS, $binariu ); curl_setopt($chW, CURLOPT_URL, $urlQ); curl_setopt($chW, CURLOPT_HTTPHEADER, array( 'Connection: keep-alive', 'Accept: application/json, text/plain, */*', 'RequestId: 1a57f968-4e6b-6dae-eef9-fbd2092f8343', 'X-PowerBI-ResourceKey: 57ac9ab5-fac6-460a-8b59-2cc46976360e', 'Content-Type: application/json;charset=UTF-8', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36', 'ActivityId: e3978831-5ee5-454e-852b-6c72bc8183c4', 'Origin: https://app.powerbi.com', 'Sec-Fetch-Site: cross-site', 'Sec-Fetch-Mode: cors', 'Sec-Fetch-Dest: empty', 'Referer: https://app.powerbi.com/', 'Accept-Language: es-ES,es;q=0.9' )); $resultW = curl_exec($chW); curl_close($chW); $objW = json_decode($resultW, true); $testW = $objW["results"]; $test2W=$testW[0]; $pruebaW= $test2W["result"]; $resW=$pruebaW["data"]; $restW=$resW["dsr"]; $res2W=$restW["DS"]; $res2tW=$res2W[0]; $res3W=$res2tW["PH"]; $res4W=$res3W[0]; $res5W=$res4W["DM0"]; $res6W=$res5W[0]; return $res6W; } ?>