We have an API that provides weather data for the dates from 01 Nov 2024 to 10 Nov 2024. The task is to process this dataset and display it in charts.
The goal of this exercise is to create an application that displays the following charts:
- A column chart for relative humidity (
relativehumidity_2m
) - A line chart for temperature min and max (
temperature_2m_max
,temperature_2m_min
) - An area chart for direct radiation (
direct_radiation
)
The application should be written in Angular (preferred) or React with TypeScript.
- Retrieve data from the API:
- Build a single-page application.
- Display all three types of charts.
- Use a simple dashboard layout.
Feel free to use any required libraries.
Bonus:
- Store the data in a local SQL database and read from the database in the absence of an internet connection.
- Ensure a responsive design that works on both desktop and mobile views.
The "Weather Dashboard" is a simple and intuitive single-page application built in React using TypeScript. It presents weather data fetched from an API in three different charts: relative humidity, temperature (min and max), and direct radiation. This project aims to provide an easy-to-understand visual representation of weather data while including a bonus feature of offline storage.
- API Fetching: By default, the application fetches weather data from the Open Meteo API, displaying the information in charts.
- Offline Storage (Optional Bonus): The application also includes a branch with the ability to store weather data in local SQL (via IndexedDB) for offline access. This allows the app to work seamlessly without internet access.
- Main Branch: Fetches data from the API only.
- Offline Storage Branch: Contains the optional offline storage feature. Switch to the
with-offline-storage
branch for offline capability.
- Node.js (v14 or higher)
- npm (v6 or higher)
- Git
-
Clone the Repository
git clone <repository-url> cd weather-dashboard
-
Select the Desired Branch
- For default API fetching, use the main branch:
git checkout main
- For offline storage support, use the
with-offline-storage
branch:git checkout with-offline-storage
- For default API fetching, use the main branch:
-
Install Dependencies
npm install
-
Run the Application
npm start
-
View the Application
- Open your browser and navigate to
http://localhost:3000
.
- Open your browser and navigate to
- By default (main branch), the application will always try to fetch data from the API.
- The offline storage feature (with-offline-storage branch) allows the application to fall back on local data if there is no network connectivity.
- React & React Chart.js:
- For building interactive and reusable components and charts.
- SQL.js & IndexedDB (in the
with-offline-storage
branch):- Used to provide offline capabilities by storing weather data locally.
weather-dashboard/
│
├── public/ # Public assets folder
│
├── src/ # Source files
│ ├── components/ # Reusable React components
│ │ ├── AreaChart.tsx
│ │ ├── ColumnChart.tsx
│ │ └── LineChart.tsx
│ │
│ ├── services/ # Services folder for data fetching and database logic
│ │ ├── weatherService.ts
│ │ └── databaseService.ts
│ │
│ ├── App.module.css # CSS styles for App component
│ ├── App.tsx # Main App component
│ ├── index.css # Global CSS styles
│ ├── index.tsx # Entry point of the React application
│ └── react-app-env.d.ts # TypeScript environment definitions
│
├── .gitignore # Ignored files for Git
├── package.json # Dependencies and project scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
This project includes basic unit tests to ensure reliability. Run the tests using the following command:
npm test
- Run the app in different environments (e.g., with and without network connectivity) to test the offline storage capability.
- Test the charts to ensure the correct data is displayed in the correct format.
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Push the changes and open a Pull Request.