<commit_before>### This program will collected Med PC data files and match them to a data profile for saving to an excel workbook.
### Preconditions: All data files must have the same structure and fit the same profile.
### It is recommended to open either multiple files with single subjects or one file with multiple subjects.
### Where an MSN has not used the Y2KCOMPLIANT command, the data was collected in the 21st century.

import xlrd
import xlsxwriter
import re
import itertools

def GEToperant(GETprofile, MPCdatafiles, outputfile,
               exportfilename = 1,
               exportstartdate = 1,
               exportenddate = 1,
               exportsubject = 1,
               exportexperiment = 1,
               exportgroup = 1,
               exportbox = 1,
               exportstarttime = 1,
               exportendtime = 1,
               exportmsn = 1):
    '''
    GEToperant takes three arguments:
    GETprofile, which must be an Excel file
    MPCdatafiles, which must be a list of one or more Med-PC data files
    outputfile, which must be an Excel file

    GEToperant will read the data from the MPCdatafiles and will
    output the headers and the data described in GETprofile. It will
    save this in the Excel file specified by outputfile.

    Preconditions: All sessions in each file must have the same data.
    If arrays or variables are present in some of the MPC data but not others
    then this will cause the output data to be sorted incorrectly.
    The profile must be designed according to the instructions in the GUI.
    '''


        ### This first part will read the data profile and develop a series of lists
Label = list()
LabelStartValue = list()
LabelIncrement = list()
ArrayVar = list()
StartElement = list()
ArrayIncrement = list()
StopElement = list()

if 'xlsx' in GETprofile[-4:].lower():
    ### Import an Excel-based GEToperant profile
    profile_xl = xlrd.open_workbook(GETprofile)
    profile_xl_sheets = profile_xl.sheet_names()
    profilesheet = profile_xl.sheet_by_name(profile_xl_sheets[0])

for r in range(1,max(range(profilesheet.nrows))+1):
    cell0 = profilesheet.cell(r,0)
    Label.append(str(cell0).split("\'")[1])
    
    cell1 = profilesheet.cell(r,1)
    if 'empty' in str(cell1):
        LabelStartValue.append(None)
    elif 'number' in str(cell1):
        LabelStartValue.append(int(float(str(cell1).split(":")[1])))

    cell2 = profilesheet.cell(r,2)
    if 'empty' in str(cell2):
        LabelIncrement.append(None)
    elif 'number' in str(cell2):
        LabelIncrement.append(int(float(str(cell2).split(":")[1])))

    cell3 = profilesheet.cell(r,3)
    ArrayVar.append(str(cell3).split("\'")[1])

    cell4 = profilesheet.cell(r,4)
    StartElement.append(int(float(str(cell4).split(":")[1])))

    cell5 = profilesheet.cell(r,5)
    if 'empty' in str(cell5):
        ArrayIncrement.append(None)
    elif 'number' in str(cell5):
        ArrayIncrement.append(int(float(str(cell5).split(":")[1])))

    cell6 = profilesheet.cell(r,6)
    if 'empty' in str(cell6) or 'text' in str(cell6):
        StopElement.append(None)
    elif 'number' in str(cell6):
        StopElement.append(int(float(str(cell6).split(":")[1])))

    elif 'mrp' in GETprofile[-3:].lower():
        rowprofile = open(GETprofile, 'r').readlines()
        for i in range(0, len(rowprofile), 2):
            ### For each label in the MRP, decide if it is a data value, if so, then import it
            row_check = re.search(r'\D\(', rowprofile[i+1])
            if row_check != None:
                Label.append(rowprofile[i][:len(rowprofile[i])-1])
                LabelStartValue.append(None)
                LabelIncrement.append(None)
                ArrayVar.append(rowprofile[i+1][0])
                StartElement.append(int(rowprofile[i+1][2:-2]))<commit_msg>Version 0.93a<commit_after>### This program will collected Med PC data files and match them to a data profile for saving to an excel workbook.
