read game start and end time from a file

This commit is contained in:
2025-11-23 22:24:04 -08:00
parent 36c36018d1
commit 661d5f29f0
6 changed files with 21 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
/target
*~
teams.json

1
Cargo.lock generated
View File

@ -347,6 +347,7 @@ dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-link 0.2.1",
]

View File

@ -5,7 +5,7 @@ edition = "2024"
[dependencies]
actix-web = "4.12.0"
chrono = "0.4.42"
chrono = {version="0.4.42", features = ["serde"]}
csv = "1.3"
geo = "0.31.0"
geojson = "0.24.2"

View File

@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -y libssl3 ca-certificates && apt-get clea
COPY --from=builder /usr/src/app/Neighborhood_Map_Atlas_Neighborhoods.geojson /
COPY --from=builder /usr/src/app/map.html /
COPY --from=builder /usr/src/app/teams.json /
COPY --from=builder /usr/src/app/times.json /
COPY --from=builder /usr/src/app/target/release/mapbattle /usr/local/bin/mapbattle
EXPOSE 8080
CMD ["mapbattle"]

View File

@ -16,9 +16,6 @@ use std::io::Write;
use tokio::time;
use std::time::Duration;
const DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%SZ";
#[get("/legend-data")]
async fn legend_data() -> impl Responder {
let teams = read_teams();
@ -73,11 +70,10 @@ async fn update_scores()-> Result<(), Box<dyn Error>> {
.build()?;
let mut teams = read_teams();
// Configure time range
let start_date = NaiveDateTime::parse_from_str("2025-11-13T11:55:07Z", DATE_FORMAT)?;
let end_date = NaiveDateTime::parse_from_str("2025-11-13T15:55:07Z", DATE_FORMAT)?;
let (start_date, end_date) = read_times();
for team in &mut teams {
team.scores.clear();
for player in team.players.clone() {
println!("Processing player: {} ({})", player.username, team.name);
let body = scores::get_changesets_for_user(player.username.clone(), &client).await?;
@ -101,3 +97,8 @@ fn read_teams() -> Vec<Team> {
let text: String = fs::read_to_string("teams.json").expect("file should be present");
serde_json::from_str(&text).unwrap()
}
fn read_times() -> (NaiveDateTime, NaiveDateTime) {
let text: String = fs::read_to_string("times.json").expect("file should be present");
serde_json::from_str(&text).unwrap()
}

View File

@ -91,8 +91,16 @@ pub mod scores {
pub async fn changesets_to_points(changesets: Vec<Vec<OwnedAttribute>>) -> HashMap<String, i32> {
let mut result: HashMap<String, i32> = HashMap::new();
for changeset in changesets {
let min_lat = changeset.clone().into_iter().find(|att| att.name.local_name.eq("min_lat")).unwrap().value;
let min_lon = changeset.clone().into_iter().find(|att| att.name.local_name.eq("min_lon")).unwrap().value;
let min_lat = changeset.clone().into_iter().find(|att| att.name.local_name.eq("min_lat"));
if min_lat.is_none() {
continue;
}
let min_lat = min_lat.unwrap().value;
let min_lon = changeset.clone().into_iter().find(|att| att.name.local_name.eq("min_lon"));
if min_lon.is_none() {
continue;
}
let min_lon = min_lon.unwrap().value;
let min_lat: f64 = min_lat.parse().unwrap_or_default();
let min_lon: f64 = min_lon.parse().unwrap_or_default();
// TODO get the points from the changes_count