pub struct PriceData { /* private fields */ }Expand description
Holds a set of price slots and provides some utility functions for working with price data.
Implementations§
Source§impl PriceData
impl PriceData
Sourcepub async fn query<TZ: TimeZone>(
zone: AwattarZone,
start: Option<DateTime<TZ>>,
end: Option<DateTime<TZ>>,
) -> Result<Self, AwattarError>
pub async fn query<TZ: TimeZone>( zone: AwattarZone, start: Option<DateTime<TZ>>, end: Option<DateTime<TZ>>, ) -> Result<Self, AwattarError>
Query prices from the awattar API between the given start- and end-datetime in the given zone.
§Examples
use awattar_api::{AwattarZone, PriceData};
use chrono::{Local, TimeZone};
let prices = PriceData::query(
AwattarZone::Germany,
Some(Local.ymd(2022, 08, 1).and_hms(0, 0, 0)),
Some(Local.ymd(2022, 08, 2).and_hms(0, 0, 0)),
)
.await
.unwrap();
println!("Prices: {:?}", prices);Sourcepub async fn query_date(
zone: AwattarZone,
date: NaiveDate,
) -> Result<Self, AwattarError>
pub async fn query_date( zone: AwattarZone, date: NaiveDate, ) -> Result<Self, AwattarError>
Query prices from the awattar API for a given date.
The NaiveDate is converted to a timezone-aware Date using the given AwattarZones local
timezone. This always yields price data from 00:00 on the start date to 00:00 on the
end-date (24 slots on days without switch between daylight saving and standard time).
§Examples
use awattar_api::{AwattarZone, PriceData};
use chrono::Local;
let prices = PriceData::query_date(AwattarZone::Germany, Local::today().naive_local())
.await
.unwrap();
println!("Prices: {:?}", prices);Sourcepub fn from_slots(slots: Vec<PriceSlot>, zone: AwattarZone) -> Self
pub fn from_slots(slots: Vec<PriceSlot>, zone: AwattarZone) -> Self
Sourcepub fn slots_iter(&self) -> impl Iterator<Item = &PriceSlot>
pub fn slots_iter(&self) -> impl Iterator<Item = &PriceSlot>
Provides an iterator over all PriceSlots this instance holds. Useful for things like
calculating the average price over a day.
§Examples
use awattar_api::{AwattarZone, PriceData};
use chrono::Local;
let prices = PriceData::query_date(AwattarZone::Germany, Local::today().naive_local())
.await
.unwrap();
let avg_price = prices.slots_iter().fold(0, |sum, slot| sum + slot.price_cents_per_mwh())
/ prices.len() as i32;Sourcepub fn slot_for_datetime<TZ: TimeZone>(
&self,
datetime: DateTime<TZ>,
) -> Option<&PriceSlot>
pub fn slot_for_datetime<TZ: TimeZone>( &self, datetime: DateTime<TZ>, ) -> Option<&PriceSlot>
Finds and returns the PriceSlot for the given datetime.
If no slot could be found, None is returned.
Sourcepub fn min_price(&self) -> Option<&PriceSlot>
pub fn min_price(&self) -> Option<&PriceSlot>
Returns the PriceSlot with the lowest price.
If this instance does not contain any price slots, None is returned.
Sourcepub fn max_price(&self) -> Option<&PriceSlot>
pub fn max_price(&self) -> Option<&PriceSlot>
Returns the PriceSlot with the highest price.
If this instance does not contain any price slots, None is returned.
Sourcepub fn zone(&self) -> AwattarZone
pub fn zone(&self) -> AwattarZone
Returns the zone this instance belongs in.