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

Updates

parent dadd26b9
No related branches found
No related tags found
No related merge requests found
Showing
with 563 additions and 24 deletions
"""
Example student code. This file is automatically generated from the files in the instructor-directory
"""
import numpy as np
import itertools
def bacteriaGrowth(n0, alpha, K, N):
"""
Calculate time until bacteria growth exceed N starting from a population of n0 bacteria.
hints:
* consider n0
* alpha > 0
:param n0:
:param alpha:
:param K:
:param N:
:return:
"""
# TODO: 7 lines missing.
raise NotImplementedError("Implement function body")
def clusterAnalysis(reflectance):
reflectance = np.asarray(reflectance)
I1 = np.arange(len(reflectance)) % 2 == 1
while True:
m = np.asarray( [np.mean( reflectance[~I1] ), np.mean( reflectance[I1] ) ] )
I1_ = np.argmin( np.abs( reflectance[:, np.newaxis] - m[np.newaxis, :] ), axis=1) == 1
if all(I1_ == I1):
break
I1 = I1_
return I1 + 1
def fermentationRate(measuredRate, lowerBound, upperBound):
# Insert your code here
return np.mean( [r for r in measuredRate if lowerBound < r < upperBound] )
def removeIncomplete(id):
""" Hints:
* Take a look at the example in the exercise.
"""
id = np.asarray(id)
id2 = []
for i, v in enumerate(id):
if len( [x for x in id if int(x) == int(v) ] ) == 3:
id2.append(v)
return np.asarray(id2)
if __name__ == "__main__":
# I = clusterAnalysis([1.7, 1.6, 1.3, 1.3, 2.8, 1.4, 2.8, 2.6, 1.6, 2.7])
# print(I)
print(fermentationRate(np.array([20.1, 19.3, 1.1, 18.2, 19.7, 121.1, 20.3, 20.0]), 15, 25))
# print(removeIncomplete(np.array([1.3, 2.2, 2.3, 4.2, 5.1, 3.2, 5.3, 3.3, 2.1, 1.1, 5.2, 3.1])))
# Problem 1: Write a function which add two numbers
# clusterAnalysis([2, 1, 2, 4, 5])
"""
Example student code. This file is automatically generated from the files in the instructor-directory
"""
from src.unitgrade2.unitgrade2 import Report, UTestCase, cache
from src.unitgrade2 import evaluate_report_student
import numpy as np
import looping
from looping import bacteriaGrowth, clusterAnalysis, removeIncomplete, fermentationRate
def trlist(x):
s = str(list(x))
if len(s) > 30:
s = s[:30] + "...]"
return s
class Bacteria(UTestCase):
""" Bacteria growth rates """
def stest(self, n0, alpha, K, N):
g = bacteriaGrowth(n0=n0, alpha=alpha, K=K, N=N)
self.title = f"bacteriaGrowth({n0}, {alpha}, {K}, {N}) = {g} ?"
self.assertEqualC(g)
def test_growth1(self):
""" Hints:
* Make sure to frobulate the frobulator.
"""
self.stest(100, 0.4, 1000, 500)
def test_growth2(self):
self.stest(10, 0.4, 1000, 500)
def test_growth3(self):
self.stest(100, 1.4, 1000, 500)
def test_growth4(self):
self.stest(100, 0.0004, 1000, 500)
def test_growth5(self):
"""
hints:
* What happens when n0 > N? (in this case return t=0) """
self.stest(100, 0.4, 1000, 99)
class ClusterAnalysis(UTestCase):
""" Test the cluster analysis method """
def stest(self, n, seed):
np.random.seed(seed)
x = np.round(np.random.rand(n), 1)
I = clusterAnalysis(x)
self.title = f"clusterAnalysis({list(x)}) = {list(I)} ?"
self.assertEqualC(list(I))
def test_cluster1(self):
""" Hints:
* Make sure to frobulate the frobulator.
* Just try harder
"""
self.stest(3, 10)
def test_cluster2(self):
self.stest(4, 146)
def test_cluster3(self):
self.stest(5, 12)
def test_cluster4(self):
"""
Cluster analysis for tied lists
Hints:
* It may be that an observations has the same distance to the two clusters. Where do you assign it in this case?
"""
x = np.array([10.0, 12.0, 10.0, 12.0, 9.0, 11.0, 11.0, 13.0])
self.assertEqualC(list(clusterAnalysis(x) ) )
class RemoveIncomplete(UTestCase):
""" Remove incomplete IDs """
def stest(self, x):
I = list( removeIncomplete(x) )
self.title = f"removeId({trlist(x)}) = {trlist(I)} ?"
self.assertEqualC(I)
@cache
def rseq(self, max, n):
np.random.seed(42)
return np.random.randint(max, size=(n,) ) + (np.random.randint(2, size=(n,) )+1)/10
def test_incomplete1(self):
self.stest( np.array([1.3, 2.2, 2.3, 4.2, 5.1, 3.2, 5.3, 3.3, 2.1, 1.1, 5.2, 3.1]) )
def test_incomplete2(self):
self.stest( np.array([1.1, 1.2, 1.3, 2.1, 2.2, 2.3]) )
def test_incomplete3(self):
self.stest(np.array([5.1, 5.2, 4.1, 4.3, 4.2, 8.1, 8.2, 8.3]) )
def test_incomplete4(self):
self.stest(np.array([1.1, 1.3, 2.1, 2.2, 3.1, 3.3, 4.1, 4.2, 4.3]) )
def test_incomplete5(self):
self.stest(self.rseq(10, 40))
class FermentationRate(UTestCase):
""" Test the fermentation rate question """
def stest(self, x, lower, upper):
I = fermentationRate(x, lower, upper)
s = trlist(x)
self.title = f"fermentationRate({s}, {lower}, {upper}) = {I:.3f} ?"
self.assertEqualC(I)
@cache
def rseq(self, max, n):
np.random.seed(42)
return np.random.randint(max, size=(n,) ) + (np.random.randint(3, size=(n,) )+1)/n
def test_rate1(self):
self.stest(np.array([20.1, 19.3, 1.1, 18.2, 19.7, 121.1, 20.3, 20.0]), 15, 25)
def test_rate2(self):
self.stest(np.array([20.1, 19.3, 1.1, 18.2, 19.7, 121.1, 20.3, 20.0]), 1, 200)
def test_rate3(self):
self.stest(np.array([1.75]), 1, 2)
def test_rate4(self):
self.stest(np.array([20.1, 19.3, 1.1, 18.2, 19.7, 121.1, 20.3, 20.0]), 18.2, 20)
class Report1Flat(Report):
title = "Week 4: Looping"
questions = [(ClusterAnalysis, 10), (RemoveIncomplete, 10), (Bacteria, 10), (FermentationRate, 10),]
pack_imports = [looping]
if __name__ == "__main__":
# Uncomment to simply run everything as a unittest:
# unittest.main(verbosity=2)
evaluate_report_student(Report1Flat())
This diff is collapsed.
File added
File added
File added
File added
import os
from autolab.autolab import deploy_assignment
from unitgrade_private2.autolab.autolab import deploy_assignment
if __name__ == "__main__":
wdir = os.getcwd()
args = [('example_simplest', 'cs101', 'report1_grade.py', 'report1_grade.py'),
args = [('example_simplest', 'programs', 'report1_grade.py', 'report1_grade.py'),
('example_framework', 'cs102', 'report2_grade.py', 'report2_grade.py'),
('example_docker', 'cs103', 'report3_complete_grade.py', 'report3_grade.py'),
]
......
---
general:
name: cs101
name: programs
description: ''
display_name: CS 101 Report 1
handin_filename: Report1_handin.token
handin_directory: handin
max_grace_days: 0
handout: cs101-handout.tar
writeup: writeup/cs101.html
handout: programs-handout.tar
writeup: writeup/programs.html
max_submissions: -1
disable_handins: false
max_size: 2
......
......@@ -25,7 +25,7 @@ def pfiles():
student_token_file = 'Report1_handin.token'
instructor_grade_script = 'report1_grade.py'
grade_file_relative_destination = "cs101\report1_grade.py"
grade_file_relative_destination = "programs\report1_grade.py"
with open(student_token_file, 'rb') as f:
results = pickle.load(f)
sources = results['sources'][0]
......@@ -55,8 +55,8 @@ def rcom(cm):
start = time.time()
rcom(command)
# pfiles()
# for f in glob.glob(host_tmp_dir + "/cs101/*"):
# print("cs101/", f)
# for f in glob.glob(host_tmp_dir + "/programs/*"):
# print("programs/", f)
# print("---")
ls = glob.glob(token)
# print(ls)
......
......@@ -55,8 +55,8 @@ def rcom(cm):
start = time.time()
rcom(command)
# pfiles()
# for f in glob.glob(host_tmp_dir + "/cs101/*"):
# print("cs101/", f)
# for f in glob.glob(host_tmp_dir + "/programs/*"):
# print("programs/", f)
# print("---")
ls = glob.glob(token)
# print(ls)
......
......@@ -55,8 +55,8 @@ def rcom(cm):
start = time.time()
rcom(command)
# pfiles()
# for f in glob.glob(host_tmp_dir + "/cs101/*"):
# print("cs101/", f)
# for f in glob.glob(host_tmp_dir + "/programs/*"):
# print("programs/", f)
# print("---")
ls = glob.glob(token)
# print(ls)
......
File added
File added
File added
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -4,25 +4,24 @@ from unitgrade_private2.hidden_create_files import setup_grade_file_report
from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
from unitgrade_private2.deployment import remove_hidden_methods
from unitgrade_private2.docker_helpers import docker_run_token_file
import shutil
import os
import glob
import pickle
from snipper.snip_dir import snip_dir
wd = os.path.dirname(__file__)
def deploy_student_files():
setup_grade_file_report(Report3, minify=False, obfuscate=False, execute=False)
# Report3.reset()
fout, ReportWithoutHidden = remove_hidden_methods(Report3, outfile="report3.py")
setup_grade_file_report(ReportWithoutHidden, minify=False, obfuscate=False, execute=False)
sdir = "../../students/cs103"
snip_dir(source_dir="../cs103", dest_dir=sdir, clean_destination_dir=True, exclude=['__pycache__', '*.token', 'deploy.py', 'report3_complete*.py'])
sdir = wd+"/../../students/cs103"
snip_dir(source_dir=wd+"/../cs103", dest_dir=sdir, clean_destination_dir=True, exclude=['__pycache__', '*.token', 'deploy.py', 'report3_complete*.py'])
return sdir
def run_student_code_on_docker(Dockerfile, student_token_file):
token = docker_run_token_file(Dockerfile_location=Dockerfile,
host_tmp_dir=os.path.dirname(Dockerfile) + "/tmp",
host_tmp_dir=os.path.dirname(Dockerfile) + "/home",
student_token_file=student_token_file,
instructor_grade_script="report3_complete_grade.py")
with open(token, 'rb') as f:
......@@ -32,17 +31,14 @@ def run_student_code_on_docker(Dockerfile, student_token_file):
if __name__ == "__main__":
# Step 1: Deploy the students files and return the directory they were written to
student_directory = deploy_student_files()
# import sys
# sys.exit()
# student_directory = "../../students/cs103"
# Step 2: Simulate that the student run their report script and generate a .token file.
os.system("cd ../../students && python -m cs103.report3_grade")
student_token_file = glob.glob(student_directory + "/*.token")[0]
# Step 3: Compile the Docker image (obviously you will only do this once; add your packages to requirements.txt).
Dockerfile = os.path.dirname(__file__) + "/../unitgrade-docker/Dockerfile"
os.system("cd ../unitgrade-docker && docker build --tag unitgrade-docker .")
Dockerfile = os.path.dirname(__file__) + "/../../../../docker_images/unitgrade-docker/Dockerfile"
os.system(f"cd {os.path.dirname(Dockerfile)} && docker build --tag unitgrade-docker .")
# Step 4: Test the students .token file and get the results-token-file. Compare the contents with the students_token_file:
checked_token = run_student_code_on_docker(Dockerfile, student_token_file)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment