Skip to content

Commit

Permalink
Merge branch 'main' into feature/playground
Browse files Browse the repository at this point in the history
  • Loading branch information
endevii committed Apr 8, 2024
2 parents 5f666b0 + 1173eb8 commit b7d1717
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 205 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ docker compose run nycmesh-node-visualizer npm run unittest
```
After running the command you should see a log of all the unit tests.

**Note:** If you made changes to the unit tests and when running ```docker compose run nycmesh-node-visualizer npm run unittest```
you don't see your changes reflected, you can rebuild the container by running ```docker-compose up --build```.

## How to connect to PostgreSQL in docker container
Start the docker container
```
Expand Down
1 change: 0 additions & 1 deletion app/components/Antennas.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Circle, Popup } from 'react-leaflet';
import 'leaflet/dist/leaflet.css';

Expand Down
106 changes: 51 additions & 55 deletions app/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
LayerGroup,
useMap,
} from 'react-leaflet';
// import L from 'leaflet';

import L, { LatLngExpression } from 'leaflet';
import 'leaflet/dist/leaflet.css';

Expand All @@ -19,14 +19,9 @@ import Antennas from './Antennas';
import SectorLobes from './SectorLobes';
import AntennaInfo from './AntennaInfo';

// Temporary until the API is up and running
import access_points from '../../access_points.json';
import { Device } from '../accessPointTypes';

import { useAppSelector, useAppDispatch, useAppStore } from '../../lib/hooks';

// import { AccessPoint, Antenna } from '../types';
import { AccessPoint, SectorlobeData } from '../types';
import { AccessPoint, SectorlobeData, Antenna } from '../types';

import { initializeActual } from '../../lib/features/actual/actualSlice';

Expand Down Expand Up @@ -147,43 +142,43 @@ export default function Map() {
const dispatch = useAppDispatch();

useEffect(() => {
// async function fetchData(path: string, maxRetries = 3, retryDelay = 1000) {
// for (let attempt = 1; attempt <= maxRetries; attempt++) {
// try {
// const response = await fetch(path);
// if (!response.ok) {
// throw new Error(`${response.status} error: Failed to fetch`);
// }

// const responseJson = (await response.json()) as Antenna[];
// console.log('Antennas Data:', responseJson);
// return responseJson;
// } catch (e) {
// if (e instanceof Error) {
// console.error(`Attempt ${attempt} failed: ${e.message}`);
// if (attempt === maxRetries) throw e; // Rethrow error on last attempt
// await new Promise((resolve) => setTimeout(resolve, retryDelay)); // Wait before retrying
// }
// }
// }
// }

const fetchDataAndSetAntennasData = () => {
// const url = '/api/v1/antenna/';
async function fetchData(path: string, maxRetries = 3, retryDelay = 1000) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await fetch(path);
if (!response.ok) {
throw new Error(`${response.status} error: Failed to fetch`);
}

const responseJson = (await response.json()) as Antenna[];
console.log('Antennas Data:', responseJson);
return responseJson;
} catch (e) {
if (e instanceof Error) {
console.error(`Attempt ${attempt} failed: ${e.message}`);
if (attempt === maxRetries) throw e; // Rethrow error on last attempt
await new Promise((resolve) => setTimeout(resolve, retryDelay)); // Wait before retrying
}
}
}
}

const fetchDataAndSetAntennasData = async () => {
const url = '/api/v1/antenna/';
try {
const accessPoints = access_points;
const accessPoints = await fetchData(url);
if (accessPoints) {
const antennasData: AccessPoint[] = accessPoints.map(
(ap: Device) => ({
id: ap.identification.id,
modelName: ap.identification.modelName,
lat: ap.location.latitude.toString(),
lon: ap.location.longitude.toString(),
frequency: ap.overview.frequency || 0,
azimuth: ap.location.heading || 0,
antenna_status: ap.overview.status || 'N/A',
cpu: ap.overview.cpu || -1,
ram: ap.overview.ram || -1,
(ap: Antenna) => ({
id: ap.id,
modelName: ap.modelname,
lat: ap.latitude,
lon: ap.longitude,
frequency: ap.frequency || 0,
azimuth: ap.azimuth || 0,
antenna_status: ap.antenna_status || 'N/A',
cpu: ap.cpu || -1,
ram: ap.ram || -1,
})
);

Expand Down Expand Up @@ -214,10 +209,9 @@ export default function Map() {
}
};

// fetchDataAndSetAntennasData().catch((error) => {
// console.error(error);
// });
fetchDataAndSetAntennasData();
fetchDataAndSetAntennasData().catch((error) => {
console.error(error);
});
}, [store]);

useEffect(() => {
Expand Down Expand Up @@ -371,16 +365,18 @@ export default function Map() {
}
/>
) : null}
<button
className={
!intersectionToggle
? 'transition-all hover:text-gray-400'
: 'absolute right-2 top-2 transition-all hover:text-gray-400'
}
onClick={() => setIntersectionToggle(!intersectionToggle)}
>
{!intersectionToggle ? 'Check' : 'Close'}
</button>
{intersections.length > 0 ? (
<button
className={
!intersectionToggle
? 'transition-all hover:text-gray-400'
: 'absolute right-2 top-2 transition-all hover:text-gray-400'
}
onClick={() => setIntersectionToggle(!intersectionToggle)}
>
{!intersectionToggle ? 'Check' : 'Close'}
</button>
) : null}
</div>
{toggleInfo ? (
<AntennaInfo
Expand Down
1 change: 0 additions & 1 deletion app/components/SectorLobes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import SectorLobe from './SectorLobe';
import { useAppSelector } from '../../lib/hooks';

// Types are temporary until the API is up and running
// import { AccessPoint, ReducedPoints, SectorLobesProps } from '../types';
import { AccessPoint, ReducedPoints } from '../types';

export default function SectorLobes() {
Expand Down
4 changes: 3 additions & 1 deletion app/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LatLngExpression, LatLngTuple } from 'leaflet';

// Interfaces

export type Antenna = {
id: string;
name: string;
Expand Down Expand Up @@ -55,6 +54,9 @@ export interface InfoProps {
getToggle: boolean;
changeToggle: () => void;
}
export interface SectorLobesProps {
antennasData: AccessPoint[];
}

export interface SectorLobesProps {
antennasData: AccessPoint[];
Expand Down
Loading

0 comments on commit b7d1717

Please sign in to comment.