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}
})
.then(o=>{
//console.log(`"${o.path}"`);
let line = new google.maps.Polyline({
path:o.path,
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"
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]]
name = "arrayref"
version = "0.3.7"
@ -494,6 +503,7 @@ dependencies = [
"anyhow",
"async-std",
"chrono",
"geo-types",
"reqwest",
"serde",
"serde_json",
@ -920,6 +930,17 @@ dependencies = [
"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]]
name = "getrandom"
version = "0.1.16"
@ -1247,6 +1268,12 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libm"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
@ -1326,6 +1353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [
"autocfg",
"libm",
]
[[package]]

View file

@ -9,6 +9,7 @@ edition = "2021"
anyhow = "1.0.79"
async-std = { version = "1.12.0", features = ["tokio1", "attributes"] }
chrono = "0.4.34"
geo-types = "0.7.12"
reqwest = "0.11.24"
#sea-orm = "0.12.14"
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:
- test with BC buses
- show lines for broome county buses
- Make buttons change color to indicate toggle
- Prevent buses from going backwards
- 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
- Fix the UI so console and alert aren't needed
- 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
- walking time (don't remove it)
- bus travel time
- layover time
- layover time (both waiting for the initial bus and any intermediary buses)
- ultimate arrival time
- make route checking allow for specifying a future time
- use a DB via SeaORM to avoid spaming APIs
- 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 anyhow;
extern crate chrono;
extern crate geo_types;
//extern crate sea_orm;
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());
Route{
id:route.id,
color:route.color,
color:"#".to_owned()+&route.color,
name:route.name,
poly_line,
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())?;
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()
.map(|stop|{
enc_float(stop.lat)
"".to_owned()//enc_float(stop.lat) + &enc_float(stop.lon)
})
.reduce(|s1,s2|s1+&s2).unwrap_or("".into())
}
fn enc_float(num:f64)->String{
let mut working:i32 = (num*1e5).round() as i32;
//hopethis does what's needed
working<<=1;
if num < 0.0 {
working = !working;
}
let mut bits:[bool;30] = [false;30];
for i in 0..30{
bits[i] = working % 2 == 1;
working >>=1;
}
bits.chunks(5).rev()
.map(|bools|{
let mut accu:u8 = 0;
for i in 0..5{
accu += if bools[4-i]{
1
} else {0};
accu <<=1;
}
accu |= 0x20;
accu +=63;
char::from(accu)
}).collect::<String>()
let working:i32 = invoke_e5(num);
let working = two_comp(working,num);
let working = lshf(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
}
else {
n
}
}
fn lshf(n:i32)->i32{
n << 1
}
fn if_negative_invert(n:i32, orig:f64)->i32{
if orig < 0.0{
n ^ -1
}
else {
n
}
}
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)]