services.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:dsmr-reader 作者: dennissiemensma 项目源码 文件源码
def electricity_tariff_percentage(start_date):
    """ Returns the total electricity consumption percentage by tariff (high/low tariff). """
    totals = DayStatistics.objects.filter(day__gte=start_date).aggregate(
        electricity1=Sum('electricity1'),
        electricity2=Sum('electricity2'),
    )

    # Empty data will crash.
    if not all(totals.values()):
        return None

    global_total = totals['electricity1'] + totals['electricity2']
    totals['electricity1'] = math.ceil(totals['electricity1'] / global_total * 100)
    totals['electricity2'] = 100 - totals['electricity1']
    return totals
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号