def test_get_survey_participation(self):
        """Get count of particpants at each marker."""
        pds = self.mock_one_finished_one_unfinished(1)
        survey_id = pds[0].survey_id
        start = datetime.date.today()
        end = start + datetime.timedelta(days=1)
        result = ParticipantData.participation(survey_id=survey_id,
                                               start=start,
                                               end=end)
        expected = [
            {
                'value': '1',
                'n': 1,
                'survey_ordinal': 1
            },
            {
                'value': '100',
                'n': 1,
                'survey_ordinal': 1
            },
        ]
        self.assertEqual(result, expected)

        # The same result should also now be available in memcache, so if we
        # clear the db the result should be the same.
        ParticipantData.delete_multi(pds)
        result = ParticipantData.participation(survey_id=survey_id,
                                               start=start,
                                               end=end)
        self.assertEqual(result, expected)
    def test_get_project_cohort_participation(self):
        """Get stats for all surveys in the project cohort."""
        pds1 = self.mock_one_finished_one_unfinished(1)
        pds2 = self.mock_one_finished_one_unfinished(2)
        project_cohort_id = pds1[0].project_cohort_id
        ProjectCohort(
            id=project_cohort_id,
            program_label=self.program_label,
        ).put()
        start = datetime.date.today()
        end = start + datetime.timedelta(days=1)

        expected = [
            {
                'value': '1',
                'n': 1,
                'survey_ordinal': 1
            },
            {
                'value': '100',
                'n': 1,
                'survey_ordinal': 1
            },
            {
                'value': '1',
                'n': 1,
                'survey_ordinal': 2
            },
            {
                'value': '100',
                'n': 1,
                'survey_ordinal': 2
            },
        ]

        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id, start=start, end=end)
        self.assertEqual(result, expected)

        # The same result should also now be available in memcache, so if we
        # clear the db the result should be the same.
        ParticipantData.delete_multi(pds1 + pds2)
        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id, start=start, end=end)
        self.assertEqual(result, expected)

        # It should also work if some other kwargs are set with value None.
        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id,
            start=start,
            end=end,
            cohort_label=None)
        self.assertEqual(result, expected)
    def test_get_cohort_participation(self):
        """Get stats for all surveys in a cohort."""
        pc_id1 = 'ProjectCohort_one'
        pc_id2 = 'ProjectCohort_two'
        pds11 = self.mock_one_finished_one_unfinished(1, pc_id=pc_id1)
        pds12 = self.mock_one_finished_one_unfinished(2, pc_id=pc_id1)
        pds21 = self.mock_one_finished_one_unfinished(1, pc_id=pc_id2)
        pds22 = self.mock_one_finished_one_unfinished(2, pc_id=pc_id2)

        expected = [
            {
                'value': '1',
                'n': 2,
                'survey_ordinal': 1
            },
            {
                'value': '100',
                'n': 2,
                'survey_ordinal': 1
            },
            {
                'value': '1',
                'n': 2,
                'survey_ordinal': 2
            },
            {
                'value': '100',
                'n': 2,
                'survey_ordinal': 2
            },
        ]

        stats = ParticipantData.participation(program_label=self.program_label,
                                              cohort_label=self.cohort_label)
        self.assertEqual(stats, expected)
    def test_nobody_done(self):
        """If no one finished the survey, counts are zero."""
        survey = Survey.create([], ordinal=1, program_label=self.program_label)
        survey.put()
        kwargs = {
            'key': 'progress',
            'program_label': self.program_label,
            'project_id': 'Project_12345678',
            'cohort_label': '2017_spring',
            'project_cohort_id': 'ProjectCohort_12345678',
            'code': 'trout viper',
            'survey_id': survey.uid,
            'survey_ordinal': survey.ordinal,
        }

        pd = [
            ParticipantData.create(participant_id='Participant_unfinished1',
                                   value=1,
                                   **kwargs),
            ParticipantData.create(participant_id='Participant_unfinished2',
                                   value=1,
                                   **kwargs),
        ]
        ParticipantData.put_multi(pd)

        result = ParticipantData.participation(survey_id=pd[0].survey_id)
        expected = [
            {
                'value': '1',
                'n': 2,
                'survey_ordinal': 1
            },
        ]

        self.assertEqual(result, expected)
Example #5
0
 def test_project_cohort_participation(self):
     pid = self.test_create_portal_pd()
     results = ParticipantData.participation(
         project_cohort_id='ProjectCohort_12345678')
     expected = [
         {
             'survey_ordinal': 1,
             'value': '100',
             'n': 1
         },
         {
             'survey_ordinal': 2,
             'value': '33',
             'n': 1
         },
     ]
     self.assertEqual(results, expected)
Example #6
0
 def test_counts_exclude_testing(self):
     """Aggregated counts should ignore testing pd."""
     pid = self.test_create_portal_pd(testing=True)
     results = ParticipantData.participation(survey_id='Survey_1')
     self.assertEqual(results, [])
Example #7
0
 def test_survey_participation(self):
     pid = self.test_create_portal_pd()
     results = ParticipantData.participation(survey_id='Survey_1')
     expected = {'survey_ordinal': 1, 'value': '100', 'n': 1}
     self.assertEqual(results[0], expected)