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

Contains all values of the generated energy per time unit

Fields§

§time_unit: TimeUnit

Implementations§

source§

impl GeneratedEnergy

source

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

returns the timestamped energy values

Examples found in repository?
examples/use_api.rs (line 69)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() -> Result<(), Box<dyn Error>> {
    env_logger::init();

    let args: Vec<String> = env::args().collect();
    if args.len() < 3 {
        println!("usage: use_api <API_KEY> <SITE_ID>");
        return Ok(());
    }
    let api_key: &str = args[1].as_ref();
    let site_id: u32 = args[2].parse()?;
    println!("Accessing API using {api_key} for site {site_id}");

    println!("Getting information of all sites of customer");
    for site in list(api_key)? {
        println!("Id: {}\tName: {}", site.id, site.name);
    }

    println!("Getting information of site {site_id}");
    let site_details = details(api_key, site_id)?;
    println!(
        "Id = {}\tstatus: {}\t peak_power: {}",
        site_details.id,
        site_details.status,
        site_details
            .peak_power
            .into_format_args(kilowatt, uom::fmt::DisplayStyle::Description)
    );

    println!("Getting period of available data of site {site_id}");
    let data_period = data_period(api_key, site_id)?;
    println!(
        "Data available from {} until {}",
        data_period.start_date, data_period.end_date
    );

    println!("Getting overview of site {site_id}");
    let overview = overview(api_key, site_id)?;
    println!(
        "Site generated {:.2} and today {:.2}",
        overview
            .life_time_data
            .energy
            .into_format_args(megawatt_hour, DisplayStyle::Abbreviation),
        overview
            .current_power
            .power
            .into_format_args(kilowatt, DisplayStyle::Description)
    );

    println!("Getting energy generation of past day");
    let now = Local::now().naive_local();
    let period: DataPeriod = DataPeriod {
        start_date: now.date(),
        end_date: now.date(),
    };
    let time_unit = TimeUnit::Hour;
    let energy = energy(api_key, site_id, period, time_unit)?;
    for e in energy.values() {
        println!(
            "\t{} - {}",
            e.date,
            e.value
                .map(|v| format!(
                    "{}",
                    v.into_format_args(watt_hour, DisplayStyle::Abbreviation)
                ))
                .unwrap_or_else(|| "No value".to_string())
        );
    }
    println!("Getting power generation of past hour");
    let now = Local::now().naive_local();
    let power = power(api_key, site_id, now - Duration::hours(1), now)?;
    for e in power.values() {
        println!(
            "\t{} - {}",
            e.date,
            e.value
                .map(|v| format!("{}", v.into_format_args(watt, DisplayStyle::Description)))
                .unwrap_or_else(|| "No value".to_string())
        );
    }

    Ok(())
}

Trait Implementations§

source§

impl Clone for GeneratedEnergy

source§

fn clone(&self) -> GeneratedEnergy

Returns a copy 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 GeneratedEnergy

source§

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

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

impl<'de> Deserialize<'de> for GeneratedEnergy

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

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 Twhere T: for<'de> Deserialize<'de>,