-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ivozilkenat/hackhpi24
- Loading branch information
Showing
27 changed files
with
389 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import './css/Vehicle.css'; | ||
|
||
function Bus({ data }) { | ||
return ( | ||
<div> | ||
<h2>{data.type}</h2> | ||
<p>ID: {data.id}</p> | ||
<p>Latitude: {data.position.lat}</p> | ||
<p>Longitude: {data.position.lon}</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default Bus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import L from 'leaflet'; | ||
import './../../node_modules/leaflet/dist/leaflet.css' | ||
import './css/RealtimeMap.css'; | ||
import 'leaflet-realtime'; | ||
import Bus from './Bus'; | ||
import Tram from './Tram'; | ||
import Train from './Train'; | ||
import { Marker } from 'react-leaflet'; | ||
import { MapContainer, TileLayer, useMap } from 'react-leaflet'; | ||
|
||
function RealtimeMap() { | ||
const map = useMap(); | ||
const [data, setData] = useState([]); | ||
|
||
useEffect(() => { | ||
const bounds = map.getBounds(); | ||
const upperLeft = bounds.getNorthWest(); | ||
const lowerRight = bounds.getSouthEast(); | ||
fetch('https://hackhpi24.ivo-zilkenat.de/api/trafficData/', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
"bounds": { | ||
"upper-left": { | ||
"lat": upperLeft.lat, | ||
"lon": upperLeft.lng | ||
}, | ||
"lower-right": { | ||
"lat": lowerRight.lat, | ||
"lon": lowerRight.lng | ||
} | ||
} | ||
}) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
setData(data); | ||
}); | ||
}, []); | ||
data["2"] = {"id": "2", "type": "bus", "position": {"lat": 52.3906, "lon": 13.0645}}; | ||
|
||
return Object.values(data).map(item => ( | ||
<Marker position={[item.position.lat, item.position.lon]}> | ||
{item.type === "bus" && <Bus data={item} />} | ||
{item.type === "tram" && <Tram data={item} />} | ||
{item.type === "train" && <Train data={item} />} | ||
</Marker> | ||
)); | ||
} | ||
|
||
function MapComponent() { | ||
return ( | ||
<MapContainer center={[52.3906, 13.0645]} zoom={13} className="map"> | ||
<TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" /> | ||
<RealtimeMap /> | ||
</MapContainer> | ||
); | ||
} | ||
|
||
export default MapComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import './css/Title.css'; | ||
|
||
function Title() { | ||
return ( | ||
<div className="Title"> | ||
<h1>SFPOPOS</h1> | ||
<div className="Title-Subtitle">San Franciscos Privately Owned Public Spaces</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import './css/Vehicle.css'; | ||
|
||
function Train({ data }) { | ||
return ( | ||
<div> | ||
<h2>{data.type}</h2> | ||
<p>ID: {data.id}</p> | ||
<p>Latitude: {data.position.lat}</p> | ||
<p>Longitude: {data.position.lon}</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default Train; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import './css/Vehicle.css'; | ||
|
||
function Tram({ data }) { | ||
return ( | ||
<div> | ||
<h2>{data.type}</h2> | ||
<p>ID: {data.id}</p> | ||
<p>Latitude: {data.position.lat}</p> | ||
<p>Longitude: {data.position.lon}</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default Tram; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import './css/Vehicle.css'; | ||
|
||
function Vehicle({ data }) { | ||
return ( | ||
<div> | ||
<h2>{data.type}</h2> | ||
<p>ID: {data.id}</p> | ||
<p>Latitude: {data.position.lat}</p> | ||
<p>Longitude: {data.position.lon}</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default Vehicle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.map { | ||
height: 400px; | ||
width: 800px; | ||
display: block; | ||
margin-left: auto; | ||
margin-right: auto; | ||
border-radius: 0.5rem; | ||
box-shadow: 0 0 1rem rgba(0, 0, 0, 0.4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.Title { | ||
box-sizing: border-box; | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: baseline; | ||
padding: 1em; | ||
margin-bottom: 2em; | ||
background-color: rgb(192, 45, 26); | ||
color: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.bus{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Dict, List | ||
from models import trafficDataItem | ||
|
||
trafficDataDict: Dict[str, trafficDataItem.TrafficDataItem] = dict() | ||
|
||
# Example traffic data (you would fetch or compute this data in a real application) | ||
trafficDataDict = { | ||
"1": trafficDataItem.TrafficDataItem( | ||
id="1", | ||
type="Bus", | ||
subType="City Bus", | ||
position=trafficDataItem.Position(lat=40.7128, lon=-74.0060), | ||
line="Line 1", | ||
direction="North", | ||
utilization=trafficDataItem.Utilization(abs=30, rel=0.6) | ||
), | ||
# Add more items as needed... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import httpx | ||
from fastapi import HTTPException | ||
from models import trafficDataItem | ||
import asyncio | ||
import database | ||
|
||
async def fetch_radar_data(north: float, west: float, south: float, east: float, results: int = 256, duration: int = 30, frames: int = 3, polylines: bool = True, language: str = "en"): | ||
url = "https://v6.vbb.transport.rest/radar" | ||
params = { | ||
"north": north, | ||
"west": west, | ||
"south": south, | ||
"east": east, | ||
"results": results, | ||
"duration": duration, | ||
"frames": frames, | ||
"polylines": polylines, | ||
"language": language | ||
} | ||
|
||
async with httpx.AsyncClient() as client: | ||
response = await client.get(url, params=params) | ||
|
||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
raise HTTPException(status_code=response.status_code, detail="Failed to fetch radar data from VBB API") | ||
|
||
async def fetch_radar_data_periodically(period_time: int = 1): | ||
while True: | ||
await asyncio.sleep(period_time) # Wait for n seconds | ||
# print("Fetching radar data...") | ||
radar_data = await fetch_radar_data( | ||
north=52.4288, | ||
west=12.96249, | ||
south=52.35401, | ||
east=13.16608, | ||
results=1024, | ||
duration=period_time * 2, | ||
frames=2, | ||
polylines=True, | ||
language="en" | ||
) | ||
|
||
database.trafficDataDict = dict() | ||
for movement in radar_data["movements"]: | ||
|
||
database.trafficDataDict[movement["tripId"]] = trafficDataItem.TrafficDataItem( | ||
id=movement["tripId"], | ||
type=movement["line"]["mode"], | ||
subType=movement["line"]["product"], | ||
position=trafficDataItem.Position( | ||
lon=movement["location"]["longitude"], | ||
lat=movement["location"]["latitude"] | ||
), | ||
line=movement["line"]["name"], | ||
direction=movement["direction"], | ||
utilization=trafficDataItem.Utilization( | ||
abs=None, | ||
rel=None | ||
) | ||
) | ||
|
||
|
Oops, something went wrong.