<commit_before>import desisurvey
import desisurvey.tiles
import desisurvey.rules
import desisurvey.plan
import desisurvey.scheduler
import desiutil.log
import re
import os
import shutil
import subprocess
from desisurvey.scripts import collect_etc
import desimodel.io
import numpy as np


def yesno(question):
    """Simple Yes/No Function."""
    prompt = f'{question}? (y/n): '
    ans = input(prompt).strip().lower()
    if ans not in ['y', 'n', 'yes', 'no']:
        print(f'{ans} is invalid, please try again...')
        return yesno(question)
    if ans == 'y':
        return True
    return False


def afternoon_plan(night=None, exposures=None,
                   configfn='config.yaml',
                   spectra_dir=None,
                   desisurvey_output=None, nts_dir=None, sv=False,
                   surveyops=None):
    """Perform daily afternoon planning.

    Afternoon planning identifies tiles available for observation and assigns
    priorities.  It must be performed before the NTS can identify new tiles to
    observe.

    Params
    ------
    night : str
        Night to plan (YYYMMDD).  Default tonight.

    exposures : str
        File name of exposures file to restore.  Default of None looks in
        $SURVEYOPS/ops/exposures.csv.

    configfn : str
        File name of desisurvey config to use for plan.

    spectra_dir : str
        Directory where spectra are found.

    desisurvey_output : str
        Afternoon planning config is stored to desisurvey_output/{night}/.
        Default to DESISURVEY_OUTPUT if None.

    nts_dir : str
        Store afternoon planning to desisurvey_output/{nts_dir} rather than
        to desisurvey_output/{night}.
        Default to None.

    sv : bool
        if True, trigger special tweaking of OBSCONDITIONS in tile file,
        donefrac in status file.

    surveyops : str
        surveyops SVN directory.  Default of None triggers looking at the
        SURVEYOPS environment variable.
    """
    log = desiutil.log.get_logger()
    if night is None:
        night = desisurvey.utils.get_current_date()
    else:
        night = desisurvey.utils.get_date(night)
    nightstr = desisurvey.utils.night_to_str(night)

    if desisurvey_output is None:
        if os.environ.get('DESISURVEY_OUTPUT') is None:
            log.error('Must set environment variable '
                      'DESISURVEY_OUTPUT!')
            return
        desisurvey_output = os.environ['DESISURVEY_OUTPUT']

    if os.path.exists(configfn):
        dirname, fname = os.path.split(configfn)
        if dirname == '':
            configfn = './'+configfn
    else:
        configfn = os.path.join(desisurvey_output, configfn)

    config = desisurvey.config.Configuration(configfn)
    nts_survey = config.survey()

    if nts_dir is None:
        subdir = nightstr + '-' + nts_survey.lower()
    else:
        subdir = nts_dir
    directory = os.path.join(desisurvey_output, subdir)
    if not os.path.exists(directory):
        os.mkdir(directory)
        os.chmod(directory, 0o2777)

    surveyopsdir = (surveyops if surveyops is not None
                    else os.environ.get('SURVEYOPS', None))
    if surveyopsdir is not None:
        ret = subprocess.run(['svn', 'up',
                              os.path.join(surveyopsdir, 'ops')])
        ret = subprocess.run(
            ['svn', 'up',
             os.path.join(surveyopsdir, 'mtl', 'mtl-done-tiles.csv')])
        if ret.returncode != 0:
            log.info('Failed to update surveyops.')
    else:
        log.info('SURVEYOPS directory not found; not performing '
                 'surveyops updates.')
<commit_msg>Fix typo in name of mtl-done-tiles file.<commit_after>import desisurvey
import desisurvey.tiles
import desisurvey.rules
import desisurvey.plan
import desisurvey.scheduler
import desiutil.log
import re
import os
import shutil
import subprocess
from desisurvey.scripts import collect_etc
import desimodel.io
import numpy as np


def yesno(question):
    """Simple Yes/No Function."""
    prompt = f'{question}? (y/n): '
    ans = input(prompt).strip().lower()
    if ans not in ['y', 'n', 'yes', 'no']:
        print(f'{ans} is invalid, please try again...')
        return yesno(question)
    if ans == 'y':
        return True
    return False


def afternoon_plan(night=None, exposures=None,
                   configfn='config.yaml',
                   spectra_dir=None,
                   desisurvey_output=None, nts_dir=None, sv=False,
                   surveyops=None):
    """Perform daily afternoon planning.

    Afternoon planning identifies tiles available for observation and assigns
    priorities.  It must be performed before the NTS can identify new tiles to
    observe.

    Params
    ------
    night : str
        Night to plan (YYYMMDD).  Default tonight.

    exposures : str
        File name of exposures file to restore.  Default of None looks in
        $SURVEYOPS/ops/exposures.csv.

    configfn : str
        File name of desisurvey config to use for plan.

    spectra_dir : str
        Directory where spectra are found.

    desisurvey_output : str
        Afternoon planning config is stored to desisurvey_output/{night}/.
        Default to DESISURVEY_OUTPUT if None.

    nts_dir : str
        Store afternoon planning to desisurvey_output/{nts_dir} rather than
        to desisurvey_output/{night}.
        Default to None.

    sv : bool
        if True, trigger special tweaking of OBSCONDITIONS in tile file,
        donefrac in status file.

    surveyops : str
        surveyops SVN directory.  Default of None triggers looking at the
        SURVEYOPS environment variable.
    """
    log = desiutil.log.get_logger()
    if night is None:
        night = desisurvey.utils.get_current_date()
    else:
        night = desisurvey.utils.get_date(night)
    nightstr = desisurvey.utils.night_to_str(night)

    if desisurvey_output is None:
        if os.environ.get('DESISURVEY_OUTPUT') is None:
            log.error('Must set environment variable '
                      'DESISURVEY_OUTPUT!')
            return
        desisurvey_output = os.environ['DESISURVEY_OUTPUT']

    if os.path.exists(configfn):
        dirname, fname = os.path.split(configfn)
        if dirname == '':
            configfn = './'+configfn
    else:
        configfn = os.path.join(desisurvey_output, configfn)

    config = desisurvey.config.Configuration(configfn)
    nts_survey = config.survey()

    if nts_dir is None:
        subdir = nightstr + '-' + nts_survey.lower()
    else:
        subdir = nts_dir
    directory = os.path.join(desisurvey_output, subdir)
    if not os.path.exists(directory):
        os.mkdir(directory)
        os.chmod(directory, 0o2777)

    surveyopsdir = (surveyops if surveyops is not None
                    else os.environ.get('SURVEYOPS', None))
    if surveyopsdir is not None:
        ret = subprocess.run(['svn', 'up',
                              os.path.join(surveyopsdir, 'ops')])
        ret = subprocess.run(
            ['svn', 'up',
             os.path.join(surveyopsdir, 'mtl', 'mtl-done-tiles.ecsv')])
        if ret.returncode != 0:
            log.info('Failed to update surveyops.')
    else:
        log.info('SURVEYOPS directory not found; not performing '
                 'surveyops updates.')

{'fraction_non_alphanumeric': 0.09131859131859132, 'fraction_numerical': 0.001638001638001638, 'mean_word_length': 2.3093947606142726, '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': '5202995', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2214, 'n_words': 622}