Skip to content

Instantly share code, notes, and snippets.

@joshdabosh
Last active February 25, 2020 05:29
Show Gist options
  • Save joshdabosh/cca20d9ddb90c7149c23650cba7b990a to your computer and use it in GitHub Desktop.
Save joshdabosh/cca20d9ddb90c7149c23650cba7b990a to your computer and use it in GitHub Desktop.
trebuchets :\
# group 10
import matplotlib.pyplot as plt
import numpy as np
avg = lambda x: sum(x)/len(x)
prune = lambda x: [i for i in x if i != None]
def err(x,y):
try:
r = abs((x+y)/y) # because the theoretical value is from a different point than the where we measure,
# we have to use + instead of - to get the actual distance traveled by the projectile
except TypeError:
r = None
return r
# x vals
GROUP_X = [5, 8, 9, 7]
GROUP_X_a = [5, 8, 9, 7, None]
CLASS_X = [0, 9, -6, 8, 42, 0, 29, -24.5, 5, -15, 0, 5, -3, 20, 20.5,\
10, 15, 9.5, 8, -16, 8, 4, -10, 0, 30, 19, 28.5, -16, 9, -20,\
6, 8, -1, 7, 25, 21, 10, -24, 7, -19, 9, 0, -1, 7, 0, 17, 23,\
-21, None, -21]
GRADE_X = [0, 9, -6, 8, 42, 0, 29, -24.5, 5, -15, 0, 5, -3, 20, 20.5,\
10, 15, 9.5, 8, -16, 8, 4, -10, 0, 30, 19, 28.5, -16, 9, -20,\
6, 8, -1, 7, 25, 21, 10, -24, 7, -19, 9, 0, -1, 7, 0, 17, 23,\
-21, None, 21, -8, 8, -7, -6, -18, -10, 0, 10, -7, 25.5, -5, 5, -6.5,\
2, 1, -10, -3.5, 5, -12, 2.5, -3, -10, -8.5, -2, 12, -5,\
-13, 13, -6, -4, -2.5, 0, -13, 1, 9, -5, -5, 11, -7, 11.5,\
-2, -8, -9, -11, -3, -25, -6.5, 12.0, -7, 2, -5, -33, -20, 10,\
3, 6, -4, -6, -5, -28, -23, -12, 3, 3, -3, 16, -2, -40, -22, -10,\
8, -5, 0, -9, -12.5, -40, -17, 30, 5, -6, -13, 18, -8.5, -38, -30,\
5, 14, -8, -5, 12, 43, 4, 9, 4, -15, 20, 21, -16, 1, 24, 3, 7, -9,\
-8, 10, 19, -4.5, 5, 30, 12, -0.5, 14, 0, 7, 13.5, -17.5, 13.5,\
21, 1, 6, -11, -13, 10, 18, -2, 3, 36, 11, 0, -16, -18, 12,\
11, 4, 1]
# y vals
GROUP_Y = [-50, -50, -50, -50]
GROUP_Y_a = [-50, -50, -50, -50, None]
CLASS_Y = [-29, -4, 9, -13, 30.5, -52, 25, 28, -50, 65, -31.5, -8, 10, -53,\
34, -50, 52, 28, -50, -68, -32, -4, 9, -34, 18, -16, 40, 37, -50, -71,\
-21, -3, 12, -40, 20.5, -21, 54, 29, -50, -69, -23, -9, 11, -30, 10,\
-18, 50, 37, None, -65]
GRADE_Y = [-29, -4, 9, -13, 30.5, -52, 25, 28, -50, 65, -31.5, -8, 10, -53,\
34, -50, 52, 28, -50, -68, -32, -4, 9, -34, 18, -16, 40, 37, -50, -71,\
-21, -3, 12, -40, 20.5, -21, 54, 29, -50, -69, -23, -9, 11, -30, 10,\
-18, 50, 37, None, -65, 10.5, 28.5, 8, 9, 27, -80, -2.5, 60, -11, -4, 11, 60, 10, 17,\
29, -75, 0, 55, -8.5, -12, 12, 85, 13, 19, 26, -55, 3, 59, -7, -10,\
13.5, 42, 20, 14, 27, -60, -4, 60, -6, -13.5, 9, 35, 11, 17, 29,\
-60, 0, 62, -9, 16, 10, -26, 5, 20, 43, 9, -114, -20, -1, -23, -5,\
23, 34, 22, -119, 6.5, -1, -26, 0, 22, 50, 20, -120, -6.5, 0, -23,\
10, 15, 43, 15, -116, 9.5, 0, -26, 5, 22, 43, 19, -124, 15.5,\
72, 37, -40, 139, 50, 40, -2.5, -16, -18.5, 44, 40, -50, 67, 38,\
42, -1, -1, -19, 74, 50, -43, 71, 50, 40, 0, -18.5, -28, 70, 50,\
-50, 67, 45, 41, 5, -4.5, -24, 73, 46, -50, 67, 39, 38, 6, 20,\
-18.5]
# stella calculated values (only for X)
GROUP_EXP = [225]
CLASS_EXP = [114, 142, 140, 117, 117, 150, 148, 116, 225, 241]
GRADE_EXP = [114, 142, 140, 117, 117, 150, 148, 116, 225, 241,\
1.185, 1.47, 1.57, 1, 0.898, 1.962, 1.68, 0.952, 0.6825, 1.5,\
159, 193, 200, 0.99, 166.5, 133, 250, 133, 105, 149, 214, 60,\
60, 148, 90, 143, 155]
# error
GROUP_ERR = prune([err(a,b) for a, b in zip(GROUP_Y_a, GROUP_EXP*len(GROUP_Y))])
CLASS_ERR = prune([err(a,b) for a, b in zip(CLASS_Y, CLASS_EXP*len(CLASS_Y))])
GRADE_ERR = prune([err(a,b) for a, b in zip(GRADE_Y, GRADE_EXP*len(GRADE_Y))])
AVG_GROUP_ERR = avg(GROUP_ERR)
AVG_CLASS_ERR = avg(CLASS_ERR)
AVG_GRADE_ERR = avg(GRADE_ERR)
GROUP_X, CLASS_X, GRADE_X = map(prune, [GROUP_X, CLASS_X, GRADE_X])
GROUP_Y, CLASS_Y, GRADE_Y = map(prune, [GROUP_Y, CLASS_Y, GRADE_Y])
# probably the worst idea but im on 6 hrs sleep soooooooooooooooooooo
desc = {str(GROUP_X): "Group 10 Experimental X Values",
str(CLASS_X): "Block A Experimental X Values",
str(GRADE_X): "Grade Experimental X Values",
str(GROUP_Y): "Group 10 Experimental Y Values",
str(CLASS_Y): "Block A Experimental Y Values",
str(GRADE_Y): "Grade Experimental Y Values",
str(GROUP_ERR): "Group 10 Error",
str(CLASS_ERR): "Block A Error",
str(GRADE_ERR): "Grade Error",
}
# actually graphing :\
# loop 違ゔギ
for ref in [GROUP_X, CLASS_X, GRADE_X, GROUP_Y, CLASS_Y, GRADE_Y, GROUP_ERR, CLASS_ERR, GRADE_ERR]:
fig = plt.figure(num=None, figsize=(6, 4), dpi=100)
ax1 = fig.add_subplot(111)
ax1.set_title(desc[str(ref)], fontsize=12)
calc = ax1.boxplot(ref, vert=False)
mini, maxi = round(min(ref), 2), round(max(ref), 2)
q1 = round(np.percentile(ref, 25), 2)
median = round(np.percentile(ref, 50), 2)
q3 = round(np.percentile(ref, 75), 2)
iqr = round(abs(q3-q1), 2)
fig.text(0.5, 0.01, "The 5 number summary is: {}, {}, {}, {}, {} with an IQR of {}".format(mini, q1, median, q3, maxi, iqr), ha="center")
mini, maxi = min(ref), max(ref)
plt.savefig(desc[str(ref)].lower().replace(" ", "_") + ".png")
print("Average group error: " + str(round(AVG_GROUP_ERR*100, 3)) + " %")
print("Average class error: " + str(round(AVG_CLASS_ERR*100, 3)) + " %")
print("Average grade error: " + str(round(AVG_GRADE_ERR*100, 3)) + " %")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment