-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from carvilsi/improv-doc-1
Improv doc 1
- Loading branch information
Showing
11 changed files
with
216 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::error::Error; | ||
use crate::graphs::Graphs; | ||
use crate::config::get_max_mem_usage; | ||
|
||
/// Represents stats data from the Graphs | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct GraphsStats { | ||
/// memory used by Graphs in bytes | ||
mem: usize, | ||
/// length of the Graph's vault | ||
total_edges: usize, | ||
/// total graphs | ||
total_graphs: usize, | ||
/// total attributes | ||
total_attr: usize, | ||
/// total edges | ||
total_vertices: usize, | ||
/// unique relations | ||
uniq_rel: usize, | ||
/// maximum memory usage | ||
max_mem: usize, | ||
} | ||
|
||
impl GraphsStats { | ||
/// Initializes, creating a new instance of GraphsStats | ||
pub(crate) fn init() -> Self { | ||
GraphsStats { | ||
mem: 64, | ||
total_edges: 0, | ||
total_graphs: 0, | ||
total_attr: 0, | ||
total_vertices: 0, | ||
uniq_rel: 0, | ||
max_mem: get_max_mem_usage(), | ||
} | ||
} | ||
|
||
/// Retrieves the amount of memory of the Graphs | ||
pub fn get_mem(&self) -> usize { | ||
self.mem | ||
} | ||
|
||
/// Retrieves the maximum memory allow usage for the Graphs | ||
pub fn get_max_mem(&self) -> usize { | ||
self.max_mem | ||
} | ||
/// Retrieves the length of elements in the vault | ||
pub fn get_total_graphs(&self) -> usize { | ||
self.total_graphs | ||
} | ||
|
||
/// Retrieves the amount of attributes on edges and vertex | ||
/// from graphs | ||
pub fn get_total_attr(&self) -> usize { | ||
self.total_attr | ||
} | ||
|
||
/// Retrieves the total amount of edges on Graphs | ||
pub fn get_total_edges(&self) -> usize { | ||
self.total_edges | ||
} | ||
|
||
/// Retrieves the amount of unique relations on Graphs | ||
pub fn get_uniq_rel(&self) -> usize { | ||
self.uniq_rel | ||
} | ||
|
||
/// Retrieves the total amount of vertices on Graphs | ||
pub fn get_total_vertices(&self) -> usize { | ||
self.total_vertices | ||
} | ||
|
||
/// Returns a GraphsStats object | ||
pub(crate) fn generate_stats(graphs: &Graphs) -> Self { | ||
get_stats(graphs).unwrap() | ||
} | ||
} | ||
|
||
/// private function to generate stats | ||
fn get_stats(grphs: &Graphs) -> Result<GraphsStats, Box<dyn Error>> { | ||
// lets count the amount of attributes in the graph | ||
let mut attr_counter = 0; | ||
for (_name, edges) in grphs.get_vaults().iter() { | ||
for edge in edges { | ||
attr_counter += edge.get_from_vertex().attr_len(); | ||
attr_counter += edge.get_to_vertex().attr_len(); | ||
attr_counter += edge.attr_len(); | ||
} | ||
} | ||
|
||
let stats = GraphsStats { | ||
mem: grphs.get_mem().unwrap(), | ||
total_edges: grphs.len(), | ||
total_attr: attr_counter, | ||
total_vertices: grphs.len() * 2, | ||
uniq_rel: grphs.uniq_relations().len(), | ||
total_graphs: grphs.get_vaults().len(), | ||
max_mem: get_max_mem_usage(), | ||
}; | ||
Ok(stats) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.