Skip to content

Commit

Permalink
Fix incorrect user type metrics hedyorg#2104 (hedyorg#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko authored Mar 16, 2022
1 parent 868877c commit e68cfe9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions static/js/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ export const stats = {
const anonymousRunsPerLevelDataset = generatePerLevelDataset('Anonymous users', response['per_level'], 'data.anonymous_runs', chart_colors[0], false);
const loggedRunsPerLevelDataset = generatePerLevelDataset('Logged users', response['per_level'], 'data.logged_runs', chart_colors[1], false);
const studentRunsPerLevelDataset = generatePerLevelDataset('Student users', response['per_level'], 'data.student_runs', chart_colors[2], false);
updateChart('usersPerLevelChart', [anonymousRunsPerLevelDataset, loggedRunsPerLevelDataset, studentRunsPerLevelDataset]);

const userTypes = ['anonymous_runs', 'logged_runs', 'student_runs'];
const userTypesPerWeekDatasets = generateDatasets(userTypes, response['per_week'], 'week', 'data.', chart_colors, true);
const unknownRunsPerLevelDataset = generatePerLevelDataset('Unknown type users', response['per_level'], 'data.user_type_unknown_runs', chart_colors[3], false);
updateChart('usersPerLevelChart', [anonymousRunsPerLevelDataset, loggedRunsPerLevelDataset, studentRunsPerLevelDataset, unknownRunsPerLevelDataset]);

const userTypes = ['anonymous_runs', 'logged_runs', 'student_runs', 'user_type_unknown_runs'];
const userTypeLabelMapper = (e: string) => {
if (e === 'anonymous_runs') return 'Anonymous users';
if (e === 'logged_runs') return 'Logged users';
if (e === 'student_runs') return 'Student users';
return 'Unknown type users'
};
const userTypesPerWeekDatasets = generateDatasets(userTypes, response['per_week'], 'week', 'data.', chart_colors, true, userTypeLabelMapper);
updateChart('usersPerWeekChart', userTypesPerWeekDatasets);

// update quiz scores per level charts
Expand All @@ -74,7 +81,7 @@ export const stats = {

// update quiz scores per week charts
const levels_quizzes = flattenWeekProps(response['per_week'], ['completed_quizzes', 'abandoned_quizzes'], (el: string) => el.toLowerCase().startsWith('l'));
console.log(levels_quizzes);

const completedQuizPerWeekDatasets = generateDatasets(levels_quizzes, response['per_week'], 'week', 'data.completed_quizzes.', chart_colors, false);
const abandonedQuizPerWeekDatasets = generateDatasets(levels_quizzes, response['per_week'], 'week', 'data.abandoned_quizzes.', chart_colors, false);
const maxScorePerWeekDatasets = generateDatasets(levels_quizzes, response['per_week'], 'week', 'data.quiz_score_max.', chart_colors, false);
Expand Down
2 changes: 1 addition & 1 deletion website/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,4 @@ def parse_date(self, d, default):

def to_year_week(self, d):
cal = d.isocalendar()
return f'{cal[0]}-{cal[1]}'
return f'{cal[0]}-{cal[1]:02d}'
10 changes: 8 additions & 2 deletions website/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def _data_to_response_per_level(data):
_add_value_to_result(res, 'anonymous_runs', data['anonymous_runs'], is_counter=True)
_add_value_to_result(res, 'logged_runs', data['logged_runs'], is_counter=True)
_add_value_to_result(res, 'student_runs', data['student_runs'], is_counter=True)
_add_value_to_result(res, 'user_type_unknown_runs', data['user_type_unknown_runs'], is_counter=True)

_add_value_to_result(res, 'abandoned_quizzes', data['total_attempts'] - data['completed_attempts'], is_counter=True)
_add_value_to_result(res, 'completed_quizzes', data['completed_attempts'], is_counter=True)
Expand Down Expand Up @@ -167,6 +168,7 @@ def _to_response(data, values_field, series_selector, values_map=None):
_add_value_to_result(res[values], 'anonymous_runs', d['anonymous_runs'], is_counter=True)
_add_value_to_result(res[values], 'logged_runs', d['logged_runs'], is_counter=True)
_add_value_to_result(res[values], 'student_runs', d['student_runs'], is_counter=True)
_add_value_to_result(res[values], 'user_type_unknown_runs', d['user_type_unknown_runs'], is_counter=True)

min_, max_, avg_ = _score_metrics(d['scores'])
_add_dict_to_result(res[values], 'quiz_score_min', series, min_)
Expand All @@ -184,8 +186,9 @@ def _to_response(data, values_field, series_selector, values_map=None):
def _add_value_to_result(target, key, source, is_counter=False):
if source is not None and (source > 0 if is_counter else True):
if not target.get(key):
target[key] = {}
target[key] = source
target[key] = source
else:
target[key] += source


def _add_dict_to_result(target, key, series, source, is_counter=False):
Expand Down Expand Up @@ -234,6 +237,7 @@ def _initialize():
'anonymous_runs': 0,
'logged_runs': 0,
'student_runs': 0,
'user_type_unknown_runs': 0,
'total_attempts': 0,
'completed_attempts': 0,
'scores': []
Expand Down Expand Up @@ -279,6 +283,8 @@ def _add_user_type_runs(data, id_, value):
data['logged_runs'] += value
if id_ == UserType.STUDENT.value:
data['student_runs'] += value
if id_ == UserType.ALL.value:
data['user_type_unknown_runs'] += value


def _split_keys_data(k, v, keys):
Expand Down

0 comments on commit e68cfe9

Please sign in to comment.