import olsr_1d_utils

def solveLinearRegression(X, Y):
    (a, b) = olsr_1d_utils.calculateCoefficients(X, Y)

    Yhat = olsr_1d_utils.calculateYhat(a, b, X)
    olsr_1d_utils.plotDataAndPrediction(X,Y,Yhat)

    r2 = olsr_1d_utils.calculateRSquared(Y, Yhat)

    print("a:", a, "b:", b)
    print("the r-squared is:", r2)

def solveMooreProblem():
    (X, Y) = olsr_1d_utils.loadDataMooreProblem()
    solveLinearRegression(X, Y)

def solveBrainVsBodyWeightProblem():
    (X, Y) = olsr_1d_utils.loadDataWeightsProblem()
    solveLinearRegression(X, Y)

def solveFoodTruckProblem():
    (X, Y) = olsr_1d_utils.loadDataFoodTruckProfitsProblem()
    solveLinearRegression(X, Y)

def run():
    problemsToSolve = ["moore", "weights", "foodTruck"]
    for index, problemKeyname in enumerate(problemsToSolve):
        if (index == 0):
            solveMooreProblem()
        elif (index == 1):
            solveBrainVsBodyWeightProblem()
        elif (index == 2):
            solveFoodTruckProblem()

if __name__ == '__main__':
    run()