<commit_before>from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from mosaicportfolio.models import RepositoryActivity, Repository, \
    ProjectRepository
import logging
logger = logging.getLogger(__name__)
def make_user_graph(user):
    '''
    Creates a Graph for all the activities of all the projects of a user.
    '''
    project_repositories = ProjectRepository.objects.filter(project__user=user)
    grouped_activities = {}
    for prep in project_repositories:
        grouped_activities[prep.project.name] = RepositoryActivity.objects.filter(repository=prep.repository).filter(login=prep.login)
    return Graph(_("Activity graph"), TableData(grouped_activities)).to_dict()

def make_project_graph(project):
    '''
    Creates a Graph for all the activities of a project.
    '''
    project_repositories = ProjectRepository.objects.filter(project=project)
    grouped_activities = {}
    for prep in project_repositories:
        grouped_activities[prep.project.name] = RepositoryActivity.objects.filter(repository=prep.repository).filter(login=prep.login)
    return Graph(_("Activity graph"), TableData(grouped_activities)).to_dict()

class Graph(object):
    '''
    The data required for constructing a Google Chart graph. 
    '''
    
    def __init__(self, title, table):
        '''
        Creates a graph with the desired title, based on the content of a Table. 
        '''
        self.title = title
        self.table = table
    
    def to_dict(self):
        return {'title': self.title, 'vTitle': _("Activities"), 'hTitle': _('Time'), 'table': self.table.to_list()}
     
class TableData(object):<commit_msg>fixed graphing, no more self-overriding<commit_after>from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from mosaicportfolio.models import RepositoryActivity, Repository, \
    ProjectRepository
import logging
logger = logging.getLogger(__name__)

def get_activities_for_project_repository(prep):
    return RepositoryActivity.objects.filter(repository=prep.repository).filter(login=prep.login)

def make_user_graph(user):
    '''
    Creates a Graph for all the activities of all the projects of a user.
    '''
    project_repositories = ProjectRepository.objects.filter(project__user=user)
    grouped_activities = {}
    for prep in project_repositories:
        if not grouped_activities.has_key(prep.project.name):
            grouped_activities[prep.project.name] = []
        grouped_activities[prep.project.name].extend(get_activities_for_project_repository(prep))
    return Graph(_("Activity graph"), TableData(grouped_activities)).to_dict()

def make_project_graph(project):
    '''
    Creates a Graph for all the activities of a project.
    '''
    project_repositories = ProjectRepository.objects.filter(project=project)
    activities = []
    for prep in project_repositories:
        activities.extend(get_activities_for_project_repository(prep))
    grouped_activities = {}
    grouped_activities[project.name] = activities
    return Graph(_("Activity graph"), TableData(grouped_activities)).to_dict()

class Graph(object):
    '''
    The data required for constructing a Google Chart graph. 
    '''
    
    def __init__(self, title, table):
        '''
        Creates a graph with the desired title, based on the content of a Table. 
        '''
        self.title = title
        self.table = table
    
    def to_dict(self):
        return {'title': self.title, 'vTitle': _("Activities"), 'hTitle': _('Time'), 'table': self.table.to_list()}
     
class TableData(object):
{'fraction_non_alphanumeric': 0.10146126275158533, 'fraction_numerical': 0.0, 'mean_word_length': 3.949522510231924, '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': '6595482', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1002, 'n_words': 250}