]> git.scottworley.com Git - tattlekey/commitdiff
server: Write reports as CSV
authorScott Worley <scottworley@scottworley.com>
Tue, 10 Oct 2023 23:34:12 +0000 (16:34 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 11 Oct 2023 01:50:37 +0000 (18:50 -0700)
server/Cargo.lock
server/Cargo.toml
server/src/main.rs

index 1dbac3d9e1aa14b2c818d2410f68a2be4864349f..316d8310cfe51d6809266368cf3eecdb686b1184 100644 (file)
@@ -2,6 +2,104 @@
 # It is not intended for manual editing.
 version = 3
 
 # It is not intended for manual editing.
 version = 3
 
+[[package]]
+name = "csv"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
+dependencies = [
+ "csv-core",
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "csv-core"
+version = "0.1.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
+
+[[package]]
+name = "memchr"
+version = "2.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "ryu"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
+
+[[package]]
+name = "serde"
+version = "1.0.188"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.188"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
 [[package]]
 name = "tattlekey-server"
 version = "0.0.1"
 [[package]]
 name = "tattlekey-server"
 version = "0.0.1"
+dependencies = [
+ "csv",
+ "serde",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
index a77bdd3288e5247bfa86137658e7c3d1e7b0843f..9fbdf1fb80b71e4f03f78887a0dacaaa7a172c37 100644 (file)
@@ -11,3 +11,5 @@ version = "0.0.1"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+csv = "1.3.0"
+serde = { version = "1.0", features = ["derive"] }
index 37de6bd44fae83acde13602b49a1a90876938441..071c4b26e74a7fc9103c76fd954c431abefaf9a1 100644 (file)
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+use serde::Serialize;
 use std::collections::HashMap;
 use std::net::UdpSocket;
 use std::time::{Duration, SystemTime};
 
 const MESSAGE_SIZE: usize = 12;
 
 use std::collections::HashMap;
 use std::net::UdpSocket;
 use std::time::{Duration, SystemTime};
 
 const MESSAGE_SIZE: usize = 12;
 
-#[derive(Eq, Debug, Hash, PartialEq)]
+#[derive(Eq, Debug, Hash, PartialEq, Serialize)]
 struct MessageKey {
     epoch: u32,
     device: u16,
 struct MessageKey {
     epoch: u32,
     device: u16,
@@ -79,6 +80,7 @@ impl Range {
 }
 
 fn main() {
 }
 
 fn main() {
+    let mut log = csv::Writer::from_writer(std::io::stdout());
     let mut presses = HashMap::<MessageKey, Range>::new();
     let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address");
     loop {
     let mut presses = HashMap::<MessageKey, Range>::new();
     let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address");
     loop {
@@ -92,13 +94,14 @@ fn main() {
                     continue;
                 }
                 let message = Message::try_from(filled_buf).expect("I can't count");
                     continue;
                 }
                 let message = Message::try_from(filled_buf).expect("I can't count");
+                log.serialize((&message.key, message.t))
+                    .expect("Couldn't write log");
+                log.flush().expect("Couldn't flush log");
                 if let Some(r) = presses.get_mut(&message.key) {
                     if !r.contains(&message.t) {
                         r.extend(&message.t);
                 if let Some(r) = presses.get_mut(&message.key) {
                     if !r.contains(&message.t) {
                         r.extend(&message.t);
-                        println!("Updated press: {:?}: {r:?}", message.key);
                     }
                 } else {
                     }
                 } else {
-                    println!("Got new press: {:?}: {:?}", message.key, message.t);
                     presses.insert(message.key, Range::new(&message.t));
                 }
             }
                     presses.insert(message.key, Range::new(&message.t));
                 }
             }