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
impl GeneratedEnergy
Sourcepub fn values(&self) -> Vec<GeneratedEnergyValue>
pub fn values(&self) -> Vec<GeneratedEnergyValue>
returns the timestamped energy values
Examples found in repository?
examples/use_api.rs (line 68)
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 GeneratedEnergy
impl Clone for GeneratedEnergy
Source§fn clone(&self) -> GeneratedEnergy
fn clone(&self) -> GeneratedEnergy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for GeneratedEnergy
impl Debug for GeneratedEnergy
Source§impl<'de> Deserialize<'de> for GeneratedEnergy
impl<'de> Deserialize<'de> for GeneratedEnergy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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§
impl Freeze for GeneratedEnergy
impl RefUnwindSafe for GeneratedEnergy
impl Send for GeneratedEnergy
impl Sync for GeneratedEnergy
impl Unpin for GeneratedEnergy
impl UnwindSafe for GeneratedEnergy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more