MCPcopy Create free account
hub / github.com/Pometry/Raphtory / one_path_algorithm

Function one_path_algorithm

examples/netflow/src/netflow_one_path_node.rs:35–102  ·  view source on GitHub ↗
(
    nf_e_edge_expl: EvalEdgeView<'graph, '_, G, CS, ()>,
    no_time: bool,
)

Source from the content-addressed store, hash-verified

33}
34
35fn one_path_algorithm<'graph, G: GraphViewOps<'graph>, CS: ComputeState>(
36 nf_e_edge_expl: EvalEdgeView<'graph, '_, G, CS, ()>,
37 no_time: bool,
38) -> usize {
39 // MATCH
40 // (E)<-[nf1:Netflow]-(B)<-[login1:Events2v]-(A), (B)<-[prog1:Events1v]-(B)
41 // WHERE A <> B AND B <> E AND A <> E
42 // AND login1.eventID = 4624
43 // AND prog1.eventID = 4688
44 // AND nf1.dstBytes > 100000000
45 // // time constraints within each path
46 // AND login1.epochtime < prog1.epochtime
47 // AND prog1.epochtime < nf1.epochtime
48 // AND nf1.epochtime - login1.epochtime <= 30
49 // RETURN count(*)
50
51 let a_id = nf_e_edge_expl.src().id();
52 let b_id = nf_e_edge_expl.dst().id();
53 // First we remove any A->A edges, no cyclces allowed
54 if a_id == b_id {
55 return 0usize;
56 }
57 // for the netflow B we now look for all E edges that have the dstBytes Prop
58 let dst_bytes_val = nf_e_edge_expl
59 .properties()
60 .get("dstBytes")
61 .into_i64()
62 .unwrap_or(0);
63 // For the nf1 we filter any edges from B that do not have the byte size (<=1e8)
64 // we only watch B->E edges that are >1e8
65 if dst_bytes_val <= 100000000 {
66 return 0usize;
67 }
68
69 // Now we save the time of nf1
70 let nf1_time = nf_e_edge_expl.time().map(|t| t.t()).unwrap_or_default();
71 let mut time_bound = nf1_time.saturating_sub(30);
72 if no_time {
73 time_bound = 0;
74 }
75
76 // Find all the login events satisfying the time constraint and count the program starts that fall in the window
77 let event_count = nf_e_edge_expl
78 .src()
79 .window(time_bound, nf1_time)
80 .layers("Events2v4624")
81 .into_iter()
82 .flat_map(|v| {
83 v.in_edges()
84 .iter()
85 .filter(|e| e.src().id() != a_id && e.src().id() != b_id)
86 .flat_map(|e| e.explode())
87 })
88 .flat_map(|login_exp| {
89 login_exp
90 .dst()
91 .window(login_exp.time().unwrap().t().saturating_add(1), nf1_time)
92 .layers("Events1v4688")

Callers 1

get_one_hop_countsFunction · 0.85

Calls 15

unwrapMethod · 0.80
idMethod · 0.45
srcMethod · 0.45
dstMethod · 0.45
into_i64Method · 0.45
getMethod · 0.45
propertiesMethod · 0.45
mapMethod · 0.45
timeMethod · 0.45
tMethod · 0.45
countMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected