def get_experimental_runs_by_mission( args) -> Dict[str, Dict[float, Dict[str, List[np.array]]]]: runs_by_mission: Dict[str, Dict[float, Dict[str, List[np.array]]]] = dict() log_fns = log_analysis.get_from_db(args.log_db, log_type=args.log_type) for label, log_fn_list in log_fns.items(): mission_fns = set([x[2] for x in log_fn_list]) for mission_fn in mission_fns: if label == "nominal": delay = 0 topic = "None" log_data_list = [ x[3] for x in log_analysis.convert_logs_husky( log_fn_list, alt_bag_base=args.alt_bag_base) ] delay_topic_dict = dict({0.0: {"None": log_data_list}}) runs_by_mission[mission_fn] = delay_topic_dict elif label == "experimental": logging.debug(f"mission_fns: {mission_fns}") delay_topic_dict = get_delay_topic_dict( log_fn_list, delay=delay, log_type=args.log_type, alt_bag_base=args.alt_bag_base) #nominal_dict[mission_fn] = dict({delay: topic_dict}) runs_by_mission[mission_fn] = delay_topic_dict return runs_by_mission
def get_topic_results_dict(args): bag_fns = log_analysis.get_from_db(args.log_db, log_type=args.log_type) all_bag_fns_list = bag_fns["nominal"] + bag_fns["experimental"] all_mission_fns = set([x[2] for x in all_bag_fns_list]) one_mission_fns = [x for x in all_mission_fns if args.one_mission in x] assert (len(one_mission_fns) <= 1) bag_fns_one_mission = [ x for x in all_bag_fns_list if x[2] == one_mission_fns[0] ] bag_data_one_mission = log_analysis.convert_logs_husky( bag_fns_one_mission, alt_bag_base=args.alt_bag_base) topic_dict = dict() time_dict = dict() for bag_fn, topic_delay_fn, mission_fn, log_data in bag_data_one_mission: completion_time = log_analysis.completion_time(log_data, log_type="husky") topic, delay = log_analysis.mut_fn_to_topic_delay( topic_delay_fn, log_type=args.log_type) mission = log_analysis.mission_to_list( mission_fn, log_type=args.log_type, alt_mission_base=args.alt_mission_base) dist_dict = log_analysis.distance_to_each_waypoint( log_data, mission, log_type="husky", final_dist=args.final_distance) result_dict = log_analysis.reaches_waypoints(dist_dict, mission, log_type="husky", tolerance=args.threshold) result = all([x for x in result_dict.values()]) if topic == None or topic == "None": assert (delay == 0), delay if topic not in topic_dict: topic_dict[topic] = dict({delay: {"pass": 0, "fail": 0}}) if delay not in topic_dict[topic]: topic_dict[topic][delay] = dict({"pass": 0, "fail": 0}) if topic not in time_dict: time_dict[topic] = dict({delay: {"pass": [], "fail": []}}) if delay not in time_dict[topic]: time_dict[topic][delay] = dict({"pass": [], "fail": []}) if result: topic_dict[topic][delay]["pass"] = \ 1 + topic_dict[topic][delay]["pass"] time_dict[topic][delay]["pass"] = \ [completion_time] + time_dict[topic][delay]["pass"] else: topic_dict[topic][delay]["fail"] = \ 1 + topic_dict[topic][delay]["fail"] time_dict[topic][delay]["fail"] = \ [completion_time] + time_dict[topic][delay]["fail"] logging.debug(f"topic_dict: {topic_dict}") logging.debug(f"time_dict: {time_dict}") assert (topic_dict.keys() == time_dict.keys()) for topic in topic_dict.keys(): topic_dict[topic][0.0] = { "pass": topic_dict["None"][0.0]["pass"], "fail": topic_dict["None"][0.0]["fail"] } topic_dict[topic][0.0]["pass"] = topic_dict["None"][0.0]["pass"] topic_dict[topic][0.0]["fail"] = topic_dict["None"][0.0]["fail"] time_dict[topic][0.0] = { "pass": time_dict["None"][0.0]["pass"], "fail": time_dict["None"][0.0]["fail"] } return topic_dict, time_dict
def waypoint_distance_by_topic(args): assert (type(args.delay) == float), args.delay assert (args.one_mission), args.one_mission bag_fns = log_analysis.get_from_db(args.log_db, log_type=args.log_type) all_bag_fns_list = bag_fns["nominal"] + bag_fns["experimental"] logging.debug(f"all_bag_fns_list: {all_bag_fns_list}") all_mission_fns = set([x[2] for x in all_bag_fns_list]) one_mission_fns = [x for x in all_mission_fns if args.one_mission in x] assert (len(one_mission_fns) == 1) bag_fns_one_mission = [ x for x in all_bag_fns_list if x[2] == one_mission_fns[0] ] bag_fns_one_mission_one_delay = [ x for x in bag_fns_one_mission if (args.delay == log_analysis.mut_fn_to_topic_delay( x[1], log_type="husky")[1]) ] logging.debug( f"len(bag_fns_one_mission_one_delay): {len(bag_fns_one_mission_one_delay)}" ) bag_data_one_mission_one_delay = log_analysis.convert_logs_husky( bag_fns_one_mission_one_delay, alt_bag_base=args.alt_bag_base) topic_dict = dict() for bag_fn, topic_delay_fn, mission_fn, log_data \ in bag_data_one_mission_one_delay: topic, delay = log_analysis.mut_fn_to_topic_delay( topic_delay_fn, log_type=args.log_type) assert ( delay == args.delay ), f"delay_from_fn: {delay}, args.delay: {args.delay}\ntopic_delay_fn: {topic_delay_fn}" mission_as_list = log_analysis.mission_to_list( mission_fn, log_type=args.log_type, alt_mission_base=args.alt_mission_base) waypoint_dict = log_analysis.distance_to_each_waypoint( log_data, mission_as_list, log_type=args.log_type, final_dist=args.final_distance) if topic not in topic_dict: topic_dict[topic] = [] topic_dict[topic] = topic_dict[topic] + [waypoint_dict] mean_topic_dict = dict() std_topic_dict = dict() for topic, topic_list in topic_dict.items(): logging.debug(f"topic: {topic} topic_list: {topic_list}") num_data_points = len(topic_list) num_waypoints = len(topic_list[0]) logging.debug( f"topic: {topic} num_data_points: {num_data_points} num_waypoints: {num_waypoints}" ) for waypoint in sorted(topic_list[0].keys()): vals = [x[waypoint] for x in topic_list] mean = statistics.mean(vals) std = statistics.stdev(vals) if topic not in mean_topic_dict: mean_topic_dict[topic] = dict() if topic not in std_topic_dict: std_topic_dict[topic] = dict() mean_topic_dict[topic][waypoint] = mean std_topic_dict[topic][waypoint] = std print("Mean \\\\") print_table(mean_topic_dict, "waypoint_distance_delay", args.log_type) print("Standard Deviation \\\\") print_table(std_topic_dict, "waypoint_distance_delay", args.log_type) return
def waypoint_distance(args): # get the appropriate group of data. do this only once. bag_fns = log_analysis.get_from_db(args.log_db, log_type=args.log_type) all_bag_fns_list = bag_fns["nominal"] + bag_fns["experimental"] mission_fns = set([x[2] for x in all_bag_fns_list]) logging.debug(f"mission_fns: {mission_fns}") husky_bag_data: Dict[str, Tuple[str, str, np.array]] = dict() dist_by_label_mission: Dict[str, Dict[str, List[Dict[int, float]]]] = dict() mean_by_label_mission: Dict[str, Dict[str, Dict[int, float]]] = dict() std_by_label_mission: Dict[str, Dict[str, Dict[int, float]]] = dict() for label in ("nominal", "experimental"): logging.info(f"Analzying data for {label}") # bag_data is a list of Tuples. # Each tuple is bag_fn, delay_fn, mission_fn, log_data # log_data is an np.array of [time_elapsed, x_pos, y_pos, z_pos if args.log_type == "husky": bag_data = log_analysis.convert_logs_husky( bag_fns[label], alt_bag_base=args.alt_bag_base) elif args.log_type == "ardu": bag_data = log_analysis.convert_logs_ardu( bag_fns[label], alt_bag_base=args.alt_bag_base) husky_bag_data[label] = bag_data if args.one_mission: mission_fns = [x for x in mission_fns if args.one_mission in x] print(mission_fns) # Separate by mission for mission_fn in mission_fns: mission_as_list = log_analysis.mission_to_list( mission_fn, log_type=args.log_type, alt_mission_base=args.alt_mission_base) mission_data = [x for x in bag_data if x[2] == mission_fn] logging.debug(f"*" * 80) # logging.debug(f"\n\nlabel: {label}, mission: {mission_fn}:\n {mission_data}") logging.debug(f"\n\nlabel: {label}, mission: {mission_fn}") dists_list = [] for bag_fn, delay_fn, mission_fn_loc, log_data in mission_data: assert (mission_fn.strip() == mission_fn_loc.strip() ), f"{mission_fn} {mission_fn_loc}" if label == "nominal": logging.debug(f"Delay_fn should be None: {delay_fn}") else: pass # logging.debug(f"Delay_fn should *not* be None: {delay_fn}") if len(log_data) == 0: logging.error(f"log data missing for bag: {bag_fn}") continue logging.debug(f"log data found for bag: {bag_fn}") dists = log_analysis.distance_to_each_waypoint( log_data, mission_as_list, log_type=args.log_type, final_dist=args.final_distance) logging.debug(f"waypoint_distance: dists: {dists}") dists_list.append(dists) if label not in dist_by_label_mission: dist_by_label_mission[label] = dict() dist_by_label_mission[label][mission_fn] = dists_list #logging.debug(f"*"*80) #logging.debug(f"\n\ndist_by_label_mission[{label}][{mission_fn}]: {dist_by_label_mission[label][mission_fn]}") mean_dist_dict = dict() std_dict = dict() if args.graph == "waypoint_distance": if len(dists_list) != 0: for waypoint in dists_list[0].keys(): vals = [x[waypoint] for x in dists_list] mean = statistics.mean(vals) mean_dist_dict[waypoint] = mean try: std = statistics.stdev(vals) except statistics.StatisticsError as e: logging.warn("Not computing standard deviation") logging.warn(f"Only {len(vals)} data points") std = 0 std_dict[waypoint] = std if label not in mean_by_label_mission: mean_by_label_mission[label] = dict() mean_by_label_mission[label][mission_fn] = mean_dist_dict if label not in std_by_label_mission: std_by_label_mission[label] = dict() std_by_label_mission[label] = std_dict print("Mean \\\\") print_table(mean_by_label_mission, args.graph, args.log_type) logging.debug("Std deviation doesn't work yet")
def waypoint_distance_delay(args): assert (args.one_mission) bag_fns = log_analysis.get_from_db(args.log_db, log_type=args.log_type) all_bag_fns_list = bag_fns["nominal"] + bag_fns["experimental"] all_mission_fns = set([x[2] for x in all_bag_fns_list]) logging.debug(f"all_mission_fns: {all_mission_fns}") one_mission_fns = [x for x in all_mission_fns if args.one_mission in x] assert (len(one_mission_fns) <= 1) bag_fns_one_mission = [ x for x in all_bag_fns_list if x[2] == one_mission_fns[0] ] if args.log_type == "husky": bag_data_one_mission = log_analysis.convert_logs_husky( bag_fns_one_mission, alt_bag_base=args.alt_bag_base) elif args.log_type == "ardu": bag_data_one_mission = log_analysis.convert_logs_ardu( bag_fns_one_mission, alt_bag_base=args.alt_bag_base) mut_fns = [x[1] for x in bag_data_one_mission] logging.debug(f"mut_fns: {mut_fns}") delay_dict = dict() for bag_fn, topic_delay_fn, mission_fn, log_data in bag_data_one_mission: if len(log_data) == 0: logging.warn(f"no data for {bag_fn}") continue topic, delay = log_analysis.mut_fn_to_topic_delay( topic_delay_fn, log_type=args.log_type) mission_as_list = log_analysis.mission_to_list( mission_fn, log_type=args.log_type, alt_mission_base=args.alt_mission_base) waypoint_dict = log_analysis.distance_to_each_waypoint( log_data, mission_as_list, log_type=args.log_type, final_dist=args.final_distance) logging.debug( f"waypoint_distance_delay: waypoint_dict: {waypoint_dict}") if delay not in delay_dict: delay_dict[delay] = [] delay_dict[delay] = delay_dict[delay] + [waypoint_dict] mean_delay_dict = dict() std_delay_dict = dict() for delay, delay_list in delay_dict.items(): logging.debug(f"delay: {delay} delay_list: {delay_list}") num_data_points = len(delay_list) if num_data_points < 2: continue num_waypoints = len(delay_list[0]) logging.debug( f"delay: {delay} num_data_points: {num_data_points} num_waypoints: {num_waypoints}" ) for waypoint in sorted(delay_list[0].keys()): vals = [x[waypoint] for x in delay_list] mean = statistics.mean(vals) std = statistics.stdev(vals) if delay not in mean_delay_dict: mean_delay_dict[delay] = dict() if delay not in std_delay_dict: std_delay_dict[delay] = dict() mean_delay_dict[delay][waypoint] = mean std_delay_dict[delay][waypoint] = std print("Mean \\\\") print_table(mean_delay_dict, args.graph, args.log_type) print("Standard Deviation \\\\") print_table(std_delay_dict, args.graph, args.log_type) return