aboutsummaryrefslogtreecommitdiff
path: root/src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2022-04-28 01:32:54 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-04-28 01:33:08 +0200
commit55cd53f4e6b1e13d2866a84a9631be8f89651cf2 (patch)
tree5b77ffc3311b490d4f979055e97823011280aace /src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte
parentae52909d00cdcda30d6ed07e302c0a50abe70b75 (diff)
downloadAurora-data-55cd53f4e6b1e13d2866a84a9631be8f89651cf2.tar.gz
Aurora-data-55cd53f4e6b1e13d2866a84a9631be8f89651cf2.zip
Add one hour forecast
Diffstat (limited to 'src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte')
-rw-r--r--src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte b/src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte
new file mode 100644
index 0000000..7e13c2b
--- /dev/null
+++ b/src/components/Forecast/ThreeDayForecast/ThreeDayForecast.svelte
@@ -0,0 +1,77 @@
+<script lang="ts">
+ import PredictionItem from './PredictionItem.svelte';
+
+ import { onMount } from 'svelte';
+ import { earth_weather, space_weather } from '../../../stores';
+
+ const monthNames = ["January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"
+ ];
+
+ let predictions;
+
+ space_weather.subscribe(assembleWeatherData);
+ earth_weather.subscribe(assembleWeatherData);
+
+ async function assembleWeatherData() {
+ if ($space_weather.updating || $earth_weather.updating) {
+ predictions = null;
+ return;
+ }
+
+ // First just reorganize the space_weather data
+ let forecast = $space_weather.usnoaa_data_raw.noaa_planetary_k_index_forecast.filter(x => x.observed !== "observed");
+ predictions = forecast.map(
+ pred => ({
+ "time": pred.time,
+ "kp": pred.kp,
+ "observed": pred.observed,
+ "temp": null,
+ "clouds": null,
+ "hasNOMETData": $earth_weather.available
+ })
+ );
+
+ // Add earth weather data if it is available
+ if ($earth_weather.available) {
+ predictions.forEach((pred, i) => {
+ let closestDate = new Date(0,0,0);
+ let temp;
+ let clouds;
+
+ $earth_weather.yr_data_raw.properties.timeseries.forEach((earth_pred, i) => {
+ let predDate = new Date(earth_pred.time);
+ if (Math.abs(predDate.getTime() - pred.time.getTime()) < Math.abs(closestDate.getTime() - pred.time.getTime())) {
+ closestDate = predDate;
+ temp = (earth_pred["data"]["instant"]["details"]["air_temperature"]);
+ clouds = earth_pred["data"]["instant"]["details"]["cloud_area_fraction"];
+ }
+ });
+
+ predictions[i] = {
+ ...predictions[i], "temp": temp, "clouds": clouds
+ }
+ });
+ }
+
+ }
+
+</script>
+
+<style>
+ .prediction-table {
+ height: 100%;
+ overflow-y: scroll;
+ padding-bottom: 1rem;
+ }
+
+ .prediction-table::-webkit-scrollbar {
+ display: none;
+ }
+</style>
+
+<div class="prediction-table">
+ {#each predictions as prediction, i}
+ <PredictionItem {prediction}/>
+ {/each}
+</div>