コード例 #1
0
ファイル: app.py プロジェクト: dangkhoa2014/hothoods-frontend
def ziptrend(zipcode=None):
    """
    Return info about a particular zip code.
    Used to power the graph.
    """
    if not zipcode:
        raise Exception, 'page_not_found'
    
    # Get name of neighborhood
    hoodnames = model.query_hoodnames(zip=zipcode)
    hoodname = hoodnames[zipcode]
    boroname = model.query_borough(zipcode)
    
    # Get price history
    history = []
    for row in g.dbsession.resolve_query(model.zipquery.format(zipcode=zipcode)):
        history.append({"date": row[0], "price": float(row[1])})
        lasttime = row[0]
        lastprice = float(row[1])
    
    # Get forecast
    if lasttime:
        dateformat = "%Y-%m-%d"
        forecasts = []
        #forecasts = [{"date": lasttime, "price": lastprice, "lo80": lastprice, "hi80": lastprice}]
        forecast_query = g.dbsession.resolve_query(model.forecastquery.format(zipcode=zipcode))
        junctiontime = dt.strptime(lasttime, dateformat) + relativedelta(months=forecast_query[0][0])
        history.append({"date": dt.strftime(junctiontime, dateformat), "price": np.exp(float(forecast_query[0][1]))})
        for row in forecast_query:
            forecasttime = dt.strptime(lasttime, dateformat) + relativedelta(months=row[0]+1)
            forecasts.append({"date": dt.strftime(forecasttime, dateformat), "price": np.exp(float(row[1])), "lo80": np.exp(float(row[2])), "hi80": np.exp(float(row[3]))})
    return(jsonify(boroname=boroname, hoodname=hoodname, prices=history, forecasts=forecasts))
コード例 #2
0
def mapinfo():
    """
    Return general info about all zip codes on the map.
    Used to construct the map when the user lands.
    """
    # Get name of neighborhood
    hoodnames = dict(model.query_hoodnames())
    currentprices = dict(g.dbsession.resolve_query(model.currentpricequery))
    ret = []
    for row in g.dbsession.resolve_query(model.summary_query):
        zip = row[0]
        name = row[1].title()
        price = row[2]
        earlypred = np.exp(row[3])
        pred = np.exp(row[4])
        growth = (pred / earlypred) - 1
        ret.append({
            "zip": zip,
            "hoodname": name,
            "price": price,
            "earlypred": earlypred,
            "prediction": pred,
            "growth": growth
        })
    return (jsonify(zips=ret))
コード例 #3
0
def ziptrend(zipcode=None):
    """
    Return info about a particular zip code.
    Used to power the graph.
    """
    if not zipcode:
        raise Exception, 'page_not_found'

    # Get name of neighborhood
    hoodnames = model.query_hoodnames(zip=zipcode)
    hoodname = hoodnames[zipcode]
    boroname = model.query_borough(zipcode)

    # Get price history
    history = []
    for row in g.dbsession.resolve_query(
            model.zipquery.format(zipcode=zipcode)):
        history.append({"date": row[0], "price": float(row[1])})
        lasttime = row[0]
        lastprice = float(row[1])

    # Get forecast
    if lasttime:
        dateformat = "%Y-%m-%d"
        forecasts = []
        #forecasts = [{"date": lasttime, "price": lastprice, "lo80": lastprice, "hi80": lastprice}]
        forecast_query = g.dbsession.resolve_query(
            model.forecastquery.format(zipcode=zipcode))
        junctiontime = dt.strptime(
            lasttime, dateformat) + relativedelta(months=forecast_query[0][0])
        history.append({
            "date": dt.strftime(junctiontime, dateformat),
            "price": np.exp(float(forecast_query[0][1]))
        })
        for row in forecast_query:
            forecasttime = dt.strptime(
                lasttime, dateformat) + relativedelta(months=row[0] + 1)
            forecasts.append({
                "date": dt.strftime(forecasttime, dateformat),
                "price": np.exp(float(row[1])),
                "lo80": np.exp(float(row[2])),
                "hi80": np.exp(float(row[3]))
            })
    return (jsonify(boroname=boroname,
                    hoodname=hoodname,
                    prices=history,
                    forecasts=forecasts))
コード例 #4
0
ファイル: app.py プロジェクト: dangkhoa2014/hothoods-frontend
def mapinfo():
    """
    Return general info about all zip codes on the map.
    Used to construct the map when the user lands.
    """
    # Get name of neighborhood
    hoodnames = dict(model.query_hoodnames())
    currentprices = dict(g.dbsession.resolve_query(model.currentpricequery))
    ret = []
    for row in g.dbsession.resolve_query(model.summary_query):
        zip = row[0]
        name = row[1].title()
        price = row[2]
        earlypred = np.exp(row[3])
        pred = np.exp(row[4])
        growth = (pred / earlypred)-1
        ret.append({
            "zip": zip,
            "hoodname": name,
            "price": price,
            "earlypred": earlypred,
            "prediction": pred,
            "growth": growth})
    return(jsonify(zips=ret))