Skip to content

Commit

Permalink
Merge pull request #195 from dataforgoodfr/fix/180
Browse files Browse the repository at this point in the history
Gestion des Nan #180
  • Loading branch information
njouanin authored Jul 4, 2024
2 parents 1a6f580 + 53aace9 commit 9954325
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions backend/bloom/tasks/create_update_excursions_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,24 @@ def get_duration(x) -> float:
df.loc[df["segment_duration"] >= 2100, "type"] = "DEFAULT_AIS"

# calculate average speed in knot
df.loc[df["type"] != "DEFAULT_AIS", "average_speed"] = df["distance"] / (df["segment_duration"] / 3600)
df["average_speed"] = df["distance"] / (df["segment_duration"] / 3600)

# set last_vessel_segment
df["last_vessel_segment"] = 0
df["last_vessel_segment"].iloc[-1] = 1

# check if segment ends in a port (only for segment with average_speed < maximal_speed_to_check_if_in_port or with type 'DEFAULT_AIS')
def get_port(x, session):
if ((x.average_speed < maximal_speed_to_check_if_in_port) | (x.type == 'DEFAULT_AIS')):
if x.type == 'DEFAULT_AIS' or x.average_speed < maximal_speed_to_check_if_in_port:
res = port_repository.get_closest_port_in_range(session, x.end_longitude, x.end_latitude,
threshold_distance_to_port)
if res:
(port_id, distance) = res
return port_id
else:
return np.NaN
return None
else:
return np.NaN
session.close()
return None

df["port"] = df.apply(get_port, axis=1, args=(session,))

Expand All @@ -224,7 +223,7 @@ def get_port(x, session):
# on its ending position, distance traveled and a given average exit speed
df["excursion_id"] = np.NaN
for a in df.index:
if (df["port"].iloc[a] >= 0):
if df["port"].iloc[a] is not None and df["port"].iloc[a] >= 0:
if (open_ongoing_excursion):
close_excursion(session, ongoing_excursion_id, int(df["port"].iloc[a]),
df["end_latitude"].iloc[a],
Expand Down

0 comments on commit 9954325

Please sign in to comment.