每隔两个小时统计一下提交问卷的数量

 obj = Questionnaire.objects.filter(id=request.GET.get("questionnaire_id")).first()
    time_start = obj.start_datetime
    count_whole = []
    time_whole =[]
    while time_start < obj.end_datetime:
        # 转化为时间戳
        a = time_start.strftime("%Y-%m-%d %H:%M:%S")
        timearray = time.strptime(a, "%Y-%m-%d %H:%M:%S")
        timestamp = int(time.mktime(timearray))

        time_whole.append(timestamp)
        end_time = time_start + datetime.timedelta(hours=2)
        count = QuestionnaireItem.objects.filter(questionnaire_id=request.GET.get("questionnaire_id"),submit_time__gt=time_start,submit_time__lt=end_time).count()
        time_start = end_time
        count_whole.append(count)

    b = obj.end_datetime.strftime("%Y-%m-%d %H:%M:%S")
    timearray = time.strptime(b, "%Y-%m-%d %H:%M:%S")
    timestamp = int(time.mktime(timearray))
    time_whole.append(timestamp)
    res["pv"] = pv
    res["recycled"] = recycled
    res["time_whole"] = time_whole
    res["count_whole"] = count_whole
    return JsonResponse(res)

 

posted on 2018-05-28 21:38  海燕。  阅读(99)  评论(0编辑  收藏  举报