Skip to content

Commit 5b07708

Browse files
committed
Reformat metrics file
1 parent 75d2d82 commit 5b07708

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

behavior_metrics/utils/metrics.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,6 @@ def get_statistics(stats_filename, perfect_lap_checkpoints, circuit_diameter):
105105
for index, row in dataframe_pose.iterrows():
106106
checkpoints.append(row)
107107

108-
# average_speed
109-
lap_statistics = get_distance_completed(lap_statistics, checkpoints)
110-
lap_statistics, previous_lap_point = get_average_speed(lap_statistics, stats_filename, checkpoints)
111-
# percentage_completed
112-
lap_statistics = get_percentage_completed(lap_statistics, checkpoints, perfect_lap_checkpoints)
113-
# additional stats
114-
lap_statistics = get_lap_completed_stats(lap_statistics, circuit_diameter, previous_lap_point)
115-
116-
shutil.rmtree(stats_filename.split('.bag')[0])
117-
return lap_statistics
118-
119-
120-
def get_distance_completed(lap_statistics, checkpoints):
121-
end_point = checkpoints[len(checkpoints) - 1]
122-
lap_statistics['completed_distance'] = circuit_distance_completed(checkpoints, end_point)
123-
return lap_statistics
124-
125-
126-
def get_average_speed(lap_statistics, stats_filename, checkpoints):
127108
data_file = stats_filename.split('.bag')[0] + '/clock.csv'
128109
dataframe_pose = pd.read_csv(data_file)
129110
clock_points = []
@@ -144,11 +125,28 @@ def get_average_speed(lap_statistics, stats_filename, checkpoints):
144125
previous_lap_point = ckp_iter
145126
seconds_start = start_clock['clock.secs']
146127
seconds_end = clock_points[len(clock_points) - 1]['clock.secs']
128+
129+
lap_statistics = get_distance_completed(lap_statistics, checkpoints)
130+
lap_statistics = get_average_speed(lap_statistics, seconds_start, seconds_end)
131+
lap_statistics = get_percentage_completed(lap_statistics, checkpoints, perfect_lap_checkpoints, seconds_start, seconds_end, laps)
132+
lap_statistics = get_lap_completed_stats(lap_statistics, circuit_diameter, previous_lap_point, lap_point)
133+
134+
shutil.rmtree(stats_filename.split('.bag')[0])
135+
return lap_statistics
136+
137+
138+
def get_distance_completed(lap_statistics, checkpoints):
139+
end_point = checkpoints[len(checkpoints) - 1]
140+
lap_statistics['completed_distance'] = circuit_distance_completed(checkpoints, end_point)
141+
return lap_statistics
142+
143+
144+
def get_average_speed(lap_statistics, seconds_start, seconds_end):
147145
lap_statistics['average_speed'] = lap_statistics['completed_distance'] / (seconds_end - seconds_start)
148-
return lap_statistics, previous_lap_point
146+
return lap_statistics
149147

150148

151-
def get_percentage_completed(lap_statistics, checkpoints, perfect_lap_checkpoints):
149+
def get_percentage_completed(lap_statistics, checkpoints, perfect_lap_checkpoints, seconds_start, seconds_end, laps):
152150
# Find last and first checkpoints for retrieving percentage completed
153151
first_checkpoint = checkpoints[0]
154152
first_checkpoint = np.array([first_checkpoint['pose.pose.position.x'], first_checkpoint['pose.pose.position.y']])
@@ -174,12 +172,12 @@ def get_percentage_completed(lap_statistics, checkpoints, perfect_lap_checkpoint
174172
if dist < min_distance_last:
175173
min_distance_last = dist
176174
last_perfect_checkpoint_position = i
177-
178175
if first_perfect_checkpoint_position > last_perfect_checkpoint_position and lap_statistics['completed_distance'] > MIN_COMPLETED_DISTANCE_EXPERIMENT and seconds_end - seconds_start > MIN_EXPERIMENT_TIME:
179176
lap_statistics['percentage_completed'] = (((len(perfect_lap_checkpoints) - first_perfect_checkpoint_position + last_perfect_checkpoint_position) / len(perfect_lap_checkpoints)) * 100) + laps * 100
180177
else:
181178
if seconds_end - seconds_start > MIN_EXPERIMENT_TIME:
182-
lap_statistics['percentage_completed'] = (((last_perfect_checkpoint_position - first_perfect_checkpoint_position) / len(perfect_lap_checkpoints)) * 100) + laps * 100
179+
lap_statistics['percentage_completed'] = (((last_perfect_checkpoint_position - first_perfect_checkpoint_position) / len(
180+
perfect_lap_checkpoints)) * 100) + laps * 100
183181
else:
184182
lap_statistics['percentage_completed'] = (((last_perfect_checkpoint_position - first_perfect_checkpoint_position) / len(perfect_lap_checkpoints)) * 100)
185183
lap_statistics = get_robot_position_deviation_score(perfect_lap_checkpoints, checkpoints, lap_statistics)
@@ -269,7 +267,7 @@ def get_robot_position_deviation_score(perfect_lap_checkpoints, checkpoints, lap
269267
return lap_statistics
270268

271269

272-
def get_lap_completed_stats(lap_statistics, circuit_diameter, previous_lap_point):
270+
def get_lap_completed_stats(lap_statistics, circuit_diameter, previous_lap_point, lap_point):
273271
# If lap is completed, add more statistic information
274272
if type(lap_point) is not int and lap_statistics['percentage_completed'] > LAP_COMPLETED_PERCENTAGE:
275273
if abs(((lap_statistics['completed_distance'] / circuit_diameter) * 100) - lap_statistics['percentage_completed']) > 5:
@@ -283,4 +281,4 @@ def get_lap_completed_stats(lap_statistics, circuit_diameter, previous_lap_point
283281
else:
284282
logger.info('Lap not completed')
285283

286-
return lap_statistics
284+
return lap_statistics

0 commit comments

Comments
 (0)