def get_random_coordinates_sudden_dip(num_coordinates): result = [] current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] for i in range(num_coordinates / 3): distance_travelled = SEED_VELOCITY * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) for i in range(num_coordinates / 3): distance_travelled = (SEED_VELOCITY - 10) * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) for i in range(num_coordinates / 3): distance_travelled = SEED_VELOCITY * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) result.append(first_car_data) return result
def get_motion_for_vehicles(num_vehicles, num_coordinates): result = {} # Initialization for i in range(num_vehicles): unique_id = uuid.uuid4() result[unique_id] = [] current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp # Working for i in range(num_coordinates): current_key = "temporary" changes = {} for key in result.keys(): current_key = key random_conditions = randomize_conditions(5) if current_velocity + random_conditions['velocity_change'] < 55: current_velocity = current_velocity - random_conditions['velocity_change'] distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate changes['car_id'] = str(key) changes['latitude'] = current_coordinate[0] changes['longitude'] = current_coordinate[1] changes['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") #endfor time_stamp = time_stamp + datetime.timedelta(0, 60) result[current_key].append(changes) pass #endfor return result
def get_n_car_motion_for_random_coordinates(num_coordinates, num_cars): result = [] current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] for i in range(num_coordinates): random_error = random.random() random_range = random.randint(0, 5) velocity_change = random_range*random_error random_direction = random.randint(0, 1) if random_direction == 0: current_velocity = current_velocity - velocity_change elif random_direction == 1: current_velocity = current_velocity + velocity_change distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) result.append(first_car_data) for i in range(num_cars-1): secondary_car_data = get_car_motion_for_coordinates(first_car_data, first_stamp) result.append(secondary_car_data) return result
def get_random_coordinates_with_accident(num_coordinates): current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE accident = random.randint(1, num_coordinates-1) has_crashed = False for x in xrange(1,num_coordinates): random_dict = randomize_conditions(5) if has_crashed: has_crashed = False current_velocity = SEED_VELOCITY_CRASHED if x == accident: has_crashed = True current_velocity = 0 csv = str(current_coordinate[0]) + ',' + str(current_coordinate[1]) + ', Accident' print(csv) continue if random_dict['direction'] == 0: current_velocity = current_velocity - random_dict['velocity_change'] elif random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) csv = str(current_coordinate[0]) + ',' + str(current_coordinate[1]) + ' : ' + str(distance_travelled) print(csv)
def get_random_coordinates_sudden_dip(num_coordinates): result = [] current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] for i in range(num_coordinates/3): distance_travelled = SEED_VELOCITY * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) for i in range(num_coordinates/3): distance_travelled = (SEED_VELOCITY-10) * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) for i in range(num_coordinates/3): distance_travelled = SEED_VELOCITY * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) result.append(first_car_data) return result
def get_random_coordinates_positive_acceleration(num_coordinates): current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE for i in range(num_coordinates): random_error = random.random() random_range = random.randint(0, 5) velocity_change = random_range*random_error current_velocity = current_velocity + velocity_change distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate csv = str(next_coordinate[0]) + ',' + str(next_coordinate[1]) print(csv)
def get_random_coordinates_positive_acceleration(num_coordinates): current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE for i in range(num_coordinates): random_error = random.random() random_range = random.randint(0, 5) velocity_change = random_range * random_error current_velocity = current_velocity + velocity_change distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate csv = str(next_coordinate[0]) + ',' + str(next_coordinate[1]) print(csv)
def get_weather_dependent_motion_for_vehicles(num_vehicles, num_coordinates): result = {} # Initialization for i in range(num_vehicles): unique_id = uuid.uuid4() result[unique_id] = [] current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp # Working for i in range(num_coordinates): current_key = "temporary" changes = {} for key in result.keys(): current_key = key random_conditions = randomize_conditions(5) weather = weather_conditions(current_coordinate, datetime.now()) current_velocity = get_speed_change(current_velocity, weather, result[key][-1]) distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate changes['car_id'] = str(key) changes['latitude'] = current_coordinate[0] changes['longitude'] = current_coordinate[1] changes['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") changes['windspeed'] = weather['wind'] changes['snow'] = weather['snow'] changes['tmin'] = weather['tmin'] vehicle_set[key] = (changes['latitude'], changes['longitude']) accident_vehicle = check_accident(key) #endfor time_stamp = time_stamp + datetime.timedelta(0, 60) result[current_key].append(changes) pass #endfor return result
def get_n_car_motion_for_random_coordinates(num_coordinates, num_cars): result = [] current_velocity = SEED_VELOCITY current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] for i in range(num_coordinates): random_error = random.random() random_range = random.randint(0, 5) velocity_change = random_range * random_error random_direction = random.randint(0, 1) if random_direction == 0: current_velocity = current_velocity - velocity_change elif random_direction == 1: current_velocity = current_velocity + velocity_change distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) result.append(first_car_data) for i in range(num_cars - 1): secondary_car_data = get_car_motion_for_coordinates( first_car_data, first_stamp) result.append(secondary_car_data) return result
def get_random_coordinates_sudden_dip_varying(num_coordinates): result = [] current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] current_velocity = SEED_VELOCITY for i in range(num_coordinates / 3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 10: current_velocity = current_velocity - random_dict[ 'velocity_change'] current_velocity = current_velocity - 8 for i in range(num_coordinates / 3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 6: current_velocity = current_velocity - random_dict[ 'velocity_change'] current_velocity = current_velocity + 8 for i in range(num_coordinates / 3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = time_stamp.strftime("%Y-%m-%d %H:%M:%S") first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 10: current_velocity = current_velocity - random_dict[ 'velocity_change'] result.append(first_car_data) return result
def get_random_coordinates_sudden_dip_varying(num_coordinates): result = [] current_coordinate = SEED_COORDINATE time_stamp = datetime.datetime.now() first_stamp = time_stamp unique_id = uuid.uuid4() first_car_data = [] current_velocity = SEED_VELOCITY for i in range(num_coordinates/3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 10: current_velocity = current_velocity - random_dict['velocity_change'] current_velocity = current_velocity - 8 for i in range(num_coordinates/3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 6: current_velocity = current_velocity - random_dict['velocity_change'] current_velocity = current_velocity + 8 for i in range(num_coordinates/3): distance_travelled = current_velocity * SEED_TIME next_coordinate = geo.predict_next_coordinate(current_coordinate, distance_travelled, SEED_DIRECTION) current_coordinate = next_coordinate json_object = {} json_object['car_id'] = str(unique_id) json_object['latitude'] = current_coordinate[0] json_object['longitude'] = current_coordinate[1] json_object['time_stamp'] = str(time_stamp) first_car_data.append(json_object) time_stamp = time_stamp + datetime.timedelta(0, 300) random_dict = randomize_conditions(2) print(i, current_velocity) if random_dict['direction'] == 1: current_velocity = current_velocity + random_dict['velocity_change'] if random_dict['direction'] == 0: if current_velocity + random_dict['velocity_change'] > 10: current_velocity = current_velocity - random_dict['velocity_change'] result.append(first_car_data) return result