Ejemplo n.º 1
0
def get_weighted_quotas(project_id, task_type_id, detail_level):
    """
    Build quota statistics. It counts the number of frames done for each day.
    A shot is considered done at the first feedback request. If time spent is
    filled for it, it weights the result with the frame number with the time
    spents. If there is no time spent, it considers that the work was done
    from the wip date to the feedback date.
    It computes the shot count and the number of seconds too.
    """
    fps = projects_service.get_project_fps(project_id)
    timezone = user_service.get_timezone()
    shot_type = get_shot_type()
    quotas = {}
    query = (Task.query.filter(Task.project_id == project_id).filter(
        Entity.entity_type_id == shot_type["id"]).filter(
            Task.task_type_id == task_type_id).filter(
                Task.end_date != None).join(
                    Entity, Entity.id == Task.entity_id).join(
                        Project, Project.id == Task.project_id).join(
                            TimeSpent,
                            Task.id == TimeSpent.task_id).add_columns(
                                Entity.nb_frames,
                                TimeSpent.date,
                                TimeSpent.duration,
                                TimeSpent.person_id,
                            ))
    result = query.all()

    for (task, nb_frames, date, duration, person_id) in result:
        person_id = str(person_id)
        if task.duration > 0 and nb_frames is not None:
            nb_frames = round(nb_frames * (duration / task.duration))
            _add_quota_entry(quotas, person_id, date, timezone, nb_frames, fps)

    query = (Task.query.filter(Task.project_id == project_id).filter(
        Entity.entity_type_id == shot_type["id"]).filter(
            Task.task_type_id == task_type_id).filter(
                Task.real_start_date != None).filter(
                    Task.end_date != None).filter(TimeSpent.id == None).join(
                        Entity, Entity.id == Task.entity_id).join(
                            Project, Project.id == Task.project_id).outerjoin(
                                TimeSpent, Task.id == TimeSpent.task_id).join(
                                    Task.assignees).add_columns(
                                        Entity.nb_frames, Person.id))
    result = query.all()

    for (task, nb_frames, person_id) in result:
        business_days = (date_helpers.get_business_days(
            task.real_start_date, task.end_date) + 1)
        if nb_frames is not None:
            nb_frames = round(nb_frames / business_days) or 0
        else:
            nb_frames = 0
        date = task.real_start_date
        for x in range((task.end_date - task.real_start_date).days + 1):
            if date.weekday() < 5:
                _add_quota_entry(quotas, str(person_id), date, timezone,
                                 nb_frames, fps)
            date = date + timedelta(1)
    return quotas
Ejemplo n.º 2
0
def get_raw_quotas(project_id, task_type_id, detail_level):
    """
    Build quota statistics in a raw way. It counts the number of frames done
    for each day. A shot is considered done at the first feedback request (end
    date). It considers that all the work was done at the end date.
    It computes the shot count and the number of seconds too.
    """
    fps = projects_service.get_project_fps(project_id)
    timezone = user_service.get_timezone()
    shot_type = get_shot_type()
    quotas = {}
    query = (Task.query.filter(Task.project_id == project_id).filter(
        Entity.entity_type_id == shot_type["id"]).filter(
            Task.task_type_id == task_type_id).filter(
                Task.end_date != None).join(
                    Entity, Entity.id == Task.entity_id).join(
                        Project, Project.id == Task.project_id).join(
                            Task.assignees).add_columns(
                                Entity.nb_frames, Person.id))
    result = query.all()

    for (task, nb_frames, person_id) in result:
        date = task.end_date
        if nb_frames is None:
            nb_frames = 0
        _add_quota_entry(quotas, str(person_id), date, timezone, nb_frames,
                         fps)
    return quotas
Ejemplo n.º 3
0
def get_timezoned_interval(start, end):
    """
    Get all day off entries for given person, year.
    """
    timezone = user_service.get_timezone()
    return (date_helpers.get_string_with_timezone_from_date(start, timezone),
            date_helpers.get_string_with_timezone_from_date(end, timezone))
Ejemplo n.º 4
0
def get_timezoned_interval(start, end):
    """
    Get time intervals adapted to the user timezone.
    """
    timezone = user_service.get_timezone()
    return date_helpers.get_timezoned_interval(start, end, timezone)