Ejemplo n.º 1
0
def select(paras):
    a = time.time()
    gmaps = Client(key='AIzaSyAdtMHxfsESr0OuVdGuseM_VW_uiDtahJY')
    address = paras['street'] + ", " + paras['city'] + ", " + paras['state']
    latitude, longtitude = geofind(address)
    print "Location convertion: " + str(latitude) + str(longtitude)
    time_start_mon = int(paras['s_mon'])
    time_start_day = int(paras['s_day'])
    time_start_hour = int(paras['s_hou'])
    time_end_mon = int(paras['e_mon'])
    time_end_day = int(paras['e_day'])
    time_end_hour = int(paras['e_hou'])
    radius = paras['r']
    start_time = datetime.datetime(YEAR, time_start_mon, time_start_day,
                                   time_start_hour, 0)
    end_time = datetime.datetime(YEAR, time_end_mon, time_end_day,
                                 time_end_hour, 0)
    start_epoch_time = time.mktime(start_time.timetuple()) * 1000
    print "start" + str(start_epoch_time)
    end_epoch_time = time.mktime(end_time.timetuple()) * 1000
    distance = "3959*acos((sin({3}/57.29577951)*sin(latitude/57.29577951)+cos({3}/57.29577951)*cos(latitude/57.29577951)*cos(abs(longtitude-({2}))/57.29577951))) <{4}"
    querystr = (
        "select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} and "
        + distance + " order by user;").format(start_epoch_time,
                                               end_epoch_time, longtitude,
                                               latitude, radius)

    if (paras['r'] == '0'):
        querystr = (
            "select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} order by user;"
        ).format(start_epoch_time, end_epoch_time)
    print querystr
    con, cur = sql_execute(querystr)
    b = time.time()
    f = open('timestamp', 'w')
    f.write(str(b - a))
    f.close()
    data = []
    while True:
        dat = cur.fetchone()
        if dat == None:
            break
        data.append(dat)
    # print "paras['type']=" + paras['type'] # paras['type']=0
    if (paras['type'] == '0'):
        return top_k_similar(data, paras['option1'], paras['option2'],
                             paras['deadline'])
    if (paras['type'] == '1'):
        return mst.call_mst(data, paras['deadline'])
    if (paras['type'] == '2'):
        return kmeans_new.call_kmeans(data, paras['deadline'],
                                      int(paras['option1']))
    if (paras['type'] == '3'):
        return represent.call_represent(data, paras['deadline'],
                                        int(paras['option1']))
    else:
        return [], []
    pass
Ejemplo n.º 2
0
def select(paras):
    gmaps = GoogleMaps()
    address = paras['street'] + ", " + paras['city'] + ", " + paras['state']
    latitude, longtitude = gmaps.address_to_latlng(address)
    print "Location convertion: " + str(latitude) + str(longtitude)
    time_start_mon = int(paras['s_mon'])
    time_start_day = int(paras['s_day'])
    time_start_hour = int(paras['s_hou'])
    time_end_mon = int(paras['e_mon'])
    time_end_day = int(paras['e_day'])
    time_end_hour = int(paras['e_hou'])
    radius = paras['r']
    start_time = datetime.datetime(2012, time_start_mon, time_start_day,
                                   time_start_hour, 0)
    end_time = datetime.datetime(2012, time_end_mon, time_end_day,
                                 time_end_hour, 0)
    start_epoch_time = time.mktime(start_time.timetuple()) * 1000
    end_epoch_time = time.mktime(end_time.timetuple()) * 1000
    distance = "3959*acos((sin({3}/57.29577951)*sin(latitude/57.29577951)+cos({3}/57.29577951)*cos(latitude/57.29577951)*cos(abs(longtitude-({2}))/57.29577951))) <{4}"
    querystr = (
        "select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} and "
        + distance + " order by user;").format(start_epoch_time,
                                               end_epoch_time, longtitude,
                                               latitude, radius)

    if (paras['r'] == '0'):
        querystr = (
            "select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} order by user;"
        ).format(start_epoch_time, end_epoch_time)
    print querystr
    con, cur = sql_execute(querystr)

    data = []
    while True:
        dat = cur.fetchone()
        if dat == None:
            break
        data.append(dat)
    if (paras['type'] == '0'):
        return top_k_similar(data, paras['option1'], paras['option2'],
                             paras['deadline'])
    if (paras['type'] == '1'):
        return mst.call_mst(data, paras['deadline'])
    if (paras['type'] == '2'):
        return kmeans_new.call_kmeans(data, paras['deadline'],
                                      int(paras['option1']))
    if (paras['type'] == '3'):
        return represent.call_represent(data, paras['deadline'],
                                        int(paras['option1']))
    else:
        return [], []
    pass
Ejemplo n.º 3
0
def select(paras):
	a = time.time()
	gmaps = GoogleMaps()
        address = paras['street']+", "+ paras['city']+", "+paras['state']
        latitude, longtitude = geofind(address)
        print "Location convertion: " + str(latitude) + str(longtitude)
        time_start_mon = int(paras['s_mon'])
        time_start_day = int(paras['s_day'])
        time_start_hour = int(paras['s_hou'])
        time_end_mon = int(paras['e_mon'])
        time_end_day = int(paras['e_day'])
        time_end_hour = int(paras['e_hou'])
        radius = paras['r']
        start_time = datetime.datetime(YEAR, time_start_mon, time_start_day, time_start_hour, 0)
        end_time = datetime.datetime(YEAR, time_end_mon, time_end_day, time_end_hour, 0)
        start_epoch_time = time.mktime(start_time.timetuple()) * 1000
	print "start" + str(start_epoch_time)
        end_epoch_time = time.mktime(end_time.timetuple()) * 1000
        distance = "3959*acos((sin({3}/57.29577951)*sin(latitude/57.29577951)+cos({3}/57.29577951)*cos(latitude/57.29577951)*cos(abs(longtitude-({2}))/57.29577951))) <{4}"
	querystr = ("select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} and " + distance + " order by user;").format(start_epoch_time, end_epoch_time, longtitude, latitude, radius)
	
	if (paras['r'] == '0'):
		querystr = ("select user, uid, feature, longtitude, latitude, time, size from Meta_data where time >= {0} and time <= {1} order by user;").format(start_epoch_time, end_epoch_time)
	print querystr
	con, cur = sql_execute(querystr)
	b = time.time()
	f = open('timestamp', 'w')
	f.write(str(b-a))
	f.close()
	data = []
	while True:
		dat = cur.fetchone()
		if dat == None:
			break
		data.append(dat)
	# print "paras['type']=" + paras['type'] # paras['type']=0
	if (paras['type'] == '0'):
		return top_k_similar(data, paras['option1'], paras['option2'], paras['deadline'])
	if (paras['type'] == '1'):
		return mst.call_mst(data, paras['deadline'])
	if (paras['type'] == '2'):
		return kmeans_new.call_kmeans(data, paras['deadline'], int(paras['option1']))
	if (paras['type'] == '3'):
		return represent.call_represent(data, paras['deadline'], int(paras['option1']))
	else:
		return [], []
	pass