Exemple #1
0
    def stat(self, attribute=""):
        stat = {}
        stat['name'] = str(self)
        stat['used'] = db.getNodeIdByAttribute("archive_type", str(self))
        stat['state1'] = len(intersection([stat['used'], db.getNodeIdByAttribute("archive_state", "1")]))
        stat['state2'] = len(intersection([stat['used'], db.getNodeIdByAttribute("archive_state", "3")]))
        stat['state3'] = len(intersection([stat['used'], db.getNodeIdByAttribute("archive_state", "3")]))
        stat['used'] = len(stat['used'])

        if attribute == "":
            return stat
        elif attribute in stat.keys():
            return stat[attribute]
 def logs_divergence(baseline_logs, updated_logs):
     log_intersection = len(intersection(baseline_logs, updated_logs))
     log_union = len(union(baseline_logs, updated_logs))
     IOU = 1.0
     if log_union > 0:
         IOU = log_intersection / float(log_union)
     return 1 - IOU
Exemple #3
0
    def archive_thread(self):
        if not time:
            return
        while True:
            time.sleep(int(config.get("archive.interval", 60)))
            archive_nodes_3 = db.getNodeIdByAttribute("archive_state", "3")
            archive_nodes_2 = []

            date_now = format_date(now(), "yyymmddhhmmss")

            for manager in self.manager:
                # search for nodes to archive after access over period (state 2)
                for n in db.getNodeIdByAttribute("archive_state", "2"):
                    try:
                        node = tree.getNode(n)
                        if node.get("archive_date"):
                            date_archive = format_date(parse_date(node.get("archive_date"), "%Y-%m-%dT%H:%M:%S"), "yyymmddhhmmss")
                            if date_now >= date_archive:
                                archive_nodes_2.append(long(node.id))
                    except:
                        pass

                # union to get all nodes with state 3 and 2 with over period
                archive_nodes = union((archive_nodes_3, archive_nodes_2))
                nodes = intersection((db.getNodeIdByAttribute("archive_type", str(manager)), archive_nodes))

                # run action defined in manager
                try:
                    self.manager[manager].actionArchive(nodes)
                except:
                    pass
Exemple #4
0
    def load(self, parts: List[str]):

        with open(self.filepath_json_live) as f:
            json_read = json.load(f)

        for part in utils.intersection(parts, list(json_read.keys())):
            self.score[part] = {}

            self.score[part]['notes'] = json_read[part]['notes']
Exemple #5
0
 def search(self, q):
     global searcher, subnodes
     log.info('search: %s for node %s %s' % (q, str(self.id), str(self.name)))
     self._makePersistent()
     if q.startswith('searchcontent='):
         return searcher.query(q)
     items = subnodes(self)
     if not isinstance(items, list):
         items = items.getIDs()
     return NodeList(intersection([items, searcher.query(q)]))
Exemple #6
0
 def search(self, q):
     global searcher, subnodes
     log.info('search: %s for node %s %s' %
              (q, str(self.id), str(self.name)))
     self._makePersistent()
     if q.startswith('searchcontent='):
         return searcher.query(q)
     items = subnodes(self)
     if not isinstance(items, list):
         items = items.getIDs()
     return NodeList(intersection([items, searcher.query(q)]))
Exemple #7
0
    def run(self):
        js_logs = {
            'in_baseline':
            len(self.baseline_js_logs.js_messages),
            'in_upgraded':
            len(self.updated_js_logs.js_messages),
            'in_both':
            len(
                intersection(self.baseline_js_logs.js_messages,
                             self.updated_js_logs.js_messages))
        }

        network_logs = {
            'in_baseline':
            len(self.baseline_network_logs.network_messages),
            'in_upgraded':
            len(self.updated_network_logs.network_messages),
            'in_both':
            len(
                intersection(self.baseline_network_logs.network_messages,
                             self.updated_network_logs.network_messages))
        }

        risk_score_js = Scores.logs_divergence(
            self.baseline_js_logs.js_messages,
            self.updated_js_logs.js_messages)

        risk_score_network = Scores.logs_divergence(
            self.baseline_network_logs.network_messages,
            self.updated_network_logs.network_messages)
        risk_score = max(risk_score_js, risk_score_network)
        self.result = {
            'javascript': js_logs,
            'network': network_logs,
            'risk_score': risk_score
        }
        return self.result
