Skip to content

Commit 6c8cf24

Browse files
committed
2 parents f63572d + 21d9c22 commit 6c8cf24

10 files changed

Lines changed: 319 additions & 69 deletions

Week_0_python/a_tutorial_strings_format.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"\n",
132132
"The curly brackets tell the format function to \"fill in\" the variables that are passed in. Python provides a much nicer way of doing this with **f(\"\")** which we'll show below. It's useful to see the more traditional, C++ or Matlab version first.\n",
133133
"TODO edits to try/do\n",
134-
" - add in a 3rd variable to print\n",
134+
" - add in a 3rd variable to pring\n",
135135
" - print with 5 decimal places\n",
136136
" - print out the same variable twice in one line"
137137
]

Week_0_python/c_practice_strings.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"metadata": {},
7373
"source": [
7474
"# Practice: String editing \n",
75-
"The first two problems just involve a simple replacement. The third problem involves multiple steps."
75+
"The first two problems just to do a simple replacement. The third problem involves multiple steps."
7676
]
7777
},
7878
{

Week_0_python/d_tutorial_list.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@
204204
"# for the c programmer, there is no for (i = 0, i < n, i++) equivalent\n",
205205
"my_list_result = []\n",
206206
"for i in range(0, len(my_list_todos)):\n",
207-
" if my_list_todos[i] == \"add\":\n",
207+
" if my_list_todos[i] is \"add\":\n",
208208
" my_list_result.append(my_list_lhs_numbers[i] + my_list_rhs_numbers[i])\n",
209-
" elif my_list_todos[i] == \"multiply\":\n",
209+
" elif my_list_todos[i] is \"multiply\":\n",
210210
" my_list_result.append(my_list_lhs_numbers[i] * my_list_rhs_numbers[i])\n",
211-
" elif my_list_todos[i] == \"skip\":\n",
211+
" elif my_list_todos[i] is \"skip\":\n",
212212
" pass \n",
213213
" else:\n",
214214
" # This is the RIGHT way to do this, so you catch if someone mis-typed something\n",
@@ -244,11 +244,11 @@
244244
"\n",
245245
"# Notice i, n\n",
246246
"for i, n in enumerate(my_list_todos):\n",
247-
" if n == \"add\":\n",
247+
" if n is \"add\":\n",
248248
" my_list_result.append(my_list_lhs_numbers[i] + my_list_rhs_numbers[i])\n",
249-
" elif n == \"multiply\":\n",
249+
" elif n is \"multiply\":\n",
250250
" my_list_result.append(my_list_lhs_numbers[i] * my_list_rhs_numbers[i])\n",
251-
" elif n == \"skip\":\n",
251+
" elif n is \"skip\":\n",
252252
" pass # This is the RIGHT way to do this, so you catch if someone mis-typed something\n",
253253
" else:\n",
254254
" raise ValueError(f\"Expected add, multiply, or skip, got {n}\")\n",
@@ -266,11 +266,11 @@
266266
"# Note also that this does NOT require an index variable i - it's all handled for you\n",
267267
"my_list_result = [] # Set list back to empty\n",
268268
"for n, lhs, rhs in zip(my_list_todos, my_list_lhs_numbers, my_list_rhs_numbers):\n",
269-
" if n == \"add\":\n",
269+
" if n is \"add\":\n",
270270
" my_list_result.append(lhs + rhs)\n",
271-
" elif n == \"multiply\":\n",
271+
" elif n is \"multiply\":\n",
272272
" my_list_result.append(lhs * rhs)\n",
273-
" elif n == \"skip\":\n",
273+
" elif n is \"skip\":\n",
274274
" pass \n",
275275
" else:\n",
276276
" # This is the RIGHT way to do this, so you catch if someone mis-typed something\n",

Week_1_data_structures/HW_1_numpy_and_plotting.ipynb

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"# \"success yn\" - the successful pick, y/n data\n",
107107
"# \"n picks\" - the total number of picks\n",
108108
"# \"n successful\" - the number of successful picks\n",
109+
"# \"n unsuccessful\" - the number of unsuccessful picks\n",
109110
"# Note: Do these two after you read in the json file\n",
110111
"# \"n timesteps\" - the number of time steps\n",
111112
"# \"n total dims\" - the total number of data channels per time step\n",
@@ -126,7 +127,7 @@
126127
},
127128
"outputs": [],
128129
"source": [
129-
"# TODO: Read in proxy_data_diescription.json\n",
130+
"# TODO: Read in proxy_data_description.json\n",
130131
"# - calculate number of channels\n",
131132
"# - calculate number of time steps\n",
132133
"\n",
@@ -473,6 +474,19 @@
473474
" json.dump(pick_data_description, f, indent=4)"
474475
]
475476
},
477+
{
478+
"cell_type": "code",
479+
"execution_count": null,
480+
"metadata": {
481+
"tags": []
482+
},
483+
"outputs": [],
484+
"source": [
485+
"# These commands will force JN to actually re-load the external file when you re-execute the import command\n",
486+
"%load_ext autoreload\n",
487+
"%autoreload 2"
488+
]
489+
},
476490
{
477491
"cell_type": "code",
478492
"execution_count": null,
@@ -654,6 +668,13 @@
654668
"- min and max - pass in the minimum and maximum values for that channel (use to draw lines)\n"
655669
]
656670
},
671+
{
672+
"cell_type": "markdown",
673+
"metadata": {},
674+
"source": [
675+
"This problem is manually graded; see slides and Gradescope rubric."
676+
]
677+
},
657678
{
658679
"cell_type": "code",
659680
"execution_count": null,
@@ -714,18 +735,6 @@
714735
"plt.tight_layout()"
715736
]
716737
},
717-
{
718-
"cell_type": "code",
719-
"execution_count": null,
720-
"metadata": {
721-
"deletable": false,
722-
"editable": false
723-
},
724-
"outputs": [],
725-
"source": [
726-
"grader.check(\"plot_function\")"
727-
]
728-
},
729738
{
730739
"cell_type": "markdown",
731740
"metadata": {
@@ -827,12 +836,12 @@
827836
"cell_type": "code",
828837
"execution_count": null,
829838
"metadata": {
830-
"deletable": false,
831-
"editable": false
839+
"tags": []
832840
},
833841
"outputs": [],
834842
"source": [
835-
"grader.check(\"plot_specific_channels\")"
843+
"# Manual grade\n",
844+
"print(\"This is a manually-graded question; there is no grader.check() function. See rubric and slides for more information on expected output.\")"
836845
]
837846
},
838847
{
@@ -871,6 +880,18 @@
871880
"fig.set_tight_layout(tight=True)\n"
872881
]
873882
},
883+
{
884+
"cell_type": "code",
885+
"execution_count": null,
886+
"metadata": {
887+
"tags": []
888+
},
889+
"outputs": [],
890+
"source": [
891+
"# Manual grade\n",
892+
"print(\"This is a manually-graded question; there is no grader.check() function. See rubric and slides for more information on expected output.\")"
893+
]
894+
},
874895
{
875896
"cell_type": "markdown",
876897
"metadata": {
@@ -1097,44 +1118,6 @@
10971118
}
10981119
]
10991120
},
1100-
"plot_function": {
1101-
"name": "plot_function",
1102-
"points": 3,
1103-
"suites": [
1104-
{
1105-
"cases": [
1106-
{
1107-
"code": ">>> print(\"This problem is manually graded, look at the slides for the expected plot\")\n",
1108-
"hidden": false,
1109-
"locked": false
1110-
}
1111-
],
1112-
"scored": true,
1113-
"setup": "",
1114-
"teardown": "",
1115-
"type": "doctest"
1116-
}
1117-
]
1118-
},
1119-
"plot_specific_channels": {
1120-
"name": "plot_specific_channels",
1121-
"points": 0,
1122-
"suites": [
1123-
{
1124-
"cases": [
1125-
{
1126-
"code": ">>> print(\"This question is manually graded, look at the slides for the expected plot\")\n",
1127-
"hidden": false,
1128-
"locked": false
1129-
}
1130-
],
1131-
"scored": true,
1132-
"setup": "",
1133-
"teardown": "",
1134-
"type": "doctest"
1135-
}
1136-
]
1137-
},
11381121
"reverse_dictionary": {
11391122
"name": "reverse_dictionary",
11401123
"points": 3,

Week_1_data_structures/Lab_1_arrays_and_dictionaries.ipynb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,23 @@
674674
"source": [
675675
"# TEST CODE\n",
676676
"# The correct answers are in Lab1_check_results.json. You can write test code here to check\n",
677-
"# each value in turn, make sure the slicing is the correct size. This will not be graded."
677+
"# each value in turn, make sure the slicing is the correct size. This will not be graded.\n",
678+
"\n",
679+
"# See the slides for how to debug this if it doesn't pass the test"
680+
]
681+
},
682+
{
683+
"cell_type": "code",
684+
"execution_count": null,
685+
"metadata": {
686+
"tags": []
687+
},
688+
"outputs": [],
689+
"source": [
690+
"# These commands will force JN to actually re-load the external file when you re-execute the import command\n",
691+
"\n",
692+
"%load_ext autoreload\n",
693+
"%autoreload 2"
678694
]
679695
},
680696
{

Week_1_data_structures/a_tutorial_numpy.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"print(f\"Element in second row, first column: {data_from_csv[1, 0]}\")\n",
136136
"# The -1 says get the last element (see slicing)\n",
137137
"print(f\"Element in last row, last column: {data_from_csv[-1, -1]}\")\n",
138-
"print(f\"Element in third row, last column: {data_from_csv[2, -1]}\")"
138+
"print(f\"Element in third row, last column: {data_from_csv[1, -1]}\")"
139139
]
140140
},
141141
{
@@ -199,7 +199,7 @@
199199
"\n",
200200
"Note: One of the most common errors is to forget the [] or the () around the list of dimensions - you don't need it for one dimensional arrays, but you will for more than one - otherwise, you get a TypeError: data type not understood\n",
201201
"\n",
202-
"Create a **2 X 3** array of zeros\n",
202+
"Create a **3 X 5 X 2** array of zeros\n",
203203
"\n",
204204
"TODO: Try creating a matrix of a different size"
205205
]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# Just a helper function to check if two json files are the same
3+
4+
import numpy as np
5+
import json as json
6+
7+
# Compare dictionaries or data to files
8+
def compare_files(student_answer, soln_file_name):
9+
# Student is always the first argument
10+
student = student_answer
11+
# If it's a file name, then load that file
12+
if isinstance(student_answer, str):
13+
with open("Data/" + student_answer, "r") as fp:
14+
student = json.load(fp)
15+
16+
# Second filename is always the solution, stored in a file or a dictionary. Load it if it is a file.
17+
soln = soln_file_name
18+
if isinstance(soln_file_name, str):
19+
with open("Data/" + soln_file_name, "r") as fp:
20+
soln = json.load(fp)
21+
22+
# If soln is a dictionary, then do the first if statement
23+
if isinstance(soln, dict):
24+
# Loop through all elements of the dictionary
25+
for k, v in soln.items():
26+
try:
27+
if k == "Data channels":
28+
# The data channels list
29+
for i, d in enumerate(student[k]):
30+
if d != v[i]:
31+
print(f"miss-match value {d} {v[i]}")
32+
return False
33+
else:
34+
if v != student[k]:
35+
print(f"Miss-match key-item {k} {v} {student[k]}")
36+
return False
37+
except KeyError:
38+
print(f"Missing key {k}")
39+
return False
40+
return True
41+
else:
42+
# soln is a list.
43+
if len(soln) != len(student): # Check lists are same length
44+
print(f"Mismatched number of elements, solution {len(soln)} yours {len(student)}")
45+
return False
46+
47+
# For each item in each list
48+
for ce, cs in zip(soln, student):
49+
# Each item is a dictionary - loop through the solution keys
50+
for k, v in ce.items():
51+
try:
52+
# Check if the values in the keys are similar
53+
if not np.isclose(v, cs[k], atol=0.01):
54+
print(f"Value for key {k} is {cs[k]}, expected {v}")
55+
return False
56+
except KeyError:
57+
print(f"Missing key {k} or not a number {cs[k]}")
58+
return False
59+
return True
60+
61+

Week_2_functions/Lab_2_functions.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
"# Use b_successful to pick out the rows that are successful. Send all column data for the selected rows.\n",
403403
"# Wrist torque data has 3 dimensions (x,y,z)\n",
404404
"# There's two errors here - one that actually will create incorrect results, one that just *happens* to work\n",
405-
"# correctly, although it doesn't do what the first sentance says...\n",
405+
"# correctly, although it doesn't do what the first sentence says...\n",
406406
"ret_wrist_torque_successful = calc_stats_for_channel(wrist_torque_data[b_successful], n_dims=1)\n",
407407
"\n",
408408
"# The minimum should be in the third (last) element in the list, the \"min\" key\n",

0 commit comments

Comments
 (0)