Пример #1
0
def changePredict(plant_num, collectedColor, idealColor):
    # Save the full data set to a 2D list
    dataArray = QueryData.collectData(plant_num)
    waterVals = dataArray[0]
    colorVals = dataArray[1]

    # Find the difference between the ideal and collected color
    difference = 1 - (1.0 * collectedColor / idealColor)
    newWater = waterVals[-1]

    # If the difference is significant in either direction, update based on correlation
    if difference > 0.05:
        slope = abs(regression(waterVals, colorVals))
        addAmt = slope * abs(collectedColor - idealColor)
        lastWater = waterVals[-1]
        newWater = lastWater + addAmt
    elif difference < -0.05:
        slope = abs(regression(waterVals, colorVals))
        addAmt = slope * abs(collectedColor - idealColor)
        lastWater = waterVals[-1]
        newWater = lastWater - addAmt
    healthy = True

    # Remove extreme irrigation volume changes
    if newWater > 30:
        while newWater > 7:
            newWater -= 1.1837513
            healthy = False
    if newWater < 2:
        while newWater < 5:
            newWater += 0.391
            healthy = False
    return newWater, healthy
Пример #2
0
def findW(plant_num, newTemp, newLight):
    dataArray = QueryData.collectData(plant_num)
    waterVals = dataArray[0]
    colorVals = dataArray[1]
    tempVals = dataArray[2]
    lightVals = dataArray[3]
    correlations = []
    correlations.append(regression(waterVals, colorVals))
    correlations.append(regression(tempVals, colorVals))
    correlations.append(regression(lightVals, colorVals))
    mseArray = []
    wArray = []

    # Use correlations to find predicted value and calculate loss accordingly
    for x in range(0, len(waterVals)):
        w = random.randint(0, 100)
        w = float(w) / 10.0
        totalArr = []
        wArray.append(w)
        for x in range(int(len(colorVals))):
            total = correlations[0] * waterVals[x] + correlations[
                1] * tempVals[x] + correlations[2] * lightVals[x]
            totalArr.append(int(w * total))
        mseArray.append(round(getMSE(totalArr, colorVals) / 10, 2))

    # Utilize quadric regression to plot MSE values
    x = Symbol('x')
    A, B, C = np.polyfit(wArray, mseArray, 2)
    y = A * x**2 + B * x + C
    yprime = str(y.diff(x))
    arr = yprime.split(' + ')
    if len(arr) == 1:
        arr = yprime.split(' - ')

    # Parse and convert output to find ideal weight based on loss calculation
    stra = str(arr[1])
    strb = str(arr[0][0:-2])
    converta = float(stra[0:10])
    convertb = float(strb[0:10])
    predictedW = float(converta) / (float(convertb))
    idealCol = GetIdealColor.idealColor()

    # Use weights to find theoretical predicted irrigation volume
    temporary = float(idealCol) / predictedW
    temporary -= (correlations[1] * newTemp + correlations[2] * newLight)
    theoreticalX = temporary / correlations[0]

    # Remove extreme irrigation volume changes
    if theoreticalX < 0:
        theoreticalX *= -1
    healthy = True
    if theoreticalX > 30:
        while theoreticalX > 7:
            theoreticalX -= 1.1837513
            healthy = False
    if theoreticalX < 2:
        while theoreticalX < 5:
            theoreticalX *= 1.23754
            healthy = False

    # Return theoretical irrigation volume and crop health status
    return theoreticalX, healthy