import numpy as np
import statsmodels.api as sm

#y=[334813954.5,334612251.4,338634429.3,336135420.5,336544677.7,338262133.9,341166870.8,339698797,341454262.4,342469635.7,348320130.3,358133870.2,357404773.2,362257957.1,366713654.7,373177176.2,380447221.7,389429045.8,393749645.4,398215487,404001590.1,406838103.4,409393218.4,416484870.7,417262498.6,418428600.7,426489263.4,432695056.9,434844986.8,445126700.2,456613535.7,464002645.6,472555503.1,479743974.8,488433920.6,499677545.7,498688789.7,500154226.9,499743345.4,507550897.6,515829040.1,529359938.7,534488813.9,538942475.1,548316177.3,573280835.7,581911218.8,600825039.5,598543850.3,597356628.2,599468343.6,605500168.7,608766323,631951390.7,642818280.8,660429285.8,669203885.1,663867106.3,655754575,638045575.9,629093610.2,624451611.3,624818642.8,627009081.2,631972835,637904321.2,635861172.6,635703302.5,642738971.7,646467324.9,654909034.9,681297184.2]
#
#x = [
#	 [448041014.9,464302861.3,470623476.2,467337338.8,477759698.4,497833197.2,496683854.9,514195161.4,529921077.7,522330606.2,542497735.2,531322156,546566449.7,546457599.7,552417301.7,540883586.9,550364364.7,571081900.5,560712489.9,564453640.1,578376406,594959244.7,649393116.1,681324371,696240839.1,717339511.7,726774235.5,717466895.1,734443524.2,724025183.4,702544608.9,702186503.4,721666004.1,733487084.6,759920047.5,772978981.2,812211396.6,795865036.6,810078803.3,811785099.5,819296842.5,864893849.5,871417308.3,909614954.5,949414566.5,1048972479,1041693932,1041038781,1075745443,1098771737,1139560290,1114186738,1107971347,1112294198,1104384628,1099312024,1092806800,1087740817,1091672465,1096633451,1120447553,1126152702,1169954804,1182230774,1214597020,1227110913,1232817778,1237418569,1272041888,1295498930,1327552457,1304963227],
#     [134956107.7,145581998.2,149641507.7,147868059.8,160313739.9,166260413.1,159760118.3,169141029.5,168349177.9,160611844.9,165522357.6,165619360.4,183149150.8,173987600.9,180339259.1,171550097,180213251.6,181732095.3,161132674.8,156831407.7,156281088.9,157409502.1,213103416.7,259818006.2,274416106.1,302865329.3,306878648.4,302494358.4,314752462.8,258431020.5,250776703.3,241528245.3,265251854.9,293599157.1,307336539,322501058.1,369750023.8,284318176.8,295805315.3,309288794.5,319876041,352008119.7,373491846.4,399506332.2,423646057.2,508731164.2,501907884.1,489003240.5,527292269.8,547232138.5,424682209.9,449249349.7,448413389.7,434770417.1,448921543.4,467544315.2,452386305.2,480202651.4,477513161.5,489094290.6,513028523.8,504639420.2,510702444.8,520555464.9,545849528.2,420104222,415748698.5,400211533.5,399864018.2,411016038.1,421146149.1,405639865.1],
#     [177607839.7,180946565,183290289.1,183783262.7,181680214,185280227.6,185601490,186386911.7,188520905,189779314.8,187071783.7,183934680.6,184672224.1,186120108.3,187617165.7,188756832.7,191508972.3,202313574,219650070.1,233382677,246981163.2,261177341.2,253437763.1,227981934.2,227730584.4,226723386.9,231665253.2,231431316.4,236736543.9,269329650.7,266975673.5,269855949.5,271980257.9,262804588.3,270096026.6,264051805.7,267551363.4,342477455.7,340381813,336025262.7,335187607.1,331020492.5,331049964.3,337330332.9,351612551.5,351714396.1,362309190.1,366220974.8,370626530.5,375634578.9,499728677.2,447644350.7,436716474.9,431810165.8,421612429,390985109.7,394880993.7,374394531.5,372149145.6,373392276.2,382589360.2,397549713.8,407890215,428969314.2,432138444.6,544772752.2,572277270.8,576804442.2,591252604.1,594389830.3,599235661.4,619335578.2],
#	 [106429430.7,106760593.6,107021921.9,105591661.1,103855199.4,112170578.9,116251944.7,122540893.7,136720889.4,136578724.1,152486075.2,134235024.3,138882348.9,147260226.6,145183766.6,142508086.5,139622421.9,148634722,143009483,138097163.5,139711162.5,141836295.9,147332435.7,150607585.6,156003012,150668104.3,149681113.8,145099163.4,143817430.1,156855323.8,145578419.3,151807671.9,145841777.4,138742330.4,142819880.8,136400815.3,134175961.1,128257367.1,133287278.3,124352855,123291490.1,140355962.4,125353667.1,132125774.8,130947359.3,148250900.7,135218280.2,127885140,130608429.7,128390407.2,164646964.1,166254246.7,171437988.5,192923468.6,182296426.4,188926617.3,193708248.5,181678650.8,189833651.9,169963479.1,170736613.6,169914533.8,193009295.4,176008880.1,179966454.8,204311606.5,186626225.9,201109459.4,219853796.5,227746954,241617660.9,203293674.2]
#    ]

def reg_m(y, x):
    ones = np.ones(len(x[0]))
    X = sm.add_constant(np.column_stack((x[0], ones)),prepend=False)
    for ele in x[1:]:
        col = np.column_stack((ele, X))
        X = sm.add_constant(col,prepend=False)

    results = sm.OLS(y, X).fit()
    #print (results.summary())
    # return {"coef":list(reversed(results.params)),
    #                  "stdError":list(reversed(results.bse)),
    #                  "t":list(reversed(results.tvalues)) ,
    #                  "pvalues":list(reversed(results.pvalues)) ,
    #                  "bic":results.bic,
    #                  "aic":results.aic}
    return results
    #return jsonify(regressionResult))
#reg_m(y,x)
