@@ -18,7 +18,7 @@ use iced::widget::canvas::Cache;
1818use plotters:: style:: RGBAColor ;
1919use ts_storage:: { database_factory, sqlite:: SQLiteTSDB , DBBackend , DataValue , Flow } ;
2020use ts_storage:: { DataPoint , TimeSeries } ;
21- use std:: { cell:: RefCell , slice:: Iter , sync:: RwLock } ;
21+ use std:: { cell:: RefCell , f64 :: { MAX , MIN } , path :: PathBuf , slice:: Iter , sync:: RwLock } ;
2222
2323// testing to adapt to issue of not refrencing well enough?
2424use std:: sync:: Arc ;
@@ -53,10 +53,7 @@ impl ToString for DataSource {
5353pub struct IntermediateBackend {
5454 pub source_type : DataSource ,
5555 pub database_interface : Option < Arc < Box < dyn TSDBInterface > > > ,
56- // for access management
57- // selected_flow: Option<i64>,
58- // FIXME should be Id of attribute instead
59- // pub selected_series_attributes: Option<Vec<i64>>,
56+ pub database_path : Option < PathBuf > ,
6057}
6158
6259impl IntermediateBackend {
@@ -66,16 +63,17 @@ impl IntermediateBackend {
6663 // if it was selected we know that its available!
6764 let db_connection = self . database_interface . clone ( ) . unwrap ( ) ;
6865 let flow = db_connection. get_flow_by_id ( * value) . unwrap ( ) . unwrap ( ) ;
69- let bounds = db_connection
70- . get_flow_bounds ( & flow)
71- . expect ( "no bounds could be received for flow" ) ;
72-
73- Some ( ZoomBound {
74- lower : bounds. xmin ,
75- upper : bounds. xmax ,
76- } )
77-
78- // Some(bounds.unwrap())
66+ let maybe_bounds = db_connection
67+ . get_flow_bounds ( & flow) ;
68+ match maybe_bounds{
69+ Ok ( boundaries) => {
70+ Some ( ZoomBound {
71+ lower : boundaries. xmin ,
72+ upper : boundaries. xmax ,
73+ } )
74+ }
75+ _ => None
76+ }
7977 }
8078 _ => None ,
8179 }
@@ -86,17 +84,17 @@ impl IntermediateBackend {
8684 collection_of_series : Option < Vec < i64 > > ,
8785 ) -> Option < ZoomBound > {
8886 if let Some ( series) = self . receive_active_timeseries ( collection_of_series) {
89- let db_conection = self . database_interface . clone ( ) . unwrap ( ) ;
87+ let db_connection = self . database_interface . clone ( ) . unwrap ( ) ;
9088
91- let mut lowest_y: f64 = DEFAULT_Y_MIN ;
92- let mut highest_y: f64 = DEFAULT_Y_MAX ;
89+ let mut lowest_y: f64 = MAX ;
90+ let mut highest_y: f64 = MIN ;
9391 for series_id in series {
94- let boundaries = db_conection
92+ let boundaries = db_connection
9593 . get_time_series_bounds ( & series_id)
9694 . expect ( "could not receive boundaries" ) ;
97- if let Some ( _ ) = boundaries. ymin {
98- let lower = boundaries . ymin . unwrap ( ) ;
99- let upper = boundaries . ymax . unwrap ( ) ;
95+ if let ( Some ( y_min ) , Some ( y_max ) ) = ( & boundaries. ymin , & boundaries . ymax ) {
96+ let lower = y_min ;
97+ let upper = y_max ;
10098 // guaranteed to be DataValue
10199 match series_id. ts_type {
102100 DataValue :: Float ( _) => {
@@ -113,6 +111,15 @@ impl IntermediateBackend {
113111 }
114112 }
115113 }
114+
115+ // println!("Debug: y boundaries are:\n low:{:?}\n high: {:?}",lowest_y,highest_y);
116+ if lowest_y == highest_y {
117+ // ASSUME: found constant, hence creating new boundaries
118+ let old_constant = lowest_y;
119+ lowest_y = old_constant - 10.0 ;
120+ highest_y = old_constant + 10.0 ;
121+ }
122+
116123 return Some ( ZoomBound {
117124 lower : lowest_y,
118125 upper : highest_y,
@@ -256,8 +263,7 @@ impl Clone for IntermediateBackend {
256263 IntermediateBackend {
257264 source_type : self . source_type . clone ( ) ,
258265 database_interface : self . database_interface . clone ( ) ,
259- // selected_flow: self.selected_flow.clone(),
260- // selected_series_attributes: self.selected_series_attributes.clone(),
266+ database_path : self . database_path . clone ( ) ,
261267 }
262268 }
263269}
@@ -267,20 +273,20 @@ impl IntermediateBackend {
267273 match source {
268274 DataSource :: Sqllite => {
269275 let db_interface: Arc < Box < dyn TSDBInterface > > = Arc :: new (
270- database_factory :: < SQLiteTSDB > ( DBBackend :: SQLite ( path_db) )
276+ database_factory :: < SQLiteTSDB > ( DBBackend :: SQLite ( path_db. clone ( ) ) )
271277 . expect ( "could not parse database" ) ,
272278 ) ;
273279 println ! ( "initialized database of time {:?}" , source) ;
274280 IntermediateBackend {
275281 source_type : source. clone ( ) ,
276282 database_interface : Some ( db_interface) ,
277- // selected_flow: None,
278- // selected_series_attributes: None,
283+ database_path : Some ( PathBuf :: from ( path_db) )
279284 }
280285 }
281286 _ => IntermediateBackend {
282287 source_type : source. clone ( ) ,
283288 database_interface : None ,
289+ database_path : None ,
284290 // selected_flow: None,
285291 // selected_series_attributes: None,
286292 } ,
0 commit comments