Esempio n. 1
0
def allparam():
    data = request.get_json()
    print(data)
    print type(data)
    train_number = int(data['conditions'][0]['train'])
    train_class = data['conditions'][1]['class']
    quota = data['conditions'][2]['quota']
    hours = int(data['hours_before'])
    waiting_list = int(data['waiting_list'])
    indv_prediction = getPrediction([{'train': train_number}, {'class': train_class}, {'quota' : quota}], hours, waiting_list, socket)
    a = indv_prediction
    del a['data']
    del a['message']
    del a['prediction_val']
    a['index'] = data['index']

    print(a['probability'])

    if a['probability']<41:
        print("Reached")
        orig = data['from']
        source = data['to']
        origIATA = mydict[orig]
        sourceIATA = mydict[source]

        surl = 'http://api.sandbox.amadeus.com/v1.2/airports/autocomplete?apikey=u24iOTgpuRfGjF0SOSAhJyYKAj7myKPu&term=' + sourceIATA
        ourl = 'http://api.sandbox.amadeus.com/v1.2/airports/autocomplete?apikey=u24iOTgpuRfGjF0SOSAhJyYKAj7myKPu&term=' + origIATA

        s =  requests.get(surl)
        o = requests.get(ourl)

        print s.content
        print o.content

        s = json.loads(s.content)
        o = json.loads(o.content)
        s = s[0]['value']
        o = o[0]['value']
        date = data['date']
        url = 'http://api.sandbox.amadeus.com/v1.2/flights/extensive-search?origin=' + o + '&destination=' + s + '&departure_date=' + date + '&one-way=true&apikey=u24iOTgpuRfGjF0SOSAhJyYKAj7myKPu'
        print(url)
        f = requests.get(url)
        a['flight'] = json.loads(f.content)

    # resp = Response(jsonify(**a))
    # resp.headers['Access-Control-Allow-Origin'] = '*'
    return jsonify(**a)
#writer = csv.writer(ofile, delimiter='\t', quotechar='"', quoting=csv.QUOTE_ALL)
#writer.writerow(['pnr', 'train', 'class', 'quota', 'hours', 'wl', 'original status', 'original prediction', 'new prediction', 'new status'])
predictions = prediction_db.find({'status' : {'$in':['failure', 'success']}}).sort([('boarding_time',1)])
i=0
success = 0
failure = 0
orig_succes = 0
orig_failure = 0
for row in predictions:
    print i
    train_number = row['train']
    train_class = row['class']
    quota = row['quota']
    hours = row['hours_before']
    waiting_list = row['waiting_list']
    indv_prediction = getPrediction([{'train': train_number}, {'class': train_class}, {'quota' : quota}], hours, waiting_list, socket)

    if row['status'] == 'failure':
        orig_failure += 1
        if indv_prediction["prediction_val"] == 0 :
            new_prediction = 'na'
        elif indv_prediction["prediction_val"] * row['prediction'] < 0: #in db positive means success, in prediction positive means no chance of booking
            new_prediction = 'success'
            success += 1
        else:
            new_prediction = 'failure'
            failure += 1
    elif row['status'] == 'success':
        orig_succes += 1
        if indv_prediction["prediction_val"] == 0 :
            new_prediction = 'na'
Esempio n. 3
0
	def GET(self, train, hours, wl, quota, cl):
		print hours
		return functions.getPrediction([{'train': train},{'class': cl},{'quota': quota}], int(hours), int(wl))