Exemple #8
0
def from_json(filepath, parts=['melody', 'chord', 'root']) -> music21.stream.Score:

    with open(filepath) as f:
        json_read = json.load(f)

    partmap = {}

    for name_part in utils.intersection(parts, list(json_read.keys())):
        part = music21.stream.Part()

        notes = nl.NoteLive.parse_list(
            json_read[name_part]['notes']
        )

        for note_live in notes:

            note = music21.note.Note(
                pitch=note_live.pitch
            )
            note.duration = music21.duration.Duration(
                note_live.beats_duration
            )

            part.insert(
                note_live.beat_start,
                note
            )

        if name_part == 'chord':
            part.makeVoices()

        part.makeRests(fillGaps=True)

        part.makeMeasures()

        part.id = name_part

        part.partName = name_part

        partmap[name_part] = part

    score = music21.stream.Score()

    for _, part in partmap.items():
        score.append(part)

    return score
Exemple #9
0
def get_covering_tests(coverage, dict_of_modified_coverable_lines,
                       covering_type):
    list_of_covering_tests = []
    for key, covering_lines in dict_of_modified_coverable_lines.items():
        for test_method, i_covering_lines in coverage[key].items():
            covering_test_with_score = {}
            lines_covered = utils.intersection(
                list(map(int, i_covering_lines)),
                covering_lines[covering_type])
            detailed_lines_covered = {}
            if len(lines_covered) > 0:
                covering_test_with_score['test'] = test_method
                detailed_lines_covered['class'] = key
                detailed_lines_covered['lines_covered'] = lines_covered
                detailed_lines_covered['bug_fix_code_covered'] = \
                    (len(lines_covered) / len(covering_lines[covering_type])) * 100

                covering_test_with_score[
                    'detailed_lines_covered'] = detailed_lines_covered
                list_of_covering_tests.append(covering_test_with_score)

    return list_of_covering_tests
# ----------------------------------------------------------------------------------------------------------------------
# Test intersection, jaccard, and bboxes_intersection function
# gt [ymin, xmin, ymax, xmax]
test_gt_bbox = tf.constant([[[2, 1, 5, 4]],
                            [[2, 2, 7, 5]],
                            [[4, 1, 6, 3]]], dtype=tf.float32)

# pred [ymin, xmin, ymax, xmax]
test_pred_bbox = tf.constant([[[1, 3, 3, 6]],
                              [[3, 3, 5, 5]],
                              [[1, 4, 3, 6]]], dtype=tf.float32)

tf.print(f"test gt", tf.shape(test_gt_bbox))
tf.print(f"test pred", tf.shape(test_pred_bbox))

inter = intersection(test_pred_bbox, test_gt_bbox)
tf.print(f"test intersection shape", tf.shape(inter))
tf.print(f"test intersection", inter)

jac = jaccard(test_pred_bbox, test_gt_bbox)
tf.print(f"test jaccard shape", tf.shape(jac))
tf.print(f"test jaccard", jac)
# ----------------------------------------------------------------------------------------------------------------------
# test bbox interaction for random crop
# Todo make it clear
test_ref_bbox = tf.constant([[0, 0, 1, 1]], dtype=tf.float32)
test_pred_bbox = tf.constant([[0.1, 0.3, 0.3, 0.6],
                              [0.3, 0.3, 0.5, 0.5],
                              [0.1, 0.4, 0.3, 0.6]], dtype=tf.float32)
bbox_iter = bboxes_intersection(test_ref_bbox, test_pred_bbox)
tf.print(f"test bbox inter shape", tf.shape(bbox_iter))
Exemple #11
0
 def execute(self):
     ids1 = self.a.execute()
     if not len(ids1):
         return ids1
     ids2 = self.b.execute()
     return intersection([ids1, ids2])
Exemple #12
0
 def execute(self):
     ids = self.a.execute()
     if not len(ids):
         return ids
     return intersection([ids, self.b.execute()])
Exemple #13
0
 def execute(self):
     ids = self.a.execute()
     if not len(ids):
         return ids
     return intersection([ids, self.b.execute()])
Exemple #14
0
 def execute(self):
     ids1 = self.a.execute()
     if not len(ids1):
         return ids1
     ids2 = self.b.execute()
     return intersection([ids1, ids2])