compute_delay.py 文件源码

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

项目:nmbs-realtime-feed 作者: datamindedbe 项目源码 文件源码
def remove_redundant_delays(conn, delays):
    if len(delays.values()) == 0:
        return delays  # no new delays to add
    ids = delays.keys()
    cur = conn.cursor(cursor_factory=RealDictCursor)
    query = """ SELECT * FROM realtime_updates WHERE id IN %(ids)s """
    cur.execute(query, {'ids': tuple(ids)})
    results = cur.fetchall()
    cur.close()
    existing_delays = {get_delay_id(r): r for r in results}
    new_delays = {}
    for key, delay in delays.iteritems():
        # if stop already registered in datbase
        if key in existing_delays:
            current = existing_delays[key]
            # and the file we're reading now is newer than the file in the database
            if current['s3_path'] < delay['s3_path']:
                # and the timings is different
                if current['arrival_delay'] != delay['arrival_delay'] \
                        or current['departure_delay'] != delay['departure_delay']:
                    # then store the change
                    new_delays[key] = delay
        else:
            new_delays[key] = delay
    return new_delays
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号