예제 #1
0
def pickup_select_according_time(start_time_string, end_time_string):
    pickup_all_day_f = open(pickup_all_day_file, 'r')

    start_time_datetime = datetime.strptime(start_time_string,
                                            '%Y-%m-%d %H:%M:%S')
    end_time_datetime = datetime.strptime(end_time_string, '%Y-%m-%d %H:%M:%S')
    start_time_timestamp = time.mktime(
        time.strptime(start_time_string, '%Y-%m-%d %H:%M:%S'))
    end_time_timestamp = time.mktime(
        time.strptime(end_time_string, '%Y-%m-%d %H:%M:%S'))

    pickup_according_time_f = open(
        pickup_according_time_file_dir + 'pickup_' +
        pickup_all_day_filename.split('.')[0].split('_')[1] + '_' +
        str(start_time_datetime.hour) + '-' + str(start_time_datetime.minute) +
        '_' + str(end_time_datetime.hour) + '-' +
        str(end_time_datetime.minute) + '.txt', 'w')

    pickup_number_according_time = 0
    for line in pickup_all_day_f.readlines():
        attrs = lib.parse_pickup_line(line)
        pickup_time_string = attrs['pickup_time']
        pickup_time_datetime = datetime.strptime(pickup_time_string,
                                                 '%Y-%m-%d %H:%M:%S')
        pickup_time_timestamp = time.mktime(
            time.strptime(pickup_time_string, '%Y-%m-%d %H:%M:%S'))
        if start_time_timestamp <= pickup_time_timestamp < end_time_timestamp:
            #print line
            pickup_number_according_time = pickup_number_according_time + 1
            pickup_according_time_f.write(line)

    pickup_all_day_f.close()
    print 'the number of pickup point between ' + start_time_string + ' and ' + end_time_string + ' is ' + ':', pickup_number_according_time
def pickup_select_according_time(start_time_string,end_time_string):
	start_time_datetime = datetime.strptime(start_time_string,'%Y-%m-%d %H:%M:%S')
	end_time_datetime = datetime.strptime(end_time_string,'%Y-%m-%d %H:%M:%S')
	pickup_f_according_time = open(pickup_file_according_dir + 'pickup_' + pickup_filename.split('.')[0].split('_')[1] + '_' + str(start_time_datetime.hour) + '-' + str(start_time_datetime.minute) + '_' + str(end_time_datetime.hour) + '-' + str(end_time_datetime.minute) + '.txt','w')
	pickup_number_according_time = 0
	for line in pickup_f.readlines():
		attrs = lib.parse_pickup_line(line)
		pickup_time_string = attrs['pickup_time']
		pickup_time_datetime = datetime.strptime(pickup_time_string,'%Y-%m-%d %H:%M:%S')
		if pickup_time_datetime.hour >= start_time_datetime.hour and pickup_time_datetime.hour <= end_time_datetime.hour and pickup_time_datetime.minute >= start_time_datetime.minute and pickup_time_datetime.minute <= end_time_datetime.minute:
			print line
			pickup_number_according_time = pickup_number_according_time + 1
			pickup_f_according_time.write(line)
	print 'the number of pick up point between ' + start_time_string + ' and ' + end_time_string + ' is ' + ':', pickup_number_according_time
def pickup_select_according_time(start_time_string, end_time_string):
    start_time_datetime = datetime.strptime(start_time_string,
                                            '%Y-%m-%d %H:%M:%S')
    end_time_datetime = datetime.strptime(end_time_string, '%Y-%m-%d %H:%M:%S')
    pickup_f_according_time = open(
        pickup_file_dir + 'kMeans/' + 'pickup_' +
        str(start_time_datetime.hour) + '-' + str(start_time_datetime.minute) +
        '_' + str(end_time_datetime.hour) + '-' +
        str(end_time_datetime.minute) + '.txt', 'w')
    pickup_number_according_time = 0
    for line in pickup_f.readlines():
        attrs = lib.parse_pickup_line(line)
        pickup_time_string = attrs['pickup_time']
        pickup_time_datetime = datetime.strptime(pickup_time_string,
                                                 '%Y-%m-%d %H:%M:%S')
        if pickup_time_datetime.hour >= start_time_datetime.hour and pickup_time_datetime.hour <= end_time_datetime.hour and pickup_time_datetime.minute >= start_time_datetime.minute and pickup_time_datetime.minute <= end_time_datetime.minute:
            print line
            pickup_number_according_time = pickup_number_according_time + 1
            pickup_f_according_time.write(line)
    print 'the number of pick up point between ' + start_time_string + ' and ' + end_time_string + ' is ' + ':', pickup_number_according_time
def pickup_select_according_time(start_time_string,end_time_string):
	pickup_all_day_f = open(pickup_all_day_file,'r')

	start_time_datetime = datetime.strptime(start_time_string,'%Y-%m-%d %H:%M:%S')
	end_time_datetime = datetime.strptime(end_time_string,'%Y-%m-%d %H:%M:%S')
	start_time_timestamp = time.mktime(time.strptime(start_time_string,'%Y-%m-%d %H:%M:%S'))
	end_time_timestamp = time.mktime(time.strptime(end_time_string,'%Y-%m-%d %H:%M:%S'))

	pickup_according_time_f = open(pickup_according_time_file_dir + 'pickup_' + pickup_all_day_filename.split('.')[0].split('_')[1] + '_' + str(start_time_datetime.hour) + '-' + str(start_time_datetime.minute) + '_' + str(end_time_datetime.hour) + '-' + str(end_time_datetime.minute) + '.txt','w')

	pickup_number_according_time = 0
	for line in pickup_all_day_f.readlines():
		attrs = lib.parse_pickup_line(line)
		pickup_time_string = attrs['pickup_time']
		pickup_time_datetime = datetime.strptime(pickup_time_string,'%Y-%m-%d %H:%M:%S')
		pickup_time_timestamp = time.mktime(time.strptime(pickup_time_string,'%Y-%m-%d %H:%M:%S'))
		if start_time_timestamp <= pickup_time_timestamp < end_time_timestamp:
			#print line
			pickup_number_according_time = pickup_number_according_time + 1
			pickup_according_time_f.write(line)
	
	pickup_all_day_f.close()
	print 'the number of pickup point between ' + start_time_string + ' and ' + end_time_string + ' is ' + ':', pickup_number_according_time