diff --git a/Cargo.lock b/Cargo.lock index a434d64..50ed4bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,12 +215,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - [[package]] name = "either" version = "1.6.1" @@ -323,21 +317,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.21" @@ -345,7 +324,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -354,34 +332,6 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" -[[package]] -name = "futures-executor" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" - -[[package]] -name = "futures-macro" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "futures-sink" version = "0.3.21" @@ -400,16 +350,10 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -448,12 +392,6 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - [[package]] name = "hermit-abi" version = "0.1.19" @@ -527,19 +465,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-rustls" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" -dependencies = [ - "http", - "hyper", - "rustls", - "tokio", - "tokio-rustls", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -574,33 +499,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "influxdb-export" -version = "0.1.0" -dependencies = [ - "energiatili-config", - "energiatili-model", - "env_logger", - "futures", - "influxdb2_client", - "tokio", -] - -[[package]] -name = "influxdb2_client" -version = "0.1.0" -source = "git+https://github.com/influxdata/influxdb_iox?rev=bf39649d64e2890e2ae9e5a4e245c67624d2df43#bf39649d64e2890e2ae9e5a4e245c67624d2df43" -dependencies = [ - "bytes", - "futures", - "reqwest", - "serde", - "serde_json", - "snafu", - "url", - "uuid", -] - [[package]] name = "instant" version = "0.1.12" @@ -1035,7 +933,6 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls", "hyper-tls", "ipnet", "js-sys", @@ -1046,60 +943,19 @@ dependencies = [ "percent-encoding", "pin-project-lite", "proc-macro-hack", - "rustls", - "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "tokio", "tokio-native-tls", - "tokio-rustls", - "tokio-util", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", "winreg", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi", -] - -[[package]] -name = "rustls" -version = "0.20.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" -dependencies = [ - "log", - "ring", - "sct", - "webpki", -] - -[[package]] -name = "rustls-pemfile" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7522c9de787ff061458fe9a829dc790a3f5b22dc571694fc5883f448b94d9a9" -dependencies = [ - "base64", -] - [[package]] name = "ryu" version = "1.0.10" @@ -1122,16 +978,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "sct" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "security-framework" version = "2.6.1" @@ -1210,28 +1056,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" -[[package]] -name = "snafu" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5177903bf45656592d9eb5c0e22f408fc023aae51dbe2088889b71633ba451f2" -dependencies = [ - "doc-comment", - "snafu-derive", -] - -[[package]] -name = "snafu-derive" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410b26ed97440d90ced3e2488c868d56a86e2064f5d7d6f417909b286afe25e5" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "socket2" version = "0.4.4" @@ -1242,12 +1066,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "syn" version = "1.0.96" @@ -1385,17 +1203,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.23.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" -dependencies = [ - "rustls", - "tokio", - "webpki", -] - [[package]] name = "tokio-util" version = "0.7.3" @@ -1481,12 +1288,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "url" version = "2.2.2" @@ -1499,15 +1300,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom", -] - [[package]] name = "vcpkg" version = "0.2.15" @@ -1618,25 +1410,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" -dependencies = [ - "webpki", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 39faa3d..26b65f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ members = [ "energiatili-config", "energiatili-import", "energiatili-model", - "influxdb-export", ] [profile.release] diff --git a/energiatili-config/src/lib.rs b/energiatili-config/src/lib.rs index 581342b..174f0b6 100644 --- a/energiatili-config/src/lib.rs +++ b/energiatili-config/src/lib.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; #[derive(Default, Serialize, Deserialize)] pub struct Config { pub energiatili: Energiatili, - pub influxdb: InfluxDB, } #[derive(Default, Serialize, Deserialize)] @@ -15,14 +14,6 @@ pub struct Energiatili { pub password: String, } -#[derive(Default, Serialize, Deserialize)] -pub struct InfluxDB { - pub url: String, - pub token: String, - pub org: String, - pub bucket: String, -} - impl Config { pub fn read() -> io::Result { let mut config_dir = dirs::config_dir().ok_or_else(|| { diff --git a/influxdb-export/Cargo.toml b/influxdb-export/Cargo.toml deleted file mode 100644 index a183983..0000000 --- a/influxdb-export/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "influxdb-export" -version = "0.1.0" -authors = ["Ossi Herrala "] -license = "MIT" -edition = "2021" - -[dependencies] -energiatili-config = { path = "../energiatili-config" } -energiatili-model = { path = "../energiatili-model" } -env_logger = "0.9" -futures = "0.3" -influxdb2_client = { git = "https://github.com/influxdata/influxdb_iox", rev = "bf39649d64e2890e2ae9e5a4e245c67624d2df43" } -tokio = { version = "1", features = [ "macros", "rt-multi-thread" ] } diff --git a/influxdb-export/README.md b/influxdb-export/README.md deleted file mode 100644 index 9a6c812..0000000 --- a/influxdb-export/README.md +++ /dev/null @@ -1,2 +0,0 @@ - -# InfluxDB diff --git a/influxdb-export/src/main.rs b/influxdb-export/src/main.rs deleted file mode 100644 index 8488041..0000000 --- a/influxdb-export/src/main.rs +++ /dev/null @@ -1,108 +0,0 @@ -use std::io; - -use energiatili_model::measurement::{Measurements, Resolution, Tariff}; -use energiatili_model::model::Model; -use influxdb2_client::models::data_point::{DataPoint, DataPointError}; - -#[tokio::main] -async fn main() { - env_logger::init(); - - let config = match energiatili_config::Config::read() { - Ok(config) => config, - Err(err) => { - eprintln!("ERROR: {}", err); - std::process::exit(1); - } - }; - let db_url = config.influxdb.url; - let db_token = config.influxdb.token; - let db_org = config.influxdb.org; - let db_bucket = config.influxdb.bucket; - - let stdin = io::stdin().lock(); - let model = Model::from_reader(stdin).expect("read JSON Model"); - let measurements = Measurements::from(&model); - let dp_stream = DataPointStream::new(measurements); - - let client = influxdb2_client::Client::new(db_url, db_token); - client - .write(&db_org, &db_bucket, dp_stream) - .await - .expect("write to influxdb"); -} - -struct DataPointStream { - measurements: std::collections::btree_set::IntoIter, -} - -impl DataPointStream { - fn new(measurements: Measurements) -> Self { - Self { - measurements: measurements.0.into_iter(), - } - } -} - -use std::pin::Pin; -use std::task::{Context, Poll}; - -impl futures::Stream for DataPointStream { - type Item = DataPoint; - - fn size_hint(&self) -> (usize, Option) { - self.measurements.size_hint() - } - - fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - let measurement = match self.measurements.next() { - Some(m) => m, - None => return Poll::Ready(None), - }; - let dp = convert(&measurement).expect("convert measurement to datapoint"); - Poll::Ready(Some(dp)) - } -} - -use energiatili_model::measurement::Measurement; - -fn convert(m: &Measurement) -> Result { - let mut dp = influxdb2_client::models::DataPoint::builder("energiatili"); - - dp = dp.timestamp(m.timestamp.timestamp_nanos()); - dp = dp.field("consumption", m.consumption); - dp = dp.field("quality", i64::from(m.quality)); - - if let Some(price) = m.price.energy { - dp = dp.field("energy_price", price); - } - - if let Some(price) = m.price.transfer { - dp = dp.field("transfer_price", price); - } - - if let (Some(e), Some(t)) = (m.price.energy, m.price.transfer) { - dp = dp.field("price", e + t); - } - - if !m.temperature.is_nan() { - dp = dp.field("temperature", m.temperature); - } - - if m.resolution == Resolution::Hour { - dp = match m.tariff { - Tariff::Day => dp.tag("tariff", "day"), - Tariff::Night => dp.tag("tariff", "night"), - Tariff::Simple => dp, - }; - } - - dp = match m.resolution { - Resolution::Hour => dp.tag("resolution", "hour"), - Resolution::Day => dp.tag("resolution", "day"), - Resolution::Month => dp.tag("resolution", "month"), - Resolution::Year => dp.tag("resolution", "year"), - }; - - dp.build() -}