function to gather the data on the mchoice questions
open the output file for writing
open the input and output files as csv files
create an empty problem dictionary
loop through the rows
get the event
if event is mChoice
get the divid, user, timestamp, and answer
if no dictionary for this problem create one and add this user and answer
if user in dictionary
for each multiple choice question total the number of correct responses
loop through the users
write out the problem id and percent who got it correct
total_attempted = len(user_dict)
percent_correct = total_correct / total_attempted
csv_writer.writerow([prob, total_correct, total_attempted, percent_correct])
outFile.close()
return len(probDict)
num = mchoice_worker("mChoiceSmall.csv", "mchoiceResults.csv")
print(f"The number of unique questions is {num}")
import unittest
class myTests(unittest.TestCase):
def setUp(self):
dir = os.path.dirname(__file__)
inFile = open(os.path.join(dir, "mchoiceResults.csv"))
csv_in = csv.reader(inFile)
self.datad = {}
for cols in csv_in:
self.datad[cols[0]] = (int(cols[1]), int(cols[2]), float(cols[3]))
def testLen(self):
self.assertEqual(len(self.datad), 3, "num unique problems")
def testData(self):
self.assertEqual(self.datad["q2_2_1"][0], 7, "num attempted for q2_2_1")
self.assertEqual(self.datad["q2_2_1"][1], 7, "num correct for q2_2_1")
self.assertAlmostEqual(self.datad["q2_2_1"][2], 100, 2, "percent for q2_2_1")
self.assertEqual(self.datad["q2_2_2"][0], 4, "num attempted for q2_2_2")
self.assertEqual(self.datad["q2_2_2"][1], 7, "num correct for q2_2_2")
self.assertAlmostEqual(self.datad["q2_2_2"][2], 57.14, 2, "percent for q2_2_2")
unittest.main(verbosity=3)
You have attempted of activities on this page