def rows(self): startdate = json_format_datetime(self.datespan.startdate_utc) enddate = json_format_datetime(self.datespan.enddate_utc) data = FRISMSLog.view("sms/by_domain", startkey=[self.domain, "SMSLog", startdate], endkey=[self.domain, "SMSLog", enddate], include_docs=True, reduce=False).all() result = [] direction_map = { INCOMING: _("Incoming"), OUTGOING: _("Outgoing"), } message_bank_messages = get_message_bank(self.domain, for_comparing=True) case_cache = CaseDbCache(domain=self.domain, strip_history=False, deleted_ok=True) user_cache = UserCache() show_only_survey_traffic = self.show_only_survey_traffic() for message in data: if message.direction == OUTGOING and not message.processed: continue if show_only_survey_traffic and message.xforms_session_couch_id is None: continue # Add metadata from the message bank if it has not been added already if (message.direction == OUTGOING) and ( not message.fri_message_bank_lookup_completed): add_metadata(message, message_bank_messages) if message.couch_recipient_doc_type == "CommCareCase": recipient = case_cache.get(message.couch_recipient) else: recipient = user_cache.get(message.couch_recipient) if message.chat_user_id: sender = user_cache.get(message.chat_user_id) else: sender = None study_arm = None if message.couch_recipient_doc_type == "CommCareCase": study_arm = case_cache.get( message.couch_recipient).get_case_property("study_arm") timestamp = ServerTime(message.date).user_time( self.timezone).done() result.append([ self._fmt(self._participant_id(recipient)), self._fmt(study_arm or "-"), self._fmt(self._originator(message, recipient, sender)), self._fmt_timestamp(timestamp), self._fmt(message.text), self._fmt(message.fri_id or "-"), self._fmt(direction_map.get(message.direction, "-")), ]) return result
def rows(self): data = SMS.by_domain( self.domain, start_date=self.datespan.startdate_utc, end_date=self.datespan.enddate_utc ).exclude( direction=OUTGOING, processed=False ).order_by('date') if self.show_only_survey_traffic(): data = data.filter( xforms_session_couch_id__isnull=False ) result = [] direction_map = { INCOMING: _("Incoming"), OUTGOING: _("Outgoing"), } message_bank_messages = get_message_bank(self.domain, for_comparing=True) FormProcessorInterface(self.domain).casedb_cache( domain=self.domain, strip_history=False, deleted_ok=True ) user_cache = UserCache() for message in data: # Add metadata from the message bank if it has not been added already if (message.direction == OUTGOING) and (not message.fri_message_bank_lookup_completed): add_metadata(message, message_bank_messages) if message.couch_recipient_doc_type == "CommCareCase": recipient = case_cache.get(message.couch_recipient) else: recipient = user_cache.get(message.couch_recipient) if message.chat_user_id: sender = user_cache.get(message.chat_user_id) else: sender = None study_arm = None if message.couch_recipient_doc_type == "CommCareCase": study_arm = case_cache.get(message.couch_recipient).get_case_property("study_arm") timestamp = ServerTime(message.date).user_time(self.timezone).done() result.append([ self._fmt(self._participant_id(recipient)), self._fmt(study_arm or "-"), self._fmt(self._originator(message, recipient, sender)), self._fmt_timestamp(timestamp), self._fmt(message.text), self._fmt(message.fri_id or "-"), self._fmt(direction_map.get(message.direction,"-")), ]) return result
def rows(self): data = SMS.by_domain(self.domain, start_date=self.datespan.startdate_utc, end_date=self.datespan.enddate_utc).exclude( direction=OUTGOING, processed=False).order_by('date') if self.show_only_survey_traffic(): data = data.filter(xforms_session_couch_id__isnull=False) result = [] direction_map = { INCOMING: _("Incoming"), OUTGOING: _("Outgoing"), } message_bank_messages = get_message_bank(self.domain, for_comparing=True) FormProcessorInterface(self.domain).casedb_cache(domain=self.domain, strip_history=False, deleted_ok=True) user_cache = UserCache() for message in data: # Add metadata from the message bank if it has not been added already if (message.direction == OUTGOING) and ( not message.fri_message_bank_lookup_completed): add_metadata(message, message_bank_messages) if message.couch_recipient_doc_type == "CommCareCase": recipient = case_cache.get(message.couch_recipient) else: recipient = user_cache.get(message.couch_recipient) if message.chat_user_id: sender = user_cache.get(message.chat_user_id) else: sender = None study_arm = None if message.couch_recipient_doc_type == "CommCareCase": study_arm = case_cache.get( message.couch_recipient).get_case_property("study_arm") timestamp = ServerTime(message.date).user_time( self.timezone).done() result.append([ self._fmt(self._participant_id(recipient)), self._fmt(study_arm or "-"), self._fmt(self._originator(message, recipient, sender)), self._fmt_timestamp(timestamp), self._fmt(message.text), self._fmt(message.fri_id or "-"), self._fmt(direction_map.get(message.direction, "-")), ]) return result
def rows(self): startdate = json_format_datetime(self.datespan.startdate_utc) enddate = json_format_datetime(self.datespan.enddate_utc) data = FRISMSLog.view("sms/by_domain", startkey=[self.domain, "SMSLog", startdate], endkey=[self.domain, "SMSLog", enddate], include_docs=True, reduce=False).all() result = [] direction_map = { INCOMING: _("Incoming"), OUTGOING: _("Outgoing"), } message_bank_messages = get_message_bank(self.domain, for_comparing=True) FormProcessorInterface(self.domain).casedb_cache( domain=self.domain, strip_history=False, deleted_ok=True ) user_cache = UserCache() show_only_survey_traffic = self.show_only_survey_traffic() for message in data: if message.direction == OUTGOING and not message.processed: continue if show_only_survey_traffic and message.xforms_session_couch_id is None: continue # Add metadata from the message bank if it has not been added already if (message.direction == OUTGOING) and (not message.fri_message_bank_lookup_completed): add_metadata(message, message_bank_messages) if message.couch_recipient_doc_type == "CommCareCase": recipient = case_cache.get(message.couch_recipient) else: recipient = user_cache.get(message.couch_recipient) if message.chat_user_id: sender = user_cache.get(message.chat_user_id) else: sender = None study_arm = None if message.couch_recipient_doc_type == "CommCareCase": study_arm = case_cache.get(message.couch_recipient).get_case_property("study_arm") timestamp = ServerTime(message.date).user_time(self.timezone).done() result.append([ self._fmt(self._participant_id(recipient)), self._fmt(study_arm or "-"), self._fmt(self._originator(message, recipient, sender)), self._fmt_timestamp(timestamp), self._fmt(message.text), self._fmt(message.fri_id or "-"), self._fmt(direction_map.get(message.direction,"-")), ]) return result
def get_participant_message_counts(self, message_bank_messages, case): result = {} for entry in message_bank_messages: result[entry["message"]._id] = 0 participant_messages = self.get_participant_messages(case) for sms in participant_messages: if sms.xforms_session_couch_id is None and sms.direction == OUTGOING: if not sms.fri_message_bank_lookup_completed: add_metadata(sms, message_bank_messages) if sms.fri_message_bank_message_id in result: result[sms.fri_message_bank_message_id] += 1 return result
def get_participant_message_counts(self, message_bank_messages, case): result = {} for entry in message_bank_messages: result[entry["message"]._id] = 0 participant_messages = self.get_participant_messages(case) for sms in participant_messages: if sms.chat_user_id is not None: if not sms.fri_message_bank_lookup_completed: add_metadata(sms, message_bank_messages) if sms.fri_message_bank_message_id in result: result[sms.fri_message_bank_message_id] += 1 return result
def rows(self): startdate = json_format_datetime(self.datespan.startdate_utc) enddate = json_format_datetime(self.datespan.enddate_utc) data = FRISMSLog.view("sms/by_domain", startkey=[self.domain, "SMSLog", startdate], endkey=[self.domain, "SMSLog", enddate], include_docs=True, reduce=False).all() result = [] direction_map = { INCOMING: _("Incoming"), OUTGOING: _("Outgoing"), } message_bank_messages = get_message_bank(self.domain, for_comparing=True) case_cache = CaseDbCache(domain=self.domain, strip_history=False, deleted_ok=True) user_cache = UserCache() for message in data: # Add metadata from the message bank if it has not been added already if (message.direction == OUTGOING) and (not message.fri_message_bank_lookup_completed): add_metadata(message, message_bank_messages) if message.couch_recipient_doc_type == "CommCareCase": recipient = case_cache.get(message.couch_recipient) else: recipient = user_cache.get(message.couch_recipient) if message.chat_user_id: sender = user_cache.get(message.chat_user_id) else: sender = None study_arm = None if message.couch_recipient_doc_type == "CommCareCase": study_arm = case_cache.get(message.couch_recipient).get_case_property("study_arm") timestamp = tz_utils.adjust_datetime_to_timezone(message.date, pytz.utc.zone, self.timezone.zone) result.append([ self._fmt(self._participant_id(recipient)), self._fmt(study_arm or "-"), self._fmt(self._originator(message, recipient, sender)), self._fmt_timestamp(timestamp), self._fmt(message.text), self._fmt(message.fri_id or "-"), self._fmt(direction_map.get(message.direction,"-")), ]) return result