<commit_before># vim: set ai ts=4 sw=4 et:

from django.db import models
from mysite.search.models import Project, Bug
import datetime

class Person(models.Model):
    """ A human bean. """
    # {{{
    name = models.CharField(max_length=200)
    username = models.CharField(max_length=200)
    password_hash_md5 = models.CharField(
            max_length=200)
    #FIXME: Get specific length of hash
    time_record_was_created = models.DateTimeField(
            default=datetime.datetime.now())
    last_polled = models.DateTimeField(
            blank=True, null=True)
    last_touched = models.DateTimeField()
    poll_on_next_web_view = models.BooleanField(
            default=True)

    def save(self, *args, **kwargs):
        self.last_touched = datetime.datetime.now()
        super(Person, self).save(*args, **kwargs)

    def fetch_contrib_data_from_ohloh(self):
        import ohloh
        oh = ohloh.get_ohloh()
        ohloh_contrib_info_list = oh.get_contribution_info_by_username(
                self.username)
        for ohloh_contrib_info in ohloh_contrib_info_list:
            p2p_rel = PersonToProjectRelationship()
            p2p_rel.person = self
            p2p_rel.from_ohloh_contrib_info(ohloh_contrib_info)
            p2p_rel.save()
        self.last_polled = datetime.datetime.now()
        self.save()

    # }}}

class PersonToProjectRelationship(models.Model):
    """ Many-to-one relation between projects and people """
    # {{{
    person = models.ForeignKey(Person)
    project = models.ForeignKey(Project)
    person_role = models.CharField(max_length=200)
    tags = models.TextField() # A list of tags, delimited with spaces.
    time_record_was_created = models.DateTimeField()
    url = models.URLField(max_length=200)
    description = models.TextField()
    time_start = models.DateTimeField()
    time_finish = models.DateTimeField()
    man_months = models.PositiveIntegerField()
    primary_language = models.CharField(max_length=200)

    source = models.CharField(max_length=100)

    def save(self):
        if not self.id:
            self.time_record_was_created = datetime.date.today()

    def from_ohloh_contrib_info(self, ohloh_contrib_info):
        if not self.person:
            self.person = Person.objects.get_or_create(
                    username=ohloh_contrib_info['username'])
        else:
            pass # Don't overwrite.

        self.project, bool_created = Project.objects.get_or_create(
                name=ohloh_contrib_info['project'])
        # FIXME: Automatically populate project url here.
        self.man_months = ohloh_contrib_info['man_months']
        self.primary_language = ohloh_contrib_info['primary_language']
        self.source = "Ohloh"
        self.time_gathered_from_source = datetime.date.today()
    # }}}

"""
Not yet implemented or needed.
class Commit(models.Model):
    # {{{
    person_to_project_relationship = models.ForeignKey(
            PersonToProjectRelationship)
    person = models.ForeignKey(Person) # Redundant
    project = models.ForeignKey(Project) # Redundant
    time = models.DateTimeField()
    description = models.TextField()
    # }}}

class Tag(models.Model):
    # {{{
    text = models.CharField(max_length=50)
    type = models.CharField(max_length=50)
    # }}}

class TagTypes(models.Model):
    # {{{
    prefix = models.CharField(max_length=20)
    # }}}
"""<commit_msg>Add new model to profile: Link_PersonTo_ProjectRelationship_Tag. Apologies for the abysmal name.<commit_after># vim: set ai ts=4 sw=4 et:

from django.db import models
from mysite.search.models import Project, Bug
import datetime

class Person(models.Model):
    """ A human bean. """
    # {{{
    name = models.CharField(max_length=200)
    username = models.CharField(max_length=200)
    password_hash_md5 = models.CharField(
            max_length=200)
    #FIXME: Get specific length of hash
    time_record_was_created = models.DateTimeField(
            default=datetime.datetime.now())
    last_polled = models.DateTimeField(
            blank=True, null=True)
    last_touched = models.DateTimeField()
    poll_on_next_web_view = models.BooleanField(
            default=True)

    def save(self, *args, **kwargs):
        self.last_touched = datetime.datetime.now()
        super(Person, self).save(*args, **kwargs)

    def fetch_contrib_data_from_ohloh(self):
        import ohloh
        oh = ohloh.get_ohloh()
        ohloh_contrib_info_list = oh.get_contribution_info_by_username(
                self.username)
        for ohloh_contrib_info in ohloh_contrib_info_list:
            p2p_rel = PersonToProjectRelationship()
            p2p_rel.person = self
            p2p_rel.from_ohloh_contrib_info(ohloh_contrib_info)
            p2p_rel.save()
        self.last_polled = datetime.datetime.now()
        self.save()

    # }}}

class PersonToProjectRelationship(models.Model):
    "Many-to-one relation between projects and people."
    # {{{
    person = models.ForeignKey(Person)
    project = models.ForeignKey(Project)
    person_role = models.CharField(max_length=200)
    tags = models.TextField() # A list of tags, delimited with spaces.
    time_record_was_created = models.DateTimeField()
    url = models.URLField(max_length=200)
    description = models.TextField()
    time_start = models.DateTimeField()
    time_finish = models.DateTimeField()
    man_months = models.PositiveIntegerField()
    primary_language = models.CharField(max_length=200)

    source = models.CharField(max_length=100)

    def save(self):
        if not self.id:
            self.time_record_was_created = datetime.date.today()

    def from_ohloh_contrib_info(self, ohloh_contrib_info):
        if not self.person:
            self.person = Person.objects.get_or_create(
                    username=ohloh_contrib_info['username'])
        else:
            pass # Don't overwrite.

        self.project, bool_created = Project.objects.get_or_create(
                name=ohloh_contrib_info['project'])
        # FIXME: Automatically populate project url here.
        self.man_months = ohloh_contrib_info['man_months']
        self.primary_language = ohloh_contrib_info['primary_language']
        self.source = "Ohloh"
        self.time_gathered_from_source = datetime.date.today()
    # }}}

class Tag(models.Model):
    # {{{
    text = models.CharField(max_length=50)
    type = models.CharField(max_length=50)
    # }}}

class TagTypes(models.Model):
    # {{{
    prefix = models.CharField(max_length=20)
    # }}}

class Link_PersonToProjectRelationship_Tag(models.Model):
    "Many-to-many relation between p2prels and tags."
    # {{{
    tag = models.ForeignKey(Tag)
    person_to_project_relationship = models.ForeignKey(
            PersonToProjectRelationship)
    time_record_was_created = models.DateTimeField(
            default=datetime.datetime.now())
    source = models.CharField(max_length=200)
    # }}}
{'fraction_non_alphanumeric': 0.10161197466896948, 'fraction_numerical': 0.010362694300518135, 'mean_word_length': 3.030742459396752, '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': '5252654', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2098, 'n_words': 380}