<commit_before>from collections import defaultdict
from django.conf import settings
from jamjar.videos.models import JamJarMap

class ConcertGraph(object):

    def __init__(self, edges):
        self.edges = edges

    def search(self, video_id, graph, already_seen):
        already_seen.add(video_id)
        edges = graph[video_id]
        for edge in edges:
            next_id = edge['video']
            if next_id not in already_seen:
                self.search(next_id, graph, already_seen)

    def disjoint_graphs(self):
        graph = self.make_graph()

        video_ids = set()
        for edge in self.edges:
            video_ids.add(edge.video1.id)
            video_ids.add(edge.video2.id)

        disjoint_ids = []
        while len(video_ids) > 0:
            video_id  = video_ids.pop()
            found_ids = set()
            self.search(video_id, graph, found_ids) # the ol' python pass-by-reference lol

            video_ids -= found_ids
            disjoint_ids.append(found_ids)

        disjoint_graphs = []
        for id_set in disjoint_ids:
            adjacencies = {}
            for video_id in id_set:
                adjacencies[video_id] = graph[video_id]

            jamstarts = JamJarMap.objects.filter(video_id__in=id_set)
            if len(jamstarts) == 0 or len(adjacencies) == 0:
                continue
            else:
                start_id = jamstarts[0].start_id

            disjoint_graphs.append({
                "adjacencies": adjacencies,
                "count": len(adjacencies),
                "start_id": start_id
            })

        return disjoint_graphs

    def make_graph(self):
        # create a mapping of video_id --> video for later
        edge_map  = {}
        for edge in self.edges:
            edge_map[(edge.video1.id, edge.video2.id)] = edge

        # build an adjacency list to help with generating the graph
        video_adjacencies = defaultdict(list)<commit_msg>don't return jamjars with <= 1 video in them<commit_after>from collections import defaultdict
from django.conf import settings
from jamjar.videos.models import JamJarMap

class ConcertGraph(object):

    def __init__(self, edges):
        self.edges = edges

    def search(self, video_id, graph, already_seen):
        already_seen.add(video_id)
        edges = graph[video_id]
        for edge in edges:
            next_id = edge['video']
            if next_id not in already_seen:
                self.search(next_id, graph, already_seen)

    def disjoint_graphs(self):
        graph = self.make_graph()

        video_ids = set()
        for edge in self.edges:
            video_ids.add(edge.video1.id)
            video_ids.add(edge.video2.id)

        disjoint_ids = []
        while len(video_ids) > 0:
            video_id  = video_ids.pop()
            found_ids = set()
            self.search(video_id, graph, found_ids) # the ol' python pass-by-reference lol

            video_ids -= found_ids
            disjoint_ids.append(found_ids)

        disjoint_graphs = []
        for id_set in disjoint_ids:
            adjacencies = {}
            for video_id in id_set:
                adjacencies[video_id] = graph[video_id]

            jamstarts = JamJarMap.objects.filter(video_id__in=id_set)
            if len(jamstarts) == 0 or len(adjacencies) <= 1:
                continue
            else:
                start_id = jamstarts[0].start_id

            disjoint_graphs.append({
                "adjacencies": adjacencies,
                "count": len(adjacencies),
                "start_id": start_id
            })

        return disjoint_graphs

    def make_graph(self):
        # create a mapping of video_id --> video for later
        edge_map  = {}
        for edge in self.edges:
            edge_map[(edge.video1.id, edge.video2.id)] = edge

        # build an adjacency list to help with generating the graph
        video_adjacencies = defaultdict(list)
{'fraction_non_alphanumeric': 0.08478866109845609, 'fraction_numerical': 0.004302708175145533, 'mean_word_length': 1.8994864269992664, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3091611', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1130, 'n_words': 276}