def manual_retrace(client): customers, _, _ = parse_addresses(client) routes = [] names = [] print('customer list') print('-------------') for i in customers: print(i) print(' ') nroute = int(input('input the number of routes: ')) for i in range(0, nroute): spec_route = [] spec_names = [] while True: location, location_index = locgrab(customers) if location == None and spec_route == []: print('circuit added as empty route') break elif location == None and spec_route != []: raise ValueError('an empty location does not exist') else: spec_route.append(location_index) spec_names.append(location) if len(spec_route) > 1 and location == spec_names[0]: print(f'circuit {i} complete.') print(' ') break routes.append(spec_route) names.append(spec_names) return routes, names
def get_working_map(client): """Reduces the information matrices to reflect the working set. Filters the entries of the distance and time matrices to omit unnecessary addresses. Also returns a reversible map to the original list. May later be used for other filterable information, such as weather or predictive models. Params ------ client :: str The current client Returns ------- shrunk_dist :: numpy.array A smaller distance matrix, reflecting only the working set shrunk_dur :: numpy.array A smaller time matrix, reflecting only the working set backmap :: [] A map between the reduced set and original """ distance = parse_array(client, 'distance') duration = parse_array(client, 'time') addresses, _, working = parse_addresses(client) backmap = [] for i in range(0, len(addresses)): if addresses[i] in working: backmap.append(i) # backmap maps the ith address of the reduced list to the # backmap[i]th address of the real list. dist_split = np.split(distance, len(addresses)) dur_split = np.split(duration, len(addresses)) keeper = [] copper = [] for i in backmap: keeper.append(dist_split[i]) copper.append(dur_split[i]) shrunk_dist = np.vstack(tuple(keeper)) shrunk_dur = np.vstack(tuple(copper)) dist_split = np.split(shrunk_dist, len(addresses), axis=1) dur_split = np.split(shrunk_dur, len(addresses), axis=1) keeper = [] copper = [] for i in backmap: keeper.append(dist_split[i]) copper.append(dur_split[i]) shrunk_dist = np.hstack(tuple(keeper)) shrunk_dur = np.hstack(tuple(copper)) return shrunk_dist, shrunk_dur, backmap, addresses
def manual_cost_trace(client, routes): distance = parse_array(client, 'distance') duration = parse_array(client, 'time') customers, _, _ = parse_addresses(client) settings = get_settings(client) add_vec = [] fuel_vec = [] xpoints = [] ypoints = [] for i in customers: with open( os.getcwd() + '\\clients\\' + client + '\\customer_info\\' + i + '.json', 'r') as f: custinfo = json.load(f) add_vec.append(custinfo['proj_time']) fuel_vec.append(custinfo['proj_fuel']) ypoints.append(custinfo['lat']) xpoints.append(custinfo['lon']) add_vec = np.array(add_vec) points = Setup(duration, distance, add_vec, fuel_vec, xpoints, ypoints, settings) t_cost = [0] * len(routes) f_cost = [0] * len(routes) poly = [] for i in range(0, len(routes)): if routes[i] == []: continue init_app = np.array( [points.xpoints[routes[i][0]], points.ypoints[routes[i][0]]]) for j in range(0, len(routes[i]) - 1): try: t_cost[i] += points.d_matrix[routes[i][j]][routes[i][j + 1]] f_cost[i] += points.c_matrix[routes[i][j]][routes[i][j + 1]] xy_app = np.array([ points.xpoints[routes[i][j + 1]], points.ypoints[routes[i][j + 1]] ]) except IndexError: input('somethin dun goofed') init_app = np.vstack((init_app, xy_app)) init_app = np.vstack( (init_app, xy_app)) # I have no idea why I have to do this try: poly = np.vstack((poly, init_app)) except ValueError: poly = init_app for i in range(len(routes)): if t_cost[i] == 0: t_cost[i] = None if f_cost[i] == 0: f_cost[i] = None return t_cost, f_cost, poly, settings
def fetch_new(cur_client, customer): path = os.getcwd() + '\\clients\\' + cur_client addresses, _, _ = parse_addresses(cur_client) gmap = googlemaps.Client(key=key) origin = customer destinations = addresses origins = addresses destination = customer frommat = gmap.distance_matrix(origin, destinations, units='metric') tomat = gmap.distance_matrix(origins, destination, units='metric') with open(path + '\\infodump_horz.json', 'w') as f: json.dump(frommat, f) with open(path + '\\infodump_vert.json', 'w') as f: json.dump(tomat, f)
def set_depot(client): distance = parse_array(client, 'distance') duration = parse_array(client, 'time') customers, omissions, working = parse_addresses(client) good = False print('input "list" to see a list of available addresses') while not good: depot = input('which address would you like to set as the depot?: ') if depot == 'list': for i in working: print(i) print(' ') continue elif depot not in working: print('that address is not within the working list') print(' ') continue elif depot in working: good = True index = customers.index(depot) new_depot = [customers.pop(index)] customers = new_depot + customers #horizontal splitting dist_split = np.hsplit(distance, [index, index + 1]) distance = np.hstack((dist_split[1], dist_split[0], dist_split[2])) time_split = np.hsplit(duration, [index, index + 1]) duration = np.hstack((time_split[1], time_split[0], time_split[2])) #vertical splitting dist_split = np.vsplit(distance, [index, index + 1]) distance = np.vstack((dist_split[1], dist_split[0], dist_split[2])) time_split = np.vsplit(duration, [index, index + 1]) duration = np.vstack((time_split[1], time_split[0], time_split[2])) # path = os.getcwd() + '\\clients\\' + client addr = { 'addresses': customers, 'duds': omissions, 'working': working } pathapp = ['\\time.json', '\\distance.json', '\\customers.json'] contents = [duration.tolist(), distance.tolist(), addr] for i in range(0, 3): jdump(path + pathapp[i], contents[i]) else: print('something went wrong')
def new_data(cur_client, customer): path = os.getcwd() + '\\clients\\' + cur_client addresses, omitted, _ = parse_addresses(cur_client) with open(path + '\\infodump_vert.json', 'r') as f: vertical = json.load(f) if vertical['destination_addresses'][0] != '': with open(path + '\\infodump_horz.json', 'r') as f: horizontal = json.load(f) distance = parse_list(cur_client, 'distance') duration = parse_list(cur_client, 'time') addresses.append(vertical['destination_addresses'][0]) horz_list_dur = [] horz_list_dist = [] for dest in horizontal['rows'][0]['elements']: horz_list_dur.append(dest['duration']['value']) horz_list_dist.append(dest['distance']['value']) horz_list_dist.append(0) horz_list_dur.append(0) for i in range(0, len(distance)): distance[i].append( vertical['rows'][i]['elements'][0]['distance']['value']) duration[i].append( vertical['rows'][i]['elements'][0]['duration']['value']) distance.append(horz_list_dist) duration.append(horz_list_dur) addr = {'addresses': addresses, 'duds': omitted, 'working': addresses} loc = vertical['destination_addresses'][0] base_dict = { 'parameters': [], 'lat': 0, 'lon': 0, 'proj_time': 0, 'proj_fuel': 0, 'dF': 0, 'preset': False } jdump(path + '\\customer_info\\' + loc + '.json', base_dict) pathapp = ['\\time.json', '\\distance.json', '\\customers.json'] contents = [duration, distance, addr] for i in range(0, 3): jdump(path + pathapp[i], contents[i]) else: print('that address is a dud.')
def get_submap(client): addresses, omitted, working = parse_addresses(client) backmap = [] nonmap = [] for i in range(0, len(addresses)): if addresses[i] in working: backmap.append(i) else: nonmap.append(i) xpoints = [None] * len(addresses) ypoints = [None] * len(addresses) color = [None] * len(addresses) names = [None] * len(addresses) for i in range(0, len(addresses)): hold = addresses[i] short = textwrap.shorten(hold, 18, placeholder='...') with open( os.getcwd() + '\\clients\\' + client + '\\customer_info\\' + hold + '.json', 'r') as f: custinfo = json.load(f) if i == 0: color[i] = 'r' elif i in backmap: color[i] = 'g' elif i in nonmap: color[i] = 'k' names[i] = short ypoints[i] = custinfo['lat'] xpoints[i] = custinfo['lon'] max_x = max(xpoints) min_x = min(xpoints) xdiff = (max_x - min_x) * 0.1 max_y = max(ypoints) min_y = min(ypoints) ydiff = (max_y - min_y) * 0.1 x = [xpoints, min_x - xdiff, max_x + xdiff] y = [ypoints, min_y - ydiff, max_y + ydiff] return names, color, x, y
def revise_working(client): addresses, omitted, working = parse_addresses(client) work = set(working) correct = False print('{:<25} {:<25}'.format('addresses', 'working list')) for i in range(0, len(addresses)): if addresses[i] in work: out = '{:<25} :: ✔'.format( textwrap.shorten(addresses[i], 22, placeholder='...')) elif addresses[i] not in work: out = '{:<25} :: '.format( textwrap.shorten(addresses[i], 22, placeholder='...')) print(out) while not correct: nix = True while nix: drop = input('remove from the working list?[y/n]: ') if drop.lower() in ['y', 'yes', 'yeah', 'ye']: removal = input('input the address/re to remove: ') if removal == 'all': work = set([addresses[0]]) else: matcher = re.compile(removal, flags=re.I) removal_list = [] for element in work: if element == addresses[0]: pass elif matcher.search(element) != None: removal_list.append(element) for drop in removal_list: work.remove(drop) print(f'removed {drop}') else: nix = False print(' ') pile = True while pile: add = input('add to the working list?[y/n]: ') if add.lower() in ['y', 'yes', 'yeah', 'ye']: addition = input('input the address/re to add: ') if addition == 'all': work = set(addresses) else: matcher = re.compile(addition, flags=re.I) addition_list = [] for element in addresses: if matcher.search(element) != None: addition_list.append(element) for stuff in addition_list: work.add(stuff) print(f'added {stuff}') else: pile = False print(' ') print('{:<25} {:<25}'.format('addresses', 'working list')) print('-----------------------------------------') for i in range(0, len(addresses)): if addresses[i] in work: out = '{:<25} :: ✔'.format( textwrap.shorten(addresses[i], 22, placeholder='...')) elif addresses[i] not in work: out = '{:<25} :: '.format( textwrap.shorten(addresses[i], 22, placeholder='...')) print(out) print(' ') affirm = input('are these changes correct?[y/n]: ') if affirm.lower() in ['y', 'yes', 'yeah', 'ye']: correct = True print(' ') return addresses, omitted, list(work)