def update_mach_delivery_status(self, api_info): delivered_on = api_info[-3] delivery_status = api_info[-1] mach_id = api_info[0] if delivered_on: delivered_on = delivered_on.replace(". ", ".%s " % datetime.datetime.now().year) try: delivered_on = datetime.datetime.strptime(delivered_on, "%d.%m.%Y %H:%M:%S") berlin = pytz.timezone('Europe/Berlin') is_dst = tz_utils.is_timezone_in_dst(berlin, delivered_on) delivered_on = berlin.localize(delivered_on, is_dst=is_dst).astimezone(pytz.utc) contact = datetime.datetime.replace(self.contacted_mach_api, tzinfo=pytz.utc) td = contact - delivered_on total_seconds = abs(td.seconds + td.days * 24 * 3600) existing = self.get_by_mach_id(mach_id) # allowing three minutes of latency and making sure that the mach_id is unique if total_seconds <= 60*3 and not existing: self.mach_id = mach_id self.mach_delivery_status = delivery_status self.mach_delivered_date = delivered_on except Exception as e: logging.info("[Billing] Error parsing MACH API delivery info: %s" % e) elif delivery_status == 'accepted': # message has not been delivered yet self.mach_id = mach_id self.mach_delivery_status = delivery_status
def rows(self): rows = list() prefix = ["user"] selected_form = self.request_params.get("form") if selected_form: prefix.append("form_type") total = 0 total_seconds = 0 for user in self.users: key = [" ".join(prefix), self.domain, user.get("user_id")] if selected_form: key.append(selected_form) data = ( get_db() .view( "reports/completion_vs_submission", startkey=key + [self.datespan.startdate_param_utc], endkey=key + [self.datespan.enddate_param_utc], reduce=False, ) .all() ) for item in data: vals = item.get("value") completion_time = dateutil.parser.parse(vals.get("completion_time")).replace(tzinfo=None) completion_dst = ( False if self.timezone == pytz.utc else tz_utils.is_timezone_in_dst(self.timezone, completion_time) ) completion_time = self.timezone.localize(completion_time, is_dst=completion_dst) submission_time = dateutil.parser.parse(vals.get("submission_time")) submission_time = submission_time.replace(tzinfo=pytz.utc) submission_time = tz_utils.adjust_datetime_to_timezone( submission_time, pytz.utc.zone, self.timezone.zone ) td = submission_time - completion_time td_total = td.seconds + td.days * 24 * 3600 rows.append( [ self.get_user_link(user), self._format_date(completion_time), self._format_date(submission_time), self._view_form_link(item.get("id", "")), self.table_cell(td_total, self._format_td_status(td)), ] ) if td_total >= 0: total_seconds += td_total total += 1 self.total_row = [ "Average", "-", "-", "-", self._format_td_status(int(total_seconds / total), False) if total > 0 else "--", ] return rows
def rows(self): rows = [] total = 0 total_seconds = 0 if self.all_relevant_forms: for user in self.users: if not user.get("user_id"): # calling get_form_data with no user_id will return ALL form data which is not what we want continue for form in self.all_relevant_forms.values(): data = self.get_form_data(user.get("user_id"), form["xmlns"], form["app_id"]) for item in data: vals = item.get("value") completion_time = dateutil.parser.parse(vals.get("completion_time")).replace(tzinfo=None) completion_dst = ( False if self.timezone == pytz.utc else tz_utils.is_timezone_in_dst(self.timezone, completion_time) ) completion_time = self.timezone.localize(completion_time, is_dst=completion_dst) submission_time = dateutil.parser.parse(vals.get("submission_time")) submission_time = submission_time.replace(tzinfo=pytz.utc) submission_time = tz_utils.adjust_datetime_to_timezone( submission_time, pytz.utc.zone, self.timezone.zone ) td = submission_time - completion_time td_total = td.seconds + td.days * 24 * 3600 rows.append( [ self.get_user_link(user), self._format_date(completion_time), self._format_date(submission_time), form["name"], self._view_form_link(item.get("id", "")), self.table_cell(td_total, self._format_td_status(td)), ] ) if td_total >= 0: total_seconds += td_total total += 1 else: rows.append(["No Submissions Available for this Date Range"] + ["--"] * 5) self.total_row = [ _("Average"), "-", "-", "-", "-", self._format_td_status(int(total_seconds / total), False) if total > 0 else "--", ] return rows
def rows(self): rows = [] total = 0 total_seconds = 0 if self.all_relevant_forms: for user in self.users: if not user.get('user_id'): # calling get_form_data with no user_id will return ALL form data which is not what we want continue for form in self.all_relevant_forms.values(): data = self.get_form_data(user.get('user_id'), form['xmlns'], form['app_id']) for item in data: vals = item.get('value') completion_time = dateutil.parser.parse( vals.get('completion_time')).replace(tzinfo=None) completion_dst = False if self.timezone == pytz.utc else\ tz_utils.is_timezone_in_dst(self.timezone, completion_time) completion_time = self.timezone.localize( completion_time, is_dst=completion_dst) submission_time = dateutil.parser.parse( vals.get('submission_time')) submission_time = submission_time.replace( tzinfo=pytz.utc) submission_time = tz_utils.adjust_datetime_to_timezone( submission_time, pytz.utc.zone, self.timezone.zone) td = submission_time - completion_time td_total = (td.seconds + td.days * 24 * 3600) rows.append([ self.get_user_link(user), self._format_date(completion_time), self._format_date(submission_time), form['name'], self._view_form_link(item.get('id', '')), self.table_cell(td_total, self._format_td_status(td)) ]) if td_total >= 0: total_seconds += td_total total += 1 else: rows.append(['No Submissions Available for this Date Range'] + ['--'] * 5) self.total_row = [ _("Average"), "-", "-", "-", "-", self._format_td_status(int(total_seconds / total), False) if total > 0 else "--" ] return rows