team_dict = {'FloridaIntl': 107,
 'NorthCarolina': 232,
 'MurrayState': 211,
 'California': 46,
 'AlcornState': 9,
 'OhioState': 251,
 'AlbanyNY': 8,
 'Syracuse': 327,
 'DetroitU': 84,
 'NCCentral': 213,
 'RobertMorris': 276,
 'JamesMadison': 154,
 'GeorgiaState': 119,
 'NCState': 215,
 'CSNorthridge': 41,
 'Purdue': 269,
 'William&Mary': 393,
 'Connecticut': 71,
 'YoungstownState': 404,
 'Xavier': 402,
 'MiamiOhio': 192,
 'Towson': 349,
 'ClevelandState': 62,
 'StBonaventure': 315,
 'Dartmouth': 75,
 'BostonCollege': 30,
 'Valparaiso': 373,
 'BallState': 24,
 'ArkansasLR': 18,
 'Mississippi': 198,
 'NewOrleansU': 227,
 'Georgia': 117,
 'Massachusetts': 185,
 'CentralFlorida': 53,
 'Pennsylvania': 260,
 'PennState': 259,
 'ULMonroe': 357,
 'LSU': 160,
 'NorthernIllinois': 242,
 'Northwestern': 246,
 'LoyolaChicago': 174,
 'KansasState': 156,
 'Hofstra': 129,
 'Kansas': 155,
 'Drexel': 89,
 'StJosephs': 319,
 'SouthFlorida': 310,
 'SMU': 284,
 'IdahoU': 139,
 'Utah': 366,
 'Georgetown': 116,
 'Tulane': 351,
 'Bradley': 33,
 'BYU': 23,
 'NorthernIowa': 243,
 'DenverU': 81,
 'CalPolySLO': 43,
 'SanFrancisco': 294,
 'NewMexicoState': 226,
 'SaintMarysCA': 288,
 'Stanford': 321,
 'SanDiego': 292,
 'Pacific': 258,
 'Pepperdine': 261,
 'HoustonBaptist': 132,
 'SouthAlabama': 306,
 'SacramentoState': 285,
 'Rice': 273,
 'WiscGreenBay': 396,
 'UAB': 353,
 'Samford': 291,
 'KentState': 158,
 'Belmont': 26,
 'PortlandState': 263,
 'WrightState': 400,
 'WashingtonU': 383,
 'LoyolaMarymount': 176,
 'BoiseState': 29,
 'NorthDakota': 235,
 'Montana': 205,
 'ColoradoState': 68,
 'UCDavis': 354,
 'WinstonSalemState': 394,
 'Oregon': 256,
 'MoreheadState': 208,
 'Kentucky': 159,
 'NCGreensboro': 214,
 'Duke': 90,
 'Wofford': 399,
 'Pittsburgh': 262,
 'StPeters': 320,
 'SetonHall': 301,
 'NCWilmington': 216,
 'AppalachianSt': 11,
 'AustinPeay': 22,
 'Tennessee': 332,
 'TennesseeTech': 336,
 'Minnesota': 196,
 'Siena': 302,
 'TennesseeState': 335,
 'IdahoState': 138,
 'IowaState': 149,
 'Rider': 275,
 'MississippiSt': 199,
 'UtahState': 367,
 'WeberState': 384,
 'Niagara': 228,
 'Auburn': 21,
 'Howard': 134,
 'IndianaU': 146,
 'Princeton': 267,
 'CentralMichigan': 54,
 'Temple': 330,
 'Delaware': 78,
 'Creighton': 74,
 'Dayton': 77,
 'Cornell': 73,
 'Alabama': 3,
 'SoMississippi': 304,
 'ULLafayette': 356,
 'CalRiverside': 44,
 'NewMexico': 225,
 'Davidson': 76,
 'Butler': 38,
 'Marist': 181,
 'Rutgers': 278,
 'PortlandU': 264,
 'EWashington': 93,
 'EasternIllinois': 95,
 'Toledo': 348,
 'SEMissouriSt': 282,
 'SaintLouis': 287,
 'TennMartin': 331,
 'SouthernIllinois': 312,
 'MontanaState': 206,
 'Nevada': 223,
 'NorthernMichigan': 245,
 'Michigan': 193,
 'CalIrvine': 42,
 'Texas': 338,
 'GeoWashington': 113,
 'WakeForest': 380,
 'EastCarolina': 94,
 'Harvard': 126,
 'WesternMichigan': 390,
 'Tulsa': 352,
 'GeorgeMason': 114,
 'OregonState': 257,
 'TexasTech': 346,
 'Brown': 34,
 'VirginiaTech': 378,
 'MiddleTennSt': 195,
 'Ohio': 250,
 'LoyolaMaryland': 175,
 'WestVirginia': 386,
 'Akron': 2,
 'NorthernArizona': 240,
 'Arizona': 12,
 'Fordham': 109,
 'Fairfield': 100,
 'IPFW': 135,
 'Wisconsin': 398,
 'TexSanAntonio': 337,
 'Iowa': 148,
 'Virginia': 377,
 'TexasA&M': 339,
 'Villanova': 376,
 'MissouriSt': 202,
 'CSFullerton': 40,
 'UCLA': 355,
 'SanDiegoState': 293,
 'Elon': 98,
 'CharlotteU': 57,
 'CoastalCarolina': 63,
 'Yale': 403,
 'Colgate': 64,
 'WiscMilwaukee': 397,
 'WesternKentucky': 389,
 'IndianaState': 145,
 'TCU': 328,
 'TexasState': 345,
 'ArizonaState': 13,
 'GeorgiaSouthern': 118,
 'SouthCarolina': 307,
 'WashingtonState': 382,
 'SCUpstate': 279,
 'Marshall': 183,
 'BowlingGreen': 32,
 'StJohns': 318,
 'Louisville': 173,
 'Arkansas': 17,
 'Drake': 88,
 'Illinois': 140,
 'Oklahoma': 252,
 'Columbia': 69,
 'Depaul': 82,
 'Gonzaga': 121,
 'MichiganState': 194,
 'Duquesne': 91,
 'MemphisU': 187,
 'LongBeachState': 169,
 'USC': 361,
 'NorthernColorado': 241,
 'Hawaii': 127,
 'Northeastern': 239,
 'Missouri': 201,
 'Maryland': 184,
 'Canisius': 49,
 'FresnoState': 110,
 'JacksonvilleSt': 152,
 'CalSantaBarb': 45,
 'Monmouth': 204,
 'Clemson': 61,
 'Liberty': 166,
 'Binghamton': 28,
 'RhodeIsland': 272,
 'VaCommonwealth': 372,
 'IllinoisChicago': 141,
 'Cincinnati': 60,
 'Nebraska': 221,
 'UNLV': 360,
 'Florida': 104,
 'Manhattan': 180,
 'ArkansasState': 19,
 'WesternCarolina': 387,
 'Richmond': 274,
 'NotreDame': 248,
 'SantaClara': 297,
 'GeorgiaTech': 120,
 'BostonU': 31,
 'MiamiFlorida': 191,
 'LaSalle': 161,
 'EasternKentucky': 96,
 'UtahValley': 369,
 'Troy': 350,
 'Providence': 268,
 'Vanderbilt': 374,
 'SanJoseState': 296,
 'IUPUI': 136,
 'SouthDakotaState': 309,
 'EasternMichigan': 97,
 'TheCitadel': 347,
 'MDEasternShore': 178,
 'TexasSouthern': 344,
 'DickinsonState': 85,
 'AirForce': 1,
 'LouisianaTech': 172,
 'NichollsState': 229,
 'Buffalo': 37,
 'NorthTexas': 238,
 'OklahomaState': 253,
 'OldDominion': 254,
 'Evansville': 99,
 'UTEP': 364,
 'Wyoming': 401,
 'HoustonU': 133,
 'Furman': 111,
 'Presbyterian': 266,
 'TennesseeChat': 333,
 'IllinoisState': 142,
 'Colorado': 67,
 'Chaminade': 55,
 'ArkMonticello': 15,
 'FairleighDickinson': 101,
 'WichitaState': 392,
 'FlaAtlantic': 102,
 'FloridaState': 108,
 'OralRoberts': 255,
 'SamHouston': 289,
 'FloridaAM': 105,
 'Lipscomb': 167,
 'UtahValleySt': 370,
 'AlaskaAnchorage': 7,
 'SacredHeart': 286,
 'Marquette': 182,
 'Baylor': 25,
 'Iona': 147,
 'Vermont': 375,
 'SciencesofPhila': 299,
 'ArkFortSmith': 14,
 'NorfolkSt': 230,
 'CollCharleston': 65,
 'NorthwesternSt': 247,
 'StFrancisPA': 317,
 'MDBaltimoreCo': 177,
 'MorganState': 209,
 'Radford': 271,
 'Oakland': 249,
 'GardnerWebb': 112,
 'SouthernUtah': 314,
 'NorthFlorida': 237,
 'USCUpstate': 362,
 'DelawareState': 79,
 'SoCarolinaSt': 303,
 'SIUEdwardsville': 283,
 'Bryant': 35,
 'Jacksonville': 151,
 'LiuBrooklyn': 168,
 'StephenAustin': 322,
 'Hartford': 125,
 'TexasArlington': 341,
 'WesternIllinois': 388,
 'Centenary': 50,
 'NDakotaSt': 218,
 'UMKC': 358,
 'Hampton': 124,
 'ArkPineBluff': 16,
 'AlabamaState': 6,
 'PrairieViewA&M': 265,
 'JacksonState': 150,
 'Southern': 311,
 'MissValleySt': 197,
 'CoppinState': 72,
 'BethuneCookman': 27,
 'NCarolinaA&T': 217,
 'Grambling': 122,
 'NewHampshire': 224,
 'Winthrop': 395,
 'AlabamaA&M': 4,
 'CharlestonSou': 56,
 'VMI': 371,
 'HighPoint': 128,
 'NCAsheville': 212,
 'KennesawSt': 157,
 'Army': 20,
 'Lehigh': 165,
 'Navy': 220,
 'American': 10,
 'Lafayette': 163,
 'HolyCross': 130,
 'Bucknell': 36,
 'ETennesseeSt': 92,
 'Campbell': 48,
 'Mercer': 188,
 'Quinnipiac': 270,
 'CentralConnecticut': 52,
 'MountStMarys': 210,
 'LongIsland': 170,
 'StonyBrook': 326,
 'Maine': 179,
 'MoKansasCity': 203,
 'TexasA&MCorpus': 340,
 'SELouisiana': 281,
 'SouthDakota': 308,
 'SeattleU': 300,
 'TexasPanAmerican': 342,
 'Lamar': 164,
 'Dowling': 87,
 'SavannahState': 298,
 'RochesterCollege': 277,
 'StFrancisNY': 316,
 'Stetson': 324,
 'WesternNewMexico': 391,
 'Montreat': 207,
 'DominicanCal': 86,
 'SDakotaSt': 280,
 'FlaGulfCoast': 103,
 'Wagner': 379,
 'McNeeseState': 186,
 'SouthernMiss': 313,
 'WestAlabama': 385,
 'SanFranciscoState': 295,
 'LaSierra': 162,
 'UTArlington': 363,
 'CentralArkansas': 51,
 'CSBakersfield': 39,
 'SamHoustonSt': 290,
 'StephenFAustin': 323,
 'NebraskaOmaha': 222,
 'AlabamaHuntsville': 5,
 'NorthernKentucky': 244,
 'Longwood': 171,
 'ChicagoSt': 59,
 'GrandCanyon': 123,
 'CollOfCharleston': 66,
 'TexasSanAntonio': 343,
 'TennesseeMartin': 334,
 'Denver': 80,
 'Indiana': 144,
 'TXPanAmerican': 329,
 'StillmanCollege': 325,
 'MetroState': 190,
 'SonomaSt': 305,
 'AbileneChristian': 0,
 'NJIT': 219,
 'IncarnateWord': 143,
 'UTRioGrandeValley': 365,
 'UMassLowell': 359,
 'NorthDakotaState': 236,
 'ConcordiaStPaul': 70,
 'Chattanooga': 58,
 'NorthAlabama': 231,
 'CaliforniaBaptist': 47,
 'UtahU': 368,
 'Merrimack': 189,
 'JacksonvilleState': 153,
 'GeorgeWashington': 115,
 'Idaho': 137,
 'NorthCarolinaCentral': 234,
 'Houston': 131,
 'Washington': 381,
 'MississippiValleyState': 200,
 'NorthCarolinaAT': 233,
 'FloridaAtlantic': 106,
 'Detroit': 83}
loc_dict = {'Home':1,'Away':0,'Neutral':0.5}

import numpy as np
from flask import Flask, request, render_template
import tensorflow as tf

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/', methods=['POST'])
def get_data():
    teamx = request.form['teamx']
    teamy = request.form['teamy']
    locx = request.form['locationx']
    locy = request.form['locationy']
    xml = request.form['X_ML']
    yml = request.form['Y_ML']
    xspread = request.form['xspread']
    yspread = request.form['yspread']
    total = request.form['total']

    locxcode = loc_dict.get('locx', None)
    locycode = loc_dict.get('locy', None)
    teamxcode = team_dict.get('teamx', None)
    teamycode = team_dict.get('teamy', None)

    model_array = ['xml','teamxcode','locxcode','yml','teamycode','locycode','total','xspread','yspread']

    prediction_model = tf.keras.models.load_model(
        'main_model.h5',
        custom_objects=None,
        compile=True
    )
    encoded_prediction = prediction_model.predict(model_array)

    return render_template('outcome.html', prediction = encoded_prediction)


if __name__ == "__main__":
    app.run(debug=True)
