Skip to content

Commit

Permalink
Improved story
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Nov 25, 2023
1 parent 7ce6f5c commit bacccad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 7 additions & 5 deletions examples/dk_jets.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Use of Danish private jets

{from_date} to {to_date}, Danish private jets emitted
{emissions_tons.claim} tons of CO2e[^5], the equivalent of what **{dane_years.claim} Danes**
emit in a year[^4].
{emissions_tons.claim} tons of CO2e[^1], the equivalent of what **{dane_years.claim} Danes**
emit in a year[^2]. All of this was done by only {number_of_private_jets.claim} private jets[^3]
in {number_of_legs.claim} trips[^4].

Of these,
* {number_of_legs_less_300km} trips were less than 300 km and could have been replaced by
Expand All @@ -17,8 +18,9 @@ Ban private jets now and until they emit what equivalent means of transportation

## References

[^2]: {number_of_legs.source} - retrieved on {number_of_legs.date}
[^4]: {dane_years.source} - retrieved on {dane_years.date}
[^5]: {emissions_tons.source} - retrieved on {emissions_tons.date}
[^1]: {emissions_tons.source} - retrieved on {emissions_tons.date}
[^2]: {dane_years.source} - retrieved on {dane_years.date}
[^3]: {number_of_private_jets.source} on {number_of_private_jets.date}
[^4]: {number_of_legs.source} - retrieved on {number_of_legs.date}

Copyright Jorge Leitão, released under [CC0](https://creativecommons.org/public-domain/cc0/) - No Rights Reserved.
14 changes: 12 additions & 2 deletions examples/dk_jets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn render(context: &Context) -> Result<(), Box<dyn Error>> {
pub struct Context {
pub from_date: String,
pub to_date: String,
pub number_of_private_jets: Fact<usize>,
pub number_of_legs: Fact<usize>,
pub emissions_tons: Fact<usize>,
pub dane_years: Fact<String>,
Expand Down Expand Up @@ -78,14 +79,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
let aircrafts = load_aircrafts(client.as_ref()).await?;
let types = load_aircraft_types()?;

let dk_private_jets = aircrafts
let private_jets = aircrafts
.into_iter()
// is private jet
.filter(|(_, a)| types.contains_key(&a.model))
// is from DK
.filter(|(a, _)| a.starts_with("OY-"))
.collect::<HashMap<_, _>>();

let number_of_private_jets = Fact {
claim: private_jets.len(),
source: format!(
"All aircrafts in [adsbexchange.com](https://globe.adsbexchange.com) whose model is a private jet and tail number starts with \"OY-\""
),
date: "2023-11-06".to_string(),
};

let to = time::OffsetDateTime::now_utc().date() - time::Duration::days(1);
let from = date!(2021 - 01 - 01);

Expand All @@ -101,7 +110,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let iter = dates
.map(|date| {
let client = client.as_ref();
dk_private_jets
private_jets
.iter()
.map(move |(_, a)| flights::positions(&a.icao_number, date.clone(), 1000.0, client))
})
Expand Down Expand Up @@ -184,6 +193,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let context = Context {
from_date,
to_date,
number_of_private_jets,
number_of_legs,
emissions_tons,
dane_years,
Expand Down

0 comments on commit bacccad

Please sign in to comment.