class NeoScout::Counts
noinspection RubyTooManyInstanceVariablesInspection
Attributes
all_edges[R]
all_nodes[R]
edge_link_dst_stats[R]
edge_link_src_stats[R]
node_link_dst_stats[R]
node_link_src_stats[R]
typed_edge_props[R]
typed_edges[R]
typed_node_props[R]
typed_nodes[R]
Public Class Methods
new(typer)
click to toggle source
# File lib/neoscout/model.rb, line 48 def initialize(typer) @typer = typer reset end
Public Instance Methods
add_to_json(json)
click to toggle source
# File lib/neoscout/json_schema.rb, line 53 def add_to_json(json) all_json = JSON.cd json, %w(all) all_json['node_counts'] = @all_nodes.to_json all_json['connection_counts'] = @all_edges.to_json nodes_json = JSON.cd(json, %w(nodes)) @typed_nodes.each_pair do |type, count| skip = skip_from_json(:node, type, count) JSON.cd(nodes_json, [type])['counts'] = count.to_json unless skip end nodes_json = JSON.cd(json, %w(nodes)) @typed_node_props.each_pair do |type, props| props.each_pair do |name, count| skip = skip_from_json(:node, type, count) JSON.cd(nodes_json, [type, 'properties', name])['counts'] = count.to_json unless skip end end edges_json = JSON.cd(json, %w(connections)) @typed_edges.each_pair do |type, count| skip = skip_from_json(:edge, type, count) JSON.cd(edges_json, [type])['counts'] = count.to_json unless skip end edges_json = JSON.cd(json, %w(connections)) @typed_edge_props.each_pair do |type, props| props.each_pair do |name, count| skip = skip_from_json(:edge, type, count) JSON.cd(edges_json, [type, 'properties', name])['counts'] = count.to_json unless skip end end add_link_stats_to_json(json) end
count_edge(type, ok)
click to toggle source
# File lib/neoscout/model.rb, line 79 def count_edge(type, ok) @all_edges.incr(ok) @typed_edges[type].incr(ok) end
count_edge_prop(type, prop, ok)
click to toggle source
# File lib/neoscout/model.rb, line 84 def count_edge_prop(type, prop, ok) @typed_edge_props[type][prop].incr(ok) end
count_link_stats(edge_type, src_type, dst_type, ok)
click to toggle source
# File lib/neoscout/model.rb, line 88 def count_link_stats(edge_type, src_type, dst_type, ok) # puts "#{src_type} -- #{edge_type} -- #{dst_type} #{if ok then "CHECK" else "FAIL" end}" @node_link_src_stats[src_type][edge_type].incr(ok) @node_link_dst_stats[dst_type][edge_type].incr(ok) @edge_link_src_stats[edge_type][src_type][dst_type].incr(ok) @edge_link_dst_stats[edge_type][dst_type][src_type].incr(ok) end
count_node(type, ok)
click to toggle source
# File lib/neoscout/model.rb, line 70 def count_node(type, ok) @all_nodes.incr(ok) @typed_nodes[type].incr(ok) end
count_node_prop(type, prop, ok)
click to toggle source
# File lib/neoscout/model.rb, line 75 def count_node_prop(type, prop, ok) @typed_node_props[type][prop].incr(ok) end
reset()
click to toggle source
# File lib/neoscout/model.rb, line 53 def reset @all_nodes = Counter.new @all_edges = Counter.new @typed_nodes = Counter.new_multi_keyed :node_type @typed_edges = Counter.new_multi_keyed :edge_type @typed_node_props = Counter.new_multi_keyed :node_type, :prop_constr @typed_edge_props = Counter.new_multi_keyed :node_type, :prop_constr @node_link_src_stats = Counter.new_multi_keyed :src_type, :edge_type @node_link_dst_stats = Counter.new_multi_keyed :dst_type, :edge_type @edge_link_src_stats = Counter.new_multi_keyed :edge_type, :src_type, :dst_type @edge_link_dst_stats = Counter.new_multi_keyed :edge_type, :dst_type, :src_type end
skip_from_json(kind, type, count)
click to toggle source
# File lib/neoscout/json_schema.rb, line 89 def skip_from_json(kind, type, count) false unless count.empty? case kind when :node @typer.unknown_node_type?(type) when :edge @typer.unknown_edge_type?(type) else raise ArgumentError end end
Protected Instance Methods
add_link_stats_to_json(json)
click to toggle source
# File lib/neoscout/json_schema.rb, line 103 def add_link_stats_to_json(json) nodes_json = JSON.cd(json, %w(nodes)) @node_link_src_stats.each_pair do |type, hash| JSON.cd(nodes_json, [type])['src_stats'] = hash.to_json end @node_link_dst_stats.each_pair do |type, hash| JSON.cd(nodes_json, [type])['dst_stats'] = hash.to_json end edges_json = JSON.cd(json, %w(connections)) @edge_link_src_stats.each_pair do |type, hash| JSON.cd(edges_json, [type])['src_stats'] = hash_to_json_array('to_dst', hash) end @edge_link_dst_stats.each_pair do |type, hash| JSON.cd(edges_json, [type])['dst_stats'] = hash_to_json_array('from_src', hash) end end
hash_to_json_array(target, hash)
click to toggle source
# File lib/neoscout/json_schema.rb, line 124 def hash_to_json_array(target, hash) result = [] hash.each_pair do |key, value| inner = [] value.each_pair do |i_key, i_value| inner << { 'name' => i_key, 'counts' => i_value.to_json } end result << { 'name' => key, target => inner } end result end