<commit_before># vim: set expandtab ts=4 sw=4 filetype=python:

"""
Simple projects have tasks, people, comments, components, and
milestones.
"""

myclassname = 'SimpleProject'

from copy import copy
import logging, textwrap

import clepy, jinja2

from pitz import by_created_time
from pitz.entity import Entity
from pitz.project import Project
from pitz.exceptions import NoProject

log = logging.getLogger('pitz.simplepitz')


class Estimate(Entity):
    
    required_fields = dict(points=None)

    def __str__(self):
        return self.title


class Status(Entity):

    def __str__(self):
        return self.title

    @property
    def tasks(self):
        """
        Return tasks with this status
        """
        
        if not self.project:
            raise NoProject("Need a self.project for this!")

        else:
            return self.project.tasks(status=self)


class Milestone(Entity):
    """
    Useful for bundling tasks
    """

    plural_name = "milestones"

    @property
    def tasks(self):

        if not self.project:
            raise NoProject("I need a project before I can look up tasks!")

        tasks = self.project(type='task', milestone=self)
        tasks.title = 'Tasks in %(title)s' % self
        return tasks

    @property
    def todo(self):

        unfinished = self.tasks.does_not_match_dict(
            status=Status(title='finished'))\
        .does_not_match_dict(status=Status(title='abandoned'))

        unfinished.title = "Unfinished tasks in %(title)s" % self
        return unfinished

    @property
    def summarized_view(self):

        finished = Status(title='finished')

        a = self.tasks(status=finished).length
        b = self.tasks.length

        if b is not 0:
            pct_complete = 100*(float(a)/b)
        else:
            pct_complete = 0.0

        d = {
            'frag':self['frag'],
            'title':self['title'],
            'pct_complete':pct_complete,
            'num_finished_tasks':a,
            'num_tasks': b}
            
        s = "%(frag)s %(title)s: %(pct_complete)0.0f%% complete (%(num_finished_tasks)d / %(num_tasks)d tasks)"
        return s % d


class Task(Entity):

    plural_name = "tasks"

    allowed_types = dict(
        milestone=Milestone,
        status=Status,
        estimate=Estimate)

    required_fields = dict(
        title=None,
        description='',
        milestone=lambda proj: Milestone(proj, title='unscheduled'),
        status=lambda proj: Status(proj, title='unstarted'),
        estimate=lambda proj: Estimate(proj, title='not estimated', points=None),
        components=lambda proj: list())


    @property
    def summarized_view(self):
        """
        Short description of the task.
        """

        frag = self['frag']
        title = clepy.maybe_add_ellipses(self.title, 48)
        status = '(%s)' % self['status']
        milestone = self['milestone'].title if self['milestone'] else 'unscheduled'
        pscore = self['pscore']

        return "%(frag)s %(title)-51s %(pscore)3s %(milestone)22s %(status)12s" % locals()


    @property
    def comments(self):
        """
        Return all comments on this task.
        """
    
        b = self.project(type='comment', entity=self)
        b.title = 'Comments on %(title)s' % self
        return b.order(by_created_time)


    def abandon(self):

        if self['status'].title in ['unstarted', 'started']:
            self['status'] = Status(title='abandoned')
            return self

        else:
            raise ValueError('You can only abandon unstarted or started tasks.')


    def start(self):

        if self['status'].title in ['unstarted', 'abandoned']:<commit_msg>Tweaked format of pitz-todo<commit_after># vim: set expandtab ts=4 sw=4 filetype=python:

"""
Simple projects have tasks, people, comments, components, and
milestones.
"""

myclassname = 'SimpleProject'

from copy import copy
import logging, textwrap

import clepy, jinja2

from pitz import by_created_time
from pitz.entity import Entity
from pitz.project import Project
from pitz.exceptions import NoProject

log = logging.getLogger('pitz.simplepitz')


class Estimate(Entity):
    
    required_fields = dict(points=None)

    def __str__(self):
        return self.title


class Status(Entity):

    def __str__(self):
        return self.title

    @property
    def tasks(self):
        """
        Return tasks with this status
        """
        
        if not self.project:
            raise NoProject("Need a self.project for this!")

        else:
            return self.project.tasks(status=self)


class Milestone(Entity):
    """
    Useful for bundling tasks
    """

    plural_name = "milestones"

    @property
    def tasks(self):

        if not self.project:
            raise NoProject("I need a project before I can look up tasks!")

        tasks = self.project(type='task', milestone=self)
        tasks.title = 'Tasks in %(title)s' % self
        return tasks

    @property
    def todo(self):

        unfinished = self.tasks.does_not_match_dict(
            status=Status(title='finished'))\
        .does_not_match_dict(status=Status(title='abandoned'))

        unfinished.title = "Unfinished tasks in %(title)s" % self
        return unfinished

    @property
    def summarized_view(self):

        finished = Status(title='finished')

        a = self.tasks(status=finished).length
        b = self.tasks.length

        if b is not 0:
            pct_complete = 100*(float(a)/b)
        else:
            pct_complete = 0.0

        d = {
            'frag':self['frag'],
            'title':self['title'],
            'pct_complete':pct_complete,
            'num_finished_tasks':a,
            'num_tasks': b}
            
        s = "%(frag)s %(title)s: %(pct_complete)0.0f%% complete (%(num_finished_tasks)d / %(num_tasks)d tasks)"
        return s % d


class Task(Entity):

    plural_name = "tasks"

    allowed_types = dict(
        milestone=Milestone,
        status=Status,
        estimate=Estimate)

    required_fields = dict(
        title=None,
        description='',
        milestone=lambda proj: Milestone(proj, title='unscheduled'),
        status=lambda proj: Status(proj, title='unstarted'),
        estimate=lambda proj: Estimate(proj, title='not estimated', points=None),
        components=lambda proj: list())


    @property
    def summarized_view(self):
        """
        Short description of the task.
        """

        frag = self['frag']
        title = clepy.maybe_add_ellipses(self.title, 46)
        status = '(%s)' % self['status'].abbr

        milestone = self['milestone'].abbr \
        if self['milestone'] else '???'

        pscore = self['pscore']

        return "%(frag)6s %(title)-49s %(milestone)3s %(status)11s" \
        % locals()


    @property
    def comments(self):
        """
        Return all comments on this task.
        """
    
        b = self.project(type='comment', entity=self)
        b.title = 'Comments on %(title)s' % self
        return b.order(by_created_time)


    def abandon(self):

        if self['status'].title in ['unstarted', 'started']:
            self['status'] = Status(title='abandoned')
            return self

        else:
            raise ValueError('You can only abandon unstarted or started tasks.')


    def start(self):

        if self['status'].title in ['unstarted', 'abandoned']:
{'fraction_non_alphanumeric': 0.11941904249596558, 'fraction_numerical': 0.005244755244755245, 'mean_word_length': 2.3394701392007184, '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': '6622893', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2168, 'n_words': 550}