Beispiel #1
0
def prep(device_id):
    global stops
    stop_dict = stops
    df = pd.DataFrame()
    cv = pd.read_csv('cv/cv_%s.csv' % device_id)
    cv_cnt = len(cv)
    test = pd.read_csv('test/test_%s.csv' % device_id)
    d = route_freq(device_id,cv)
    
    for set_name in ['cv','test']:
        if set_name == 'cv':
            df = cv
        else:
            df = test
        df['route_dup_cnt'] = df['stop_id'].map(d)
        df.drop(['route_list','date','time','stamp','device_id'], axis=1, inplace=True)
        df['prob'] = True
        # repeat rows
        df = cv.reindex(np.repeat(cv.index.values,len(d)))
        df['stop_id_f'] = list(d.keys()) * cv_cnt
        df['prob'] = df['stop_id_f'] == df['stop_id']
        stop_dict = stop_dict[stop_dict['stop_id'].isin(list(d.keys()))]
        stop_dict['route_dup_cnt'] = stop_dict['stop_id'].map(d)
        #print stop_dict
        df = df.merge(stop_dict,left_on=['stop_id_f'],right_on = ['stop_id'], how='outer',sort=False,suffixes=('', 'f')).sort(['wnum','dow','tod','stop_id'])
        f = df['prob'] == False
        df.loc[f,'dup_cnt'] = 0
        df.loc[f,'fav'] = False
        df.loc[f,'stop_lat'] = df['stop_latf']
        df.loc[f,'stop_lon'] = df['stop_lonf']
        df.loc[f,'route_cnt'] = df['route_cntf']
        df.loc[f,'route_dup_cnt'] = df['route_dup_cntf']
        distance = []
        for i in range(len(df.loc[f])):
            lat1 = df.loc[i,'current_lat']
            lon1 = df.loc[i,'current_lon']
            lat2 = df.loc[i,'stop_lat']
            lon2 = df.loc[i,'stop_lon']
            distance.append(dis.dis(lat1,lon1,lat2,lon2))
        df.loc[f,'distance'] = distance
        df['stop_id'] = df['stop_idf']
        df.drop(['stop_id_f','stop_idf','stop_latf','stop_lonf','route_cntf','route_dup_cntf','agency_id'], axis=1, inplace=True)

        # save
        df['prob'] = df['prob'].map({True: 1, False : 0})
        #print df['prob'].head()
        df.to_csv('%s_weka/%s_%s.csv'%(set_name,set_name,device_id), index = False)
Beispiel #2
0
import distance
import time
import motion as mv
s=0.0
while 1:
    s=distance.dis()
    if s<=80 and s>50:
        speed=int(distance.dis()*0.9)
        mv.forward(speed)
    elif s<=50 and s>30:
        speed=int(distance.dis()*0.5)
        mv.forward(speed)
    elif s<=30:
        mv.forward(0)
        break
    elif s>80:
        mv.forward(100)
    time.sleep(0.2)
Beispiel #3
0
raw_callLog = pd.merge(raw_callLog, direction, on='stop_id', how='outer')

raw_callLog['time'] = pd.to_datetime(raw_callLog['time'],
                                     format="%Y-%m-%d %H:%M:%S",
                                     errors='coerce')

raw_callLog['tod'] = raw_callLog['time'].map(lambda x: x.hour + (x.minute/60) + (x.second/60/60))
raw_callLog['wnum'] = raw_callLog['time'].dt.week

distance = []
for i in range(len(raw_callLog)):
    lat1 = raw_callLog.loc[i,'current_lat']
    lon1 = raw_callLog.loc[i,'current_lon']
    lat2 = raw_callLog.loc[i,'stop_lat']
    lon2 = raw_callLog.loc[i,'stop_lon']
    distance.append(dis.dis(lat1,lon1,lat2,lon2))
raw_callLog['distance'] = distance

# cleansing current location geo-range
raw_callLog = raw_callLog[(raw_callLog['current_lat'] > 40.286527) & (raw_callLog['current_lat'] < 40.624502)]
raw_callLog = raw_callLog[(raw_callLog['current_lon'] > -80.05378) & (raw_callLog['current_lon'] < -79.896084)]

print (len(raw_callLog))

raw_callLog = raw_callLog[raw_callLog['stop_id'].notnull() & raw_callLog['time'].notnull()]
raw_callLog = raw_callLog[raw_callLog['distance'].notnull()]
raw_callLog = raw_callLog[raw_callLog['weekend'] == False]
print (len(raw_callLog))

raw_callLog = raw_callLog.sort_values(by=['device_id','date','time','stop_id'])
raw_callLog.to_csv('01_weekdaylog.csv',
Beispiel #4
0
raw_callLog['time'] = pd.to_datetime(raw_callLog['time'],
                                     format="%Y-%m-%d %H:%M:%S",
                                     errors='coerce')

raw_callLog['tod'] = raw_callLog['time'].map(
    lambda x: x.hour + (x.minute / 60) + (x.second / 60 / 60))
raw_callLog['wnum'] = raw_callLog['time'].dt.week

distance = []
for i in range(len(raw_callLog)):
    lat1 = raw_callLog.loc[i, 'current_lat']
    lon1 = raw_callLog.loc[i, 'current_lon']
    lat2 = raw_callLog.loc[i, 'stop_lat']
    lon2 = raw_callLog.loc[i, 'stop_lon']
    distance.append(dis.dis(lat1, lon1, lat2, lon2))
raw_callLog['distance'] = distance

# cleansing current location geo-range
raw_callLog = raw_callLog[(raw_callLog['current_lat'] > 40.286527)
                          & (raw_callLog['current_lat'] < 40.624502)]
raw_callLog = raw_callLog[(raw_callLog['current_lon'] > -80.05378)
                          & (raw_callLog['current_lon'] < -79.896084)]

print(len(raw_callLog))

raw_callLog = raw_callLog[raw_callLog['stop_id'].notnull()
                          & raw_callLog['time'].notnull()]
raw_callLog = raw_callLog[raw_callLog['distance'].notnull()]
raw_callLog = raw_callLog[raw_callLog['weekend'] == False]
print(len(raw_callLog))