frontend is coming toegether just need to put it all toegether

This commit is contained in:
Pagwin 2024-02-18 01:09:12 -05:00
parent 166fd0e35c
commit 41dc3ff223
9 changed files with 158 additions and 3 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
BBB_frontend
target

View file

@ -0,0 +1 @@
node_modules

26
BBB_frontend/Dockerfile Normal file
View file

@ -0,0 +1,26 @@
FROM debian:latest
RUN apt-get update && apt-get upgrade && apt-get -y install wget xz-utils
RUN wget https://factorio.com/get-download/stable/headless/linux64 -O factorio-stable.tar.xz
RUN tar xf factorio-stable.tar.xz
WORKDIR /factorio
RUN useradd -M factorio
RUN chown -R factorio /factorio
USER factorio
RUN mkdir -p saves
VOLUME ["/factorio/saves"]
EXPOSE 34197/udp
EXPOSE 27015/tcp
ENTRYPOINT ["/factorio/bin/x64/factorio"]
CMD ["/factorio/bin/x64/factorio", "--start-server", "/factorio/saves/default.zip"]

View file

@ -6,6 +6,16 @@
<title>Binghamton Better Bus</title>
</head>
<body>
<!-- google maps api-->
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "AIzaSyBa1wDqAMfKv30BSzSdXB-AEsk4BRD9xTw",
v: "weekly",
// Use the 'v' parameter to indicate the version to use (weekly, beta, alpha, etc.).
// Add other bootstrap parameters as needed, using camel case.
});
</script>
<div id="map"></div>
<script type="module" src="/main.js"></script>
</body>

View file

@ -1 +1,84 @@
import './style.css'
async function main(){
const {Map} = await google.maps.importLibrary("maps");
const map = new Map(document.getElementById("map"),{
center: {lat: 42.10125081757972, lng:-75.94181323552698},
zoom: 14
});
const UI = document.createElement("div");
UI.id = "UI";
const from_lattitude_input = document.createElement("input");
from_lattitude_input.placeholder = "42.10125081757972";
from_lattitude_input.type = "number";
from_lattitude_input.id = "from_lattitude_input";
UI.appendChild(from_lattitude_input);
const from_longitude_input = document.createElement("input");
from_longitude_input.type = "number";
from_longitude_input.placeholder = "-75.94181323552698";
from_longitude_input.id = "from_longitude_input";
UI.appendChild(from_longitude_input);
const from_pos_button = document.createElement("button");
from_pos_button.id = "from_pos_button";
from_pos_button.innerText = "Set Start Position";
let from_pos_toggle = false;
UI.appendChild(from_pos_button);
from_pos_button.addEventListener("click",e=>{
from_pos_toggle = !from_pos_toggle;
to_pos_toggle = false;
});
const to_lattitude_input = document.createElement("input");
to_lattitude_input.placeholder = "42.10125081757972";
to_lattitude_input.type = "number";
UI.appendChild(to_lattitude_input);
const to_longitude_input = document.createElement("input");
to_longitude_input.type = "number";
to_longitude_input.placeholder = "-75.94181323552698";
UI.appendChild(to_longitude_input);
const to_pos_button = document.createElement("button");
to_pos_button.id = "to_pos_button"
to_pos_button.innerText = "Set End Position"
let to_pos_toggle = false;
to_pos_button.addEventListener("click",e=>{
to_pos_toggle = !to_pos_toggle;
from_pos_toggle = false;
});
UI.appendChild(to_pos_button);
const sub_button = document.createElement("button");
sub_button.addEventListener("click",submit_func(map));
sub_button.id = "sub_button";
sub_button.innerText = "Submit";
UI.appendChild(sub_button);
map.addListener("click", e=>{
const {lat, lng} = e.latLng;
if(from_pos_toggle){
from_lattitude_input.value = lat();
from_longitude_input.value = lng();
}
if(to_pos_toggle){
to_lattitude_input.value = lat();
to_longitude_input.value = lng();
}
});
document.body.appendChild(UI)
const time = new Date().toISOString();
}
function submit_func(map){
//TODO: grab the path and show the poly lines and the bus route name
async function submit(clickEvent){
let from_lat = document.getElementById("from_lattitude_input");
let from_lon = document.getElementById("from_longitude_input");
}
return submit;
}
main();

View file

@ -32,6 +32,13 @@ body {
height: 100%;
margin: 0 auto;
padding: 0rem;
position: absolute;
}
#UI {
display: grid;
grid-template-columns: repeat(3, 1fr);
position:relative;
}
button {

26
Dockerfile Normal file
View file

@ -0,0 +1,26 @@
FROM debian:latest
RUN apt-get update && apt-get upgrade && apt-get -y install wget xz-utils
RUN wget https://factorio.com/get-download/stable/headless/linux64 -O factorio-stable.tar.xz
RUN tar xf factorio-stable.tar.xz
WORKDIR /factorio
RUN useradd -M factorio
RUN chown -R factorio /factorio
USER factorio
RUN mkdir -p saves
VOLUME ["/factorio/saves"]
EXPOSE 34197/udp
EXPOSE 27015/tcp
ENTRYPOINT ["/factorio/bin/x64/factorio"]
CMD ["/factorio/bin/x64/factorio", "--start-server", "/factorio/saves/default.zip"]

View file

@ -1,11 +1,14 @@
# BinghamtonBetterBus
Currently just an api to get the best bus route from point a to point b, currently building frontend
to run you need a file called GOOGLE_API_KEY in the dir the app is run in which has access to the routes api
## TODO:
- Build frontend
- test with OCCT buses
- Change api to give a not shitty poly line for Broome county buses
- refactor to work within docker and setup within docker-compose
- make route checking more advanced with better walking heuristic
- make route checking more advanced by allowing multiple factors with multiple weights including
- walking time (don't remove it)

View file

@ -54,8 +54,6 @@ struct LocIn{
longitude: f64
}
fn build_route_body_pain(path:&[crate::types::Coords])->serde_json::Value{
let time = chrono::offset::Utc::now()
.to_rfc3339_opts(chrono::SecondsFormat::Nanos,true);
let inter = &path[1..path.len()-1];
let val = serde_json::json!({
"origin":{
@ -68,7 +66,6 @@ fn build_route_body_pain(path:&[crate::types::Coords])->serde_json::Value{
"intermediates": inter,
"travelMode": "DRIVE",
"routingPreference": "TRAFFIC_UNAWARE",
"departureTime": time,
"computeAlternativeRoutes": false,
"routeModifiers": {
"avoidTolls": false,