-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
232 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "cargo" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" | ||
target-branch: "dev" | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: cargo fmt | ||
name: cargo fmt | ||
entry: cargo +nightly fmt | ||
language: system | ||
types: [rust] | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
group_imports="StdExternalCrate" | ||
imports_granularity="Crate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,71 @@ | ||
use std::sync::Arc; | ||
use air_traffic_simulator::engine::world_data::{AirportData, Runway}; | ||
use air_traffic_simulator::WorldData; | ||
use color_eyre::Report; | ||
use glam::Vec2; | ||
use color_eyre::Result; | ||
|
||
use air_traffic_simulator::{ | ||
WorldData, | ||
engine::world_data::{AirportData, Runway}, | ||
}; | ||
use color_eyre::{Report, Result}; | ||
|
||
use crate::utils::{SURF_CLIENT, get_url, parse_coords}; | ||
|
||
pub async fn airports(world_data: &mut WorldData) -> Result<()> { | ||
let client = surf::client().with(surf::middleware::Redirect::new(5)); | ||
let string = client.send(surf::get("https://docs.google.com/spreadsheets/d/11E60uIBKs5cOSIRHLz0O0nLCefpj7HgndS1gIXY_1hw/export?format=csv&gid=0")) | ||
.await.map_err(|a| Report::msg(a.to_string()))? | ||
.body_string() | ||
.await.map_err(|a| Report::msg(a.to_string()))?; | ||
let string = get_url("https://docs.google.com/spreadsheets/d/11E60uIBKs5cOSIRHLz0O0nLCefpj7HgndS1gIXY_1hw/export?format=csv&gid=0").await?; | ||
let mut reader = csv::Reader::from_reader(string.as_bytes()); | ||
fn parse_coords(c: &str) -> Vec2 { | ||
let mut a = c.trim().split(' '); | ||
Vec2::new(a.next().and_then(|a| a.parse().ok()).unwrap(), a.next().and_then(|a| a.parse().ok()).unwrap()) | ||
} | ||
world_data.airports = reader.records().map(|res| { | ||
let res = res?; | ||
if !res.get(1).unwrap().contains("Airfield") && !res.get(1).unwrap().contains("Airport") { | ||
return Ok(None) | ||
} | ||
let mut runways = vec![]; | ||
for i in [3, 7, 11, 15] { | ||
if res.get(i).is_none_or(|a| a.is_empty()) { | ||
if i == 3 { | ||
return Ok(None) | ||
|
||
world_data.airports = reader | ||
.records() | ||
.map(|res| { | ||
let res = res?; | ||
if !res.get(1).unwrap().contains("Airfield") && !res.get(1).unwrap().contains("Airport") | ||
{ | ||
return Ok(None); | ||
} | ||
let mut runways = vec![]; | ||
for i in [3, 7, 11, 15] { | ||
if res.get(i).is_none_or(|a| a.is_empty()) { | ||
if i == 3 { | ||
return Ok(None); | ||
} | ||
break; | ||
} | ||
break | ||
runways.push(Arc::new(Runway { | ||
name: res.get(i + 2).unwrap().into(), | ||
start: parse_coords(res.get(i).unwrap()), | ||
end: parse_coords(res.get(i + 1).unwrap()), | ||
altitude: 0.0, | ||
class: res | ||
.get(i + 3) | ||
.unwrap() | ||
.chars() | ||
.next() | ||
.unwrap() | ||
.to_string() | ||
.into(), | ||
})); | ||
runways.push(Arc::new(Runway { | ||
name: res.get(i + 2).unwrap().into(), | ||
start: parse_coords(res.get(i + 1).unwrap()), | ||
end: parse_coords(res.get(i).unwrap()), | ||
altitude: 0.0, | ||
class: res | ||
.get(i + 3) | ||
.unwrap() | ||
.chars() | ||
.next() | ||
.unwrap() | ||
.to_string() | ||
.into(), | ||
})); | ||
} | ||
runways.push(Arc::new(Runway { | ||
name: res.get(i+2).unwrap().into(), | ||
start: parse_coords(res.get(i).unwrap()), | ||
end: parse_coords(res.get(i+1).unwrap()), | ||
altitude: 0.0, | ||
class: res.get(i+3).unwrap().chars().next().unwrap().to_string().into(), | ||
})); | ||
runways.push(Arc::new(Runway { | ||
name: res.get(i+2).unwrap().into(), | ||
start: parse_coords(res.get(i+1).unwrap()), | ||
end: parse_coords(res.get(i).unwrap()), | ||
altitude: 0.0, | ||
class: res.get(i+3).unwrap().chars().next().unwrap().to_string().into(), | ||
})); | ||
} | ||
Ok(Some(Arc::new(AirportData { | ||
name: res.get(0).unwrap().into(), | ||
code: res.get(0).unwrap().into(), | ||
runways: runways.into(), | ||
}))) | ||
}).collect::<Result<Vec<_>>>()?.into_iter().flatten().collect(); | ||
Ok(Some(Arc::new(AirportData { | ||
name: res.get(0).unwrap().into(), | ||
code: res.get(0).unwrap().into(), | ||
runways: runways.into(), | ||
}))) | ||
}) | ||
.collect::<Result<Vec<_>>>()? | ||
.into_iter() | ||
.flatten() | ||
.collect(); | ||
Ok(()) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::cell::LazyCell; | ||
|
||
use color_eyre::{Report, Result}; | ||
use glam::Vec2; | ||
|
||
pub fn parse_coords(c: &str) -> Vec2 { | ||
let mut a = c.trim().split(' '); | ||
Vec2::new( | ||
a.next().and_then(|a| a.parse().ok()).unwrap(), | ||
a.next().and_then(|a| a.parse().ok()).unwrap(), | ||
) | ||
} | ||
|
||
pub static SURF_CLIENT: LazyCell<surf::Client> = | ||
LazyCell::new(|| surf::client().with(surf::middleware::Redirect::new(5))); | ||
pub async fn get_url(url: &'static str) -> Result<String> { | ||
SURF_CLIENT | ||
.send(surf::get(url)) | ||
.await | ||
.map_err(|a| Report::msg(a.to_string()))? | ||
.body_string() | ||
.await | ||
.map_err(|a| Report::msg(a.to_string())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters