def drawfenkai(filename): from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + "\\" + "starlog") for path_file in other: TimePic = [] for i in range(len(path_file)): temp = [] path_file_name = parent_path + path_file[i] + os.sep + filename # print(path_file_name) data = np.loadtxt(path_file_name, dtype=str, delimiter=",", usecols=(0, 1, 2), unpack=False) start = data[1][1].split(" ")[0] for i in range(len(data)): tmp = [] tmp.append(canculateDate(data[i][1], start)) tmp.append(canculateDate(data[i][2], start)) tmp.append(data[i][0]) temp.append(tmp) TimePic.append(temp) print(path_file_name) drewPic(TimePic, path_file_name)
def drawfenkai(filename): from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + '\\' + 'starlog') for path_file in other: TimePic = [] for i in range(len(path_file)): temp = [] path_file_name = parent_path + path_file[i] + os.sep + filename #print(path_file_name) data = np.loadtxt(path_file_name, dtype=str, delimiter=',', usecols=(0, 1, 2), unpack=False) start = data[1][1].split(' ')[0] for i in range(len(data)): tmp = [] tmp.append(canculateDate(data[i][1], start)) tmp.append(canculateDate(data[i][2], start)) tmp.append(data[i][0]) temp.append(tmp) TimePic.append(temp) print(path_file_name) drewPic(TimePic, path_file_name)
def create_model(labelFileName='RClabelTime.txt'): FileName=[] from getDir import GetDirName import os getdir=GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles,AllFiles,other=getdir.getUserFiles(parent_path+'\\'+'starlog') for path_file in other: for i in range(len(path_file)): path_file_name=parent_path+path_file[i]+os.sep+labelFileName FileName.append(path_file_name) train_set=[] for file in FileName: #一个file 就是一天的数据路径,也就是一天的数据,外层一个for循环就是 写找完一天的记录 ondaydata=np.loadtxt(file,dtype=str,delimiter=',',usecols=(0,1,3)) #label,starttime,continuetime tempsentence=[] for i in range(len(ondaydata)): datasstrip=ondaydata[i][1].split(' ') word=ondaydata[i][0]+'_'+datasstrip[0]+'_'+time2hour(datasstrip[1])+'_'+str(int(ondaydata[i][2])//(10*60)) tempsentence.append(word) train_set.append(tempsentence) dic = corpora.Dictionary(train_set) corpus = [dic.doc2bow(text) for text in train_set] tfidf = models.TfidfModel(corpus) corpus_tfidf = tfidf[corpus] lda = models.LdaModel(corpus_tfidf, id2word = dic, num_topics = 24) corpus_lda = lda[corpus_tfidf] lda.save(".\\LDA_all_27\\SemanticLda"+str(24)+".txt") dic.save(".\\LDA_all_27\\SemanticDic"+str(24)+".txt") tfidf.save(".\\LDA_all_27\\SemanticTFIDF"+str(24)+".txt") return lda,dic,tfidf,train_set,AllUserFiles
def calculate_user_sim_onBluetooth(): userlist = [] getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + os.sep + 'starlog') for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[ i] + os.sep + 'bluetooth.txt' if os.path.exists(path_file_name): userlist.append(path_file_name.split(os.sep)[-3]) userlist = list(set(userlist)) print userlist for i in range(len(userlist) - 1): for j in range(i, len(userlist)): print userlist[i], userlist[j] result = calculate_bluetooth_sim(userlist[i], userlist[j]) ans.write(userlist[i]) ans.write(',') ans.write(userlist[j]) ans.write(',') ans.write(str(result)) ans.write('\n')
def get_fenlei_user(): wifi_path=[] getdir=GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles,AllFiles,other=getdir.getUserFiles(parent_path+os.sep+'starlog') for path_file in other: for i in range(len(path_file)): path_file_name=parent_path+path_file[i]+os.sep+'wifi.txt' wifi_path.append(path_file_name) return wifi_path
def get_fenlei_user(): wifi_path = [] getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + os.sep + "starlog") for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[i] + os.sep + "bluetooth.txt" if os.path.exists(path_file_name): wifi_path.append(path_file_name) #####Trans_btoothjson_txt(path_file_name) first time to excue this func will create blueeth csv file with add model to do return wifi_path
def mian(): from Semantics_of_Trajectories import Calculate_semantic_of_point from stop_points import getfullfilepath full = getfullfilepath() for n in range(len(full)): path_file = full[n].replace("locationGPS.txt", "location.txt") gps_data, timestamp, accur = get_data(path_file) # print len(accur) # print len(timestamp) labels, SP = getStayPoint(gps_data, timestamp, disthreshold=90, timethreshold=180) # print len(labels) # print(len(labels)-1) print (full[n]) labels.append(labels[len(labels) - 1]) #!!!!!!!!注意,labels的长度可能为0 好奇怪 # print len(labels) # print len(SP) # print SP stoppointlabel = [] labDIC = {} for i in range(len(SP)): value = Calculate_semantic_of_point.Match_semantics(SP[i], 90) stoppointlabel.append(value) labDIC[i] = value init_rs_staypoint_time(labels, gps_data, timestamp, accur, SP, labDIC, path_file) # 分类的用户的文件夹 from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + "\\" + "starlog") for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[i] + os.sep + "location.txt" gps_data, timestamp, accur = get_data(path_file_name) labels, SP = getStayPoint(gps_data, timestamp, disthreshold=90, timethreshold=180) print (path_file[i]) labels.append(labels[len(labels) - 1]) #!!!!!!!!注意,labels的长度可能为0 好奇怪 stoppointlabel = [] labDIC = {} for i in range(len(SP)): value = Calculate_semantic_of_point.Match_semantics(SP[i], 90) stoppointlabel.append(value) labDIC[i] = value init_rs_staypoint_time(labels, gps_data, timestamp, accur, SP, labDIC, path_file_name)
def mian(): from Semantics_of_Trajectories import Calculate_semantic_of_point from stop_points import getfullfilepath full=getfullfilepath() for n in range(len(full)): path_file=full[n].replace('locationGPS.txt','location.txt') gps_data,timestamp,accur = get_data(path_file) # print len(accur) # print len(timestamp) labels,SP = getStayPoint(gps_data,timestamp,disthreshold=90,timethreshold=180) #print len(labels) #print(len(labels)-1) print(full[n]) labels.append(labels[len(labels)-1]) #!!!!!!!!注意,labels的长度可能为0 好奇怪 # print len(labels) # print len(SP) # print SP stoppointlabel=[] labDIC={} for i in range(len(SP)): value=Calculate_semantic_of_point.Match_semantics(SP[i],90) stoppointlabel.append(value) labDIC[i]=value init_rs_staypoint_time(labels,gps_data,timestamp,accur,SP,labDIC,path_file) #分类的用户的文件夹 from getDir import GetDirName import os getdir=GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles,AllFiles,other=getdir.getUserFiles(parent_path+'\\'+'starlog') for path_file in other: for i in range(len(path_file)): path_file_name=parent_path+path_file[i]+os.sep+'location.txt' gps_data,timestamp,accur = get_data(path_file_name) labels,SP = getStayPoint(gps_data,timestamp,disthreshold=90,timethreshold=180) print(path_file[i]) labels.append(labels[len(labels)-1]) #!!!!!!!!注意,labels的长度可能为0 好奇怪 stoppointlabel=[] labDIC={} for i in range(len(SP)): value=Calculate_semantic_of_point.Match_semantics(SP[i],90) stoppointlabel.append(value) labDIC[i]=value init_rs_staypoint_time(labels,gps_data,timestamp,accur,SP,labDIC,path_file_name)
def main(): from label_add_time import GetSemanticGPSpath full=GetSemanticGPSpath() for n in range(len(full)): path_file=full[n].replace('semanticGPS.txt','RC_stoppoint.txt') print(path_file) Read_RC_stoppoint(path_file) print 'ok.....have process over' #分类的用户的文件夹 from getDir import GetDirName import os getdir=GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles,AllFiles,other=getdir.getUserFiles(parent_path+'\\'+'starlog') for path_file in other: for i in range(len(path_file)): path_file_name=parent_path+path_file[i]+os.sep+'RC_stoppoint.txt' Read_RC_stoppoint(path_file_name) print 'ok.....have process over'
def RC_Label_Time_process(): filelist = GetSemanticGPSpath() lda = ldaHelper() for file in filelist: f = file.replace('semanticGPS.txt', 'RC_stoppoint.txt') write_labelTime2file(lda.Add_RCtimestamp(f), f) print('have done %s' % f) #分类的用户的文件夹 from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + '\\' + 'starlog') for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[ i] + os.sep + 'RC_stoppoint.txt' write_labelTime2file(lda.Add_RCtimestamp(path_file_name), path_file_name)
def main(): from label_add_time import GetSemanticGPSpath full = GetSemanticGPSpath() for n in range(len(full)): path_file = full[n].replace('semanticGPS.txt', 'RC_stoppoint.txt') print(path_file) Read_RC_stoppoint(path_file) print 'ok.....have process over' #分类的用户的文件夹 from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + '\\' + 'starlog') for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[ i] + os.sep + 'RC_stoppoint.txt' Read_RC_stoppoint(path_file_name) print 'ok.....have process over'
def create_model(labelFileName='RClabelTime.txt'): FileName = [] from getDir import GetDirName import os getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles, AllFiles, other = getdir.getUserFiles(parent_path + '\\' + 'starlog') for path_file in other: for i in range(len(path_file)): path_file_name = parent_path + path_file[i] + os.sep + labelFileName FileName.append(path_file_name) train_set = [] for file in FileName: #一个file 就是一天的数据路径,也就是一天的数据,外层一个for循环就是 写找完一天的记录 ondaydata = np.loadtxt(file, dtype=str, delimiter=',', usecols=(0, 1, 3)) #label,starttime,continuetime tempsentence = [] for i in range(len(ondaydata)): datasstrip = ondaydata[i][1].split(' ') word = ondaydata[i][0] + '_' + datasstrip[0] + '_' + time2hour( datasstrip[1]) + '_' + str(int(ondaydata[i][2]) // (10 * 60)) tempsentence.append(word) train_set.append(tempsentence) dic = corpora.Dictionary(train_set) corpus = [dic.doc2bow(text) for text in train_set] tfidf = models.TfidfModel(corpus) corpus_tfidf = tfidf[corpus] lda = models.LdaModel(corpus_tfidf, id2word=dic, num_topics=24) corpus_lda = lda[corpus_tfidf] lda.save(".\\LDA_all_27\\SemanticLda" + str(24) + ".txt") dic.save(".\\LDA_all_27\\SemanticDic" + str(24) + ".txt") tfidf.save(".\\LDA_all_27\\SemanticTFIDF" + str(24) + ".txt") return lda, dic, tfidf, train_set, AllUserFiles
def calculate_user_sim_onBluetooth(): userlist = [] getdir = GetDirName() parent_path = os.path.dirname(os.getcwd()) AllUserFiles,AllFiles,other = getdir.getUserFiles(parent_path+os.sep+'starlog') for path_file in other: for i in range(len(path_file)): path_file_name = parent_path+path_file[i]+os.sep+'bluetooth.txt' if os.path.exists(path_file_name): userlist.append(path_file_name.split(os.sep)[-3]) userlist = list(set(userlist)) print userlist for i in range(len(userlist)-1): for j in range(i,len(userlist)): print userlist[i],userlist[j] result= calculate_bluetooth_sim(userlist[i],userlist[j]) ans.write(userlist[i]) ans.write(',') ans.write(userlist[j]) ans.write(',') ans.write(str(result)) ans.write('\n')
file_processGPS.writelines(',') file_processGPS.writelines('0.0') file_processGPS.write('\n') file_processGPS.close() def drewgps(weidu, jindu, date): fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(jindu, weidu, c='r', marker='.') plt.title('location of : %s' % date) plt.savefig('.\\GPS_pic\\' + date + '.png', dpi=800) plt.close() #plt.show() if __name__ == '__main__': getdir = GetDirName() dirlist = [] dirlist = getdir.printPath(".\\GPS_Get_PreProcesser") print(dirlist) for wenjianjia in dirlist: print ".\\GPS_Get_PreProcesser" + '\\' + wenjianjia + '\\' + 'location.txt', wenjianjia readfile( ".\\GPS_Get_PreProcesser" + '\\' + wenjianjia + '\\' + 'location.txt', wenjianjia) #下面是写分开每个用户的结果哦 AllUserFiles, AllFiles, other = getdir.getUserFiles() for wenjianjia in AllFiles: readfile(wenjianjia + os.sep + 'location.txt', wenjianjia)
file_processGPS.writelines(',') file_processGPS.writelines(i[1]) file_processGPS.writelines(',') file_processGPS.writelines(i[2]) file_processGPS.writelines(',') file_processGPS.writelines(i[3]) file_processGPS.writelines(',') file_processGPS.writelines('0.0') file_processGPS.write('\n') file_processGPS.close() def drewgps(weidu,jindu,date): fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(jindu,weidu,c='r',marker='.') plt.title('location of : %s' % date) plt.savefig('.\\GPS_pic\\'+date+'.png',dpi=800) plt.close() #plt.show() if __name__=='__main__': getdir=GetDirName() dirlist=[] dirlist=getdir.printPath(".\\GPS_Get_PreProcesser") print(dirlist) for wenjianjia in dirlist: print ".\\GPS_Get_PreProcesser"+ '\\' + wenjianjia + '\\' + 'location.txt',wenjianjia readfile(".\\GPS_Get_PreProcesser"+ '\\' + wenjianjia + '\\' + 'location.txt',wenjianjia) #下面是写分开每个用户的结果哦 AllUserFiles,AllFiles,other=getdir.getUserFiles() for wenjianjia in AllFiles: readfile(wenjianjia + os.sep+ 'location.txt',wenjianjia)