Skip to content

Commit

Permalink
Release trustfall v0.7 plus updates to core and stubgen crates. (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Nov 17, 2023
1 parent 30f1d51 commit 64ebfd5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
rustflags: ""

- name: Publishing?
id: version
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions trustfall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions trustfall/examples/weather/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,\
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 20 additions & 5 deletions trustfall/examples/weather/metar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub(crate) struct CsvMetarReport {
pub(crate) temp_c: Option<f64>,
pub(crate) dewpoint_c: Option<f64>,

pub(crate) wind_dir_degrees: Option<u16>,
pub(crate) wind_dir_degrees: Option<String>,
pub(crate) wind_speed_kt: Option<u16>,
pub(crate) wind_gust_kt: Option<u16>,

pub(crate) visibility_statute_mi: Option<f64>,
pub(crate) visibility_statute_mi: Option<String>,

pub(crate) altim_in_hg: Option<f64>,
pub(crate) sea_level_pressure_mb: Option<f64>,
Expand Down Expand Up @@ -127,6 +127,7 @@ pub(crate) struct MetarReport {

pub(crate) wind_speed_kts: Option<u16>,
pub(crate) wind_direction: Option<u16>,
pub(crate) wind_direction_variable: Option<bool>,
pub(crate) wind_gusts_kts: Option<u16>,

pub(crate) temperature: Option<f64>,
Expand Down Expand Up @@ -174,7 +175,7 @@ impl From<CsvMetarReport> 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)),
Expand All @@ -183,14 +184,28 @@ impl From<CsvMetarReport> 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,
observation_time: csv_metar.observation_time,
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,
Expand Down Expand Up @@ -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();
Expand Down
23 changes: 12 additions & 11 deletions trustfall/examples/weather/metar_weather.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]
}
Expand Down
2 changes: 1 addition & 1 deletion trustfall_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions trustfall_stubgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 }
Expand Down

0 comments on commit 64ebfd5

Please sign in to comment.