DO.py 文件源码

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

项目:electricitymap 作者: tmrowco 项目源码 文件源码
def merge_production(thermal, total):
    """
    Takes thermal generation and total generation and merges them using 'datetime' key.
    Returns a defaultdict.
    """

    d = defaultdict(dict)
    for each in (thermal, total):
        for elem in each:
            d[elem['datetime']].update(elem)

    final = sorted(d.values(), key=itemgetter("datetime"))

    def get_datetime(hour):
        at = arrow.now('America/Dominica').floor('day')
        dt = (at.shift(hours=int(hour) - 1)).datetime
        return dt

    for item in final:
        i = item['datetime']
        j = get_datetime(i)
        item['datetime'] = j

    return final
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号