def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run").fetchall() db.close() test_types = {} tests_per_user = {} for run in testruns: name = run['name'] test_types.setdefault(name, 0) test_types[name] += 1 user = run['id_user'] tests_per_user.setdefault(user, []).append(run) test_types = { k: v for k, v in sorted(test_types.items(), key=lambda x: -x[1]) } tests_ten_and_below = {} tests_above_ten = {} for user, runs in tests_per_user.items(): if len(runs) > 15: dic = tests_above_ten else: dic = tests_ten_and_below for run in runs: name = run['name'] dic.setdefault(name, 0) dic[name] += 1 labels = list(test_types.keys()) dics = [test_types, tests_ten_and_below, tests_above_ten] height = 0.9 / len(dics) data = [] for i, dic in enumerate(dics): ys = [dic[l] for l in labels] data.append(([height * -i - ii for ii, _ in enumerate(ys)], ys)) return { 'data': data, 'method': 'barh', 'yticks': [-x - height / 2 for x in range(len(labels))], 'ylabel': "Task type", 'xlabel': "Number of test-runs", 'legend': ['#$r>0$', '#$r\leq15$', '#$r\geq16$'], 'title': 'Test-runs grouped by test type', 'kwargs': { 'legend': { 'title': "Runs/User:", }, 'barh': { 'height': height, 'tick_label': [l.title() for l in labels], } } }
def get_data(): db = get_db() runs = db.execute(f'SELECT * FROM test_run').fetchall() dates = { 'total': {}, 'notCompleted': {}, 'successful': {}, } for run in runs: date = run['t_start'].split(' ')[0] dates['total'].setdefault(date, 0) dates['total'][date] += 1 if not run['t_stop'].strip(): dates['notCompleted'].setdefault(date, 0) dates['notCompleted'][date] += 1 if run_successful(run): dates['successful'].setdefault(date, 0) dates['successful'][date] += 1 users = db.execute("SELECT * FROM test_user").fetchall() totalParticipants = len(users) totalTests = sum(dates['total'].values()) totalTestsCorrect = sum(dates['successful'].values()) totalTestsUncompleted = sum(dates['notCompleted'].values()) ratioSuccess = (totalTestsCorrect - totalTestsUncompleted) / totalTests * 100 ratioSuccess = f"{ratioSuccess:.1f}" dump_vars([('totalParticipants', totalParticipants), ('totalTests', totalTests), ('totalTestsCorrect', totalTestsCorrect), ('totalTestsUncompleted', totalTestsUncompleted), ('totalTestsIncorrect', totalTests - totalTestsUncompleted - totalTestsCorrect), ('varTotalRatioSuccess', ratioSuccess)]) return { 'data': [incremental_sum(dates[k]) for k in ['total', 'successful']], 'legend': ['Answers', 'Correct Answers'], 'xlabel': "Date of test-run", 'ylabel': "Number of test-runs", 'title': "Total number test-runs", }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() tests_per_user = {} user_totals = {} for run in testruns: id_user = run['id_user'] tests_per_user.setdefault(id_user, {}) type_run = run['name'] tests_per_user[id_user].setdefault(type_run, []).append(run) user_totals.setdefault(id_user, 0) user_totals[id_user] += 1 for user, value in user_totals.items(): if value < 16: del tests_per_user[user] results_per_type = {} for user, dict_types in tests_per_user.items(): for run_type, runs in dict_types.items(): results_per_type.setdefault(run_type, []) data_run_user = [] result_history = [] for x, run in enumerate(runs, start=1): success = run_successful(run) result_history.append(success) prob = len([v for v in result_history if v ]) / len(result_history) * 100 data_run_user.append((x, prob)) results_per_type[run_type].append(data_run_user) order = [ 'employee hours', 'team workload', 'task dependencies', 'team performance', ] data = [] for name in order: data_lists = results_per_type[name] for run_user in data_lists: data.append((zip(*run_user))) dx = 0.9 / 2 return { 'data': data, # 'legend': [l.title() for l in order], 'method': 'lines', # 'xticks': range(1,16), # 'yticks': range(110)[::10], # 'widths': 0.9/2, # 'markers': markers, # 'colors': colors, # 'legend': handlers_for_legend, # 'kwargs': { # 'legend': { # 'fontsize': 'x-small', ## 'loc': 'upper left', ## 'bbox_to_anchor': [.22, 1.0], # }, # 'scatter': { # 'alpha': 0.7, # 's': 2, # } # }, 'ylabel': "Task percentage", 'xlabel': "Test index, from the first test-run and onwards", }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() testruns = fix.testruns(testruns) dx = 0.9/4 labels = list(reversed(order)) def get_data(valid): tests_per_user = {} for run in testruns: user = run['id_user'] tests_per_user.setdefault(user, 0) tests_per_user[user] += 1 valid_users = [u for u,num in tests_per_user.items() if valid(num)] run_per_type = {} for run in testruns: if not run['id_user'] in valid_users: continue test_type = run['name'] start, stop = run_to_datetimes(run) diff = stop-start run_per_type.setdefault(test_type, []).append(diff) data = [] for x, l in enumerate(labels): times = sorted(run_per_type[l]) len_times = len(times) average = sum([d.seconds+d.microseconds/1e6 for d in times])/len_times if len_times-1%2: mean = times[int((len_times-1)/2)].seconds else: index = int((len_times-1)/2) mean = (times[index] + times[index+1]).seconds/2 data.append((x+dx/2, average)) data.append((x-dx/2, mean)) return data data = get_data(valid=lambda num: num<16) data_outliers = [(x-dx*2, v) for x,v in get_data(valid=lambda num: num>15)] data = [ (zip(*data[0::2])), (zip(*data[1::2])), (zip(*data_outliers[0::2])), (zip(*data_outliers[1::2])), ] return { 'method': 'barh', 'data': data, 'yticks': ([x-0.9/4 for x in range(len(labels))], [l.title() for l in labels]), 'legend': [ 'Average #$r\leq15$', 'Median #$r\leq15$', 'Average #$r\geq16$', 'Median #$r\geq16$', ], 'ylabel': "Task type", 'xlabel': "Seconds", 'kwargs': { 'barh': { 'height': dx, }, 'legend': { 'fontsize': 'small', } } }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() tests_per_user = {} for run in testruns: id_user = run['id_user'] tests_per_user.setdefault(id_user, []).append(run) success_per_type = {'regular': {}, 'outlier': {}} for _, runs in tests_per_user.items(): if len(runs) > 15: dic = success_per_type['outlier'] else: dic = success_per_type['regular'] for x, run in enumerate(runs, start=1): if x > 15: break # run_type = run['name'] # dic.setdefault(run_type, {}) dic.setdefault(x, {}) result = run_successful(run) dic[x].setdefault(result, 0) dic[x][result] += 1 data = {'regular': [], 'outlier': []} for type_result, x_dics in success_per_type.items(): for _, values in x_dics.items(): total = sum(values.values()) val = values.get(True, 0) data[type_result].append(val / total * 100) dx = 0.9 / 2 data = [ (zip(*[(i - dx / 2, v) for i, v in enumerate(data['regular'], start=1)])), (zip(*[(i + dx / 2, v) for i, v in enumerate(data['outlier'], start=1)])), ] method = 'bar' return { 'data': data, 'method': method, 'xticks': range(1, 16), 'yticks': range(110)[::10], # 'widths': 0.9/2, # 'markers': markers, # 'colors': colors, # 'legend': handlers_for_legend, 'kwargs': { 'legend': { 'fontsize': 'x-small', # 'loc': 'upper left', # 'bbox_to_anchor': [.22, 1.0], }, 'bar': { 'width': dx, } }, 'ylabel': "Percentage", 'xlabel': "Test index, from the first test-run and onwards", }
def get_data(): db = get_db() runs = db.execute('SELECT t_created, str_id FROM test_user').fetchall() answers = db.execute("SELECT * FROM answer").fetchall() db.close() dates = {} answers_per_question = {} for answer in answers: answers_per_question.setdefault(answer['question'], []).append(answer) questions = [ q for q in answers_per_question.keys() if q[:4] in ['init', 'inti'] ] q_transform = {q: q.split('_', 1)[-1] for q in questions} q_final = { 'age': 'age', 'identifies': 'identifies as', 'screen_size': 'screen size', 'device_type': 'input type', } categories = { 'identifies': ['female', 'male', 'other'], 'device_type': ['mouse', 'trackpad', 'touch', 'other'], 'screen': ['desktop', 'laptop', 'tablet', 'mobile'], } ans_data_per_q = {} for q, aans in answers_per_question.items(): if q not in questions: continue q = q_final[q_transform[q]] for aa in aans: a = aa['answer'] ans_data_per_q.setdefault(q, set()) ans_data_per_q[q].add(aa['str_id']) completed_preq = ans_data_per_q['age'] completed_post = ans_data_per_q['age'] questions_post = [ q for q in answers_per_question.keys() if q[:4] not in ['init', 'inti'] ] questions_post = questions_post[5] completed_post = { a['str_id'] for a in answers_per_question[questions_post] } dates_preq = {} dates_post = {} for time, id_user in runs: date = time.split(' ')[0] dates.setdefault(date, 0) dates[date] += 1 if id_user in completed_preq: dates_preq.setdefault(date, 0) dates_preq[date] += 1 if id_user in completed_post: dates_post.setdefault(date, 0) dates_post[date] += 1 return { 'data': [incremental_sum(d) for d in [dates, dates_preq, dates_post]], 'legend': ['Past consent form', 'Completed pre-survey', 'Completed post-survey'], 'xlabel': "Date of test-run", 'ylabel': "Number of test-runs", 'title': "Number of users at each milestone", }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() tests_per_user = {} for run in testruns: user = run['id_user'] tests_per_user.setdefault(user, []).append(run) # tests_per_user = dict([ # (u,n) for u,n in tests_per_user.items() if len(n) < 16 # ]) tests_per_state = {} tests_per_state_outliers = {} for user, runs in tests_per_user.items(): for run in runs: if len(runs) > 15: dic = tests_per_state_outliers else: dic = tests_per_state name = run['name'] dic.setdefault(name, {}) success = run_successful(run) dic[name].setdefault(success, 0) dic[name][success] += 1 order = [ 'employee hours', 'team workload', 'task dependencies', 'team performance' ] dh = 0.9 / 2 ys_true, ys_false = [], [] ys_true_outliers, ys_false_outliers = [], [] init = 1.0 * (len(order) - 1) for i, name in enumerate(order): i = init - i total = sum([v for v in tests_per_state[name].values()]) ys_true.append((i, tests_per_state[name][True] / total * 100)) # ys_false.append((i-dh*2-0.3, tests_per_state[name][False]/total*100)) total = sum([v for v in tests_per_state_outliers[name].values()]) ys_true_outliers.append( (i - dh, tests_per_state_outliers[name][True] / total * 100)) # ys_false_outliers.append((i-dh*3-0.3, tests_per_state_outliers[name][False]/total*100)) method = 'barh' data = [ (zip(*ys_true)), (zip(*ys_true_outliers)), ] print(data) return { 'data': data, 'method': method, 'kwargs': { 'barh': { 'height': dh, }, 'legend': { 'fontsize': 'x-small', }, }, 'yticks': zip(*[(init - i + dh / 2 - 0.9 / 2, l.title()) for i, l in enumerate(order)]), 'legend': [ '#$r\leq15$', '#$r\geq16$', ], 'xticks': range(0, 110)[::10], 'xlabel': 'Percentage', 'ylabel': 'Task type', 'title': 'Success-rates for different task-types', }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() tests_per_user = {} for run in testruns: user = run['id_user'] tests_per_user.setdefault(user, []).append(run['name']) tests_per_user = [(u, n) for u, n in tests_per_user.items() if len(n) > 15] types = {} data, widths, xticks, xlabels, colors, markers = [], [], [], [], [], [] group_width = 0.8 for _, names in tests_per_user: for x, name in enumerate(names, start=1): types.setdefault(x, {}) types[x].setdefault(name, 0) types[x][name] += 1 order = [ 'employee hours', 'team workload', 'task dependencies', 'team performance' ] method = 'bar' mappings_style = dict(zip(order, zip(iter_colors, iter_markers(method)))) handlers_for_legend = {n: 0 for n in order} bar_num = 0 for x, dict_types in types.items(): total = sum(dict_types.values()) sum_prev = 0 bars_at_x = [] for name, value in sorted(dict_types.items(), key=lambda x: -x[1]): value = value / total * 100 bars_at_x.append((name, value + sum_prev)) sum_prev += value # Print in inverted order. for name, value in reversed(bars_at_x): if value == 0: continue handlers_for_legend[name] = bar_num color, marking = mappings_style[name] colors.append(color) markers.append(marking) bar_num += 1 data.append((x, value)) return { 'data': data, 'method': method, 'legend': handlers_for_legend, 'markers': markers, 'colors': colors, 'yticks': range(110)[::20], 'xticks': [1] + list(range(10, 110)[::10]), 'ylabel': "Percentage", 'xlabel': "Test index, from the first test-run and onwards", 'title': "Relation task order and task type, outliers", 'kwargs': { 'legend': { 'bbox_to_anchor': (1.0, 0.5), 'loc': 'center right', 'fontsize': 'small', }, 'bar': { 'linewidth': 1, } } }
def get_data(): db = get_db() testruns = db.execute("SELECT * FROM test_run WHERE t_stop").fetchall() db.close() tests_per_user = {} for run in testruns: user = run['id_user'] tests_per_user.setdefault(user, []).append(run['name']) tests_per_user = [(u, n) for u, n in tests_per_user.items() if len(n) < 16] types = {} data, widths, xticks, xlabels, colors, markers = [], [], [], [], [], [] group_width = 0.8 for _, names in tests_per_user: for x, name in enumerate(names, start=1): types.setdefault(x, {}) types[x].setdefault(name, 0) types[x][name] += 1 order = [ 'employee hours', 'team workload', 'task dependencies', 'team performance' ] method = "bar" mappings_style = dict(zip(order, zip(iter_colors, iter_markers(method)))) handlers_for_legend = {} num_bar = 0 for x, dict_types in types.items(): xticks.append(x + group_width / 2) xlabels.append(x) total = sum(dict_types.values()) i = 0 for name in order: value = dict_types.get(name) if not value: continue widths.append(group_width / len(dict_types)) color, marker = mappings_style[name] colors.append(color) markers.append(marker) handlers_for_legend[name] = num_bar dx = widths[-1] bx = x + dx / 2 + dx * i by = (value / total * 100) data.append((bx, by)) num_bar += 1 i += 1 return { 'data': data, 'method': method, 'xticks': (xticks, xlabels), 'yticks': range(110)[::10], 'widths': widths, 'markers': markers, 'colors': colors, 'legend': handlers_for_legend, 'size': (0.7 * 8.3, 2.5), 'kwargs': { 'legend': { 'fontsize': 'x-small', 'loc': 'upper left', 'bbox_to_anchor': [.22, 1.0], }, }, 'ylabel': "Percentage", 'xlabel': "Test index, from the first test-run and onwards", 'title': "Relation task order and task type, regular", }