コード例 #1
0
def test_watch_score_by_huid(mocker, es_resp_maker):
    episode = Episode({'mpid': '456-efg', 'duration': 1800000})
    agg_data = {
        'by_huid': {
            'buckets': [
                {
                    # student watched 70% of the lecture
                    'key': '12121212',
                    'by_inpoint': {
                        'buckets': [1, 2, 3, 4, 5, 6, 7]
                    }
                },
                {
                    # student watched 40%
                    'key': '99999999',
                    'by_inpoint': {
                        'buckets': [1, 2, 3, 4]
                    }
                }
            ]
        }
    }
    es_resp = es_resp_maker(aggregations=agg_data)
    la = LectureAttendance(episode, es_resp)
    assert la.watch_score('12121212') == 70
    assert la.watch_score('99999999') == 40
コード例 #2
0
def test_lecture(client, mocker, student_list_maker):

    ep = Episode({
        'series': '20170110207',
        'title': 'Lecture 11',
        'mpid': 'ea00b6b4-713a-48e2-9b3d-500504aa7615',
        'course': 'Baz 101',
        'duration': 101010101,
        'start': datetime.now()
    })
    mocker.patch('le_dash.es.Episode.findone', return_value=ep)

    student_list = student_list_maker(('45678', 'Paul', 'S', 'Rudd'),
                                      ('67890', 'Twilight', 'P', 'Sparkle'),
                                      ('837465', 'Chief', 'C', 'Burns'))
    scores = [33, 89, 66]
    mock_attendance = []
    for student in student_list:
        mock_attendance.append({
            'student': Student(student),
            'score': scores.pop(0)
        })
    mocker.patch('le_dash.rollcall.lecture_attendance',
                 return_value=mock_attendance)

    response = client.get(
        '/attendance/lecture/ea00b6b4-713a-48e2-9b3d-500504aa7615/')
    assert b'Baz 101' in response.content
    assert b'Lecture 11' in response.content
    assert b'<td>Twilight P Sparkle</td>' in response.content
    assert b'<td>837465</td>' in response.content
    assert b'<td>66</td>' in response.content
コード例 #3
0
ファイル: views.py プロジェクト: harvard-dce/le-dash
def lecture(request, mpid):
    episode = Episode.findone(mpid=mpid)
    attendance = rollcall.lecture_attendance(episode.mpid)
    context = {
        'mpid': mpid,
        'episode': episode,
        'attendance': attendance
    }
    return render(request, 'attendance/lecture.html', context)
コード例 #4
0
ファイル: rollcall.py プロジェクト: harvard-dce/le-dash
def lecture_attendance(mpid, sort_key='student.last_name'):
    episode = Episode.findone(mpid=mpid)
    students = [Student(x) for x in get_student_list(episode.series)]
    attendance = LectureAttendance.from_episode(episode)
    student_attendance = []
    for student in students:
        score = attendance.watch_score(student.huid)
        student_attendance.append({'student': student, 'score': score})
    return sorted(student_attendance,
                  key=lambda x: getattr(x['student'], 'last_name'))
コード例 #5
0
ファイル: views.py プロジェクト: harvard-dce/le-dash
def detailed(request, mpid):
    episode = Episode.findone(mpid=mpid)
    if episode:
        context = {'mpid': mpid,
                   'title': episode.title,
                   'course_name': episode.course,
                   'series': episode.series}
    else:
        context = {'mpid': mpid}
    return render(request, 'attendance/detailed.html', context)
コード例 #6
0
ファイル: views.py プロジェクト: harvard-dce/le-dash
def data(request, mpid):
    q = StudentSummaryWatchQuery(mpid)
    resp = q.execute()
    results = resp.to_dict()

    episode = Episode.findone(mpid=mpid)
    if episode:
        student_data = banner.get_student_list(episode.series)
        results['students'] = student_data

    return JsonResponse(results)
