Skip to content

Commit 0fc159a

Browse files
MoritzFluMoritz Flüchter
andauthored
Merge viz tool updates (#4)
* Merge viz tool updates * Fix ts_storage path * CHange rust_ts_storage dependancy to s_storage --------- Co-authored-by: Moritz Flüchter <moritz.fluechter@uni-tuebingen.de>
1 parent e727137 commit 0fc159a

17 files changed

+199
-95
lines changed

tcbee/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

viz-tool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "viz-tool"
2+
name = "tcp_visualization_application"
33
version = "0.1.0"
44
authors = ["ScatteredDrifter"]
55
edition = "2021"

viz-tool/src/main.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ use iced_aw::Tabs;
3838
use ts_storage::{DataValue, TSDBInterface};
3939
use std::cell::RefCell;
4040
use std::sync::{Arc, RwLock};
41+
use std::thread::sleep;
42+
use std::time::{Duration, Instant};
4143

4244
// ---- //
4345
// --- //
4446

4547
// fn main() -> iced::Result {
4648
fn main() -> iced::Result {
49+
println!("Hi, this application was written by Evelyn :>\n this message is a secret");
4750
iced::application("TCPFLOW", StateContainer::update, StateContainer::view)
4851
.theme(StateContainer::theme)
4952
.run()
@@ -104,16 +107,34 @@ impl Default for StateContainer {
104107
screen_multi_flow_plotting: ScreenMultiFlowPlotting::new(settings.clone()),
105108
screen_modify_database: ScreenModifyDatabase::new(settings.clone()),
106109
application_settings: settings,
107-
theme: Theme::CatppuccinFrappe,
110+
// theme: Theme::CatppuccinFrappe,
111+
theme: Theme::GruvboxLight,
108112
}
109113
}
110114
}
111115

112116
// Implementations for ICED
113117
impl StateContainer {
114118
fn update(&mut self, message: Message) {
119+
print!("{esc}c", esc = 27 as char);
115120
match message {
116-
Message::TabSelected(new_screen) => self.screen = new_screen,
121+
Message::TabSelected(new_screen) => {
122+
match self.screen {
123+
ActiveScreen::DatabaseModification => {
124+
self.screen_modify_database.reset();
125+
}
126+
ActiveScreen::SingleGraphPlot => {
127+
self.screen_plotting.reset();
128+
}
129+
ActiveScreen::MultipleGraphPlot => {
130+
self.screen_multi_flow_plotting.reset();
131+
}
132+
_ => {
133+
134+
}
135+
}
136+
self.screen = new_screen
137+
}
117138
Message::TabClosed(_) => {}
118139
Message::ScreenSettings(message) => self.screen_settings.update(message),
119140
Message::ScreenHome(message) => self.screen_home.update(message),

viz-tool/src/modules/backend/intermediate_backend.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use iced::widget::canvas::Cache;
1818
use plotters::style::RGBAColor;
1919
use ts_storage::{database_factory, sqlite::SQLiteTSDB, DBBackend, DataValue, Flow};
2020
use 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?
2424
use std::sync::Arc;
@@ -53,10 +53,7 @@ impl ToString for DataSource {
5353
pub 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

6259
impl 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
},

viz-tool/src/modules/backend/lib_system_io.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// - filesystem interactionA
44

55
use crate::DataSource;
6-
use std::path::PathBuf;
6+
use std::{fs::{self, Metadata}, path::PathBuf, time::{SystemTime, UNIX_EPOCH}};
77

88
pub fn receive_source_from_path(path: &PathBuf) -> Option<DataSource> {
99
let extension = path.extension().unwrap().to_str().unwrap();
@@ -13,3 +13,21 @@ pub fn receive_source_from_path(path: &PathBuf) -> Option<DataSource> {
1313
_ => None,
1414
}
1515
}
16+
17+
pub fn receive_file_metadata(path: &PathBuf) -> String {
18+
let metadata_object = fs::metadata(path).unwrap();
19+
let file_size = metadata_object.len();
20+
let file_size_as_mb = (file_size / 1_048_576) as f64;
21+
let maybe_cr_time = metadata_object.created();
22+
let cr_time = match maybe_cr_time{
23+
Ok(cr_time) => {
24+
format!("{:?}",cr_time.duration_since(UNIX_EPOCH))
25+
}
26+
Err(_) => {
27+
"could not obtain creation time".to_string()
28+
}
29+
};
30+
let bundled_information = String::from(format!("size:{:?}mb\ncreated:{:?}",file_size_as_mb,cr_time));
31+
bundled_information
32+
33+
}

viz-tool/src/modules/ui/lib_screens/screen_database_modification.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,9 @@ impl Screen for ScreenModifyDatabase {
459459

460460
combined_content.map(Message::ScreenModifyDatabase)
461461
}
462+
463+
fn reset(&mut self) {
464+
self.clear_flow_data();
465+
self.selected_flow = TcpFlowWrapper::default();
466+
}
462467
}

viz-tool/src/modules/ui/lib_screens/screen_home.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,7 @@ impl Screen for ScreenHome {
216216
// let window_content = generate_one_fourth_layout::<MessageHome>(headline_content, sidebar, explanation_field)
217217
window_content.map(Message::ScreenHome)
218218
}
219+
fn reset(&mut self) {
220+
221+
}
219222
}

viz-tool/src/modules/ui/lib_screens/screen_multiple_flow_plotting.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum MessageMultiFlowPlotting {
5252
GraphGenerationRequested,
5353
SplitChartRequested(bool),
5454
DrawLineSeriesRequested(bool),
55+
UnselectAllSeries,
5556
// zooming
5657
SliderZoomLX(f64),
5758
SliderZoomRX(f64),
@@ -275,6 +276,10 @@ impl ScreenMultiFlowPlotting {
275276
_ => {}
276277
}
277278
}
279+
MessageMultiFlowPlotting::UnselectAllSeries => {
280+
self.first_tcp_flow.selected_series = None;
281+
self.second_tcp_flow.selected_series = None;
282+
}
278283
_ => (),
279284

280285
}
@@ -328,6 +333,7 @@ impl ScreenMultiFlowPlotting {
328333
MessageMultiFlowPlotting::FlowOneSelected,
329334
MessageMultiFlowPlotting::FlowOneFeatureSelected,
330335
MessageMultiFlowPlotting::FlowOneFeatureDeselected,
336+
MessageMultiFlowPlotting::UnselectAllSeries,
331337
)
332338
.width(Length::FillPortion(FLOW1_SELECTION_PORTION));
333339
let selector_flow_2 = display_combined_flow_selection(
@@ -337,6 +343,7 @@ impl ScreenMultiFlowPlotting {
337343
MessageMultiFlowPlotting::FlowTwoSelected,
338344
MessageMultiFlowPlotting::FlowTwoFeatureSelected,
339345
MessageMultiFlowPlotting::FlowTwoFeatureDeselected,
346+
MessageMultiFlowPlotting::UnselectAllSeries,
340347
)
341348
.width(Length::FillPortion(FLOW2_SELECTION_PORTION));
342349
let content = Row::new()
@@ -388,7 +395,7 @@ impl ScreenMultiFlowPlotting {
388395
}
389396

390397
fn generate_chart_view(&self) -> Element<'_,MessageMultiFlowPlotting> {
391-
let generate_top_info:bool = !self.render_chart && self.first_tcp_flow.selected_series.is_some() && self.second_tcp_flow.selected_series.is_some();
398+
let generate_top_info:bool = self.render_chart && self.first_tcp_flow.selected_series.is_some() && self.second_tcp_flow.selected_series.is_some();
392399
let maybe_legends = generate_legends_for_charts(generate_top_info, &self.plot_data);
393400
let mouse_position = display_current_mouse_position(self.current_position);
394401
let merged_top_info = Row::new()
@@ -475,4 +482,10 @@ impl Screen for ScreenMultiFlowPlotting {
475482

476483
padded_content.map(Message::ScreenMultipleFlowPlot)
477484
}
485+
486+
fn reset(&mut self) {
487+
self.first_tcp_flow = TcpFlowWrapper::default();
488+
self.second_tcp_flow = TcpFlowWrapper::default();
489+
self.plot_data = None;
490+
}
478491
}

