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):


    # get trajectory dataset
    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']




    # Update region density
    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']

        # Only update NULL 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 = []
    # Convert Tra to TR
    region_set = set()
    for trajectory in dataset:
        #points = trajectory['points']
        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})


    # buil rid and serial id map
    region_list = list(region_set)
    del region_set

    '''return jsonify({'list':region_list,'TRD': TRD})'''

    # replace rid to serial id



    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)

    # get score of each serial id
    score_list = r.json()['score']



    # convert serial id to original rid
    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]})

        # Update ROI score
        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})

results matching ""

    No results matching ""