Struct solar_api::GeneratedEnergy
source · pub struct GeneratedEnergy {
pub time_unit: TimeUnit,
/* private fields */
}Expand description
Contains all values of the generated energy per time unit
Fields§
§time_unit: TimeUnitImplementations§
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 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
impl Clone for GeneratedEnergy
source§fn clone(&self) -> GeneratedEnergy
fn clone(&self) -> GeneratedEnergy
Returns a copy 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 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