<commit_before># -*- coding: utf-8 -*-
"""
@author: drsmith-wisc
"""

from os import getenv
import pymssql
import numpy as np

server = 'sql2008.pppl.gov\sql2008'
username = getenv('USER') or getenv('USERNAME')
password = '<PASSWORD>'
database = 'nstxlogs'
port = '62917'

try:
    connection = pymssql.connect(server=server, user=username,
                                 password=password, database=database,
                                 port=port, as_dict=True)
except:
    connection = pymssql.connect(server=server, user='drsmith',
                                 password=password, database=database,
                                 port=port, as_dict=True)

shot_query_prefix = ('SELECT username, rundate, shot, xp, topic, text, entered, voided '
                     'FROM entries '
                     'WHERE voided IS null')

shotlist_query_prefix = ('SELECT DISTINCT rundate, shot, xp, voided '
                         'FROM entries '
                         'WHERE voided IS null')


def iterable(obj):
    try:
        iter(obj)
        if type(obj) is str:
            return False
        return True
    except TypeError:
        return False


def get_shotlist(rundate=[], xp=[], verbose=False):
    cursor = connection.cursor()
    cursor.execute('SET ROWCOUNT 80')

    shotlist = []   # start with empty shotlist
    rundate_list = rundate
    if not iterable(rundate_list):      # if it's just a single date
        rundate_list = [rundate_list]   # put it into a list
    for rundate in rundate_list:
        query = ('{} and rundate={} ORDER BY shot ASC'.
                 format(shotlist_query_prefix, rundate))

        cursor.execute(query)

        rows = cursor.fetchall()
        if verbose:
            print('Rundate {}'.format(rundate))
            for row in rows:
                print('   {} in XP {}'.format(row['shot'], row['xp']))
        shotlist.extend([row['shot'] for row in rows  # add shots to shotlist
                        if row['shot'] is not None])

    xp_list = xp
    if not iterable(xp_list):           # if it's just a single xp
        xp_list = [xp_list]             # put it into a list
    for xp in xp_list:
        query = ('{} and xp={} ORDER BY shot ASC'.
                 format(shotlist_query_prefix, xp))

        cursor.execute(query)

        rows = cursor.fetchall()
        if verbose:
            print('XP {}'.format(xp))
            for row in rows:
                print('   {} on rundate {}'.
                      format(row['shot'], row['rundate']))
        shotlist.extend([row['shot'] for row in rows  # add shots to shotlist
                        if row['shot'] is not None])
<commit_msg>updated format statement<commit_after># -*- coding: utf-8 -*-
"""
@author: drsmith-wisc
"""

from os import getenv
import pymssql
import numpy as np

server = 'sql2008.pppl.gov\sql2008'
username = getenv('USER') or getenv('USERNAME')
password = '<PASSWORD>'
database = 'nstxlogs'
port = '62917'

try:
    connection = pymssql.connect(server=server, user=username,
                                 password=password, database=database,
                                 port=port, as_dict=True)
except:
    connection = pymssql.connect(server=server, user='drsmith',
                                 password=password, database=database,
                                 port=port, as_dict=True)

shot_query_prefix = ('SELECT username, rundate, shot, xp, topic, text, entered, voided '
                     'FROM entries '
                     'WHERE voided IS null')

shotlist_query_prefix = ('SELECT DISTINCT rundate, shot, xp, voided '
                         'FROM entries '
                         'WHERE voided IS null')


def iterable(obj):
    try:
        iter(obj)
        if type(obj) is str:
            return False
        return True
    except TypeError:
        return False


def get_shotlist(rundate=[], xp=[], verbose=False):
    cursor = connection.cursor()
    cursor.execute('SET ROWCOUNT 80')

    shotlist = []   # start with empty shotlist
    rundate_list = rundate
    if not iterable(rundate_list):      # if it's just a single date
        rundate_list = [rundate_list]   # put it into a list
    for rundate in rundate_list:
        query = ('{} and rundate={} ORDER BY shot ASC'.
                 format(shotlist_query_prefix, rundate))

        cursor.execute(query)

        rows = cursor.fetchall()
        if verbose:
            print('Rundate {}'.format(rundate))
            for row in rows:
                print('   {shot} in XP {xp}'.format(**row))
        shotlist.extend([row['shot'] for row in rows  # add shots to shotlist
                        if row['shot'] is not None])

    xp_list = xp
    if not iterable(xp_list):           # if it's just a single xp
        xp_list = [xp_list]             # put it into a list
    for xp in xp_list:
        query = ('{} and xp={} ORDER BY shot ASC'.
                 format(shotlist_query_prefix, xp))

        cursor.execute(query)

        rows = cursor.fetchall()
        if verbose:
            print('XP {}'.format(xp))
            for row in rows:
                print('   {shot} on rundate {rundate}'.format(**row))
        shotlist.extend([row['shot'] for row in rows  # add shots to shotlist
                        if row['shot'] is not None])

{'fraction_non_alphanumeric': 0.10923423423423423, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 1.8650537634408602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '599031', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1516, 'n_words': 450}