In [1]:
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
In [2]:
def progress(n, p, n_required, p_required):
""" Return a progress fraction from 0 to 1.
n: number of questions answered
p: fraction of questions correct
n_required: minimum number of questions that need to have been answered to complete the module.
p_required: minimum percentage of questions that need to have been answered correctly.
"""
n_frac = min(1.0, n / n_required)
p_frac = min(1.0, p / p_required)
return (n_frac + p_frac) / 2.0
In [3]:
n_max, n_required, p_required = 100, 50, 0.8
In [10]:
n_range = np.linspace(1, n_max, n_max)
p_range = np.linspace(0, 1.0, 100)
In [11]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y = np.meshgrid(n_range, p_range)
zs = np.array([progress(n, p, n_required, p_required) for n, p in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
ax.plot_surface(X, Y, Z, cmap=plt.cm.jet, rstride=1, cstride=1, linewidth=0)
ax.set_xlabel('Questions answered')
ax.set_ylabel('Fraction of correct answers')
ax.set_zlabel('Progress bar percentage')
plt.show()
In [6]:
def progress_via_answers(correct, incorrect, n_required, p_required):
""" Return a progress fraction from 0 to 1.
correct: number of questions answered correctly
incorrect: number of questions answered incorrectly
n_required: minimum number of questions that need to have been answered to complete the module.
p_required: minimum percentage of questions that need to have been answered correctly.
"""
n = correct + incorrect
p = correct / float(max(1, n))
return progress(n, p, n_required, p_required)
In [8]:
correct_range = np.linspace(1, n_max, n_max)
incorrect_range = np.linspace(1, n_max, n_max)
In [9]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y = np.meshgrid(correct_range, incorrect_range)
zs = np.array([progress_via_answers(qc, qi, n_required, p_required) for qc, qi in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
ax.plot_surface(X, Y, Z, cmap=plt.cm.jet, rstride=1, cstride=1, linewidth=0)
ax.set_xlabel('Questions correct')
ax.set_ylabel('Questions incorrect')
ax.set_zlabel('Progress bar percentage')
plt.show()