Example #1
0
def test_first_last_days_for_month():
    month_for = '2/2020'
    month = 2
    year = 2020
    first_day, last_day = first_last_days_for_month(month_for=month_for)
    assert first_day.month == month
    assert last_day.month == month
    assert first_day.year == year
    assert last_day.year == year
    assert first_day.day == 1
    assert last_day.day == 29
Example #2
0
def get_month_course_metrics(site, course_id, month_for, **_kwargs):
    """Returns a dict with the metrics for the given site, course, month

    This function provides first generation metrics
    Initially this function returns a partial set of the course monthly metrics:
    * active users
    * course enrollments
    * number of learners completed
    """
    # TODO: handle invalid "month_for" exception
    # month, year = [int(val) for val in month_for.split('/')]
    # start_date = datetime.date(year=year, month=month, day=1)
    # end_date = datetime.date(year=year, month=month, day=days_in_month(start_date))

    first_day, last_day = first_last_days_for_month(month_for)
    params_dict = dict(site=site,
                       course_id=course_id,
                       start_date=first_day,
                       end_date=last_day)

    active_users = get_mau_from_site_course(site=site,
                                            course_id=course_id,
                                            year=first_day.year,
                                            month=first_day.month)
    course_enrollments = get_course_enrolled_users_for_time_period(
        **params_dict)
    num_learners_completed = get_course_num_learners_completed_for_time_period(
        **params_dict)
    avg_days_to_complete = get_course_average_days_to_complete_for_time_period(
        **params_dict)
    avg_progress = get_course_average_progress_for_time_period(**params_dict)

    return dict(
        course_id=course_id,
        month_for=month_for,
        active_users=active_users.count(),
        course_enrollments=course_enrollments,
        num_learners_completed=num_learners_completed,
        avg_days_to_complete=avg_days_to_complete,
        avg_progress=avg_progress,
    )