#39-SMHI_view Data Connection: SMHI #151

Merged
c24elipe merged 6 commits from #39-SMHI_view into team_2_week_1 2026-04-10 10:13:51 +00:00
Collaborator

Implemented the SMHI observations (metobs) and SMHI forecast (snow1gv1) API:s. This is related to issue #39. The code also contains two files to demo the hooks.

changes made:
added useSMHIObservations.js (metobs API)
added useSMHIForecast.js (snow1gv1 API)
added SMHITemperatureView.js (metobs demo)
added SMHIForecastCard.js (snow1gv1 demo)

testing:
checked that the demo views/cards showed the correct data fetched from SMHI

note:
The react hooks are fairly simple, and discard some choices the API:s give us. The issue might need to be revisited in the future.

Implemented the SMHI observations (metobs) and SMHI forecast (snow1gv1) API:s. This is related to issue #39. The code also contains two files to demo the hooks. changes made: added useSMHIObservations.js (metobs API) added useSMHIForecast.js (snow1gv1 API) added SMHITemperatureView.js (metobs demo) added SMHIForecastCard.js (snow1gv1 demo) testing: checked that the demo views/cards showed the correct data fetched from SMHI note: The react hooks are fairly simple, and discard some choices the API:s give us. The issue might need to be revisited in the future.
Collaborator

All data is shown on the app and tested everything locally which works, nice!

Regarding the names of the files, I have some questions.

  • It could be clearer how the files work together. It could be easier to understand how the files get along if Observation or TemperatureView change name so that it is Observation and ObeservationView or Temperature and TemperatureView.
  • Another question is about the use of card and view in the file names. Forecast uses card while Temperature uses view, are they both not views?
  • Should the naming convention be used here? Maybe camelCase for observations and forecast? I dont know, probably not

Comments:

  • Move the comment (station) in Observations to TemperatureView since that is where the data is being used, same with from Forecast (lati,longi) to ForecastCard

Other questions:

  • Do we know how often the prognose is made? Waited an hour to see it update and it did not, could be worth knowing if a card is to be made (filters may be needed). Edit an hour later: has updated since so it definitely works but did take ish 2h
All data is shown on the app and tested everything locally which works, nice! Regarding the names of the files, I have some questions. - It could be clearer how the files work together. It could be easier to understand how the files get along if Observation or TemperatureView change name so that it is Observation and ObeservationView or Temperature and TemperatureView. - Another question is about the use of card and view in the file names. Forecast uses card while Temperature uses view, are they both not views? - Should the naming convention be used here? Maybe camelCase for observations and forecast? I dont know, probably not Comments: - Move the comment (station) in Observations to TemperatureView since that is where the data is being used, same with from Forecast (lati,longi) to ForecastCard Other questions: - Do we know how often the prognose is made? Waited an hour to see it update and it did not, could be worth knowing if a card is to be made (filters may be needed). Edit an hour later: has updated since so it definitely works but did take ish 2h
Collaborator

Everything seems fine and working.
It's just unclear what each file does, and there is a lack of comments.

Everything seems fine and working. It's just unclear what each file does, and there is a lack of comments.
a24noabe force-pushed #39-SMHI_view from ae94aaed9a to c618a0edb2 2026-04-09 08:57:11 +00:00 Compare
Collaborator

@a24noabe ,

The naming and commeting looks good,
But the files "useSMHIForecast" and "useSMHIObservations" should use the function useApi that is found in "src/features/utility/sharedFeatures.js".

All you have to do is construct the URL outside of the fetch and then do the fetch using useAPi.

Example of what I mean in the useSMHIObservations-script:


import { useApi } from "../utility/sharedFeatures";

/*
  parameter: https://opendata.smhi.se/metobs/resources/parameter
  station: 83230 for Skövde
  period: latest-hour, latest-day, latest-months, corrected archive
*/
const API_URL = "https://opendata-download-metobs.smhi.se/api/version/1.0";
export function useSMHIObservations(parameter, station, period) {
   const API = `${API_URL}/parameter/${parameter}/station/${station}/period/${period}/data.json`;
   return useApi(API);
}

@a24noabe , The naming and commeting looks good, But the files "useSMHIForecast" and "useSMHIObservations" should use the function useApi that is found in "src/features/utility/sharedFeatures.js". All you have to do is construct the URL outside of the fetch and then do the fetch using useAPi. Example of what I mean in the useSMHIObservations-script: ```JAVASCRIPT import { useApi } from "../utility/sharedFeatures"; /* parameter: https://opendata.smhi.se/metobs/resources/parameter station: 83230 for Skövde period: latest-hour, latest-day, latest-months, corrected archive */ const API_URL = "https://opendata-download-metobs.smhi.se/api/version/1.0"; export function useSMHIObservations(parameter, station, period) { const API = `${API_URL}/parameter/${parameter}/station/${station}/period/${period}/data.json`; return useApi(API); } ```
changed the hooks to use the useApi method.
added some descriptions regarding the parameters for the metobs API
Author
Collaborator

I have committed and updated the pr, it's now better commented and documented and uses the proper 'useApi' function. Please note that the views included are for demo purposes on how the data can be parsed and presented

I have committed and updated the pr, it's now better commented and documented and uses the proper 'useApi' function. Please note that the views included are for demo purposes on how the data can be parsed and presented
Collaborator

image

Checked that the view code compiles, gets the correct data, and that the naming is compliant with our coding standard.

It seems to pass all these, and comments are now present.

Merging

![image](/attachments/e6f76207-456d-4248-97bf-b2522f676aa9) Checked that the view code compiles, gets the correct data, and that the naming is compliant with our coding standard. It seems to pass all these, and comments are now present. Merging
c24elipe merged commit 6aa7aa4c9d into team_2_week_1 2026-04-10 10:13:51 +00:00
c24elipe deleted branch #39-SMHI_view 2026-04-10 10:13:52 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K!151
No description provided.