historicalWeatherData.js 13.3 KB
Newer Older
Weiser's avatar
asdf  
Weiser committed
1
2
import React from "react";

Weiser's avatar
new    
Weiser committed
3
import "./weatherForecastData.css";
Weiser's avatar
asdf  
Weiser committed
4
5

const HistoricalWeatherData = (props) => {
EnesKarakas's avatar
csy    
EnesKarakas committed
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
  return (
    <div className="home-container">
      <div>
        <div className="thq-grid-5">
          <div class="filter">
            <div class="filter">
              <label for="location">Location:</label>
              <input type="text" id="city_text" placeholder="Location" />
              <br />
              <label for="region">Region:</label>
              <input type="text" id="region_text" placeholder="Region" />
              <br />
              <label>Country:</label>
              <input type="text" id="country_text" placeholder="Country" />
              <br />
              <label>Latitude:</label>
              <input type="text" id="latitude_text" placeholder="Latitude" />
              <label>Longitude:</label>
              <input type="text" id="longitude_text" placeholder="Longitude" />
              <br />
              <label>Time Zone:</label>
              <input type="text" id="timezone_text" placeholder="Timezone" />
              <br />
            </div>
            <input type="checkbox" id="latitude" class="checkBoxFilter" />
            <label for="latitude">Latitude</label>
            <br />
            <input type="checkbox" id="longitude" class="checkBoxFilter" />
            <label for="longitude">Longitude</label>
            <br />
            <input
              type="checkbox"
              id="generationtime_ms"
              class="checkBoxFilter"
            />
            <label for="generationtime_ms">Generation Time (ms)</label>
            <br />
            <input
              type="checkbox"
              id="utc_offset_seconds"
              class="checkBoxFilter"
            />
            <label for="utc_offset_seconds">UTC Offset (Seconds)</label>
            <br />
            <input type="checkbox" id="timezone" class="checkBoxFilter" />
            <label for="timezone">Timezone</label>
            <br />
            <input
              type="checkbox"
              id="timezone_abbreviation"
              class="checkBoxFilter"
            />
            <label for="timezone_abbreviation">Timezone Abbreviation</label>
            <br />
            <input type="checkbox" id="elevation" class="checkBoxFilter" />
            <label for="elevation">Elevation</label>
            <br />
            <p>Hourly</p>
            <br />
            <input type="checkbox" id="hourly_time" class="checkBoxFilter" />
            <label for="hourly_time">Hourly Time</label>
            <br />
            <input type="checkbox" id="temperature_2m" class="checkBoxFilter" />
            <label for="temperature_2m">Temperature 2m</label>
            <br />
            <input
              type="checkbox"
              id="relative_humidity_2m"
              class="checkBoxFilter"
            />
            <label for="relative_humidity_2m">Relative Humidity 2m</label>
            <br />
            <input type="checkbox" id="precipitation" class="checkBoxFilter" />
            <label for="precipitation">Precipitation</label>
            <br />
            <input
              type="checkbox"
              id="surface_pressure"
              class="checkBoxFilter"
            />
            <label for="surface_pressure">Surface Pressure</label>
            <br />
            <input type="checkbox" id="wind_speed_10m" class="checkBoxFilter" />
            <label for="wind_speed_10m">Wind Speed 10m</label>
            <br />
            <input
              type="checkbox"
              id="wind_direction_10m"
              className="checkBoxFilter"
            />
            <label for="wind_direction_10m">Wind Direction 10m</label>
            <br />
            <input
              type="checkbox"
              id="wind_gusts_10m"
              className="checkBoxFilter"
            />
            <label for="wind_gusts_10m">Wind Gusts 10m</label>
            <br />
            <p>Dayly</p>
            <br />
            <input type="checkbox" id="daily_time" class="checkBoxFilter" />
            <label for="daily_time">Daily Time</label>
            <br />
            <input
              type="checkbox"
              id="temperature_2m_max"
              class="checkBoxFilter"
            />
            <label for="temperature_2m_max">Temperature 2m Max</label>
            <br />
            <input
              type="checkbox"
              id="temperature_2m_min"
              class="checkBoxFilter"
            />
            <label for="temperature_2m_min">Temperature 2m Min</label>
            <br />
            <input
              type="checkbox"
              id="temperature_2m_mean"
              class="checkBoxFilter"
            />
            <label for="temperature_2m_mean">Temperature 2m Mean</label>
            <br />
            <input
              type="checkbox"
              id="precipitation_sum"
              class="checkBoxFilter"
            />
            <label for="precipitation_sum">Precipitation Sum</label>
            <br />
            <input
              type="checkbox"
              id="precipitation_hours"
              class="checkBoxFilter"
            />
            <label for="precipitation_hours">Precipitation Hours</label>
            <br />
            <input
              type="checkbox"
              id="wind_speed_10m_max"
              class="checkBoxFilter"
            />
            <label for="wind_speed_10m_max">Wind Speed 10m Max</label>
            <br />
            <input
              type="checkbox"
              id="wind_gusts_10m_max"
              class="checkBoxFilter"
            />
            <label for="wind_gusts_10m_max">Wind Gusts 10m Max</label>
            <br />
            <input
              type="checkbox"
              id="wind_direction_10m_dominant"
              class="checkBoxFilter"
            />
            <label for="wind_direction_10m_dominant">
              Wind Direction 10m Dominant
            </label>
            <br />
            <div>
              <label for="units">Choose a unit:</label>
Weiser's avatar
yippie    
Weiser committed
170
171
              <select name="unnits" id="units">
                <option value="world">Rest of The World</option>
EnesKarakas's avatar
csy    
EnesKarakas committed
172
173
174
                <option value="american">
                  American units: /eagles per shool shootings
                </option>
Weiser's avatar
yippie    
Weiser committed
175
              </select>
EnesKarakas's avatar
csy    
EnesKarakas committed
176
177
            </div>
            <div class="output">
Weiser's avatar
yippie    
Weiser committed
178
179
180
181
182
183
184
185
              <h2>Output:</h2>
              <br />
              <pre id="weatherData"></pre>
            </div>
            <div id="apiUrl">
              <label>API URL:</label>
              <br />
              <input className="input" type="text" id="apiUrloutput" readOnly />
Weiser's avatar
asdf  
Weiser committed
186
            </div>
Weiser's avatar
yippie    
Weiser committed
187
188
189
190
191
            <button className="APIButton" onClick={searchAPI}>
              City api
            </button>
            <br />
            <br />
Weiser's avatar
asdf  
Weiser committed
192
193
          </div>
        </div>
Weiser's avatar
yippie    
Weiser committed
194
195
      </div>
    </div>
EnesKarakas's avatar
csy    
EnesKarakas committed
196
  );
Weiser's avatar
asdf  
Weiser committed
197

EnesKarakas's avatar
csy    
EnesKarakas committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
  function getData() {
    const city_text = document.getElementById("city_text").value;
    const region_text = document.getElementById("region_text").value;
    const country_text = document.getElementById("country_text").value;
    const latitude_text = document.getElementById("latitude_text").value;
    const longitude_text = document.getElementById("longitude_text").value;
    const timezone_text = document.getElementById("timezone_text").value;

    //Checkboxes
    const latitude = document.getElementById("latitude").checked;
    const longitude = document.getElementById("longitude").checked;
    const generationtime_ms =
      document.getElementById("generationtime_ms").checked;
    const utc_offset_seconds =
      document.getElementById("utc_offset_seconds").checked;
    const timezone = document.getElementById("timezone").checked;
    const timezone_abbreviation = document.getElementById(
      "timezone_abbreviation"
    ).checked;
    const elevation = document.getElementById("elevation").checked;
    const hourly_time = document.getElementById("hourly_time").checked;
    const temperature_2m = document.getElementById("temperature_2m").checked;
    const relative_humidity_2m = document.getElementById(
      "relative_humidity_2m"
    ).checked;
    const precipitation = document.getElementById("precipitation").checked;
    const surface_pressure =
      document.getElementById("surface_pressure").checked;
    const wind_speed_10m = document.getElementById("wind_speed_10m").checked;
    const wind_direction_10m =
      document.getElementById("wind_direction_10m").checked;
    const wind_gusts_10m = document.getElementById("wind_gusts_10m").checked;
    const daily_time = document.getElementById("daily_time").checked;
    const temperature_2m_max =
      document.getElementById("temperature_2m_max").checked;
    const temperature_2m_min =
      document.getElementById("temperature_2m_min").checked;
    const temperature_2m_mean = document.getElementById(
      "temperature_2m_mean"
    ).checked;
    const precipitation_sum =
      document.getElementById("precipitation_sum").checked;
    const precipitation_hours = document.getElementById(
      "precipitation_hours"
    ).checked;
    const wind_speed_10m_max =
      document.getElementById("wind_speed_10m_max").checked;
    const wind_gusts_10m_max =
      document.getElementById("wind_gusts_10m_max").checked;
    const wind_direction_10m_dominant = document.getElementById(
      "wind_direction_10m_dominant"
    ).checked;

    let filterArray = [];

    if (latitude) {
      filterArray.push("latitude");
    }
    if (longitude) {
      filterArray.push("longitude");
    }
    if (generationtime_ms) {
      filterArray.push("generationtime_ms");
    }
    if (utc_offset_seconds) {
      filterArray.push("utc_offset_seconds");
    }
    if (timezone) {
      filterArray.push("timezone");
    }
    if (timezone_abbreviation) {
      filterArray.push("timezone_abbreviation");
    }
    if (elevation) {
      filterArray.push("elevation");
    }
    if (hourly_time) {
      filterArray.push("hourly.time");
    }
    if (temperature_2m) {
      filterArray.push("hourly.temperature_2m");
    }
    if (relative_humidity_2m) {
      filterArray.push("hourly.relative_humidity_2m");
    }
    if (precipitation) {
      filterArray.push("hourly.precipitation");
    }
    if (surface_pressure) {
      filterArray.push("hourly.surface_pressure");
    }
    if (wind_speed_10m) {
      filterArray.push("hourly.wind_speed_10m");
    }
    if (wind_direction_10m) {
      filterArray.push("hourly.wind_direction_10m");
    }
    if (wind_gusts_10m) {
      filterArray.push("hourly.wind_gusts_10m");
    }
    if (daily_time) {
      filterArray.push("daily.time");
    }
    if (temperature_2m_max) {
      filterArray.push("daily.temperature_2m_max");
    }
    if (temperature_2m_min) {
      filterArray.push("daily.temperature_2m_min");
    }
    if (temperature_2m_mean) {
      filterArray.push("daily.temperature_2m_mean");
    }
    if (precipitation_sum) {
      filterArray.push("daily.precipitation_sum");
    }
    if (precipitation_hours) {
      filterArray.push("daily.precipitation_hours");
    }
    if (wind_speed_10m_max) {
      filterArray.push("daily.wind_speed_10m_max");
    }
    if (wind_gusts_10m_max) {
      filterArray.push("daily.wind_gusts_10m_max");
    }
    if (wind_direction_10m_dominant) {
      filterArray.push("daily.wind_direction_10m_dominant");
    }

    let filterString = filterArray.join(",");

    console.log("FilterString = " + filterString);

    const apiUrl = `http://localhost:8080/historicalweather?latitude=${latitude_text}&longitude=${longitude_text}&start_date=&end_date=&filter=${filterString}`;
Weiser's avatar
asdf  
Weiser committed
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }
        return response.json();
      })
      .then((data) => {
        // Wetterdaten anzeigen
        document.getElementById("weatherData").innerText = JSON.stringify(
          data,
          null,
          2
        );
        document.getElementById("apiUrloutput").value = apiUrl;
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }
  function searchAPI() {
EnesKarakas's avatar
csy    
EnesKarakas committed
353
    const cityInput = document.getElementById("city_text").value;
Weiser's avatar
asdf  
Weiser committed
354

EnesKarakas's avatar
csy    
EnesKarakas committed
355
    const apiUrl = `http://localhost:8080/search?city=${cityInput}`;
Weiser's avatar
asdf  
Weiser committed
356
357
358
359
360
361
362
363
364
365

    fetch(apiUrl)
      .then((response) => {
        if (!response.ok) {
          throw new Error("Network response was not ok");
        }

        return response.json();
      })
      .then((data) => {
EnesKarakas's avatar
csy    
EnesKarakas committed
366
        setData(data);
Weiser's avatar
asdf  
Weiser committed
367
368
369
370
371
372
373
374
375
376
      })
      .catch((error) => {
        console.error("There was a problem with the fetch operation:", error);
      });
  }

  function boolToWord(bool) {
    return bool ? "yes" : "no";
  }
};
EnesKarakas's avatar
csy    
EnesKarakas committed
377
378
379
380
381
382
383
384
const ListItem = ({ name, country, region, lat, lon }) => {
  const handleClick = () => {
    document.getElementById("city_text").value = name;
    document.getElementById("region_text").value = country;
    document.getElementById("country_text").value = region;
    document.getElementById("latitude_text").value = lat;
    document.getElementById("longitude_text").value = lon;
  };
Weiser's avatar
asdf  
Weiser committed
385

EnesKarakas's avatar
csy    
EnesKarakas committed
386
387
388
389
390
391
392
393
394
395
396
397
  return (
    <div className="list-item" onClick={handleClick}>
      <div className="title">{name}</div>
      <div className="subtitle">
        Country: {country} <br />
        Region: {region} <br />
        Lat: {lat}, Lon: {lon}
      </div>
    </div>
  );
};
export default HistoricalWeatherData;