utilities.py 文件源码

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

项目:CommunityCellularManager 作者: facebookincubator 项目源码 文件源码
def generate_gprs_events(start_timestamp, end_timestamp):
    """Create GPRS events from data in the GPRS DB.

    Records that were generated between the specified timestamp will become
    events.  One event is created per IMSI (not one event per record).

    Args:
      start_timestamp: seconds since epoch
      end_timestamp: seconds since epoch
    """
    gprs_db = gprs_database.GPRSDB()
    # First organize the records by IMSI.
    sorted_records = {}
    for record in gprs_db.get_records(start_timestamp, end_timestamp):
        if record['imsi'] not in sorted_records:
            sorted_records[record['imsi']] = []
        sorted_records[record['imsi']].append(record)
    # Now analyze all records that we have for each IMSI.
    for imsi in sorted_records:
        up_bytes = sum(
            [r['uploaded_bytes_delta'] for r in sorted_records[imsi]])
        down_bytes = sum(
            [r['downloaded_bytes_delta'] for r in sorted_records[imsi]])
        # Do not make an event if the byte deltas are unchanged.
        if up_bytes == 0 and down_bytes == 0:
            continue
        # For now, GPRS is free for subscribers.
        cost = 0
        reason = 'gprs_usage: %s uploaded, %s downloaded' % (
            humanize.naturalsize(up_bytes), humanize.naturalsize(down_bytes))
        timespan = int(end_timestamp - start_timestamp)
        events.create_gprs_event(
            imsi, cost, reason, up_bytes, down_bytes, timespan)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号