1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import math
def get_edge_length(graph, u, v):
try:
return graph[u][v][0]['length']
except KeyError:
try:
return graph[v][u][0]['length']
except KeyError:
return 0
def format_time(time_seconds):
seconds = math.ceil(time_seconds % 60)
minutes = math.floor(time_seconds / 60)
if minutes == 0:
return f"{seconds} secondes"
return f"{minutes} minute(s) et {seconds} secondes"
def export_drone(graph, time_exec, parcours):
total_dist = 0
time_exec = time_exec / 60
total_dist += math.ceil(sum(get_edge_length(graph, u, v) for u, v in parcours))
return {
"dist":total_dist,
"time":{
"format":format_time(time_exec),
"value":time_exec
}
}
def export_deneigeuse(graph, time_exec, parcours):
total_dist = math.ceil(sum(get_edge_length(graph, u, v) for u, v in parcours))
return {
"dist":total_dist,
"time":{
"format":format_time(time_exec),
"value":time_exec
}
}
|