<commit_before>
import os

from enum import Enum

from app_config import get_project_config_path, update_config_with_sections, get_config_section, get_all_projects

class Status(object):

    class Flag(Enum):
        FAILURE = -1
        INCOMPLETE = 0
        IN_PROGRESS = 1
        COMPLETE = 2

    class Type(Enum):
        HOMOGRAPHY = "homography"
        FEATURE_TEST = "feature_test"
        OBJECT_TEST = "object_test"
        OBJECT_TRACKING = "object_tracking"
        SAFETY_ANALYSIS = "safety_analysis"
        HIGHLIGHT_VIDEO = "highlight_video"


    @classmethod
    def create_status_dict(cls):
        return {
            Status.Type.HOMOGRAPHY: Status.Flag.INCOMPLETE,
            Status.Type.FEATURE_TEST: Status.Flag.INCOMPLETE,
            Status.Type.OBJECT_TEST: Status.Flag.INCOMPLETE,
            Status.Type.OBJECT_TRACKING: Status.Flag.INCOMPLETE,
            Status.Type.SAFETY_ANALYSIS: Status.Flag.INCOMPLETE,
            Status.Type.HIGHLIGHT_VIDEO: Status.Flag.INCOMPLETE,
        }

class StatusHelper(object):
    @staticmethod
    def initalize_project(identifier):
        d = Status.create_status_dict()
        config_path = get_project_config_path(identifier)
        for (status_type, status) in d.iteritems():
            update_config_with_sections(config_path, "status", status_type.value, str(status.value))

    @staticmethod
    def set_status(identifier, status_type, val, failure_message=None):
        config_path = get_project_config_path(identifier)
        status = str(val.value)
        update_config_with_sections(config_path, "status", status_type.value, status)

        if failure_message is not None:
            update_config_with_sections(config_path, "failure_message", status_type.value, failure_message)

    @staticmethod
    def get_status(identifier):
        config_path = get_project_config_path(identifier)
        (success, value) = get_config_section(config_path, "status")
        if success:
            d = {}
            for (k,v) in value.iteritems():
                try:
                    d[Status.Type(k)] = Status.Flag(int(v))
                except Exception as e:
                    print('Failed to parse status: '+k+' with error: '+str(e))
            return d
        else:
            return None

    @staticmethod
    def get_status_raw(identifier):
        config_path = get_project_config_path(identifier)
        (success, statuses) = get_config_section(config_path, "status")
        if success:
            s, messages = get_config_section(config_path, "failure_message")<commit_msg>Fix no section error<commit_after>
import os

from enum import Enum

from app_config import get_project_config_path, update_config_with_sections, get_config_section, get_all_projects

class Status(object):

    class Flag(Enum):
        FAILURE = -1
        INCOMPLETE = 0
        IN_PROGRESS = 1
        COMPLETE = 2

    class Type(Enum):
        HOMOGRAPHY = "homography"
        FEATURE_TEST = "feature_test"
        OBJECT_TEST = "object_test"
        OBJECT_TRACKING = "object_tracking"
        SAFETY_ANALYSIS = "safety_analysis"
        HIGHLIGHT_VIDEO = "highlight_video"


    @classmethod
    def create_status_dict(cls):
        return {
            Status.Type.HOMOGRAPHY: Status.Flag.INCOMPLETE,
            Status.Type.FEATURE_TEST: Status.Flag.INCOMPLETE,
            Status.Type.OBJECT_TEST: Status.Flag.INCOMPLETE,
            Status.Type.OBJECT_TRACKING: Status.Flag.INCOMPLETE,
            Status.Type.SAFETY_ANALYSIS: Status.Flag.INCOMPLETE,
            Status.Type.HIGHLIGHT_VIDEO: Status.Flag.INCOMPLETE,
        }

class StatusHelper(object):
    @staticmethod
    def initalize_project(identifier):
        d = Status.create_status_dict()
        config_path = get_project_config_path(identifier)
        for (status_type, status) in d.iteritems():
            update_config_with_sections(config_path, "status", status_type.value, str(status.value))
        # Prevent 'Section failure_message does not exist' errors
        update_config_with_sections(config_path, "failure_message", "None", "None")

    @staticmethod
    def set_status(identifier, status_type, val, failure_message=None):
        config_path = get_project_config_path(identifier)
        status = str(val.value)
        update_config_with_sections(config_path, "status", status_type.value, status)

        if failure_message is not None:
            update_config_with_sections(config_path, "failure_message", status_type.value, failure_message)

    @staticmethod
    def get_status(identifier):
        config_path = get_project_config_path(identifier)
        (success, value) = get_config_section(config_path, "status")
        if success:
            d = {}
            for (k,v) in value.iteritems():
                try:
                    d[Status.Type(k)] = Status.Flag(int(v))
                except Exception as e:
                    print('Failed to parse status: '+k+' with error: '+str(e))
            return d
        else:
            return None

    @staticmethod
    def get_status_raw(identifier):
        config_path = get_project_config_path(identifier)
        (success, statuses) = get_config_section(config_path, "status")
        if success:
            s, messages = get_config_section(config_path, "failure_message")
{'fraction_non_alphanumeric': 0.0860093896713615, 'fraction_numerical': 0.0015023474178403756, 'mean_word_length': 2.7089136490250696, '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': '2963902', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1576, 'n_words': 309}