class Links

Public Class Methods

new(data) click to toggle source
# File bin/ffmapquery, line 18
def initialize(data)
        @data = data
        @link_list = Hash.new
        graph_json = JSON.parse(data)
        graph_nodes = Hash.new
        # Erstmal die Namen auslesen und mit ID abspeichern
        graph_json['batadv']['nodes'].each { | n |
                id = graph_json['batadv']['nodes'].index(n)
                graph_nodes[n['node_id']] = id
                graph_nodes[id] = n['node_id']
        }
        @links = Hash.new
        @links.default = 0
        # Und jetzt die Links zählen...
        graph_json['batadv']['links'].each { | l |
                # Namen von source und target auflösen
                source_id = l['source']
                target_id = l['target']
                source_node = graph_nodes[source_id].to_s
                target_node = graph_nodes[target_id].to_s
                begin
                        sl = @link_list[source_node]
                        sl = Array.new unless sl
                        sl << [target_node, 1/l['tq'], (l['vpn'] ? :vpn : :mesh)]
                        @link_list[source_node] = sl
                        if l['bidirect']
                                tl = @link_list[target_node]
                                tl = Array.new unless tl
                                tl << [source_node, 1/l['tq'], (l['vpn'] ? :vpn : :mesh)]
                                @link_list[target_node] = tl
                        end
                rescue
                        #ignored
                end
                if l['vpn']
                        @links[source_node + '_vpn'] += 1
                        @links[target_node + '_vpn'] += 1
                else
                        @links[source_node + '_mesh'] += 1
                        @links[target_node + '_mesh'] += 1
                end
        }
end

Public Instance Methods