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

updates

parent f01174d7
No related branches found
No related tags found
No related merge requests found
Showing
with 870 additions and 0 deletions
File added
This diff is collapsed.
all:
tar xf autograde.tar
cp stones.py c02105week2-handout
(cd c02105week2-handout; python3 driver_python.py)
clean:
rm -rf *~ c02105week2-handout
\ No newline at end of file
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
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())
File added
require "AssessmentBase.rb"
module C02105week2
include AssessmentBase
def assessmentInitialize(course)
super("c02105week2",course)
@problems = []
end
end
\ No newline at end of file
---
general:
name: c02105week2
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 '
display_name: '02105 week 2: Stone collection'
handin_filename: stones.py
handin_directory: handin
max_grace_days: 0
handout: c02105week2-handout.zip
writeup: writeup/writeup.html
max_submissions: -1
disable_handins: false
max_size: 2
has_svn: false
category_name: Lab
problems:
- name: Unitgrade score
description: 'Score obtained by automatic grading'
max_score: 10
optional: false
- name: Written feedback
description: 'Written (TA) feedback'
max_score: 0
optional: true
autograder:
autograde_timeout: 180
autograde_image: tango_python_tue2
release_score: true
# problems:
# - name: Correctness
# description: ''
# max_score: 100.0
# optional: false
\ No newline at end of file
# Makefile for the Hello Lab
all:
echo "Makefile called... it is empty so far. "
#gcc hello3.c -o hello3
clean:
rm -rf *~ hello3
# Makefile for the Hello Lab
all:
echo "Makefile called... it is empty so far. "
#gcc hello3.c -o hello3
clean:
rm -rf *~ hello3
This directory contains all of the code files for the Hello Lab,
including the files that are handed out to students.
Files:
# Autograder and solution files
Makefile Makefile and ...
README ... README for this directory
driver.sh* Autograder
hello.c Solution hello.c file
# Files that are handed out to students
Makefile-handout Makefile and ...
README-handout ... README handed out to students
hello.c-handout Blank hello.c file handed out to students
This directory contains all of the code files for the Hello Lab,
including the files that are handed out to students.
Files:
# Autograder and solution files
Makefile Makefile and ...
README ... README for this directory
driver.sh* Autograder
hello.c Solution hello.c file
# Files that are handed out to students
Makefile-handout Makefile and ...
README-handout ... README handed out to students
hello.c-handout Blank hello.c file handed out to students
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment