Beispiel #1
0
def startCallibration(request):
    try:
        userData = UserData.objects.get(userId=request.user.id)
    except ObjectDoesNotExist:
        userData = UserData(userId=request.user.id)
    userData.startCallibrationTime = str(int(time.time()))
    userData.stopCallibrationTime = -1
    userData.maxValuesList = None
    userData.minValuesList = None
    userData.isDirt = 1
    userData.save()
    return getHttpSuccessResponse()
Beispiel #2
0
def stopCallibration(request):
    try:
        userData = UserData.objects.get(userId=request.user.id)
    except ObjectDoesNotExist:
        userData = UserData(userId=request.user.id)
    userData.stopCallibrationTime = str(int(time.time()))

    #    userData.startCallibrationTime = 1374776866
    #    userData.stopCallibrationTime = 1374776869
    try:
        #        load calibration data per user
        rawData = DataReader.loadDataInRange(request.user.id,
                                             userData.startCallibrationTime,
                                             userData.stopCallibrationTime)
        for serialRawData in rawData:
            data = serialRawData.data.replace("\r", "").split("\t")
            if userData.minValuesList != None:  # has prev. info
                minValueList = jsonDec.decode(
                    userData.minValuesList)  #convert string to array
                maxValueList = jsonDec.decode(userData.maxValuesList)
                for i in range(len(data)):  #update min and max arrays
                    if int(data[i]) < int(minValueList[i]):
                        minValueList[i] = data[i]
                    if int(data[i]) > int(maxValueList[i]):
                        maxValueList[i] = data[i]

                userData.minValuesList = json.dumps(
                    minValueList)  #convert array to string
                userData.maxValuesList = json.dumps(maxValueList)
            else:  # first record
                userData.minValuesList = json.dumps(data)
                userData.maxValuesList = json.dumps(data)
        #clear old data
        DataReader.removeData(request.user.id, userData.stopCallibrationTime)
    except ObjectDoesNotExist:
        return getHttpResponse(0, "Serial data of the user is empty.   ")

    userData.save(force_update=True)

    return getHttpSuccessResponse()