diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6850130..f434707 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,8 +6,15 @@ - + + + + + + + + + + + diff --git a/weather_platform/apps/agw/src/measures/measures.controller.ts b/weather_platform/apps/agw/src/measures/measures.controller.ts index 42aa6c9..2def36a 100644 --- a/weather_platform/apps/agw/src/measures/measures.controller.ts +++ b/weather_platform/apps/agw/src/measures/measures.controller.ts @@ -18,6 +18,21 @@ import {Measures} from "@weather-platform/prisma-clients/Measures"; // eslint-disable-next-line @nx/enforce-module-boundaries import {MeasureGetDTOClass} from "../../../measures-service/src/DTO/MeasureGetDTOClass.dto"; +function calculateTemperature(ThermistorPin: number): number { + const R1 = 10000; // Value of R1 on the module + const c1 = 0.001129148; + const c2 = 0.000234125; + const c3 = 0.0000000876741; + + const Vo: number = ThermistorPin; + const R2: number = R1 * (1023.0 / Vo - 1.0); // Calculate the resistance on the thermistor + const logR2: number = Math.log(R2); + let T: number = 1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2); // Temperature in Kelvin + T = T - 273.15; // Convert Kelvin to Celsius + return T; +} + + @Controller('measures') export class MeasuresController { constructor( @@ -78,6 +93,10 @@ export class MeasuresController { @Param('msg_value') msg_value: string, ): Promise | null> { + if (msg_type === 'temperature') { + msg_value = calculateTemperature(Number(msg_value)).toString(); + } + const measure_create_data: MeasureCreateDTOLocalClass = { sendedInDate: sendedInDate, sensor_uuid: sensor_uuid, diff --git a/weather_platform/apps/py-tg-bot-weather-agent/main.py b/weather_platform/apps/py-tg-bot-weather-agent/main.py index 664c4fa..94d76ca 100644 --- a/weather_platform/apps/py-tg-bot-weather-agent/main.py +++ b/weather_platform/apps/py-tg-bot-weather-agent/main.py @@ -12,7 +12,7 @@ from langchain.agents import create_json_agent, AgentExecutor from langchain.agents.agent_toolkits import JsonToolkit import os -OPENAI_API = "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" +OPENAI_API = "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" os.environ["LANGCHAIN_TRACING_V2"] = "true" os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com" @@ -59,7 +59,7 @@ def fetch_get_weather_data(params={}): response = requests.get(AGW_URL + 'api/v1/measures/get-for-ai') response.raise_for_status() data = response.json() - return data[0] + return data[-10:] except requests.exceptions.RequestException as e: print('Error fetching data:', e) return None diff --git a/weather_platform/package-lock.json b/weather_platform/package-lock.json index ab8f6da..cb97358 100644 --- a/weather_platform/package-lock.json +++ b/weather_platform/package-lock.json @@ -16,6 +16,7 @@ "@nestjs/swagger": "^7.1.13", "@nx/devkit": "16.10.0", "@nx/plugin": "^16.10.0", + "@pbe/react-yandex-maps": "^1.2.5", "@prisma/client": "^5.4.1", "@swc/helpers": "~0.5.2", "axios": "^1.0.0", @@ -4346,6 +4347,20 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/@pbe/react-yandex-maps": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@pbe/react-yandex-maps/-/react-yandex-maps-1.2.5.tgz", + "integrity": "sha512-cBojin5e1fPx9XVCAqHQJsCnHGMeBNsP0TrNfpWCrPFfxb30ye+JgcGr2mn767Gbr1d+RufBLRiUcX2kaiAwjQ==", + "dependencies": { + "@types/yandex-maps": "2.1.29" + }, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "react": "^16.x || ^17.x || ^18.x" + } + }, "node_modules/@phenomnomnominal/tsquery": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@phenomnomnominal/tsquery/-/tsquery-5.0.1.tgz", @@ -5739,6 +5754,11 @@ "@types/node": "*" } }, + "node_modules/@types/yandex-maps": { + "version": "2.1.29", + "resolved": "https://registry.npmjs.org/@types/yandex-maps/-/yandex-maps-2.1.29.tgz", + "integrity": "sha512-nuibRWj3RU/9KXlCzTrRtDE+n6V9l7NbT9JakicqZ5OXIdwyb6blvV2Uwn6lB58WYm3DSUDP2I2AWlnWMc8z2w==" + }, "node_modules/@types/yargs": { "version": "17.0.26", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.26.tgz", diff --git a/weather_platform/package.json b/weather_platform/package.json index 28f2e4b..c67248b 100644 --- a/weather_platform/package.json +++ b/weather_platform/package.json @@ -12,6 +12,7 @@ "@nestjs/swagger": "^7.1.13", "@nx/devkit": "16.10.0", "@nx/plugin": "^16.10.0", + "@pbe/react-yandex-maps": "^1.2.5", "@prisma/client": "^5.4.1", "@swc/helpers": "~0.5.2", "axios": "^1.0.0", diff --git a/weather_platform/pages/src/lib/dashboard/dashboard.tsx b/weather_platform/pages/src/lib/dashboard/dashboard.tsx index 2be2e30..c786c25 100644 --- a/weather_platform/pages/src/lib/dashboard/dashboard.tsx +++ b/weather_platform/pages/src/lib/dashboard/dashboard.tsx @@ -1,15 +1,16 @@ import styles from './dashboard.module.scss'; import { AgregatorCreateForm, - AgregatorTable, - SensorsHumidityGraph, - SensorsTemperatureGraph + AgregatorTable, PotantialProblemeSensorsTable, + SensorsHumidityGraph, SensorsLuminGraph, + SensorsTemperatureGraph, SensorsVebrationsGraph } from "@weather-platform/ui-modules"; import {BaseLayout} from "@weather-platform/layout"; import {useEffect, useState} from "react"; import {Prisma, Measures} from "@weather-platform/prisma-clients/Measures"; import axios from "axios"; import {AGW_URL} from "../../../../agw"; +import {SensorsOnMap} from "@weather-platform/ui"; /* eslint-disable-next-line */ export interface DashboardProps {} @@ -29,11 +30,21 @@ export function Dashboard(props: DashboardProps) { const [dataTemperature, setDataTemperature] = useState([]); const [dataHumidity, setDataHumidity] = useState([]); + const [dataBright, setDataBright] = useState([]); + const [dataVibration, setDataVibration] = useState([]); const updateMeasureTmpData = async () => { const response = await fetchGetMeasuresList({ where: { type: 'temperature', + }, + take: 120, + orderBy: { + time: 'desc', + }, + select: { + type: true, + value: true, } }); if (response !== null) { @@ -45,6 +56,14 @@ export function Dashboard(props: DashboardProps) { const response = await fetchGetMeasuresList({ where: { type: 'humidity', + }, + take: 120, + orderBy: { + time: 'desc', + }, + select: { + type: true, + value: true, } }); if (response !== null) { @@ -52,9 +71,49 @@ export function Dashboard(props: DashboardProps) { } }; + const updateMeasureBrightData = async () => { + const response = await fetchGetMeasuresList({ + where: { + type: 'brighness', + }, + take: 120, + orderBy: { + time: 'desc', + }, + select: { + type: true, + value: true, + } + }); + if (response !== null) { + setDataBright(response); + } + }; + + const updateMeasureVibrationData = async () => { + const response = await fetchGetMeasuresList({ + where: { + type: 'vibration', + }, + take: 120, + orderBy: { + time: 'desc', + }, + select: { + type: true, + value: true, + } + }); + if (response !== null) { + setDataVibration(response); + } + }; + function upd() { updateMeasureTmpData(); updateMeasureHumidityData(); + updateMeasureBrightData(); + updateMeasureVibrationData(); } useEffect(() => { @@ -65,9 +124,21 @@ export function Dashboard(props: DashboardProps) { return ( -
- - +
+
+
+ +
+
+ +
+
+
+ + + +
+
); diff --git a/weather_platform/ui-modules/src/index.ts b/weather_platform/ui-modules/src/index.ts index d682ad2..e62b5b3 100644 --- a/weather_platform/ui-modules/src/index.ts +++ b/weather_platform/ui-modules/src/index.ts @@ -1,3 +1,6 @@ +export * from './lib/sensors-vebrations-graph/sensors-vebrations-graph'; +export * from './lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table'; +export * from './lib/sensors-lumin-graph/sensors-lumin-graph'; export * from './lib/sensors-humidity-graph/sensors-humidity-graph'; export * from './lib/sensors-temperature-graph/sensors-temperature-graph'; export * from './lib/sensors-table-item/sensors-table-item'; diff --git a/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/ok-status.gif b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/ok-status.gif new file mode 100755 index 0000000..21908af Binary files /dev/null and b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/ok-status.gif differ diff --git a/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.module.scss b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.module.scss new file mode 100644 index 0000000..45c2aa4 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.module.scss @@ -0,0 +1,7 @@ +/* + * Replace this with your own classes + * + * e.g. + * .container { + * } +*/ diff --git a/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.spec.tsx b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.spec.tsx new file mode 100644 index 0000000..f816b83 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.spec.tsx @@ -0,0 +1,10 @@ +import { render } from '@testing-library/react'; + +import PotantialProblemeSensorsTable from './potantial-probleme-sensors-table'; + +describe('PotantialProblemeSensorsTable', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); + }); +}); diff --git a/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.tsx b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.tsx new file mode 100644 index 0000000..9e0aa74 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/potantial-probleme-sensors-table/potantial-probleme-sensors-table.tsx @@ -0,0 +1,191 @@ +import styles from './potantial-probleme-sensors-table.module.scss'; +import {Measures, Prisma} from "@weather-platform/prisma-clients/Measures"; +import axios from "axios"; +import {AGW_URL} from "../../../../agw"; +import {useEffect, useState} from "react"; +import AgregatorTableItem from "../agregator-table-item/agregator-table-item"; +import OK from './ok-status.gif'; +import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js'; +import { Pie } from 'react-chartjs-2'; + +/* eslint-disable-next-line */ +export interface PotantialProblemeSensorsTableProps {} + + +ChartJS.register(ArcElement, Tooltip, Legend); + + +export function PotantialProblemeSensorsTable( + props: PotantialProblemeSensorsTableProps +) { + + const fetchGetMeasuresList = async (params: Prisma.MeasuresFindManyArgs = {}) => { + try { + const response = await axios.post( AGW_URL + '/api/v1/measures/get-with-params', params); + const data = response.data; + return data; + } catch (error) { + console.error('Error fetching data:', error); + return null; + } + }; + + const [measures, setMeasures] = useState(null); + + const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000); + + const updateMeasureData = async () => { + const response = await fetchGetMeasuresList({ + where: { + sensor_uuid: { + not: { + in: [], + }, + }, + time: { + gte: twoHoursAgo.toISOString(), + }, + }, + }); + if (response !== null) { + setMeasures(response); + } + }; + + const [measuresCount, setMeasuresCount] = useState(0); + + const updateAllMeasureData = async () => { + const response = await fetchGetMeasuresList({ + select: { + uuid: true, + } + }); + if (response !== null) { + setMeasuresCount(response.length); + } + }; + + function upd() { + updateAllMeasureData(); + updateMeasureData(); + } + + useEffect(() => { + upd(); + const interval = setInterval(upd, 5000); + return () => clearInterval(interval); + }, []); + + const data = { + labels: ['Fatal', 'Success'], + datasets: [ + { + label: '# of Votes', + data: [measures?.length || 0, measuresCount], + backgroundColor: [ + 'rgba(255, 99, 132, 0.2)', + 'rgba(54, 162, 235, 0.2)', + ], + borderColor: [ + 'rgba(255, 99, 132, 1)', + 'rgba(54, 162, 235, 1)', + ], + borderWidth: 1, + }, + ], + }; + + return ( +
+

