<commit_before>#####################################################################
## 
## gradefiles-assemble.py
##
##   Script template for assembling a collection of gradefiles from
##   a collection of graded submissions (processed using the grading
##   script).
##
##

import os                 # File/folder work (walk, path, system).
from shutil import rmtree # Deleting a folder.

#####################################################################
## Script to extract grade information from a compelted grade sheet.
##

def summary(txt):
    summary = []
    summary += [txt.split('Total:')[1].strip().split('/')[0]]

    if (txt.find('Extra credit:') != -1):
        summary += [txt.split('Extra credit:')[1].split('\n')[0].replace('+','').strip()]
    else:
        summary += [' ']

    if (txt.find('Late penalty:') != -1):
        summary += ['-'+txt.split('Late penalty:')[1].split('\n')[0].replace('-','').strip()]
    else:
        summary += [' ']

    return "\t".join(summary)

#####################################################################
## Convert every file into a gradefile ready for the gradefiles-push
## script; simultaneously display the columns for the grade sheet.
##

# Check if source directory exists.
if os.path.exists('./processed'):

    # Create and clear destination folder.
    if os.path.exists('./grades'):
        rmtree('grades')
    os.makedirs('grades')

    count = 0
    for curdir, dirs, files in os.walk('./processed/'):
        for file in files:
            txt = open('./processed/'+file, 'r').read().replace('"""', "'''").split("'''")
            if len(txt) >= 2:
                txt = txt[1]
                name = file.split('.')[0]
                target = './grades/'+name+'.py'
                open(target, 'w').write(txt[1:])
                print('Wrote file: ' + target + '\t' + summary(txt))
                count += 1

# Display count for double-checking purposes.
print('Wrote ' + str(count) + ' files.')

#eof
<commit_msg>Add code for computing grade file text totals<commit_after>#####################################################################
## 
## gradefiles-assemble.py
##
##   Script template for assembling a collection of grade files from
##   a collection of graded submissions (processed using the grading
##   script).
##
##

import os                 # File/folder work (walk, path, system).
from shutil import rmtree # Deleting a folder.

#####################################################################
## Script to extract grade information from a completed grade file.
##

def summary(txt):
    summary = []
    summary += [txt.split('Total:')[1].strip().split('/')[0]]

    if (txt.find('Extra credit:') != -1):
        summary += [txt.split('Extra credit:')[1].split('\n')[0].replace('+','').strip()]
    else:
        summary += [' ']

    if (txt.find('Late penalty:') != -1):
        summary += ['-'+txt.split('Late penalty:')[1].split('\n')[0].replace('-','').strip()]
    else:
        summary += [' ']

    return "\t".join(summary)

def total(txt):
    # Add the total score to the grade file raw text by computing
    # the sum of the component scores.
    lines = txt.split("\n")
    total = 0
    for line in lines:
        if line.find("/") != -1:
            total += int(line.split("/")[0][-2:])
    return txt + "Total:                         " + str(total).rjust(3) + "/100\n"

#####################################################################
## Convert every file into a gradefile ready for the gradefiles-push
## script; simultaneously display the column values for the grades
## spreadsheet.
##

# Check if source directory exists.
if os.path.exists('./processed'):

    # Create and clear destination folder.
    if os.path.exists('./grades'):
        rmtree('grades')
    os.makedirs('grades')

    count = 0
    for curdir, dirs, files in os.walk('./processed/'):
        for file in files:
            txt = open('./processed/'+file, 'r').read().replace('"""', "'''").split("'''")
            if len(txt) >= 2:
                txt = txt[1] # Or "addTotal(txt[1])".
                name = file.split('.')[0]
                target = './grades/'+name+'.py'
                open(target, 'w').write(txt[1:])
                print('Wrote file: ' + target + '\t' + summary(txt))
                count += 1

# Display count for double-checking purposes.
print('Wrote ' + str(count) + ' files.')

#eof

{'fraction_non_alphanumeric': 0.2608891897991424, 'fraction_numerical': 0.008350259535093659, 'mean_word_length': 2.8075601374570445, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '773932', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1224, 'n_words': 345}