本文整理汇总了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},
]