<commit_before># -*- coding: utf-8 -*-

"""
gmncurses.data
~~~~~~~~~~~~~~
"""

from datetime import datetime


# project_stats - Points

def total_points(project_stats):
    return project_stats.get("total_points", 0)

def assigned_points(project_stats):
    return project_stats.get("assigned_points", 0)

def defined_points(project_stats):
    return project_stats.get("defined_points", 0)

def defined_points_percentage(project_stats):
    try:
        return defined_points(project_stats) * 100 / total_points(project_stats)
    except ZeroDivisionError:
        return 0

def closed_points(project_stats):
    return  project_stats.get("closed_points", 0)

def closed_points_percentage(project_stats):
    try:
        return closed_points(project_stats) * 100 / total_points(project_stats)
    except ZeroDivisionError:
        return 0

def doomline_limit_points(project_stats):
    return total_points(project_stats) - assigned_points(project_stats)


# project_stats - Sprints

def total_sprints(project_stats):
    return project_stats.get("total_milestones", 0)

def completed_sprints(project):
    milestones = project.get("list_of_milestones", [])
    now = datetime.now()
    return [m for m in milestones if date(m["finish_date"]) < now]


# project - Sprints

def current_sprint(project):
    milestones = project.get("list_of_milestones", [])
    if milestones:
        return len(milestones)
    return "--"

def current_sprint_name(project):
    milestones = project.get("list_of_milestones", [])
    if milestones:
        return milestones[-1].get("name", "unknown")
    return "-----"

# project - Roles

def computable_roles(project):
    # FIXME
    return [r for r in project["roles"] if r["computable"]] if "roles" in project else []


# User Stories data

def us_ref(us):
    return us.get("ref", "--")

def us_subject(us):
    return us.get("subject", "------")

def us_total_points(us):
    return us.get("total_points", "--")


# us, project, computable roles - US points

def us_points_by_role(us, project, roles):
    us_points = us.get("points", [])
    project_points = {str(p["id"]): p for p in project["points"]}
    default_point = project["default_points"]

    points = []
    for role in roles:
        try:
            points.append(project_points[str(us_points[str(role["id"])])]["name"])
        except KeyError:
            points.append(project_points[str(default_point)]["name"])
    return points


# Misc

def date(text, date_format="%Y-%m-%d"):
    return datetime.strptime(text, date_format)
<commit_msg>Added methods to get the information from the issues stats<commit_after># -*- coding: utf-8 -*-

"""
gmncurses.data
~~~~~~~~~~~~~~
"""

from datetime import datetime


# project_stats - Points

def total_points(project_stats):
    return project_stats.get("total_points", 0)

def assigned_points(project_stats):
    return project_stats.get("assigned_points", 0)

def defined_points(project_stats):
    return project_stats.get("defined_points", 0)

def defined_points_percentage(project_stats):
    try:
        return defined_points(project_stats) * 100 / total_points(project_stats)
    except ZeroDivisionError:
        return 0

def closed_points(project_stats):
    return  project_stats.get("closed_points", 0)

def closed_points_percentage(project_stats):
    try:
        return closed_points(project_stats) * 100 / total_points(project_stats)
    except ZeroDivisionError:
        return 0

def doomline_limit_points(project_stats):
    return total_points(project_stats) - assigned_points(project_stats)


# project_stats - Sprints

def total_sprints(project_stats):
    return project_stats.get("total_milestones", 0)

def completed_sprints(project):
    milestones = project.get("list_of_milestones", [])
    now = datetime.now()
    return [m for m in milestones if date(m["finish_date"]) < now]


# project - Sprints

def current_sprint(project):
    milestones = project.get("list_of_milestones", [])
    if milestones:
        return len(milestones)
    return "--"

def current_sprint_name(project):
    milestones = project.get("list_of_milestones", [])
    if milestones:
        return milestones[-1].get("name", "unknown")
    return "-----"

# project - Roles

def computable_roles(project):
    # FIXME
    return [r for r in project["roles"] if r["computable"]] if "roles" in project else []


# User Stories data

def us_ref(us):
    return us.get("ref", "--")

def us_subject(us):
    return us.get("subject", "------")

def us_total_points(us):
    return us.get("total_points", "--")


# us, project, computable roles - US points

def us_points_by_role(us, project, roles):
    us_points = us.get("points", [])
    project_points = {str(p["id"]): p for p in project["points"]}
    default_point = project["default_points"]

    points = []
    for role in roles:
        try:
            points.append(project_points[str(us_points[str(role["id"])])]["name"])
        except KeyError:
            points.append(project_points[str(default_point)]["name"])
    return points


# issues stats - issues

def total_issues(issues_stats):
    return issues_stats.get("total_issues", 0)

def opened_issues(issues_stats):
    return issues_stats.get("opened_issues", 0)

def closed_issues(issues_stats):
    return issues_stats.get("closed_issues", 0)

def issues_statuses_stats(issues_stats):
    return issues_stats.get("issues_per_status", {})

def issues_priorities_stats(issues_stats):
    return issues_stats.get("issues_per_priority", {})

def issues_severities_stats(issues_stats):
    return issues_stats.get("issues_per_severity", {})


# Misc

def date(text, date_format="%Y-%m-%d"):
    return datetime.strptime(text, date_format)



{'fraction_non_alphanumeric': 0.13081497026932493, 'fraction_numerical': 0.005771248688352571, 'mean_word_length': 4.142985611510792, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5585290', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1810, 'n_words': 385}