コード例 #7
0
ファイル: views.py プロジェクト: harvard-dce/le-dash
def summarytable(request, mpid):
    students = rollcall.LectureAttendanceByAllStudents(mpid).all_scores()
    try:
        episode = Episode.findone(mpid=mpid)
        context = {'students': students,
                   'title': episode.title,
                   'course_name': episode.course,
                   'series': episode.series,
                   'mpid': mpid}
    except:
        context = {'students': students, 'mpid': mpid}
    return render(request, 'attendance/student-summary-table.html', context)
コード例 #8
0
ファイル: views.py プロジェクト: harvard-dce/le-dash
def series_viewing_data(request, series_id):
    q = SeriesViewingQuery(series_id)
    resp = q.execute()
    results = resp.to_dict()
    episodes_dump = Episode.findall(series=series_id, size=999)
    if episodes_dump:
        episodes = [{"mpid": episode.mpid,
                     "title": episode.title,
                     "type": episode.type,
                     "duration": episode.duration}
                    for episode in episodes_dump]
        results["episodes"] = episodes

    return JsonResponse(results)
コード例 #9
0
ファイル: test_lecture.py プロジェクト: harvard-dce/le-dash
def test_lecture(client, mocker):

    ep = Episode({
        'mpid': 'ea00b6b4-713a-48e2-9b3d-500504aa7615',
        'course': 'Foo 101',
        'title': 'Lecture 39',
        'duration': 10000099,
        'series': '20170156789',
        'start': datetime.now()
    })
    mocker.patch('lecture.views.Episode.findone', return_value=ep)

    response = client.get('/lecture/ea00b6b4-713a-48e2-9b3d-500504aa7615/')
    assert b'Foo 101' in response.content
    assert b'2:46:40' in response.content
コード例 #10
0
def test_lectures_watched_by_huid(mocker, es_resp_maker):
    eps = [
        Episode({
            'mpid': '123-abc',
            'duration': 360000
        }),
        Episode({
            'mpid': '456-efg',
            'duration': 540000
        })
    ]
    mocker.patch('le_dash.es.Episode.findall', return_value=eps)

    # lectures_watched() only counts up the # of inpoint buckets so
    # actual 'key' and 'doc_count' values don't matter
    agg_data = {
        'by_huid': {
            'buckets': [
                {
                    # student watched 100% of 1st lecture, 66% of 2nd
                    'key': '12121212',
                    'by_mpid': {
                        'buckets': [{
                            'key': '123-abc',
                            'by_inpoint': {
                                'buckets': [1, 2]
                            }
                        }, {
                            'key': '456-efg',
                            'by_inpoint': {
                                'buckets': [1, 2]
                            }
                        }]
                    }
                },
                {
                    # student watched 50% of 1st lecture, 33% of 2nd
                    'key': '99999999',
                    'by_mpid': {
                        'buckets': [{
                            'key': '123-abc',
                            'by_inpoint': {
                                'buckets': [1]
                            }
                        }, {
                            'key': '456-efg',
                            'by_inpoint': {
                                'buckets': [1]
                            }
                        }]
                    }
                }
            ]
        }
    }
    es_resp = es_resp_maker(aggregations=agg_data)
    sa = SeriesAttendance('1000000099', es_resp)

    # default ATTENDANCE_WATCHED_THRESHOLD is 50%
    assert sa.lectures_watched('12121212') == 2
    assert sa.lectures_watched('99999999') == 1

    with patch('le_dash.rollcall.ATTENDANCE_WATCHED_THRESHOLD', 70):
        assert sa.lectures_watched('12121212') == 1
        assert sa.lectures_watched('99999999') == 0
コード例 #11
0
ファイル: rollcall.py プロジェクト: harvard-dce/le-dash
 def __init__(self, series_id, es_resp=None):
     self.series_id = series_id
     self.es_resp = es_resp
     self.episodes = dict(
         (x.mpid, x) for x in Episode.findall(series=series_id))