diff --git a/frontend/src/api/WeatherData.tsx b/frontend/src/api/WeatherData.tsx index 6132e7d..dacde66 100644 --- a/frontend/src/api/WeatherData.tsx +++ b/frontend/src/api/WeatherData.tsx @@ -42,8 +42,23 @@ const fetchIndoorWeatherData = async ( } }; +const fetchIndoorPredictData = async (): Promise< + IndoorPredictData[] | null +> => { + try { + const response = await axios.get( + 'http://127.0.0.1:8000/api/v1/weather/indoor/predict/', + ); + return response.data; + } catch (error) { + console.error('Error fetching indoor predict data:', error); + return null; + } +}; + export { fetchWeatherDataList, fetchOutdoorWeatherData, fetchIndoorWeatherData, + fetchIndoorPredictData, }; diff --git a/frontend/src/components/Charts/LineChart.tsx b/frontend/src/components/Charts/LineChart.tsx index 5985439..760b091 100644 --- a/frontend/src/components/Charts/LineChart.tsx +++ b/frontend/src/components/Charts/LineChart.tsx @@ -1,6 +1,7 @@ import { ApexOptions } from 'apexcharts'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import ReactApexChart from 'react-apexcharts'; +import { fetchIndoorPredictData } from '../../api/WeatherData'; const options: ApexOptions = { legend: { @@ -110,8 +111,8 @@ const options: ApexOptions = { fontSize: '0px', }, }, - min: 0, - max: 100, + min: 10, + max: 60, }, }; @@ -123,26 +124,26 @@ interface ChartOneState { } const LineChart: React.FC = () => { - const [state, setState] = useState({ - series: [ - { - name: 'Indoor Temperature', - data: [23, 11, 22, 27, 13, 22, 37, 21, 44, 22, 30, 45], - }, + const [seriesData, setSeriesData] = useState([]); + const [categories, setCategories] = useState([]); - { - name: 'Outdoor Temperature', - data: [30, 25, 36, 30, 45, 35, 64, 52, 59, 36, 39, 51], - }, - ], - }); + useEffect(() => { + const fetchData = async () => { + const data = await fetchIndoorPredictData(); + if (data) { + const categories = data.map((item) => item.timestamp); + const indoorTempData = data.map((item) => item.indoor_temp); + const outdoorTempData = data.map((item) => item.outdoor_temp); + setCategories(categories); + setSeriesData([ + { name: 'Indoor Temperature', data: indoorTempData }, + { name: 'Outdoor Temperature', data: outdoorTempData }, + ]); + } + }; - const handleReset = () => { - setState((prevState) => ({ - ...prevState, - })); - }; - handleReset; + fetchData(); + }, []); return (
@@ -169,28 +170,16 @@ const LineChart: React.FC = () => {
-
-
- - - -
-
diff --git a/frontend/src/types/weather.ts b/frontend/src/types/weather.ts index 095d8ba..c8ebe1b 100644 --- a/frontend/src/types/weather.ts +++ b/frontend/src/types/weather.ts @@ -25,3 +25,9 @@ interface WeatherData { avg_outdoor_pm25: number; avg_outdoor_pm10: number; } + +interface IndoorPredictData { + timestamp: string; + indoor_temp: number; + outdoor_temp: number; +}