Exemple #1
0
def load_adj_info(indegree=True):
    """
    0--indegree
    1--outdegree
    return adjcency list.
    """
    tgsinfo = shd.read_tgs_info()

    p_main = re.compile("\d+,")
    p_degree = re.compile("\d+-\d+")

    if indegree:
        fname = os.path.join(root_dir,"data","adj_indegree.txt")
    else:
        fname = os.path.join(root_dir,"data","adj_outdegree.txt")

    adj = dict([(cid,[]) for cid in tgsinfo.keys()])
    tgsinfo.clear()

    with open(fname,"r") as f:
        for line in f.readlines():
            try:
                main = p_main.search(line).group()[:-1]
            except AttributeError,e:
                print e.args[0], ":", line
                continue

            degree = p_degree.findall(line)
            for d in degree:
                item = d.split("-")

                if item[0]=='0' or item[0]==main or item[0]=="88888":
                    continue

                adj[main].append((item[0], int(item[1])))
Exemple #2
0
#coding: utf-8

from app import app
from flask import render_template,url_for,jsonify,request,render_template_string
import pandas as pd
import json

# from app.helper import EvilTransform
# from test.test_asso import *
import shared as shd
import analysis as aly
# from analysis import load_od_data
from dateutil.parser import parse

# cols = ['KKID','KKMC','CLOUD_ID','X','Y']
tgsinfo = shd.read_tgs_info()               # all tgs info
adj_out = aly.load_adj_info(False)
adj_in = aly.load_adj_info(True)


@app.route('/gps-to-bd')
def gps_to_bd():
    lng = request.args.get('lng',type=float)
    lat = request.args.get('lat',type=float)

    loc = shd.gps2baidu((lng,lat))
    if loc[0] is None and loc[1] is None:
        return jsonify({'status':1,'msg':'gps loc convert failure.'})

    return jsonify({'status':0,'data':loc})