Skip to content

Commit

Permalink
fix datatype issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbrueggemann committed Feb 23, 2022
1 parent 1f82820 commit 6358565
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/subscriber_repository.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{observation::Observation, timing};
use futures::stream::TryStreamExt;
use mongodb::bson::spec::ElementType;
use mongodb::bson::{doc, Document};
use mongodb::options::FindOptions;
use mongodb::{Client, Collection};
Expand Down Expand Up @@ -32,12 +33,17 @@ impl SubscriberRepository {
let subscribers = documents
.iter()
.map(|document| {
let subscribers = document.get_i32("subscribers").unwrap();
let subscribers = match document.get("subscribers").unwrap().element_type() {
ElementType::Int32 => document.get_i32("subscribers").unwrap() as f64,
ElementType::Int64 => document.get_i64("subscribers").unwrap() as f64,
_ => 0.0,
};

let id = document.get_document("_id").unwrap();

Observation {
channel_id: id.get_str("channel").unwrap().to_string(),
value: f64::from(subscribers),
value: subscribers,
timestamp: id.get_i32("date").unwrap_or(-1),
}
})
Expand Down
Empty file.
10 changes: 8 additions & 2 deletions src/view_repository.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{observation::Observation, timing};
use futures::stream::TryStreamExt;
use mongodb::bson::spec::ElementType;
use mongodb::bson::{doc, Document};
use mongodb::options::FindOptions;
use mongodb::{Client, Collection};
Expand Down Expand Up @@ -32,12 +33,17 @@ impl ViewRepository {
let views = documents
.iter()
.map(|document| {
let views = document.get_i32("views").unwrap();
let views = match document.get("views").unwrap().element_type() {
ElementType::Int32 => document.get_i32("views").unwrap() as f64,
ElementType::Int64 => document.get_i64("views").unwrap() as f64,
_ => 0.0,
};

let id = document.get_document("_id").unwrap();

Observation {
channel_id: id.get_str("channel").unwrap().to_string(),
value: f64::from(views),
value: views,
timestamp: id.get_i32("date").unwrap_or(-1),
}
})
Expand Down

0 comments on commit 6358565

Please sign in to comment.