<commit_before>import time
import logging
import copy

logger = logging.getLogger(__name__)

from nymms.data_types import NymmsDataType, ValidationError

# state constants
OK = 0
WARN = WARNING = 1
CRIT = CRITICAL = 2
UNKNOWN = 3

# Anything over state 2 is unknown
states = ['ok', 'warning', 'critical', 'unknown']

# state type constants
SOFT = 0
HARD = 1

state_types = ['soft', 'hard']


def get_state_type_name(state_type_code):
    return state_types[state_type_code]


def get_state_name(state_code):
    if state_code > 3:
        return "unknown"
    return states[state_code]


def validate_state(state):
    value = state
    exc = ValidationError('state', value)
    if isinstance(value, basestring):
        try:
            return states.index(value.lower())
        except ValueError:
            raise exc
    elif isinstance(value, int):
        if value > 0:
            return value
    raise exc


def validate_state_type(state_type):
    value = state_type
    exc = ValidationError('state_type', value)
    if isinstance(value, basestring):
        try:
            return state_types.index(value.lower())
        except ValueError:
            raise exc
    elif isinstance(value, int):
        try:
            return state_types[value] and value
        except IndexError:
            raise exc
    raise exc<commit_msg>0 state is good as well<commit_after>import time
import logging
import copy

logger = logging.getLogger(__name__)

from nymms.data_types import NymmsDataType, ValidationError

# state constants
OK = 0
WARN = WARNING = 1
CRIT = CRITICAL = 2
UNKNOWN = 3

# Anything over state 2 is unknown
states = ['ok', 'warning', 'critical', 'unknown']

# state type constants
SOFT = 0
HARD = 1

state_types = ['soft', 'hard']


def get_state_type_name(state_type_code):
    return state_types[state_type_code]


def get_state_name(state_code):
    if state_code > 3:
        return "unknown"
    return states[state_code]


def validate_state(state):
    value = state
    exc = ValidationError('state', value)
    if isinstance(value, basestring):
        try:
            return states.index(value.lower())
        except ValueError:
            raise exc
    elif isinstance(value, int):
        if value >= 0:
            return value
    raise exc


def validate_state_type(state_type):
    value = state_type
    exc = ValidationError('state_type', value)
    if isinstance(value, basestring):
        try:
            return state_types.index(value.lower())
        except ValueError:
            raise exc
    elif isinstance(value, int):
        try:
            return state_types[value] and value
        except IndexError:
            raise exc
    raise exc
{'fraction_non_alphanumeric': 0.08478341355053684, 'fraction_numerical': 0.007034431691965938, 'mean_word_length': 2.7632311977715878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5583940', 'n_tokens_mistral': 810, 'n_tokens_neox': 783, 'n_words': 238}