diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 393628ad..066df0ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -413,6 +413,7 @@ jobs: uses: actions-rust-lang/setup-rust-toolchain@v1 with: cache: false + rustflags: "" - name: Publishing? id: version @@ -451,7 +452,6 @@ jobs: cd trustfall cargo run --example hackernews query ./examples/hackernews/example_queries/front_page_stories_with_links.ron 1 cargo run --example hackernews query ./examples/hackernews/example_queries/latest_links_by_high_karma_users.ron 1 - cargo run --example hackernews query ./examples/hackernews/example_queries/patio11_comments_on_own_blog_posts.ron 1 - name: weather example if: steps.version.outputs.is_new_version == 'yes' diff --git a/Cargo.lock b/Cargo.lock index cc315775..37da6c2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3241,11 +3241,12 @@ dependencies = [ [[package]] name = "trustfall" -version = "0.6.1" +version = "0.7.0" dependencies = [ "anyhow", "csv", "feed-rs", + "flate2", "hn_api", "regex", "reqwest 0.11.22", @@ -3259,7 +3260,7 @@ dependencies = [ [[package]] name = "trustfall_core" -version = "0.6.0" +version = "0.7.0" dependencies = [ "async-graphql-parser", "async-graphql-value", @@ -3299,7 +3300,7 @@ dependencies = [ [[package]] name = "trustfall_stubgen" -version = "0.3.0" +version = "0.4.0" dependencies = [ "anyhow", "async-graphql-parser", diff --git a/trustfall/Cargo.toml b/trustfall/Cargo.toml index b1e7c5c5..9de3f27a 100644 --- a/trustfall/Cargo.toml +++ b/trustfall/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trustfall" -version = "0.6.1" +version = "0.7.0" license = "Apache-2.0" description = "The trustfall query engine, empowering you to query everything." repository = "https://github.com/obi1kenobi/trustfall" @@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] anyhow = { workspace = true } -trustfall_core = { version = "=0.6.0", path = "../trustfall_core" } +trustfall_core = { version = "=0.7.0", path = "../trustfall_core" } trustfall_derive = { version = "=0.3.1", path = "../trustfall_derive" } [dev-dependencies] # including examples dependencies @@ -29,6 +29,7 @@ time = { version = "0.3.23", features = ["serde-human-readable"] } feed-rs = "1.0.0" hn_api = "0.1.0" csv = "1.1.6" +flate2 = "1.0" [[example]] # Running queries over RSS/Atom feeds. diff --git a/trustfall/examples/weather/main.rs b/trustfall/examples/weather/main.rs index 3cdafed3..256788a7 100644 --- a/trustfall/examples/weather/main.rs +++ b/trustfall/examples/weather/main.rs @@ -26,8 +26,7 @@ fn get_schema() -> &'static Schema { }) } -const METAR_DOC_URL: &str = - "https://aviationweather.gov/adds/dataserver_current/current/metars.cache.csv"; +const METAR_DOC_URL: &str = "https://aviationweather.gov/data/cache/metars.cache.csv.gz"; const METAR_DOC_LOCATION: &str = "/tmp/metars-clean.cache.csv"; const METAR_DOC_HEADER_ROW: &str = "\ raw_text,station_id,observation_time,latitude,longitude,temp_c,dewpoint_c,\ @@ -107,13 +106,15 @@ fn run_query(path: &str) { } fn refresh_data() { - let all_data = reqwest::blocking::get(METAR_DOC_URL).unwrap().text().unwrap(); - let write_file_path = METAR_DOC_LOCATION.to_owned() + "-temp"; + let response = reqwest::blocking::get(METAR_DOC_URL).expect("network request failed"); + let decoder = flate2::read::MultiGzDecoder::new(response); + let write_file_path = METAR_DOC_LOCATION.to_owned() + "-temp"; let write_file = File::create(&write_file_path).unwrap(); let mut buf_writer = BufWriter::new(write_file); - for line in all_data.lines() { + let contents = std::io::read_to_string(decoder).expect("failed to read file to string"); + for line in contents.lines() { if line.contains("AUTO NIL") { continue; } diff --git a/trustfall/examples/weather/metar.rs b/trustfall/examples/weather/metar.rs index 07761afb..e685f44a 100644 --- a/trustfall/examples/weather/metar.rs +++ b/trustfall/examples/weather/metar.rs @@ -20,11 +20,11 @@ pub(crate) struct CsvMetarReport { pub(crate) temp_c: Option, pub(crate) dewpoint_c: Option, - pub(crate) wind_dir_degrees: Option, + pub(crate) wind_dir_degrees: Option, pub(crate) wind_speed_kt: Option, pub(crate) wind_gust_kt: Option, - pub(crate) visibility_statute_mi: Option, + pub(crate) visibility_statute_mi: Option, pub(crate) altim_in_hg: Option, pub(crate) sea_level_pressure_mb: Option, @@ -127,6 +127,7 @@ pub(crate) struct MetarReport { pub(crate) wind_speed_kts: Option, pub(crate) wind_direction: Option, + pub(crate) wind_direction_variable: Option, pub(crate) wind_gusts_kts: Option, pub(crate) temperature: Option, @@ -174,7 +175,7 @@ impl From for MetarReport { let visibility_statute_mi = match visibility { Visibility::StatuteMiles(visibility_mi) => Some(visibility_mi), Visibility::Minimal | Visibility::Unlimited => None, - Visibility::Unknown => csv_metar.visibility_statute_mi, + Visibility::Unknown => None, }; let (visibility_unlimited, visibility_minimal) = match visibility { Visibility::StatuteMiles(_) => (Some(false), Some(false)), @@ -183,6 +184,19 @@ impl From for MetarReport { Visibility::Unknown => (None, None), }; + let (wind_direction, wind_direction_variable) = match csv_metar.wind_dir_degrees.as_deref() + { + Some("VRB") => (None, Some(true)), + Some(number) => match number.parse() { + Ok(direction) => (Some(direction), Some(false)), + Err(e) => { + eprintln!("failed to parse wind direction: {e}"); + (None, None) + } + }, + None => (None, None), + }; + Self { station_id: csv_metar.station_id, raw_report: csv_metar.raw_metar, @@ -190,7 +204,8 @@ impl From for MetarReport { latitude: csv_metar.latitude, longitude: csv_metar.longitude, wind_speed_kts: csv_metar.wind_speed_kt, - wind_direction: csv_metar.wind_dir_degrees, + wind_direction, + wind_direction_variable, wind_gusts_kts: csv_metar.wind_gust_kt, temperature: csv_metar.temp_c, dewpoint: csv_metar.dewpoint_c, @@ -240,7 +255,7 @@ fn get_visibility(raw_metar: &str) -> Visibility { if let Some(capture) = regex.captures(raw_metar) { match capture[1].trim() { "0000" => Visibility::Minimal, - "9999" | "CAVOK" => Visibility::Unlimited, + "9999" | "CAVOK" | "10+" => Visibility::Unlimited, "////" | "////SM" => Visibility::Unknown, visibility_sm if visibility_sm.ends_with("SM") => { let visibility_amount = visibility_sm.strip_suffix("SM").unwrap(); diff --git a/trustfall/examples/weather/metar_weather.graphql b/trustfall/examples/weather/metar_weather.graphql index 95d5e5ec..d42c2397 100644 --- a/trustfall/examples/weather/metar_weather.graphql +++ b/trustfall/examples/weather/metar_weather.graphql @@ -37,25 +37,26 @@ type RootSchemaQuery { } type MetarReport { - station_id: String! # for airport stations, the 4-letter ICAO airport code: KBOS for Boston Logan + station_id: String! # for airport stations, the 4-letter ICAO airport code: KBOS for Boston Logan raw_report: String! latitude: Float longitude: Float - wind_speed_kts: Int # in knots - wind_direction: Int # in degrees - wind_gusts_kts: Int # in knots + wind_speed_kts: Int # in knots + wind_direction: Int # in degrees, if known + wind_direction_variable: Boolean # true if the wind direction is inconsistent + wind_gusts_kts: Int # in knots - temperature: Float # in degrees C - dewpoint: Float # in degrees C + temperature: Float # in degrees C + dewpoint: Float # in degrees C - visibility_unlimited: Boolean # corresponds to visibility 9999 - visibility_minimal: Boolean # corresponds to visibility 0000 - visibility_statute_mi: Int # in statute miles (the "usual" miles, not nautical miles) + visibility_unlimited: Boolean # corresponds to visibility 9999 + visibility_minimal: Boolean # corresponds to visibility 0000 + visibility_statute_mi: Float # in statute miles (the "usual" miles, not nautical miles) - altimeter_in_hg: Float # in inches of mercury - sea_level_pressure_mb: Float # in milibars + altimeter_in_hg: Float # in inches of mercury + sea_level_pressure_mb: Float # in milibars cloud_cover: [MetarCloudCover!] } diff --git a/trustfall_core/Cargo.toml b/trustfall_core/Cargo.toml index b9183f76..15f5d099 100644 --- a/trustfall_core/Cargo.toml +++ b/trustfall_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trustfall_core" -version = "0.6.0" +version = "0.7.0" license = "Apache-2.0" description = "The trustfall query engine, empowering you to query everything." repository = "https://github.com/obi1kenobi/trustfall" diff --git a/trustfall_stubgen/Cargo.toml b/trustfall_stubgen/Cargo.toml index fe85f1a3..44003224 100644 --- a/trustfall_stubgen/Cargo.toml +++ b/trustfall_stubgen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trustfall_stubgen" -version = "0.3.0" +version = "0.4.0" license = "Apache-2.0" description = "Generate a Trustfall adapter stub for a given schema." repository = "https://github.com/obi1kenobi/trustfall" @@ -23,7 +23,7 @@ cli = ["dep:clap"] quote = { workspace = true } syn = { workspace = true } proc-macro2 = { workspace = true } -trustfall = { path = "../trustfall", version = "0.6.0" } +trustfall = { path = "../trustfall", version = "0.7.0" } maplit = { workspace = true } async-graphql-parser = { workspace = true } async-graphql-value = { workspace = true }