示例#1
0
def all_statistics(request):
    """
    we only run the whole stats computaion if the statistic 
    file is older than an hour
    """
    stat_file = str(settings.MEDIA_ROOT + 'daily_stats.json')
    statbuf = os.stat(stat_file)
    last_modif = datetime.datetime.fromtimestamp(statbuf.st_mtime)
    diff = datetime.datetime.now() - last_modif
    data = [] 
    if diff > datetime.timedelta(0, 86400, 0): 
        context = RequestContext(request, {'daily_stats': exercises_logs() })
    else:
        try:
            f_handle = open(stat_file)
            logs = convert(json.load(f_handle))
            for t_log in logs:
                data_0 = []
                for key, value in t_log.iteritems():
                    data_0.append(value)
                data.append(data_0)
            f_handle.close()
        except IOError as f_error:
            print "error ({0}) reading file : {1}".format(f_error.errno, \
                                                          f_error.strerror)

        context = RequestContext(request, {'daily_stats': data})
    return render_to_response("opendsa/all-stats.html", context) 
示例#2
0
def all_statistics(request):
    """
    we only run the whole stats computaion if the statistic 
    file is older than an hour
    """
    stat_file = str(settings.MEDIA_ROOT + "daily_stats.json")
    statbuf = os.stat(stat_file)
    last_modif = datetime.datetime.fromtimestamp(statbuf.st_mtime)
    diff = datetime.datetime.now() - last_modif
    data = []
    if diff > datetime.timedelta(0, 86400, 0):
        context = RequestContext(request, {"daily_stats": exercises_logs()})
    else:
        try:
            f_handle = open(stat_file)
            logs = convert(json.load(f_handle))
            for t_log in logs:
                data_0 = []
                for key, value in t_log.iteritems():
                    data_0.append(value)
                data.append(data_0)
            f_handle.close()
        except IOError as f_error:
            print "error ({0}) reading file : {1}".format(f_error.errno, f_error.strerror)

        context = RequestContext(request, {"daily_stats": data})
    return render_to_response("opendsa/all-stats.html", context)
示例#3
0
def daily_summary(request, course_instance=None):
    """
    Daily statictics view
    """
    courses_intances = CourseInstance.objects.all()

    ci_List = []
    for ci in courses_intances:
      ci_List.append(str(ci.instance_name))

    exercises_logs(course_instance)
   
 
    context = RequestContext(request, {'courses': ci_List, 'instance': course_instance,'daily_stats': str(settings.MEDIA_URL \
                                                      + 'daily_stats.json')})
    return render_to_response("opendsa/daily-ex-stats.html", context)