Exemplo n.º 1
0
def get_delta_submission(request, project_uuid):
    survey_request = SurveyWebXformQuestionnaireRequest(
        request, project_uuid, XFormSubmissionProcessor())
    to_time = convert_date_time_to_epoch(datetime.utcnow())
    from_time = int(request.GET.get('last_fetch'))
    submissions = survey_request.get_submission_from(from_time, to_time)

    return response_json_cors({
        'submissions':
        submissions,
        'last_fetch':
        convert_date_time_to_epoch(datetime.utcnow())
    })
Exemplo n.º 2
0
def get_survey_responses_for_activity_period(dbm, form_model_id, from_time,
                                             to_time):
    from_time_in_epoch = convert_date_time_to_epoch(
        from_time) if from_time is not None else None
    to_time_in_epoch = convert_date_time_to_epoch(
        to_time) if to_time is not None else None
    startkey, endkey = _get_start_and_end_key(form_model_id,
                                              from_time_in_epoch,
                                              to_time_in_epoch)

    rows = dbm.load_all_rows_in_view('survey_response_for_activity_period',
                                     descending=True,
                                     startkey=startkey,
                                     endkey=endkey)
    return [
        SurveyResponse.new_from_doc(dbm=dbm,
                                    doc=SurveyResponse.__document_class__.wrap(
                                        row['value'])) for row in rows
    ]
Exemplo n.º 3
0
    def _get_aggregate_value(self, field, aggregate_fn, date):
        entity_id = self._doc.id
        time_since_epoch_of_date = convert_date_time_to_epoch(date)
        rows = self._dbm.load_all_rows_in_view(aggregate_fn, group_level=3, descending=False,
                                               startkey=[self.type_path, entity_id, field],
                                               endkey=[self.type_path, entity_id, field, time_since_epoch_of_date])

        # The above will return rows in the format described:
        # Row key=['clinic', 'e4540e0ae93042f4b583b54b6fa7d77a'],
        #   value={'beds': {'timestamp_for_view': 1420070400000, 'value': '15'},
        #           'entity_id': {'value': 'e4540e0ae93042f4b583b54b6fa7d77a'}, 'document_type': {'value': 'Entity'},
        #           'arv': {'timestamp_for_view': 1420070400000, 'value': '100'}, 'entity_type': {'value': 'clinic'}
        #           }
        #  The aggregation map-reduce view will return only one row for an entity-id
        # From this we return the field we are interested in.
        # TODO: Hardcoding to 'latest' for now. Generalize to any aggregation function.
        return rows[0][u'value'][u'latest'] if len(rows) else None
Exemplo n.º 4
0
 def test_convert_date_time_to_epoch_when_given_a_date_object(self):
     date_object_time = date(year=1970, month=1, day=1)
     actual_epoch_time = convert_date_time_to_epoch(date_object_time, pytz.UTC)
     expected_epoch_time = 0.0
     self.assertEqual(actual_epoch_time,expected_epoch_time)