Calculate Attractive Score
Description: Calculate the attractive score given datasets
URI: /algo/AS/<name>
http method: GET
paremater
d = <density>
@app.route('/algo/AS/<name>', methods=['GET','PUT'])
def AS(name):
payload = dict()
if 'ts' in request.args:
payload['ts'] = request.args['ts']
if 'te' in request.args:
payload['te'] = request.args['te']
r = requests.get('http://127.0.0.1:5566/datasets/trajectory/'+name,params = payload)
dataset = r.json()['trajectory']
r = requests.get('http://127.0.0.1:5566/datasets/ROI/'+name)
roi_dataset = r.json()['ROI']
for roi in roi_dataset:
rid = roi['rid']
density = roi['density']
if not density is None: continue
payload = {'rid': rid}
r = requests.get('http://127.0.0.1:5566/algo/density/'+name, params = payload)
density = r.json()['density']
payload['density'] = density
r = requests.put('http://127.0.0.1:5566/datasets/ROI/'+name, json = payload)
del roi_dataset
TRD = []
region_set = set()
for trajectory in dataset:
payload = trajectory
payload_params = {}
if 'd' in request.args:
payload_params['d'] = request.args['d']
r = requests.get('http://127.0.0.1:5566/algo/tra2seq/'+name,json = payload, params = payload_params)
seq = r.json()['seq']
if len(seq) > 0:
for rid in seq:
region_set.add(rid)
TRD.append(seq)
if len(TRD) == 0:
return jsonify({'score':-1})
region_list = list(region_set)
del region_set
'''return jsonify({'list':region_list,'TRD': TRD})'''
for index in range(len(TRD)):
for i,rid in enumerate(TRD[index]):
TRD[index][i] = region_list.index(rid)
payload = {"TRD":TRD}
r = requests.get('http://127.0.0.1:5566/algo/umg',json = payload)
payload = {"UMG":r.json()["UMG"], "alpha":0.85}
r = requests.get('http://127.0.0.1:5566/algo/score',json = payload)
score_list = r.json()['score']
score_dict = dict()
for sid, score in enumerate(score_list):
try:
score_dict[region_list[sid]] = score
except IndexError:
print len(region_list), len(score_list)
return jsonify({'score':[-1]})
payload = {'rid': region_list[sid], 'score': score}
r = requests.put('http://127.0.0.1:5566/datasets/ROI/'+name, json = payload)
return jsonify({'score': score_dict})