Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl at and fix in/out degree #1399

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions raphtory-graphql/src/model/graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ impl GqlGraph {
w.into_dynamic_indexed().into()
}

async fn at(&self, time: i64) -> GqlGraph {
self.graph.at(time).into_dynamic_indexed().into()
}

async fn before(&self, time: i64) -> GqlGraph {
self.graph.before(time).into_dynamic_indexed().into()
}

async fn after(&self, time: i64) -> GqlGraph {
self.graph.after(time).into_dynamic_indexed().into()
}

async fn layer_names(&self) -> Vec<String> {
self.graph.unique_layers().map_into().collect()
}
Expand Down
36 changes: 24 additions & 12 deletions raphtory-graphql/src/model/graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,36 @@ impl Node {
}

/// Returns the number edges with this node as the source
async fn out_degree(&self, layer: Option<String>) -> usize {
match layer.as_deref() {
async fn out_degree(&self, layers: Option<Vec<String>>) -> usize {
match layers {
None => self.vv.out_degree(),
Some(layer) => match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.out_degree(),
},
Some(layers) => layers
.iter()
.map(|layer| {
let degree = match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.out_degree(),
};
degree
})
.sum(),
}
}

/// Returns the number edges with this node as the destination
async fn in_degree(&self, layer: Option<String>) -> usize {
match layer.as_deref() {
async fn in_degree(&self, layers: Option<Vec<String>>) -> usize {
match layers {
None => self.vv.in_degree(),
Some(layer) => match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.in_degree(),
},
Some(layers) => layers
.iter()
.map(|layer| {
let degree = match self.vv.layer(layer) {
None => 0,
Some(vvv) => vvv.in_degree(),
};
degree
})
.sum(),
}
}

Expand Down