<commit_before>import math

from compsoc.events.models import *
from collections import defaultdict
from django.contrib.auth.models import User

class Point:
    def __init__(self, x = 0, y = 0):
        self.x = float(x)
        self.y = float(y)
        
    def __getitem__(self, key):
        if( key == 0):
            return self.x
        elif( key == 1):
            return self.y
        else:
            raise Exception("Invalid key to Point")
        
    def __setitem__(self, key, value):
        if( key == 0):
            self.x = value
        elif( key == 1):
            self.y = value
        else:
            raise Exception("Invalid key to Point")
        
    def __unicode__(self):
        return u'(%s,%s)' % (self.x,self.y)
    
    def distance(self, point2):
        """Returns the distance between to another point"""
        return math.sqrt( ( (self[0]-point2[0])**2 + (self[1]-point2[1])**2) )
        
def ave(points):
    return reduce(lambda x,y:x+y,points)/len(points)

def distance_matrix():
    """
        Calculates a mapping from users onto distances
    """
    # Build lookup map
    # TODO: remove duplicate computations
    # weight score by frequency
    lookup = defaultdict(lambda: defaultdict(lambda: []))
    for event in Event.objects.all():
        seating = SeatingRevision.objects.filter(event=event).order_by('-number')
        if seating:
            latest = seating[0]
            cache = {}
            for s in latest.seating_set.all():
                cache[s.user_id] = Point(s.row,s.col)
            for user in cache.keys():
                for other in cache.keys():
                    if other != user:
                        lookup[user][other].append(cache[user].distance(cache[other]))
    
    results = defaultdict(lambda:{})<commit_msg>added row gutters to lan friends page<commit_after>import math

from compsoc.events.models import *
from collections import defaultdict
from django.contrib.auth.models import User

class Point:
    def __init__(self, x = 0, y = 0):
        self.x = int(x)
        self.y = int(y)
        
    def __getitem__(self, key):
        if( key == 0):
            return self.x
        elif( key == 1):
            return self.y
        else:
            raise Exception("Invalid key to Point")
        
    def __setitem__(self, key, value):
        if( key == 0):
            self.x = value
        elif( key == 1):
            self.y = value
        else:
            raise Exception("Invalid key to Point")
        
    def __unicode__(self):
        return u'(%s,%s)' % (self.x,self.y)
    
    def distance(self, point2):
        """Returns the distance between to another point"""
        # this is to insert gutters between tables
        self_x = self.x + (self.x/2)
        point2_x = point2.x + (point2.x/2)
        return math.sqrt( ( (self_x-point2_x)**2 + (self.y-point2.y)**2) )
        
def ave(points):
    return reduce(lambda x,y:x+y,points)/len(points)

def distance_matrix():
    """
        Calculates a mapping from users onto distances
    """
    # Build lookup map
    # TODO: remove duplicate computations
    # weight score by frequency
    lookup = defaultdict(lambda: defaultdict(lambda: []))
    for event in Event.objects.all():
        seating = SeatingRevision.objects.filter(event=event).order_by('-number')
        if seating:
            latest = seating[0]
            cache = {}
            for s in latest.seating_set.all():
                cache[s.user_id] = Point(s.col,s.row)
            for user in cache.keys():
                for other in cache.keys():
                    if other != user:
                        lookup[user][other].append(cache[user].distance(cache[other]))
    
    results = defaultdict(lambda:{})
{'fraction_non_alphanumeric': 0.12072167683735739, 'fraction_numerical': 0.008755638100291854, 'mean_word_length': 1.9292929292929293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3668653', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1083, 'n_words': 302}