Struct GeneratedPowerPerTimeUnit

Source
pub struct GeneratedPowerPerTimeUnit {
    pub time_unit: TimeUnit,
    /* private fields */
}
Expand description

Contains all values of the generated power per time unit

Fields§

§time_unit: TimeUnit

Implementations§

Source§

impl GeneratedPowerPerTimeUnit

Source

pub fn values(&self) -> Vec<GeneratedPowerValue>

returns all Power values that were present in the time period

Examples found in repository?
examples/use_api.rs (line 84)
12fn main() -> Result<(), Box<dyn Error>> {
13    env_logger::init();
14
15    let args: Vec<String> = env::args().collect();
16    if args.len() < 3 {
17        println!("usage: use_api <API_KEY> <SITE_ID>");
18        return Ok(());
19    }
20    let api_key: &str = args[1].as_ref();
21    let site_id: u32 = args[2].parse()?;
22    println!("Accessing API using {api_key} for site {site_id}");
23
24    println!("Getting information of all sites of customer");
25    for site in list(api_key)? {
26        println!("Id: {}\tName: {}", site.id, site.name);
27    }
28
29    println!("Getting information of site {site_id}");
30    let site_details = details(api_key, site_id)?;
31    println!(
32        "Id = {}\tstatus: {}\t peak_power: {}",
33        site_details.id,
34        site_details.status,
35        site_details
36            .peak_power
37            .into_format_args(kilowatt, uom::fmt::DisplayStyle::Description)
38    );
39
40    println!("Getting period of available data of site {site_id}");
41    let data_period = data_period(api_key, site_id)?;
42    println!(
43        "Data available from {} until {}",
44        data_period.start_date, data_period.end_date
45    );
46
47    println!("Getting overview of site {site_id}");
48    let overview = overview(api_key, site_id)?;
49    println!(
50        "Site generated {:.2} since installation and is currently generating {:.2}",
51        overview
52            .life_time_data
53            .energy
54            .into_format_args(megawatt_hour, DisplayStyle::Abbreviation),
55        overview
56            .current_power
57            .power
58            .into_format_args(watt, DisplayStyle::Description)
59    );
60
61    println!("Getting energy generation of past day");
62    let now = Local::now().naive_local();
63    let period: DataPeriod = DataPeriod {
64        start_date: now.date(),
65        end_date: now.date(),
66    };
67    let energy = energy(api_key, site_id, period, TimeUnit::Hour)?;
68    for e in energy.values() {
69        println!(
70            "\t{} - {}",
71            e.date,
72            e.value
73                .map(|v| format!(
74                    "{:7.2}",
75                    v.into_format_args(watt_hour, DisplayStyle::Abbreviation)
76                ))
77                .unwrap_or_else(|| "     No value".to_string())
78        );
79    }
80
81    println!("Getting power generation of past hour");
82    let now = Local::now().naive_local();
83    let power = power(api_key, site_id, now - Duration::hours(1), now)?;
84    for e in power.values() {
85        println!(
86            "\t{} - {}",
87            e.date,
88            e.value
89                .map(|v| format!("{:7.2}", v.into_format_args(watt, DisplayStyle::Description)))
90                .unwrap_or_else(|| "No value".to_string())
91        );
92    }
93
94    Ok(())
95}

Trait Implementations§

Source§

impl Clone for GeneratedPowerPerTimeUnit

Source§

fn clone(&self) -> GeneratedPowerPerTimeUnit

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeneratedPowerPerTimeUnit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GeneratedPowerPerTimeUnit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,