def line_callback(self,line,postgres_tbname): if line != '': attrs = lib.parse_line(line) #taxi_status_tx = str(attrs['taxi_status']) time_tx = attrs['time'] #speed_tx = str(attrs['speed']) #head_tx = str(attrs['head']) coord = [attrs['lon'],attrs['lat']] if (self.pre_occupied != attrs['taxi_status']) and ((self.pre_occupied == '0') or (self.pre_occupied == '1')): #self.coords.append(coord) #self.descs.append({'t':time_tx,'h':head_tx,'s':speed_tx,'taxi_status':taxi_status_tx}) #self.descs.append({'t':time_tx}) self.OorC = self.pre_occupied if len(self.coords) > 1: self.insert_track(postgres_tbname) self.coords = list() self.descs = list() self.OorC = '' self.pre_occupied = attrs['taxi_status'] if (attrs['taxi_status'] == '0') or (attrs['taxi_status'] == '1'): self.coords.append(coord) #self.descs.append({'t':time_tx,'h':head_tx,'s':speed_tx,'taxi_status':taxi_status_tx}) self.descs.append({'t':time_tx}) self.pre_occupied = attrs['taxi_status'] if (line == '') and (len(self.coords) > 1): self.OorC = self.pre_occupied self.insert_track(postgres_tbname) elif (line == '') and (len(self.coords) <= 1): pass
def line_callback(self,line): if line != '': attrs = lib.parse_line(line) taxi_status_tx = str(attrs['taxi_status']) time_tx = attrs['time'] speed_tx = str(attrs['speed']) head_tx = str(attrs['head']) coord = [attrs['lon'],attrs['lat']] if self.taxi_status == attrs['taxi_status']: self.coords.append(coord) self.descs.append({'t':time_tx,'h':head_tx,'s':speed_tx,'taxi_status':taxi_status_tx}) self.pre_taxi_status = attrs['taxi_status'] elif (self.taxi_status != attrs['taxi_status']) and (self.pre_taxi_status == '0'): self.coords.append(coord) self.descs.append({'t':time_tx,'h':head_tx,'s':speed_tx,'taxi_status':taxi_status_tx}) self.geo['coordinates'] = self.coords self.features.append({'geometry':self.geo,'properties':{'desc':self.descs}}) self.geo = dict() self.geo['type'] = 'LineString' self.coords = list() self.descs = list() self.pre_taxi_status = attrs['taxi_status'] if (line == '') and (self.coords != []): self.geo['coordinates'] = self.coords self.features.append({'geometry':self.geo,'properties':{'desc':self.descs}}) elif (line == '') and (self.coords == []): pass
def line_callback(self, line): if line != "": attrs = lib.parse_line(line) taxi_status_tx = str(attrs["taxi_status"]) time_tx = attrs["time"] speed_tx = str(attrs["speed"]) head_tx = str(attrs["head"]) coord = [attrs["lon"], attrs["lat"]] if self.taxi_status == attrs["taxi_status"]: self.coords.append(coord) self.descs.append({"t": time_tx, "h": head_tx, "s": speed_tx, "taxi_status": taxi_status_tx}) self.pre_taxi_status = attrs["taxi_status"] elif (self.taxi_status != attrs["taxi_status"]) and (self.pre_taxi_status == "2"): self.coords.append(coord) self.descs.append({"t": time_tx, "h": head_tx, "s": speed_tx, "taxi_status": taxi_status_tx}) self.geo["coordinates"] = self.coords self.features.append({"geometry": self.geo, "properties": {"desc": self.descs}}) self.geo = dict() self.geo["type"] = "LineString" self.coords = list() self.descs = list() self.pre_taxi_status = attrs["taxi_status"] if (line == "") and (self.coords != []): self.geo["coordinates"] = self.coords self.features.append({"geometry": self.geo, "properties": {"desc": self.descs}}) elif (line == "") and (self.coords == []): pass
def line_callback(self,line): if line != '': attrs = lib.parse_line(line) taxi_status_tx = str(attrs['taxi_status']) time_tx = attrs['time'] speed_tx = str(attrs['speed']) head_tx = str(attrs['head']) coord = [attrs['lon'],attrs['lat']] self.coords.append(coord) self.descs.append({"t":time_tx,"h":head_tx,"s":speed_tx,"taxi_status":taxi_status_tx}) self.coordnum = self.coordnum + 1 if line == '': self.geo["coordinates"] = self.coords self.features.append({"geometry":self.geo, "properties":{"desc":self.descs}})
output_file_dir = output_dir +tbname + '/' os.mkdir(output_file_dir) for file_number in range(1,len(os.listdir(input_file_dir))+1): #for file_number in range(1,2): input_f = open(input_file_dir + str(file_number) + '.txt','r') output_f = open(output_file_dir + str(file_number) + '.txt','w') #log_f = open(output_file_dir + str(file_number) + '_log.txt','w') first_line = input_f.readline() second_line = input_f.readline() if second_line == '': continue third_line = input_f.readline() if third_line == '': continue first_line_attrs = lib.parse_line(first_line) second_line_attrs = lib.parse_line(second_line) third_line_attrs = lib.parse_line(third_line) first_line_coord = [first_line_attrs['lon'], first_line_attrs['lat']] second_line_coord = [second_line_attrs['lon'],second_line_attrs['lat']] third_line_coord = [third_line_attrs['lon'],third_line_attrs['lat']] d_first_second = lib.coords_2_km(first_line_coord,second_line_coord) d_second_third = lib.coords_2_km(second_line_coord,third_line_coord) d_first_third = lib.coords_2_km(first_line_coord,third_line_coord) while True: #log_f.write(str(d_first_second) + ' ' + str(d_second_third) + ' ' + str(d_first_third) + ' ' + first_line) distance_separate = 0.5 if (first_line_attrs['taxi_status'] == third_line_attrs['taxi_status']) & (first_line_attrs['taxi_status'] != second_line_attrs['taxi_status']) & (d_first_second > distance_separate) & (d_second_third > distance_separate): #distance_separate = 1
output_file_dir = output_dir + tbname + '/' os.mkdir(output_file_dir) for file_number in range(1, len(os.listdir(input_file_dir)) + 1): #for file_number in range(1,2): input_f = open(input_file_dir + str(file_number) + '.txt', 'r') output_f = open(output_file_dir + str(file_number) + '.txt', 'w') #log_f = open(output_file_dir + str(file_number) + '_log.txt','w') first_line = input_f.readline() second_line = input_f.readline() if second_line == '': continue third_line = input_f.readline() if third_line == '': continue first_line_attrs = lib.parse_line(first_line) second_line_attrs = lib.parse_line(second_line) third_line_attrs = lib.parse_line(third_line) first_line_coord = [first_line_attrs['lon'], first_line_attrs['lat']] second_line_coord = [ second_line_attrs['lon'], second_line_attrs['lat'] ] third_line_coord = [third_line_attrs['lon'], third_line_attrs['lat']] d_first_second = lib.coords_2_km(first_line_coord, second_line_coord) d_second_third = lib.coords_2_km(second_line_coord, third_line_coord) d_first_third = lib.coords_2_km(first_line_coord, third_line_coord) while True: #log_f.write(str(d_first_second) + ' ' + str(d_second_third) + ' ' + str(d_first_third) + ' ' + first_line) distance_separate = 0.5