code done demoing for video

This commit is contained in:
Pagwin 2024-02-18 11:41:16 -05:00
parent 08bf39aab1
commit 147094d059
7 changed files with 79 additions and 30 deletions

View file

@ -105,6 +105,7 @@ async function submit(clickEvent){
return {path:google.maps.geometry.encoding.decodePath(v.poly_line), color:v.color} return {path:google.maps.geometry.encoding.decodePath(v.poly_line), color:v.color}
}) })
.then(o=>{ .then(o=>{
//console.log(`"${o.path}"`);
let line = new google.maps.Polyline({ let line = new google.maps.Polyline({
path:o.path, path:o.path,
strokeColor: o.color, strokeColor: o.color,

28
Cargo.lock generated
View file

@ -92,6 +92,15 @@ version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.7" version = "0.3.7"
@ -494,6 +503,7 @@ dependencies = [
"anyhow", "anyhow",
"async-std", "async-std",
"chrono", "chrono",
"geo-types",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
@ -920,6 +930,17 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "geo-types"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567495020b114f1ce9bed679b29975aa0bfae06ac22beacd5cfde5dabe7b05d6"
dependencies = [
"approx",
"num-traits",
"serde",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.1.16" version = "0.1.16"
@ -1247,6 +1268,12 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libm"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.3.8" version = "0.3.8"
@ -1326,6 +1353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm",
] ]
[[package]] [[package]]

View file

@ -9,6 +9,7 @@ edition = "2021"
anyhow = "1.0.79" anyhow = "1.0.79"
async-std = { version = "1.12.0", features = ["tokio1", "attributes"] } async-std = { version = "1.12.0", features = ["tokio1", "attributes"] }
chrono = "0.4.34" chrono = "0.4.34"
geo-types = "0.7.12"
reqwest = "0.11.24" reqwest = "0.11.24"
#sea-orm = "0.12.14" #sea-orm = "0.12.14"
serde = { version = "1.0.196", features = ["derive"] } serde = { version = "1.0.196", features = ["derive"] }

View file

@ -8,7 +8,7 @@ to run you need a file called GOOGLE_API_KEY in the dir the app is run in which
## TODO: ## TODO:
- test with BC buses - show lines for broome county buses
- Make buttons change color to indicate toggle - Make buttons change color to indicate toggle
- Prevent buses from going backwards - Prevent buses from going backwards
- make time estimate accurate (beyond hack divide by 3) - make time estimate accurate (beyond hack divide by 3)
@ -16,11 +16,12 @@ to run you need a file called GOOGLE_API_KEY in the dir the app is run in which
- Trim poly lines down to the bit between bus stops - Trim poly lines down to the bit between bus stops
- Fix the UI so console and alert aren't needed - Fix the UI so console and alert aren't needed
- refactor to work within docker and setup within docker-compose - refactor to work within docker and setup within docker-compose
- make route checking more advanced with better walking heuristic - make route checking more advanced with better walking heuristic (ideally taking the river into account)
- make route checking more advanced by allowing multiple factors with multiple weights including - make route checking more advanced by allowing multiple factors with multiple weights including
- walking time (don't remove it) - walking time (don't remove it)
- bus travel time - bus travel time
- layover time - layover time (both waiting for the initial bus and any intermediary buses)
- ultimate arrival time - ultimate arrival time
- make route checking allow for specifying a future time
- use a DB via SeaORM to avoid spaming APIs - use a DB via SeaORM to avoid spaming APIs
- use info in db to try and predict bus schedules in future - use info in db to try and predict bus schedules in future

View file

@ -4,6 +4,7 @@ extern crate reqwest;
extern crate tide; extern crate tide;
extern crate anyhow; extern crate anyhow;
extern crate chrono; extern crate chrono;
extern crate geo_types;
//extern crate sea_orm; //extern crate sea_orm;
mod state; mod state;

View file

@ -83,7 +83,7 @@ pub async fn broome_county_routes_get()->anyhow::Result<Vec<Route>>{
let poly_line = crate::stop::poly_encode_stops(stops.clone()); let poly_line = crate::stop::poly_encode_stops(stops.clone());
Route{ Route{
id:route.id, id:route.id,
color:route.color, color:"#".to_owned()+&route.color,
name:route.name, name:route.name,
poly_line, poly_line,
short_name: route.short_name, short_name: route.short_name,

View file

@ -68,39 +68,56 @@ pub async fn bc_stops_get()->anyhow::Result<Vec<Stop>>{
let stops:Vec<BCStop> = serde_json::from_str(body.as_str())?; let stops:Vec<BCStop> = serde_json::from_str(body.as_str())?;
Ok(stops.into_iter().map(Stop::from).collect()) Ok(stops.into_iter().map(Stop::from).collect())
} }
pub fn poly_encode_stops<I:IntoIterator<Item=Stop>>(stops:I)->String{ pub fn poly_encode_stops(stops:Vec<Stop>)->String{
println!("{:?}",stops);
stops.into_iter() stops.into_iter()
.map(|stop|{ .map(|stop|{
enc_float(stop.lat) "".to_owned()//enc_float(stop.lat) + &enc_float(stop.lon)
}) })
.reduce(|s1,s2|s1+&s2).unwrap_or("".into()) .reduce(|s1,s2|s1+&s2).unwrap_or("".into())
} }
fn enc_float(num:f64)->String{ fn enc_float(num:f64)->String{
let mut working:i32 = (num*1e5).round() as i32;
//hopethis does what's needed let working:i32 = invoke_e5(num);
working<<=1; let working = two_comp(working,num);
if num < 0.0 { let working = lshf(working);
working = !working; let working = if_negative_invert(working,num);
let chunks = chunks(working);
chunks.iter().map(|v| char::from_u32(*v as u32).unwrap()).collect()
}
fn invoke_e5(n:f64)->i32{
(n*1e5).round() as i32
}
fn two_comp(n:i32, orig:f64)->i32{
if orig < 0.0{
n^-1 + 1
} }
let mut bits:[bool;30] = [false;30]; else {
for i in 0..30{ n
bits[i] = working % 2 == 1;
working >>=1;
} }
bits.chunks(5).rev() }
.map(|bools|{
let mut accu:u8 = 0; fn lshf(n:i32)->i32{
for i in 0..5{ n << 1
accu += if bools[4-i]{ }
1 fn if_negative_invert(n:i32, orig:f64)->i32{
} else {0}; if orig < 0.0{
accu <<=1; n ^ -1
} }
accu |= 0x20; else {
accu +=63; n
char::from(accu) }
}).collect::<String>() }
fn chunks(n:i32)->[u8;6]{
let mut chunks:[u8;6] = [0;6];
for i in 0..6{
chunks[i] = (n >> (5*i) ) as u8 & 0x1f;
if i != 5 {chunks[i] |= 0x20;}
chunks[i] += 63;
}
chunks
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]