### Preconditions: All data files must have the same structure and fit the same profile.
### It is recommended to open either multiple files with single subjects or one file with multiple subjects.
### Where an MSN has not used the Y2KCOMPLIANT command, the data was collected in the 21st century.

import xlrd
import xlsxwriter
import re
import itertools

def GEToperant(GETprofile, MPCdatafiles, outputfile,
               exportfilename = 1,
               exportstartdate = 1,
               exportenddate = 1,
               exportsubject = 1,
               exportexperiment = 1,
               exportgroup = 1,
               exportbox = 1,
               exportstarttime = 1,
               exportendtime = 1,
               exportmsn = 1):
    '''
    GEToperant takes three arguments:
    GETprofile, which must be an Excel file
    MPCdatafiles, which must be a list of one or more Med-PC data files
    outputfile, which must be an Excel file

    GEToperant will read the data from the MPCdatafiles and will
    output the headers and the data described in GETprofile. It will
    save this in the Excel file specified by outputfile.

    Preconditions: All sessions in each file must have the same data.
    If arrays or variables are present in some of the MPC data but not others
    then this will cause the output data to be sorted incorrectly.
    The profile must be designed according to the instructions in the GUI.
    '''


        ### This first part will read the data profile and develop a series of lists
    Label = list()
    LabelStartValue = list()
    LabelIncrement = list()
    ArrayVar = list()
    StartElement = list()
    ArrayIncrement = list()
    StopElement = list()

    if 'xlsx' in GETprofile[-4:].lower():
        ### Import an Excel-based GEToperant profile
        profile_xl = xlrd.open_workbook(GETprofile)
        profile_xl_sheets = profile_xl.sheet_names()
        profilesheet = profile_xl.sheet_by_name(profile_xl_sheets[0])

        for r in range(1,max(range(profilesheet.nrows))+1):
            cell0 = profilesheet.cell(r,0)
            Label.append(str(cell0).split("\'")[1])
            
            cell1 = profilesheet.cell(r,1)
            if 'empty' in str(cell1):
                LabelStartValue.append(None)
            elif 'number' in str(cell1):
                LabelStartValue.append(int(float(str(cell1).split(":")[1])))

            cell2 = profilesheet.cell(r,2)
            if 'empty' in str(cell2):
                LabelIncrement.append(None)
            elif 'number' in str(cell2):
                LabelIncrement.append(int(float(str(cell2).split(":")[1])))

            cell3 = profilesheet.cell(r,3)
            ArrayVar.append(str(cell3).split("\'")[1])

            cell4 = profilesheet.cell(r,4)
            StartElement.append(int(float(str(cell4).split(":")[1])))

            cell5 = profilesheet.cell(r,5)
            if 'empty' in str(cell5):
                ArrayIncrement.append(None)
            elif 'number' in str(cell5):
                ArrayIncrement.append(int(float(str(cell5).split(":")[1])))

            cell6 = profilesheet.cell(r,6)
            if 'empty' in str(cell6) or 'text' in str(cell6):
                StopElement.append(None)
            elif 'number' in str(cell6):
                StopElement.append(int(float(str(cell6).split(":")[1])))

    elif 'mrp' in GETprofile[-3:].lower():
        rowprofile = open(GETprofile, 'r').readlines()
        for i in range(0, len(rowprofile), 2):
            ### For each label in the MRP, decide if it is a data value, if so, then import it
            row_check = re.search(r'\D\(', rowprofile[i+1])
            if row_check != None:
                Label.append(rowprofile[i][:len(rowprofile[i])-1])
                LabelStartValue.append(None)
                LabelIncrement.append(None)
                ArrayVar.append(rowprofile[i+1][0])
                StartElement.append(int(rowprofile[i+1][2:-2]))
{'fraction_non_alphanumeric': 0.10499117721199899, 'fraction_numerical': 0.01651121754474414, 'mean_word_length': 2.5727149932462856, 'pattern_counts': {'":': 10, '<': 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': '291089', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2291, 'n_words': 724}