viz-tool/src/modules/ui/lib_screens/screen_settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,8 @@ impl Screen for ScreenSettings {
273273

274274
window_content.map(Message::ScreenSettings)
275275
}
276+
277+
fn reset(&mut self) {
278+
279+
}
276280
}

viz-tool/src/modules/ui/lib_screens/screen_single_flow_plotting.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub enum MessagePlotting {
8282
// ZoomRangeChanged(f64),
8383
GraphGenerationRequested,
8484
ZoomResetRequested,
85+
UnselectAllSeries,
8586
CheckBoxMultiplePlots(bool),
8687
CheckBoxDrawLineSeries(bool),
8788
MouseEvent(iced::mouse::Event, iced::Point),
@@ -186,6 +187,7 @@ impl ScreenSingleFlowPlotting {
186187
self.render_chart = false;
187188

188189
self.tcp_flow.flow_id = Some(reference_id);
190+
self.tcp_flow.selected_series = None;
189191
let new_zoom = retrieve_default_zoom_for_one_flow(&self.application_settings, &self.tcp_flow);
190192
self.zoom_bounds = Some(new_zoom);
191193
}
@@ -219,6 +221,9 @@ impl ScreenSingleFlowPlotting {
219221
self.render_chart = false
220222
}
221223
}
224+
MessagePlotting::UnselectAllSeries => {
225+
self.tcp_flow.selected_series = None;
226+
}
222227

223228
// if called we generate the chart - otherwise not.
224229
// Could be done with a boolean but this might be unfortunate
@@ -386,7 +391,7 @@ impl ScreenSingleFlowPlotting {
386391
}
387392

388393
pub fn generate_chart_view(&self) -> Element<'_, MessagePlotting> {
389-
let generate_legends: bool = !self.render_chart
394+
let generate_legends: bool = self.render_chart
390395
&& self.tcp_flow.flow_id.is_some()
391396
&& self.tcp_flow.selected_series.is_some();
392397
let graph_top_info: Row<'_, MessagePlotting> = Row::new()
@@ -421,6 +426,7 @@ impl ScreenSingleFlowPlotting {
421426
MessagePlotting::FlowSelected,
422427
MessagePlotting::FlowFeatureSelected,
423428
MessagePlotting::FlowFeatureDeSelected,
429+
MessagePlotting::UnselectAllSeries,
424430
);
425431

426432
let combined_buttons = display_combined_flow_buttons(
@@ -522,6 +528,11 @@ impl Screen for ScreenSingleFlowPlotting {
522528

523529
content.map(Message::ScreenSingleFlowPlot)
524530
}
531+
532+
fn reset(&mut self) {
533+
self.tcp_flow = TcpFlowWrapper::default();
534+
self.processed_plot_data = None;
535+
}
525536
}
526537

527538
impl ScreenSingleFlowPlotting {

0 commit comments

Comments
 (0)