<commit_before># -*- coding: utf-8 -*-
from datetime import datetime
import hec.heclib
from hec.heclib.util import HecTime
import hec.io
import os
from os import path


def relativeFolder(folder, dssFilePath, createFolder='ifrelative'):
    """
    Return an absolute path to ``folder`` relative to ``dssFilePath``.
    
    If the path ``folder`` is already absolute, it will simply return the path. ``createFolder`` is one of
    'ifrelative', 'ifabsolute' or 'allways'.
    """
    if path.isabs(folder):
        absPath = folder
        if not path.isdir(absPath) and createFolder.lower() in ['allways', 'ifabsolute']:
            os.mkdir(absPath)
    else:
        absPath = path.join(path.dirname(dssFilePath), folder)
        if not path.isdir(absPath) and createFolder.lower() in ['allways', 'ifrelative']:
            os.mkdir(absPath)
    return absPath


class ValidationError(Exception):
    """
    An error while validating data.
    
    Based on :class:`django.core.exceptions.ValidationError`. Copyright © Django Software Foundation and individual 
    contributors. All rights reserved.
    """
    
    def __init__(self, message):
        """
        The ``message`` argument can be a single error, a list of errors. What we define as an "error" can be either 
        a simple string or an instance of ValidationError with its message attribute set, and what we define as
        list can be an actual `list` or an instance of :class:`ValidationError` with its :attr:`.error_list`` attribute
        set.
        """

        if isinstance(message, ValidationError):
            message = message.message
        
        elif isinstance(message, list):
            self.error_list = []
            for message in message:
                if not isinstance(message, ValidationError):
                    message = ValidationError(message)
                self.error_list.extend(message.error_list)
        
        else:
            self.message = message
            self.error_list = [self]
            
    def __getitem__(self, index):
        return self.error_list[index]
            
    def __str__(self):
        return repr(list(self))

    def __repr__(self):
        return "ValidationError(%r)" % self.message
    

class CancelledError(Exception):
    """Operation cancellation/interruption by the user."""

    
def _tscFromRecord(record):
    """
    Convert simple records object to HEC timeseries container
    
    :param record: Record object
    :type record: :class:`monitoring.Record`
    """   
    
    tsc = hec.io.TimeSeriesContainer()
    tsc.watershed = record.site
    tsc.location = record.location
    tsc.parameter = record.parameter
    tsc.version = record.version
    tsc.interval = record.interval
    tsc.fullName = record.fullName
    tsc.values = record.values
    tsc.times = record.times
    tsc.startTime = record.startTime
    tsc.endTime = record.endTime
    tsc.numberValues = len(record)
    tsc.units = record.units
    tsc.type = record.type<commit_msg>code formatting<commit_after># -*- coding: utf-8 -*-
import hec.heclib
import hec.io
import os
from datetime import datetime
from hec.heclib.util import HecTime
from os import path


def relativeFolder(folder, dssFilePath, createFolder='ifrelative'):
    """
    Return an absolute path to ``folder`` relative to ``dssFilePath``.
    
    If the path ``folder`` is already absolute, it will simply return the path. 
    ``createFolder`` is one of 'ifrelative', 'ifabsolute' or 'allways'.
    """
    if path.isabs(folder):
        absPath = folder
        if not path.isdir(absPath) and createFolder.lower() in ['allways', 'ifabsolute']:
            os.mkdir(absPath)
    else:
        absPath = path.join(path.dirname(dssFilePath), folder)
        if not path.isdir(absPath) and createFolder.lower() in ['allways', 'ifrelative']:
            os.mkdir(absPath)
    return absPath


class ValidationError(Exception):
    """An error while validating data."""
    

class CancelledError(Exception):
    """Operation cancellation/interruption by the user."""

    
def _tscFromRecord(record):
    """
    Convert simple records object to HEC timeseries container
    
    :param record: Record object
    :type record: :class:`monitoring.Record`
    """   
    
    tsc = hec.io.TimeSeriesContainer()
    tsc.watershed = record.site
    tsc.location = record.location
    tsc.parameter = record.parameter
    tsc.version = record.version
    tsc.interval = record.interval
    tsc.fullName = record.fullName
    tsc.values = record.values
    tsc.times = record.times
    tsc.startTime = record.startTime
    tsc.endTime = record.endTime
    tsc.numberValues = len(record)
    tsc.units = record.units
    tsc.type = record.type
{'fraction_non_alphanumeric': 0.10086333965045273, 'fraction_numerical': 0.0004211412929037692, 'mean_word_length': 2.7022603273577555, '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': '5679977', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1338, 'n_words': 395}