本文整理匯總了Python中corehq.apps.sms.models.SMS.get_counts_by_date方法的典型用法代碼示例。如果您正苦於以下問題:Python SMS.get_counts_by_date方法的具體用法?Python SMS.get_counts_by_date怎麽用?Python SMS.get_counts_by_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.apps.sms.models.SMS
的用法示例。
在下文中一共展示了SMS.get_counts_by_date方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_sms_count_info
# 需要導入模塊: from corehq.apps.sms.models import SMS [as 別名]
# 或者: from corehq.apps.sms.models.SMS import get_counts_by_date [as 別名]
def add_sms_count_info(self, result, days):
end_date = self.domain_now.date()
start_date = end_date - timedelta(days=days - 1)
counts = SMS.get_counts_by_date(self.domain, start_date, end_date, self.timezone.zone)
inbound_counts = {}
outbound_counts = {}
for row in counts:
if row.direction == INCOMING:
inbound_counts[row.date] = row.sms_count
elif row.direction == OUTGOING:
outbound_counts[row.date] = row.sms_count
inbound_values = []
outbound_values = []
for i in range(days):
dt = start_date + timedelta(days=i)
inbound_values.append({
'x': dt.strftime('%Y-%m-%d'),
'y': inbound_counts.get(dt, 0),
})
outbound_values.append({
'x': dt.strftime('%Y-%m-%d'),
'y': outbound_counts.get(dt, 0),
})
result['sms_count_data'] = [
{'key': _("Incoming"), 'values': inbound_values},
{'key': _("Outgoing"), 'values': outbound_values},
]