Convert the TRD to user movement graph
Description: Convert the TRD to user movement graph
URI: /algo/umg
http method: GET
@app.route('/algo/umg',methods=['GET'])
def umg():
if not request.json or 'TRD' not in request.json:
return jsonify({'UMG':[[-1]]})
TRD = request.json['TRD']
max_rid = 0
for seq in TRD:
for roi in seq:
max_rid = roi if roi > max_rid else max_rid
UMG = np.zeros((max_rid+1,max_rid+1))
for r1 in range(max_rid+1):
for r2 in range(max_rid+1):
if r1 == r2: continue
TRs = [tr for tr in TRD if (r1 in tr and r2 in set(tr[idx+1] for idx,x in enumerate(tr) if x == r1 and idx < len(tr)-1))]
TRsAll = [tr for tr in TRD if (r1 in tr and tr.index(r1)<len(tr)-1)]
if len(TRsAll)==0:
UMG[r1,r2] = 0
continue
deg_list = []
for tr in TRs:
payload = {'tr':tr, 'rid': r1}
r = requests.get('http://127.0.0.1:5566/algo/deg',json = payload)
deg = r.json()['deg']
deg_list.append(1/float(deg))
UMG[r1,r2] = float(sum(deg_list))/float(len(TRsAll))
return jsonify({'UMG':UMG.tolist()})