views.py 文件源码

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

项目:ac-mediator 作者: AudioCommons 项目源码 文件源码
def get_application_monitor_data(request, pk):
    """
    Returns API client usage data to be shown in the monitor page.
    This view should return a JSON response with a 'data' field including a list of API usage event.
    Each event should include a 'date' field with the timestamp as returned by Pythons Datetime.timestamp() object
    (https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp) and with a 'service' property
    with the service name (to which a request was forwarded).
    """
    #application = get_object_or_404(ApiClient, pk=pk)
    fake_data_points = list()
    today = datetime.datetime.today()
    services = get_available_services()
    import random
    N_FAKE_POINTS = 1000
    DAYS_SPAN = 60
    for i in range(0, N_FAKE_POINTS):
        fake_data_points.append({
            'date': (today - datetime.timedelta(minutes=random.randint(0, 60*24*DAYS_SPAN))).timestamp(),
            'service': random.choice(services).name,
        })
    return JsonResponse({'data': fake_data_points})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号