def collectEdgeCorrect(trial, core, timing = None, medium = None, verification = None): nodes = database.listNodes(trial) nm = {} for n in nodes: nm[n["id"]] = len(nm) nodes = list(map(lambda n: n["name"], nodes)) res = database.cursor().execute(""" SELECT n1.id,n2.id,answers.* FROM nodes AS n1, nodes AS n2 INNER JOIN answers ON (n1.id = answers.src AND n2.id = answers.dest) LEFT JOIN solutions ON (answers.solution = solutions.id) LEFT JOIN students ON (solutions.student = students.id) WHERE n1.trial = ? AND n2.trial = ? AND (timing=? OR %d) AND (medium=? OR %d) """ % (timing == None, medium == None), (trial,trial,timing,medium)).fetchall() table = [[[0,0] for n in nodes] for n in nodes] for row in res: if int(row["verification"]) & verification == verification: table[nm[row[0]]][nm[row[1]]][0] += 1 table[nm[row[0]]][nm[row[1]]][1] += 1 table = list(map(lambda r: list(map(lambda x: x[0]/x[1] if x[1] != 0 else 0, r)), table)) nodes.append("Average") for row in table: row.append("%0.2f ±%0.2f" % (mean(row), pstdev(row))) newRow = [] for col in range(len(table[0])-1): newRow.append("%0.2f ±%0.2f" % (mean(table, lambda x: float(x[col])), pstdev(table, lambda x: float(x[col])))) table.append(newRow + [""]) table = reformat(table, formatPercent, isNumber) return ["table", nodes, nodes, table]
def collectEdgeUsedCounts(trial, core, timing=None, medium=None, verification=None): nodes = database.listNodes(trial) nm = {} for n in nodes: nm[n["id"]] = len(nm) nodes = list(map(lambda n: n["name"], nodes)) res = database.cursor().execute( """ SELECT n1.id,n2.id,answers.* FROM nodes AS n1, nodes AS n2 INNER JOIN answers ON (n1.id = answers.src AND n2.id = answers.dest) LEFT JOIN solutions ON (answers.solution = solutions.id) LEFT JOIN students ON (solutions.student = students.id) WHERE n1.trial = ? AND n2.trial = ? AND (timing=? OR %d) AND (medium=? OR %d) AND (verification = ? OR %d) """ % (timing == None, medium == None, verification == None), (trial, trial, timing, medium, verification)).fetchall() table = [([0] * len(nodes)) for n in nodes] for row in res: table[nm[row[0]]][nm[row[1]]] += 1 nodes.append("Average") for row in table: row.append("%0.2f ±%0.2f" % (mean(row), pstdev(row))) newRow = [] for col in range(len(table[0]) - 1): newRow.append( "%0.2f ±%0.2f" % (mean(table, lambda x: x[col]), pstdev(table, lambda x: x[col]))) table.append(newRow + [""]) return ["table", nodes, nodes, table]
def collectEdgeCorrect(trial, core, timing=None, medium=None, verification=None): nodes = database.listNodes(trial) nm = {} for n in nodes: nm[n["id"]] = len(nm) nodes = list(map(lambda n: n["name"], nodes)) res = database.cursor().execute( """ SELECT n1.id,n2.id,answers.* FROM nodes AS n1, nodes AS n2 INNER JOIN answers ON (n1.id = answers.src AND n2.id = answers.dest) LEFT JOIN solutions ON (answers.solution = solutions.id) LEFT JOIN students ON (solutions.student = students.id) WHERE n1.trial = ? AND n2.trial = ? AND (timing=? OR %d) AND (medium=? OR %d) """ % (timing == None, medium == None), (trial, trial, timing, medium)).fetchall() table = [[[0, 0] for n in nodes] for n in nodes] for row in res: if int(row["verification"]) & verification == verification: table[nm[row[0]]][nm[row[1]]][0] += 1 table[nm[row[0]]][nm[row[1]]][1] += 1 table = list( map(lambda r: list(map(lambda x: x[0] / x[1] if x[1] != 0 else 0, r)), table)) nodes.append("Average") for row in table: row.append("%0.2f ±%0.2f" % (mean(row), pstdev(row))) newRow = [] for col in range(len(table[0]) - 1): newRow.append("%0.2f ±%0.2f" % (mean(table, lambda x: float(x[col])), pstdev(table, lambda x: float(x[col])))) table.append(newRow + [""]) table = reformat(table, formatPercent, isNumber) return ["table", nodes, nodes, table]
def collectEdgeUsedCounts(trial, core, timing = None, medium = None, verification = None): nodes = database.listNodes(trial) nm = {} for n in nodes: nm[n["id"]] = len(nm) nodes = list(map(lambda n: n["name"], nodes)) res = database.cursor().execute(""" SELECT n1.id,n2.id,answers.* FROM nodes AS n1, nodes AS n2 INNER JOIN answers ON (n1.id = answers.src AND n2.id = answers.dest) LEFT JOIN solutions ON (answers.solution = solutions.id) LEFT JOIN students ON (solutions.student = students.id) WHERE n1.trial = ? AND n2.trial = ? AND (timing=? OR %d) AND (medium=? OR %d) AND (verification = ? OR %d) """ % (timing == None, medium == None, verification == None), (trial,trial,timing,medium,verification)).fetchall() table = [([0] * len(nodes)) for n in nodes] for row in res: table[nm[row[0]]][nm[row[1]]] += 1 nodes.append("Average") for row in table: row.append("%0.2f ±%0.2f" % (mean(row), pstdev(row))) newRow = [] for col in range(len(table[0])-1): newRow.append("%0.2f ±%0.2f" % (mean(table, lambda x: x[col]), pstdev(table, lambda x: x[col]))) table.append(newRow + [""]) return ["table", nodes, nodes, table]