def get_faq() -> dict[str, list[Any]]: entries = FaqEntry.query.order_by(FaqEntry.view_count.desc()).all() groups = sorted(r.group_by(lambda e: e.category, entries).items()) result = [] for k, v in groups: v = sorted(v, key=lambda x: -(x.view_count or 0)) data = FaqEntrySchema().dump(v, many=True).data result.append([k, data]) return {"categories": result, "entries": []}
def __get_feature_score(self, feature: str, data: Table): values = data.get_values_by_headers([feature, 'rating']).rows sets = R.group_by(lambda i: 'yes' if i[feature] == 'y' else 'no', values) yes_values = self.__get_labels((sets['yes'])) no_values = self.__get_labels((sets['no'])) guess_if_yes = mode(yes_values) guess_if_no = mode(no_values) def count_correct_guesses(set, guess): return len(R.filter(lambda i: i == guess, set)) correct_yes_guesses = count_correct_guesses(yes_values, guess_if_yes) correct_no_guesses = count_correct_guesses(no_values, guess_if_no) score = ( (correct_yes_guesses + correct_no_guesses) / len(values)) * 100 return dict(score=score, feature=feature)
def group_by_empty(): assert_equal(group_by(grade)([]), {})
def test_group_by_no_curry(): assert_equal(group_by(grade, students), students_by_grade)