1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
<script lang="ts">
import { onMount } from 'svelte';
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
let longitude;
let latitude;
let locationSupported;
let dataLoading = true;
let location = "-";
let date = "-";
let kp_now = "-";
let kp_min = "-";
let kp_max = "-";
let bz = "-";
let clouds = "-";
let temp = "-";
async function getMETNorData(longitude, latitude) {
let yr_data = await fetch(`https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${latitude}&lon=${longitude}`).then(res => res.json());
clouds = yr_data["properties"]["timeseries"][0]["data"]["instant"]["details"]["cloud_area_fraction"];
temp = yr_data["properties"]["timeseries"][0]["data"]["instant"]["details"]["air_temperature"];
}
async function getLocation(longitude, latitude) {
console.log(`https://geocode.xyz/${longitude},${latitude}?geoit=json`);
let locDat = await fetch(`https://geocode.xyz/${latitude},${longitude}?geoit=json`).then(r => r.json());
console.log(locDat);
location = locDat["city"];
}
async function getUSNOAAData() {
bz = (await fetch("https://services.swpc.noaa.gov/products/summary/solar-wind-mag-field.json").then(res => res.json()))["Bz"];
let kp_data = (await fetch('https://services.swpc.noaa.gov/products/noaa-planetary-k-index-forecast.json').then(res => res.json()));
kp_data.shift();
let cDate = new Date();
let closestDate = new Date(0,0,0);
let minkp = 1000; // Just a larger number than any plausable value
let maxkp = 0;
kp_data.forEach((pred, i) => {
if (pred[1] > maxkp) {
maxkp = pred[1];
}
if (pred[1] < minkp) {
minkp = pred[1];
}
let predDate = new Date(pred[0]);
if (Math.abs(predDate.getTime() - cDate.getTime()) < Math.abs(closestDate.getTime() - cDate.getTime())) {
closestDate = predDate;
kp_now = pred[1];
}
});
kp_min = minkp.toString();
kp_max = maxkp.toString();
date = closestDate.getDay() + ". " + monthNames[closestDate.getMonth()] + " " + closestDate.getHours() + ":" + closestDate.getMinutes();
}
function fetchData() {
getUSNOAAData();
if (navigator.geolocation) {
dataLoading = true
locationSupported = true
navigator.geolocation.getCurrentPosition(setLocation, locationError)
} else {
locationSupported = false
noLocation()
}
}
function setLocation(position) {
longitude = position.coords.longitude
latitude = position.coords.latitude
getMETNorData(longitude, latitude)
getLocation(longitude, latitude);
}
function locationError(err) {
noLocation()
}
function noLocation() {
longitude = 28.283333
latitude = -15.416667
toggleLoading()
}
function toggleLoading() {
dataLoading = !dataLoading
}
onMount(fetchData);
</script>
<style>
.weatherCurrent-wrapper {
height: calc(100% + 2rem);
align-self: stretch;
font-family: Roboto, sans-serif;
font-size: 1rem;
letter-spacing: 0.05em;
--bg-opacity: 1;
background-color: #1a202c;
background-color: rgba(26, 32, 44, var(--bg-opacity));
background:
linear-gradient(
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)
), url(/Aurora-data/aurora.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.weatherCurrent-data {
width: 100%;
padding: 1.5rem;
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
--text-opacity: 1;
color: #fff;
color: rgba(255, 255, 255, var(--text-opacity));
text-align: center;
letter-spacing: 0.05em;
text-shadow: 1px 1px 2px rgba(0,0,0,.75);
}
.weatherCurrent-data-location {
display: flex;
justify-content: center;
align-content: center;
}
.weatherCurrent-data-location .symbol {
width: 1.5rem;
height: 1.5rem;
margin-right: 1rem;
}
.weatherCurrent-data-location h1 {
text-transform: uppercase;
font-family: Roboto Condensed, sans-serif;
font-size: 1.125rem;
letter-spacing: 0.1em;
margin-bottom: 0;
}
.weatherCurrent-data-kp h2 {
font-weight: 700;
font-size: 3rem;
letter-spacing: 0.05em;
line-height: 1.25;
}
.current-details {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-gap: 1rem;
gap: 1rem;
padding-bottom: 1.5rem;
text-shadow: 1px 1px 2px rgba(0,0,0,.75);
}
.current-details p {
line-height: 1.375;
}
</style>
<div class="weatherCurrent-wrapper">
<div class="weatherCurrent-data">
<div class="weatherCurrent-data-location">
<i class="symbol fas fa-map-marker-alt"></i>
<h1>{location}</h1>
</div>
<div class="weatherCurrent-data-date">
<p>{date}</p>
</div>
<div class="weatherCurrent-data-kp">
<h2>KP {kp_now}</h2>
<p>
<span className="pr-2">↑ KP {kp_max}</span>
<span className="pl-2">↓ KP {kp_min}</span>
</p>
</div>
<div class="current-details">
<div>
<p>BZ</p>
<p>{bz}</p>
</div>
<div>
<p>Temp</p>
<p>{temp}°C</p>
</div>
<div>
<p>Clouds</p>
<p>{clouds}%</p>
</div>
</div>
</div>
</div>
|