Incorect get data from Sensors

+
+
+ + + + + + + + + + + + { + measures?.map( + (measure, key) => ( + + + + + + + + ) + ) + } + +
+ Type / Value + + Last connection + + Sensor + + Created at + + status +
+
+

+ { measure.type } / { measure.value } +

+
+
+

+ { measure.time.toString() } +

+
+

+ + { measure.sensor_uuid } + +

+
+

+ { measure.createdAt.toString() } +

+
+ + + + deactive + + +
+ { + measures?.length === 0 &&
+ +

Notion not found. All sensors working correct!

+
+ } +
+ +
+ +
+
+
+ ); +} + +export default PotantialProblemeSensorsTable; diff --git a/weather_platform/ui-modules/src/lib/sensors-humidity-graph/sensors-humidity-graph.tsx b/weather_platform/ui-modules/src/lib/sensors-humidity-graph/sensors-humidity-graph.tsx index 462ea05..e923c4d 100644 --- a/weather_platform/ui-modules/src/lib/sensors-humidity-graph/sensors-humidity-graph.tsx +++ b/weather_platform/ui-modules/src/lib/sensors-humidity-graph/sensors-humidity-graph.tsx @@ -29,7 +29,7 @@ const options = { }, title: { display: true, - text: "Sensors Temperature Graph", + text: "Sensors Humidity Graph", }, }, }; @@ -47,6 +47,7 @@ export interface SensorsHumidityGraphProps { export function SensorsHumidityGraph(props: SensorsHumidityGraphProps) { const labels = props.data.map(item => parseInt(item.time)); const Humidities = props.data.map(item => parseInt(item.value)); + Humidities.reverse(); const data = { labels, diff --git a/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.module.scss b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.module.scss new file mode 100644 index 0000000..45c2aa4 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.module.scss @@ -0,0 +1,7 @@ +/* + * Replace this with your own classes + * + * e.g. + * .container { + * } +*/ diff --git a/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.spec.tsx b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.spec.tsx new file mode 100644 index 0000000..180106a --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.spec.tsx @@ -0,0 +1,10 @@ +import { render } from '@testing-library/react'; + +import SensorsLuminGraph from './sensors-lumin-graph'; + +describe('SensorsLuminGraph', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); + }); +}); diff --git a/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.tsx b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.tsx new file mode 100644 index 0000000..e815519 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-lumin-graph/sensors-lumin-graph.tsx @@ -0,0 +1,74 @@ +import styles from './sensors-lumin-graph.module.scss'; +import { + CategoryScale, + Chart as ChartJS, + Legend, + LinearScale, + LineElement, + PointElement, + Title, + Tooltip +} from "chart.js"; +import {Line} from "react-chartjs-2"; + +ChartJS.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, +); + +const options = { + responsive: true, + plugins: { + legend: { + position: "top" as const, + }, + title: { + display: true, + text: "Sensors Bright Graph", + }, + }, +}; + +interface DataPoint { + time: string; + value: string; +} + + +/* eslint-disable-next-line */ +export interface SensorsLuminGraphProps { + data: DataPoint[]; +} + +export function SensorsLuminGraph(props: SensorsLuminGraphProps) { + const labels = props.data.map(item => parseInt(item.time)); + const Lumen = props.data.map(item => parseInt(item.value)); + Lumen.reverse(); + + const data = { + labels, + datasets: [ + { + label: "Bright", + data: Lumen, + borderColor: 'rgb(255, 165, 0)', + backgroundColor: 'rgba(255, 165, 0, 0.5)', + }, + ], + }; + + return ( +
+
+ +
+
+ ); +} + +export default SensorsLuminGraph; diff --git a/weather_platform/ui-modules/src/lib/sensors-temperature-graph/sensors-temperature-graph.tsx b/weather_platform/ui-modules/src/lib/sensors-temperature-graph/sensors-temperature-graph.tsx index afa5219..27a958a 100644 --- a/weather_platform/ui-modules/src/lib/sensors-temperature-graph/sensors-temperature-graph.tsx +++ b/weather_platform/ui-modules/src/lib/sensors-temperature-graph/sensors-temperature-graph.tsx @@ -48,6 +48,7 @@ export function SensorsTemperatureGraph(props: SensorsTemperatureGraphProps) { const labels = props.data.map(item => parseInt(item.time)); const temperatures = props.data.map(item => parseInt(item.value)); + temperatures.reverse(); const data = { labels, diff --git a/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.module.scss b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.module.scss new file mode 100644 index 0000000..45c2aa4 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.module.scss @@ -0,0 +1,7 @@ +/* + * Replace this with your own classes + * + * e.g. + * .container { + * } +*/ diff --git a/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.spec.tsx b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.spec.tsx new file mode 100644 index 0000000..0a21bcc --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.spec.tsx @@ -0,0 +1,10 @@ +import { render } from '@testing-library/react'; + +import SensorsVebrationsGraph from './sensors-vebrations-graph'; + +describe('SensorsVebrationsGraph', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); + }); +}); diff --git a/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.tsx b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.tsx new file mode 100644 index 0000000..8cdd035 --- /dev/null +++ b/weather_platform/ui-modules/src/lib/sensors-vebrations-graph/sensors-vebrations-graph.tsx @@ -0,0 +1,73 @@ +import styles from './sensors-vebrations-graph.module.scss'; +import {Line} from "react-chartjs-2"; +import { + Chart as ChartJS, + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, +} from "chart.js"; + +ChartJS.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, +); + +export const options = { + responsive: true, + plugins: { + legend: { + position: "top" as const, + }, + title: { + display: true, + text: "Sensors Vibration Graph", + }, + }, +}; + +interface DataPoint { + time: string; + value: string; +} + +/* eslint-disable-next-line */ +export interface SensorsVebrationsGraphProps { + data: DataPoint[]; +} + +export function SensorsVebrationsGraph(props: SensorsVebrationsGraphProps) { + const labels = props.data.map(item => parseInt(item.time)); + const vibrations = props.data.map(item => parseInt(item.value)); + vibrations.reverse(); + + const data = { + labels, + datasets: [ + { + label: "Vibration", + data: vibrations, + borderColor: "rgb(255, 99, 132)", + backgroundColor: "rgba(255, 99, 132, 0.5)", + }, + ], + }; + + return ( +
+
+ +
+
+ ); +} + +export default SensorsVebrationsGraph; diff --git a/weather_platform/ui/src/index.ts b/weather_platform/ui/src/index.ts index 2de2b63..62a4b46 100644 --- a/weather_platform/ui/src/index.ts +++ b/weather_platform/ui/src/index.ts @@ -1,2 +1,3 @@ +export * from './lib/sensors-on-map/sensors-on-map'; export * from './lib/nav-link/nav-link'; export * from './lib/ui'; diff --git a/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.module.scss b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.module.scss new file mode 100644 index 0000000..45c2aa4 --- /dev/null +++ b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.module.scss @@ -0,0 +1,7 @@ +/* + * Replace this with your own classes + * + * e.g. + * .container { + * } +*/ diff --git a/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.spec.tsx b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.spec.tsx new file mode 100644 index 0000000..b9b1b1c --- /dev/null +++ b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.spec.tsx @@ -0,0 +1,10 @@ +import { render } from '@testing-library/react'; + +import SensorsOnMap from './sensors-on-map'; + +describe('SensorsOnMap', () => { + it('should render successfully', () => { + const { baseElement } = render(); + expect(baseElement).toBeTruthy(); + }); +}); diff --git a/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.tsx b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.tsx new file mode 100644 index 0000000..a62e882 --- /dev/null +++ b/weather_platform/ui/src/lib/sensors-on-map/sensors-on-map.tsx @@ -0,0 +1,112 @@ +import styles from './sensors-on-map.module.scss'; +import {YMaps, Map, Circle, Clusterer, Placemark} from '@pbe/react-yandex-maps'; +import {Prisma, Sensor} from "@weather-platform/prisma-clients/Sensors"; +import {Prisma as PrismaAgr, Agregator} from "@weather-platform/prisma-clients/Agregators"; +import axios from "axios"; +import {AGW_URL} from "../../../../agw"; +import {useEffect, useState} from "react"; + +/* eslint-disable-next-line */ +export interface SensorsOnMapProps {} + +export function SensorsOnMap(props: SensorsOnMapProps) { + const fetchGetSensorsList = async (params: Prisma.SensorFindManyArgs = {}) => { + try { + const response = await axios.post( AGW_URL + '/api/v1/sensors/get-with-params', params); + const data = response.data; + return data; + } catch (error) { + console.error('Error fetching data:', error); + return null; + } + }; + + const [sensors, setSensors] = useState(null); + + const updateSensorsData = async () => { + const response = await fetchGetSensorsList({ + select: { + lat: true, + lng: true, + } + }); + if (response !== null) { + setSensors(response); + } + }; + + const fetchGetAgregatorsList = async (params: PrismaAgr.AgregatorFindManyArgs = {}) => { + try { + const response = await axios.post( AGW_URL + '/api/v1/agregator/get-with-params', params); + const data = response.data; + return data; + } catch (error) { + console.error('Error fetching data:', error); + return null; + } + }; + + const [agregators, setAgregators] = useState(null); + + const updateAgregatorsData = async () => { + const response = await fetchGetAgregatorsList({ + select: { + lat: true, + lng: true, + } + }); + if (response !== null) { + setAgregators(response); + } + }; + + function upd() { + updateAgregatorsData(); + updateSensorsData(); + } + + useEffect(() => { + upd(); + const interval = setInterval(upd, 30000); + return () => clearInterval(interval); + }, []); + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // const mergedArray = [...agregators, ...sensors]; + // const temperatures = agregators.map(item => [item.lng, item.lat]); + // console.log(temperatures); + return ( +
+ + + + + {agregators?.map((agregator:any, index:any) => ( + + ))} + {sensors?.map((agregator:any, index:any) => ( + + ))} + + + +
+ ); +} + +export default SensorsOnMap;