Skip to content
Snippets Groups Projects
Commit 54569673 authored by tuhe's avatar tuhe
Browse files

updates

parent f01174d7
Branches
No related tags found
No related merge requests found
Showing
with 798 additions and 5 deletions
No preview for this file type
...@@ -5,7 +5,7 @@ from unitgrade_private.docker_helpers import compile_docker_image ...@@ -5,7 +5,7 @@ from unitgrade_private.docker_helpers import compile_docker_image
if __name__ == "__main__": if __name__ == "__main__":
## Step 1. Deploy the report file. ## Step 1. Deploy the report file.
# from report2_test import Report2 # from report2_test import Report2
from report1intro import Report1Flat from looping_tests import Report1Flat
from stones_tests import StoneReport from stones_tests import StoneReport
from unitgrade_private.hidden_create_files import setup_grade_file_report from unitgrade_private.hidden_create_files import setup_grade_file_report
from snipper.snip_dir import snip_dir from snipper.snip_dir import snip_dir
...@@ -26,12 +26,12 @@ if __name__ == "__main__": ...@@ -26,12 +26,12 @@ if __name__ == "__main__":
# Step 2: Create the cs102.tar file from the grade scripts. #!s=b # Step 2: Create the cs102.tar file from the grade scripts. #!s=b
instructor_base = f"../02105/instructor/week2" instructor_base = f"../02105/instructor/week2"
student_base = "../02631/instructor/week5" student_base = "../02105/students/week2"
from report2_test import Report2
# INSTRUCTOR_GRADE_FILE = # INSTRUCTOR_GRADE_FILE =
description = """ Hand in the file 'stones.py'. You can find the full example, including solution, here <a href="https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples/02631/instructor/week5">here</a>""" description = """ Hand in the file stones.py. You can find the full example, including solution, at https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples/02105/instructor/week2 """
output_tar = new_deploy_assignment("02105week2", # Autolab name of assignment (and name of .tar file) # description = "This is the stones-problem"
output_tar = new_deploy_assignment("c02105week2", # Autolab name of assignment (and name of .tar file)
INSTRUCTOR_BASE=instructor_base, INSTRUCTOR_BASE=instructor_base,
INSTRUCTOR_GRADE_FILE=f"{instructor_base}/stones_tests_grade.py", INSTRUCTOR_GRADE_FILE=f"{instructor_base}/stones_tests_grade.py",
STUDENT_BASE=student_base, STUDENT_BASE=student_base,
...@@ -39,6 +39,19 @@ if __name__ == "__main__": ...@@ -39,6 +39,19 @@ if __name__ == "__main__":
homework_file="stones.py", homework_file="stones.py",
description=description) description=description)
instructor_base = f"../02631/instructor/week5"
student_base = "../02631/students/week5"
# INSTRUCTOR_GRADE_FILE =
description = """ Hand in the file stones.py. You can find the full example, including solution, at https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples/02631/instructor/week5 """
# description = "This is the stones-problem"
output_tar = new_deploy_assignment("c02631week5", # Autolab name of assignment (and name of .tar file)
INSTRUCTOR_BASE=instructor_base,
INSTRUCTOR_GRADE_FILE=f"{instructor_base}/looping_tests_grade.py",
STUDENT_BASE=student_base,
autograde_image_tag=autograde_image,
homework_file="looping.py",
description=description)
# STUDENT_GRADE_FILE=f"{instructor_base}/stones_tests_grade.py", # STUDENT_GRADE_FILE=f"{instructor_base}/stones_tests_grade.py",
# What can you do? Get a report class from the .token file? # What can you do? Get a report class from the .token file?
......
File added
File added
This diff is collapsed.
all:
tar xf autograde.tar
cp stones.py 02105week2-handout
(cd 02105week2-handout; python3 driver_python.py)
clean:
rm -rf *~ 02105week2-handout
\ No newline at end of file
from stones_tests import StoneReport
from unitgrade_private.hidden_create_files import setup_grade_file_report
from snipper import snip_dir
if __name__ == "__main__":
setup_grade_file_report(StoneReport, minify=False, obfuscate=False, execute=False, with_coverage=True)
# Deploy the files using snipper: https://gitlab.compute.dtu.dk/tuhe/snipper
snip_dir(source_dir="", dest_dir="../../students/week2", exclude=['*.token', 'deploy.py'])
import os
import glob
import shutil
import sys
import subprocess
from unitgrade_private.autolab.autolab import format_autolab_json
from unitgrade_private.docker_helpers import student_token_file_runner
from unitgrade_private import load_token
import time
import unitgrade_private
verbose = False
tag = "[driver_python.py]"
if not verbose:
print("="*10)
print(tag, "Starting unitgrade evaluation...")
import unitgrade
print(tag, "Unitgrade version", unitgrade.version.__version__)
print(tag, "Unitgrade-devel version", unitgrade_private.version.__version__)
sys.stderr = sys.stdout
wdir = os.getcwd()
def pfiles():
print("> Files in dir:")
for f in glob.glob(wdir + "/*"):
print(f)
print("---")
handin_filename = "stones.py"
student_token_file = 'StoneReport_handin.token'
instructor_grade_script = 'stones_tests_grade.py'
grade_file_relative_destination = "stones_tests_grade.py"
host_tmp_dir = wdir + "/tmp"
homework_file = "stones.py"
# homework_file = "stones.py"
student_should_upload_token = False # Add these from template.
if not verbose:
pfiles()
print(f"{host_tmp_dir=}")
print(f"{student_token_file=}")
print(f"{instructor_grade_script=}")
print("Current directory", os.getcwd())
print("student_token_file", student_token_file)
for f in glob.glob(os.getcwd() + "/*"):
print(f)
try:
# This is how we get the student file structure.
command, host_tmp_dir, token = student_token_file_runner(host_tmp_dir, student_token_file, instructor_grade_script,
grade_file_relative_destination)
# run the stuff.
if not student_should_upload_token:
""" Add the student homework to the right location. """
print("Moving uploaded file from", os.path.basename(handin_filename), "to", handin_filename)
# print("file exists?", os.path.isfile(os.path.basename(handin_filename)))
shutil.move(os.path.basename(handin_filename), host_tmp_dir + "/" + handin_filename)
command = f"cd tmp && {command} --noprogress --autolab"
def rcom(cm):
rs = subprocess.run(cm, capture_output=True, text=True, shell=True)
print(rs.stdout)
if len(rs.stderr) > 0:
print(tag, "There were errors in executing the file:")
print(rs.stderr)
start = time.time()
rcom(command)
ls = glob.glob(token)
f = ls[0]
results, _ = load_token(ls[0])
except Exception as e:
if not student_should_upload_token:
print(tag, "A major error occured while starting unitgrade.")
print(tag, "This can mean the grader itself is badly configured, or (more likely) that you submitted a completely wrong file.")
print(tag, "The following is the content of the file you uploaded; is it what you expect?")
with open(host_tmp_dir + "/" + handin_filename, 'r') as f:
print( f.read() )
print(" ")
print(tag, "If you cannot resolve the problem, please contact the teacher and include details such as this log, as well as the file you submitted.")
raise e
if verbose:
print(tag, f"{token=}")
print(tag, results['total'])
format_autolab_json(results)
\ No newline at end of file
def maximum_stones(W, stone_weights):
stone_weights.sort()
T = 0
s = 0
for k, we in enumerate(stone_weights):
T += we
if T <= W:
s = s + 1
else:
break
return s
if __name__ == "__main__":
print("The following call using maximum weight of W=15 should return 5.")
print(maximum_stones(15, [2, 5, 3, 1, 8, 4, 5, 7]))
from unitgrade.framework import Report, UTestCase
from unitgrade.evaluate import evaluate_report_student
import stones
from stones import maximum_stones
# A fancy helper function to generate nicer-looking titles.
def trlist(x):
s = str(list(x))
if len(s) > 30:
s = s[:30] + "...]"
return s
class Stones(UTestCase):
""" Test of the Stones function """
def stest(self, W, stone_weights): # Helper function.
N = maximum_stones(W, stone_weights)
self.title = f"stones({W}, {trlist(stone_weights)}) = {N} ?"
self.assertEqualC(N)
def test_basecase(self):
""" Test the stones-example given in the homework """
N = maximum_stones(15, [2, 5, 3, 1, 8, 4, 5, 7])
self.assertEqual(N, 5) # Test that we can collect 5 stones.
def test_stones1(self):
self.stest(4, [4]) # One stone weighing 4 kg.
def test_stones2(self):
self.stest(4, [1, 4]) # should also give 1
def test_stones3(self):
self.stest(4, [4, 1]) # should also give 1
def test_stones4(self):
self.stest(13, [2, 5, 3, 1, 8, 4, 5, 7])
class StoneReport(Report):
title = "02105 week 2: Stone collection"
questions = [(Stones, 10),]
pack_imports = [stones]
if __name__ == "__main__":
evaluate_report_student(StoneReport())
This diff is collapsed.
File added
File added
from stones_tests import StoneReport
from unitgrade_private.hidden_create_files import setup_grade_file_report
from snipper import snip_dir
if __name__ == "__main__":
setup_grade_file_report(StoneReport, minify=False, obfuscate=False, execute=False, with_coverage=True)
# Deploy the files using snipper: https://gitlab.compute.dtu.dk/tuhe/snipper
snip_dir(source_dir="", dest_dir="../../students/week2", exclude=['*.token', 'deploy.py'])
def maximum_stones(W, stone_weights):
stone_weights.sort()
T = 0
s = 0
for k, we in enumerate(stone_weights):
T += we
if T <= W:
s = s + 1
else:
break
return s
if __name__ == "__main__":
print("The following call using maximum weight of W=15 should return 5.")
print(maximum_stones(15, [2, 5, 3, 1, 8, 4, 5, 7]))
from unitgrade.framework import Report, UTestCase
from unitgrade.evaluate import evaluate_report_student
import stones
from stones import maximum_stones
# A fancy helper function to generate nicer-looking titles.
def trlist(x):
s = str(list(x))
if len(s) > 30:
s = s[:30] + "...]"
return s
class Stones(UTestCase):
""" Test of the Stones function """
def stest(self, W, stone_weights): # Helper function.
N = maximum_stones(W, stone_weights)
self.title = f"stones({W}, {trlist(stone_weights)}) = {N} ?"
self.assertEqualC(N)
def test_basecase(self):
""" Test the stones-example given in the homework """
N = maximum_stones(15, [2, 5, 3, 1, 8, 4, 5, 7])
self.assertEqual(N, 5) # Test that we can collect 5 stones.
def test_stones1(self):
self.stest(4, [4]) # One stone weighing 4 kg.
def test_stones2(self):
self.stest(4, [1, 4]) # should also give 1
def test_stones3(self):
self.stest(4, [4, 1]) # should also give 1
def test_stones4(self):
self.stest(13, [2, 5, 3, 1, 8, 4, 5, 7])
class StoneReport(Report):
title = "02105 week 2: Stone collection"
questions = [(Stones, 10),]
pack_imports = [stones]
if __name__ == "__main__":
evaluate_report_student(StoneReport())
This diff is collapsed.
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment