diff --git "a/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.gitignore" "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..74faec048a941403f43f52372e5d23210829e026 --- /dev/null +++ "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.gitignore" @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.tuulenHyytavyys.iml +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git "a/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.name" "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.name" new file mode 100644 index 0000000000000000000000000000000000000000..57021cfad401c269b7fa1b4f7c32ba0904b7ff50 --- /dev/null +++ "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/.name" @@ -0,0 +1 @@ +tuulenHyytavyys \ No newline at end of file diff --git "a/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/indexLayout.xml" "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/indexLayout.xml" new file mode 100644 index 0000000000000000000000000000000000000000..7b08163cebc50fb3e777eea4881b68fcebc10590 --- /dev/null +++ "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/indexLayout.xml" @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="UserContentModel"> + <attachedFolders /> + <explicitIncludes /> + <explicitExcludes /> + </component> +</project> \ No newline at end of file diff --git "a/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/vcs.xml" "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/vcs.xml" new file mode 100644 index 0000000000000000000000000000000000000000..6c0b8635858dc7ad44b93df54b762707ce49eefc --- /dev/null +++ "b/ty\303\266/.idea/.idea.tuulenHyytavyys/.idea/vcs.xml" @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git "a/ty\303\266/ty\303\266/Program.cs" "b/ty\303\266/ty\303\266/Program.cs" index cd1510ff3bf9389e65fae853400ddee6d9a2277d..2ff2cc07f909cc365adab2fb66744e5dc374d551 100644 --- "a/ty\303\266/ty\303\266/Program.cs" +++ "b/ty\303\266/ty\303\266/Program.cs" @@ -13,25 +13,25 @@ namespace työ; class TuulenHyytavyys { /// <summary> - /// Ohjelman päämetodi, joka hakee säätiedot ja laskee tuulen hyytävyyden. + /// Ohjelma, joka hakee säätiedot ja laskee tuulen hyytävyyden. /// </summary> static async Task Main() { string[] timeStamps = { - "2024-01-25T12:00:00Z", - "2024-01-26T12:00:00Z", - "2024-01-27T12:00:00Z", - "2024-01-28T12:00:00Z", - "2024-01-29T12:00:00Z", - "2024-01-30T12:00:00Z", - "2024-01-31T12:00:00Z" + "2024-03-25T12:00:00Z", + "2024-03-26T12:00:00Z", + "2024-03-27T12:00:00Z", + "2024-03-28T12:00:00Z", + "2024-03-29T12:00:00Z", + "2024-03-30T12:00:00Z", + "2024-03-31T12:00:00Z" }; string place = "Jyväskylä"; string baseUrl = "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=GetFeature" + "&storedquery_id=fmi::observations::weather::timevaluepair" + $"&place={Uri.EscapeDataString(place)}" + - "¶meters=t2m,rh,windspeedms"; // http: pyyntö Ilmatieteenlaitoksen avoimen datan rajapintaan, tarkennukset: paikka Jyväskylä ja parametrit lämpötila, kosteus ja tuulennopeus + "¶meters=t2m,rh,windspeedms"; try { @@ -51,12 +51,12 @@ class TuulenHyytavyys XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable); nsManager.AddNamespace("wml2", "http://www.opengis.net/waterml/2.0"); - // Haetaan muuttujat lämpötila (t2m), suhteellinen kosteus (rh) ja tuulennopeus (windspeedms) + XmlNode? temperatureNode = xmlDoc.SelectSingleNode("(//wml2:MeasurementTVP/wml2:value)[1]", nsManager); XmlNode? humidityNode = xmlDoc.SelectSingleNode("(//wml2:MeasurementTVP/wml2:value)[2]", nsManager); XmlNode? windSpeedNode = xmlDoc.SelectSingleNode("(//wml2:MeasurementTVP/wml2:value)[3]", nsManager); - // Muokataan arvoja + string temperatureStr = temperatureNode?.InnerText.Trim() ?? "Ei löydy"; string humidityStr = humidityNode?.InnerText.Trim() ?? "Ei löydy"; string windSpeedStr = windSpeedNode?.InnerText.Trim() ?? "Ei löydy"; @@ -66,7 +66,7 @@ class TuulenHyytavyys Console.WriteLine($"Ilmankosteus: {humidityStr} %"); Console.WriteLine($"Tuulen nopeus: {windSpeedStr} m/s"); - // Tarkistetaan ja muunnetaan arvot numeerisiksi + if (double.TryParse(temperatureStr, NumberStyles.Any, CultureInfo.InvariantCulture, out double temperature) && double.TryParse(humidityStr, NumberStyles.Any, CultureInfo.InvariantCulture, out double humidity) && double.TryParse(windSpeedStr, NumberStyles.Any, CultureInfo.InvariantCulture, out double windSpeed)) @@ -76,12 +76,12 @@ class TuulenHyytavyys } else { - Console.WriteLine("Säädatan muuntaminen numeroiksi ei onnistu"); // + Console.WriteLine("Säädatan muuntaminen numeroiksi ei onnistu"); } } } } - catch (HttpRequestException e) // virhe ilmoitukset, jos pyyntö epäönnistuu + catch (HttpRequestException e) { Console.WriteLine("HTTP-pyyntö epäonnistui: " + e.Message); }