Ejemplo n.º 1
0
Archivo: server.py Proyecto: GSng/Uber
def get_coords(end_date):
    #get_prediction_for_daterange in timeser.py -> creates foreasts
    data = get_incoords(timeser.get_prediction_for_daterange(end_date))
    #ret is the dataframe for the visualization graph
    ret = [{'data':data, 'name':'forecast', 'color':'red'}]
    #retrieves the input data, transforms to ret dataframe
    actual = get_incoords(timeser.get_actual())
    #appends forecat data to input data
    ret.append({'data':actual,'name':'actual','color':'blue'})
    return ret
Ejemplo n.º 2
0
Archivo: server.py Proyecto: GSng/Uber
def predict():
    #Redundant: start_data=first proceeding period of end of dataset    
    #start_date = request.args.get('start_date', '')
    end_date = request.args.get('end_date', '2012-05-05 23:00:00+00:00')  
    if end_date=='null':
        end_date = '2012-05-05 23:00:00+00:00'
    
    #Depending on output type perform the appropriate prediction action
    #timeser.get_prediction_for_daterange builds forecast    
    output_type = request.args.get('type', 'json')
    if output_type=='coords':
        #For visualization below methods are called        
        return dumps(get_coords(end_date))    
    elif output_type=='json':
        predicted_demand = timeser.get_prediction_for_daterange(end_date, asutc=True)
        return jsonify(predicted_demand.to_dict())
    else:
        predicted_demand = timeser.get_prediction_for_daterange(end_date, asutc=True)
        odir = './generated_csvs/'
        tfile =  'temp'+str(datetime.now())+'.csv'
        predicted_demand.to_csv(odir  + tfile)
        return send_from_directory(odir, tfile)