From a3af43497cbf1020a97baba799d228d72d5a7aae Mon Sep 17 00:00:00 2001 From: Zefanja Jobse Date: Sat, 17 Feb 2024 10:56:08 +0100 Subject: [PATCH] use regex for map to reuse mapping from other parts of gametools and fix operations --- Cargo.lock | 15 +++-- Cargo.toml | 8 +-- src/gatherer/marne.rs | 146 ++++++++++++++++++++---------------------- 3 files changed, 82 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18b9699..e8736a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,6 +204,7 @@ dependencies = [ "mongodb", "num-traits", "questdb-rs", + "regex", "reqwest", "serde", "serde_derive", @@ -306,16 +307,16 @@ dependencies = [ [[package]] name = "bson" -version = "2.8.1" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88c18b51216e1f74b9d769cead6ace2f82b965b807e3d73330aabe9faec31c84" +checksum = "ce21468c1c9c154a85696bb25c20582511438edb6ad67f846ba1378ffdd80222" dependencies = [ "ahash", "base64 0.13.1", "bitvec", "chrono", "hex", - "indexmap 1.9.3", + "indexmap 2.1.0", "js-sys", "once_cell", "rand", @@ -1276,9 +1277,9 @@ checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" [[package]] name = "influxdb2" -version = "0.4.5" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e9905b42e1657450f88a3e47a9323d20862a05bf1e09c58d3391ee0916b623f" +checksum = "823356ce3ed697fd640a7db4fbaaa6c2a00bf1eceec66ae0c57c01ef98f06270" dependencies = [ "base64 0.13.1", "bytes", @@ -3051,9 +3052,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index de1f3d9..e0bb6a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ anyhow = "1.0" mongodb = "2.8" futures = "0.3" chrono = "0.4" -influxdb2 = "0.4" +influxdb2 = "0.5" influxdb2-structmap = "0.2" num-traits = "0.2" serde_json = "1.0" @@ -20,7 +20,7 @@ serde_derive = "1.0" questdb-rs = "3.1" sqlx = { version = "0.7", features = ["runtime-tokio", "postgres", "time"] } time = { version = "0.3", features = ["macros", "rand"] } - +regex = "1.10" [dependencies.clickhouse] version = "0.11" @@ -35,11 +35,11 @@ version = "0.3" features = ["tls"] [dependencies.bson] -version = "2.8" +version = "2.9" features = ["chrono-0_4"] [dependencies.tokio] -version = "1.35" +version = "1.36" features = ["full"] [dependencies.bf_sparta] diff --git a/src/gatherer/marne.rs b/src/gatherer/marne.rs index 600b760..35b4497 100644 --- a/src/gatherer/marne.rs +++ b/src/gatherer/marne.rs @@ -6,6 +6,7 @@ use crate::{ }, }; use chrono::Utc; +use regex::Regex; use sqlx::PgPool; use std::collections::HashMap; @@ -42,86 +43,77 @@ async fn server_list_to_sum( HashMap>, ) { let maps = HashMap::from([ - ("Levels/MP/MP_Amiens/MP_Amiens", "Amiens"), - ("Levels/MP/MP_Chateau/MP_Chateau", "Ballroom Blitz"), - ("Levels/MP/MP_Desert/MP_Desert", "Sinai Desert"), - ("Levels/MP/MP_FaoFortress/MP_FaoFortress", "Fao Fortress"), - ("Levels/MP/MP_Forest/MP_Forest", "Argonne Forest"), - ("Levels/MP/MP_ItalianCoast/MP_ItalianCoast", "Empire's Edge"), - ("Levels/MP/MP_MountainFort/MP_MountainFort", "Monte Grappa"), - ("Levels/MP/MP_Scar/MP_Scar", "St Quentin Scar"), - ("Levels/MP/MP_Suez/MP_Suez", "Suez"), - ("Xpack0/Levels/MP/MP_Giant/MP_Giant", "Giant's Shadow"), - ("Xpack1/Levels/MP_Fields/MP_Fields", "Soissons"), - ("Xpack1/Levels/MP_Graveyard/MP_Graveyard", "Rupture"), - ("Xpack1/Levels/MP_Underworld/MP_Underworld", "Fort De Vaux"), - ("Xpack1/Levels/MP_Verdun/MP_Verdun", "Verdun Heights"), - ( - "Xpack1-3/Levels/MP_ShovelTown/MP_ShovelTown", - "Prise de Tahure", - ), - ("Xpack1-3/Levels/MP_Trench/MP_Trench", "Nivelle Nights"), - ("Xpack2/Levels/MP/MP_Bridge/MP_Bridge", "Brusilov Keep"), - ("Xpack2/Levels/MP/MP_Islands/MP_Islands", "Albion"), - ("Xpack2/Levels/MP/MP_Ravines/MP_Ravines", "Łupków Pass"), - ("Xpack2/Levels/MP/MP_Tsaritsyn/MP_Tsaritsyn", "Tsaritsyn"), - ("Xpack2/Levels/MP/MP_Valley/MP_Valley", "Galicia"), - ("Xpack2/Levels/MP/MP_Volga/MP_Volga", "Volga River"), - ("Xpack3/Levels/MP/MP_Beachhead/MP_Beachhead", "Cape Helles"), - ("Xpack3/Levels/MP/MP_Harbor/MP_Harbor", "Zeebrugge"), - ("Xpack3/Levels/MP/MP_Naval/MP_Naval", "Heligoland Bight"), - ("Xpack3/Levels/MP/MP_Ridge/MP_Ridge", "Achi Baba"), - ("Xpack4/Levels/MP/MP_Alps/MP_Alps", "Razor's Edge"), - ("Xpack4/Levels/MP/MP_Blitz/MP_Blitz", "London Calling"), - ("Xpack4/Levels/MP/MP_Hell/MP_Hell", "Passchendaele"), - ( - "Xpack4/Levels/MP/MP_London/MP_London", - "London Calling: Scourge", - ), - ("Xpack4/Levels/MP/MP_Offensive/MP_Offensive", "River Somme"), - ("Xpack4/Levels/MP/MP_River/MP_River", "Caporetto"), + ("MP_Amiens", "Amiens"), + ("MP_Chateau", "Ballroom Blitz"), + ("MP_Desert", "Sinai Desert"), + ("MP_FaoFortress", "Fao Fortress"), + ("MP_Forest", "Argonne Forest"), + ("MP_ItalianCoast", "Empire's Edge"), + ("MP_MountainFort", "Monte Grappa"), + ("MP_Scar", "St Quentin Scar"), + ("MP_Suez", "Suez"), + ("MP_Giant", "Giant's Shadow"), + ("MP_Fields", "Soissons"), + ("MP_Graveyard", "Rupture"), + ("MP_Underworld", "Fort De Vaux"), + ("MP_Verdun", "Verdun Heights"), + ("MP_ShovelTown", "Prise de Tahure"), + ("MP_Trench", "Nivelle Nights"), + ("MP_Bridge", "Brusilov Keep"), + ("MP_Islands", "Albion"), + ("MP_Ravines", "Łupków Pass"), + ("MP_Tsaritsyn", "Tsaritsyn"), + ("MP_Valley", "Galicia"), + ("MP_Volga", "Volga River"), + ("MP_Beachhead", "Cape Helles"), + ("MP_Harbor", "Zeebrugge"), + ("MP_Naval", "Heligoland Bight"), + ("MP_Ridge", "Achi Baba"), + ("MP_Alps", "Razor's Edge"), + ("MP_Blitz", "London Calling"), + ("MP_Hell", "Passchendaele"), + ("MP_London", "London Calling: Scourge"), + ("MP_Offensive", "River Somme"), + ("MP_River", "Caporetto"), // BFV - // MP_ArcticFjell: "Fjell 652", - // MP_ArcticFjord: "Narvik", - ("Levels/MP/MP_Arras/MP_Arras", "Arras"), - // MP_Devastation: "Devastation", - // MP_Escaut: "twisted steel", - // MP_Foxhunt: "Aerodrome", - // MP_Halfaya: "Hamada", - // MP_Rotterdam: "Rotterdam", - // MP_Hannut: "Panzerstorm", - // MP_Crete: "Mercury", - ( - "Live/Greece/Kalamas/Levels/MP/MP_Kalamas/MP_Kalamas", - "Marita", - ), - // MP_Provence: "Provence", - // MP_SandAndSea: "Al sudan", - // MP_Bunker: "Operation Underground", - ("Live/Pacific/Levels/MP/MP_IwoJima/MP_IwoJima", "Iwo jima"), - // MP_TropicIslands: "Pacific storm", - // MP_WakeIsland: "Wake island", - // MP_Jungle: "Solomon islands", - // MP_Libya: "Al marj encampment", - // MP_Norway: "lofoten islands", + ("MP_ArcticFjell", "Fjell 652"), + ("MP_ArcticFjord", "Narvik"), + ("MP_Arras", "Arras"), + ("MP_Devastation", "Devastation"), + ("MP_Escaut", "twisted steel"), + ("MP_Foxhunt", "Aerodrome"), + ("MP_Halfaya", "Hamada"), + ("MP_Rotterdam", "Rotterdam"), + ("MP_Hannut", "Panzerstorm"), + ("MP_Crete", "Mercury"), + ("MP_Kalamas", "Marita"), + ("MP_Provence", "Provence"), + ("MP_SandAndSea", "Al sudan"), + ("MP_Bunker", "Operation Underground"), + ("MP_IwoJima", "Iwo jima"), + ("MP_TropicIslands", "Pacific storm"), + ("MP_WakeIsland", "Wake island"), + ("MP_Jungle", "Solomon islands"), + ("MP_Libya", "Al marj encampment"), + ("MP_Norway", "lofoten islands"), // bfv special maps - // DK_Norway: "Halvoy", - // MP_Escaut_US: "Twisted Steel US", - // MP_Hannut_US: "Panzerstorm US", - // MP_GOps_Chapter2_Arras: "Arras (Chapter 2)", - // MP_WE_Fortress_Devastation: "Devastation (Fortress)", - // MP_WE_Fortress_Halfaya: "Hamada (Fortress)", - // MP_WE_Grind_ArcticFjord: "Narvik (Grind)", - // MP_WE_Grind_Devastation: "Devastation (Grind)", - // MP_WE_Grind_Escaut: "Twisted Steel (Grind)", - // MP_WE_Grind_Rotterdam: "Rotterdam (Grind)", + ("DK_Norway", "Halvoy"), + ("MP_Escaut_US", "Twisted Steel US"), + ("MP_Hannut_US", "Panzerstorm US"), + ("MP_GOps_Chapter2_Arras", "Arras (Chapter 2)"), + ("MP_WE_Fortress_Devastation", "Devastation (Fortress)"), + ("MP_WE_Fortress_Halfaya", "Hamada (Fortress)"), + ("MP_WE_Grind_ArcticFjord", "Narvik (Grind)"), + ("MP_WE_Grind_Devastation", "Devastation (Grind)"), + ("MP_WE_Grind_Escaut", "Twisted Steel (Grind)"), + ("MP_WE_Grind_Rotterdam", "Rotterdam (Grind)"), ]); let modes = HashMap::from([ ("Conquest0", "Conquest"), ("Rush0", "Rush"), ("BreakThrough0", "Shock Operations"), - ("BreakThroughLarge0", "Operations"), + ("BreakthroughLarge0", "Operations"), ("Possession0", "War pigeons"), ("TugOfWar0", "Frontlines"), ("AirAssault0", "Air assault"), @@ -176,10 +168,12 @@ async fn server_list_to_sum( .get(&server.game_mode[..]) .unwrap_or(&&server.game_mode[..]) .to_string(); - let map = maps - .get(&server.map_name[..]) - .unwrap_or(&&server.map_name[..]) - .to_string(); + + let internal_map = match Regex::new(r"[^\/]+$").unwrap().find(&server.map_name[..]) { + Some(location) => location.as_str(), + None => &server.map_name[..], + }; + let map = maps.get(internal_map).unwrap_or(&internal_map).to_string(); regions .entry(server_region.clone())