Class: NeoScout::Counts

Inherits:
Object
  • Object
show all
Defined in:
lib/neoscout/json_schema.rb,
lib/neoscout/model.rb

Overview

noinspection RubyTooManyInstanceVariablesInspection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(typer) ⇒ Counts

Returns a new instance of Counts.



48
49
50
51
# File 'lib/neoscout/model.rb', line 48

def initialize(typer)
  @typer = typer
  reset
end

Instance Attribute Details

#all_edgesObject (readonly)

Returns the value of attribute all_edges.



35
36
37
# File 'lib/neoscout/model.rb', line 35

def all_edges
  @all_edges
end

#all_nodesObject (readonly)

Returns the value of attribute all_nodes.



34
35
36
# File 'lib/neoscout/model.rb', line 34

def all_nodes
  @all_nodes
end

Returns the value of attribute edge_link_dst_stats.



46
47
48
# File 'lib/neoscout/model.rb', line 46

def edge_link_dst_stats
  @edge_link_dst_stats
end

Returns the value of attribute edge_link_src_stats.



45
46
47
# File 'lib/neoscout/model.rb', line 45

def edge_link_src_stats
  @edge_link_src_stats
end

Returns the value of attribute node_link_dst_stats.



44
45
46
# File 'lib/neoscout/model.rb', line 44

def node_link_dst_stats
  @node_link_dst_stats
end

Returns the value of attribute node_link_src_stats.



43
44
45
# File 'lib/neoscout/model.rb', line 43

def node_link_src_stats
  @node_link_src_stats
end

#typed_edge_propsObject (readonly)

Returns the value of attribute typed_edge_props.



41
42
43
# File 'lib/neoscout/model.rb', line 41

def typed_edge_props
  @typed_edge_props
end

#typed_edgesObject (readonly)

Returns the value of attribute typed_edges.



38
39
40
# File 'lib/neoscout/model.rb', line 38

def typed_edges
  @typed_edges
end

#typed_node_propsObject (readonly)

Returns the value of attribute typed_node_props.



40
41
42
# File 'lib/neoscout/model.rb', line 40

def typed_node_props
  @typed_node_props
end

#typed_nodesObject (readonly)

Returns the value of attribute typed_nodes.



37
38
39
# File 'lib/neoscout/model.rb', line 37

def typed_nodes
  @typed_nodes
end

Instance Method Details

#add_to_json(json) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object



79
80
81
82
# 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) ⇒ Object



84
85
86
# File 'lib/neoscout/model.rb', line 84

def count_edge_prop(type, prop, ok)
  @typed_edge_props[type][prop].incr(ok)
end


88
89
90
91
92
93
94
# 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) ⇒ Object



70
71
72
73
# 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) ⇒ Object



75
76
77
# File 'lib/neoscout/model.rb', line 75

def count_node_prop(type, prop, ok)
  @typed_node_props[type][prop].incr(ok)
end

#resetObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# 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