Exemplo n.º 1
0
 def calculate_data_and_details(self):
     # As interface metric is not numeric, we'll use the following numeric representation:
     # max score = 100.0
     # node in api: score = 33.3
     # all interfaces available: score = 66.6
     # all types correct: score = 100.0
     data = None
     groundtruth = Groundtruth()
     details = None
     node_name = self.params['node']
     if node_name not in self.api_dict:
         details = "node " + node_name + " is not in api"
         groundtruth.result = False
         data = 0.0
     else:
         details = "node " + node_name + " is in api"
         groundtruth.result = True
         data = 100.0
         for interface, interface_data in self.params.items():
             if interface == "publishers" or interface == "subscribers" or interface == "services":
                 for topic_name, topic_type in interface_data:
                     #print "node_name=", node_name
                     #print "topic_name=", topic_name
                     #print "topic_type=", topic_type
                     #print "self.api_dict[node_name][interface]=", self.api_dict[node_name][interface]
                     name_check, type_check = self.check_interface(
                         topic_name, topic_type,
                         self.api_dict[node_name][interface])
                     if not name_check:
                         details += ", but " + topic_name + " is not an interface of node " + node_name + ". Interfaces are: " + str(
                             self.api_dict[node_name][interface])
                         groundtruth.result = False
                         data = 33.3
                     else:
                         if not type_check:
                             details += ", but " + topic_name + " (with type " + topic_type + ") is not an interface of node " + node_name + ". Interfaces are: " + str(
                                 self.api_dict[node_name][interface])
                             groundtruth.result = False
                             data = 66.0
                         else:  # all Ok
                             details += ", all interfaces of node " + node_name + ": OK"
                             groundtruth.result = True
                             data = 100.0
     return data, details
Exemplo n.º 2
0
    def calculate_data_and_details(self, api_dict):
        # As interface metric is not numeric, we'll use the following numeric representation:
        # max score = 100.0
        # node in api: score = 33.3
        # all interfaces available: score = 66.6
        # all types correct: score = 100.0
        data = None
        groundtruth = Groundtruth()
        details = None
        node_name = self.params['node']

        if node_name not in api_dict:
            details = "node " + node_name + " is not in api"
            groundtruth.result = Groundtruth.FAILED
            data = 0.0
            return data, details

        details = "node " + node_name + " is in api"
        groundtruth.result = Groundtruth.SUCCEEDED
        data = 100.0
        for interface, interface_data in list(self.params.items()):
            if interface == "publishers" or interface == "subscribers" or interface == "services":
                for topic_name, topic_type in interface_data:
                    #print "node_name=", node_name
                    #print "topic_name=", topic_name
                    #print "topic_type=", topic_type
                    #print "api_dict[node_name][interface]=", api_dict[node_name][interface]
                    name_check, type_check = self.check_interface(
                        topic_name, topic_type, api_dict[node_name][interface])
                    if not name_check:
                        details += ", but " + topic_name + " is not in the list of " + interface + " of node " + node_name + ". " + interface + " are: " + str(
                            api_dict[node_name][interface])
                        groundtruth.result = Groundtruth.FAILED
                        data = min(data, 33.3)
                    else:
                        if not type_check:
                            details += ", but " + topic_name + " (of type " + topic_type + ") is not in the list of " + interface + " of node " + node_name + ". " + interface + " are: " + str(
                                api_dict[node_name][interface])
                            groundtruth.result = Groundtruth.FAILED
                            data = min(data, 66.6)
        return data, details