Skip to content

Commit a2229cc

Browse files
committed
fix query.py conflicts
2 parents 81e7314 + 5805010 commit a2229cc

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

pymove/query/query.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
44
range_query,
55
knn_query,
6-
query_all_points_by_range,
6+
query_all_points_by_range,
77
88
"""
99

10+
from datetime import timedelta
1011
from typing import Optional, Text
1112

1213
import numpy as np
1314
import pandas as pd
15+
from IPython.display import clear_output
1416
from pandas import DataFrame
1517

1618
from pymove.utils import distances
1719
from pymove.utils.constants import DATETIME, LATITUDE, LONGITUDE, MEDP, MEDT, TRAJ_ID
1820
from pymove.utils.log import logger, progress_bar
1921

20-
from datetime import timedelta
21-
from IPython.display import clear_output
22-
2322

2423
def range_query(
2524
traj: DataFrame,
@@ -189,10 +188,12 @@ def _datetime_filter(
189188
minimum_distance: TimeDelta
190189
):
191190
"""
191+
Returns all the points of the DataFrame which are in a temporal distance.
192+
192193
Given a row referencing to a point, a DataFrame with
193194
multiple points and a minimum distance, it returns
194195
all the points of the DataFrame which are in a temporal
195-
distance equal or smaller than the minimum distance
196+
distance equal or smaller than the minimum distance
196197
parameter.
197198
198199
Parameters
@@ -211,16 +212,19 @@ def _datetime_filter(
211212
a temporal distance equal or smaller than the minimum
212213
distance parameter.
213214
"""
214-
datetime = row['datetime'];
215-
move_df['temporal_distance'] = (move_df['datetime'] - datetime).abs();
216-
filtered = move_df[(move_df['temporal_distance'] < minimum_distance) & (move_df['temporal_distance'] > -minimum_distance)];
217-
215+
datetime = row['datetime']
216+
move_df['temporal_distance'] = (move_df['datetime'] - datetime).abs()
217+
filtered = move_df[
218+
(move_df['temporal_distance'] < minimum_distance)
219+
& (move_df['temporal_distance'] > -minimum_distance)
220+
]
221+
218222
if (filtered.shape[0] > 0):
219223
filtered['target_id'] = row['id']
220224
filtered['target_lat'] = row['lat']
221225
filtered['target_lon'] = row['lon']
222226
filtered['target_datetime'] = row['datetime']
223-
227+
224228
return filtered
225229

226230

@@ -229,10 +233,12 @@ def _meters_filter(
229233
move_df: DataFrame,
230234
minimum_distance: float):
231235
"""
236+
Returns all the points of the DataFrame which are in a spatial distance.
237+
232238
Given a row referencing to a point, a DataFrame with
233239
multiple points and a minimum distance, it returns
234240
all the points of the DataFrame which are in a spatial
235-
distance (in meters) equal or smaller than the minimum distance
241+
distance (in meters) equal or smaller than the minimum distance
236242
parameter.
237243
238244
Parameters
@@ -243,24 +249,27 @@ def _meters_filter(
243249
The input trajectory data.
244250
minimum_distance: float
245251
the minimum spatial distance between the points in meters.
252+
246253
Returns
247-
-------
254+
-------
248255
DataFrame
249256
dataframe with all the points of move_df which are in
250257
a spatial distance equal or smaller than the minimum
251258
distance parameter.
252259
"""
253260
lat = row['lat']
254261
lon = row['lon']
255-
move_df['spatial_distance'] = distances.euclidean_distance_in_meters(lat1=lat, lon1=lon, lat2=move_df['lat'], lon2=move_df['lon'])
262+
move_df['spatial_distance'] = distances.euclidean_distance_in_meters(
263+
lat1=lat, lon1=lon, lat2=move_df['lat'], lon2=move_df['lon']
264+
)
256265
filtered = move_df[move_df['spatial_distance'] < minimum_distance]
257-
266+
258267
if (filtered.shape[0] > 0):
259268
filtered['target_id'] = row['id']
260269
filtered['target_lat'] = row['lat']
261270
filtered['target_lon'] = row['lon']
262271
filtered['target_datetime'] = row['datetime']
263-
272+
264273
return filtered
265274

266275

@@ -271,8 +280,10 @@ def query_all_points_by_range(
271280
minimum_time: Optional[TimeDelta] =timedelta(minutes=2),
272281
datetime_label: Optional[Text] = DATETIME):
273282
"""
274-
Selects only the points between two Move Dataframes
275-
that have the closest point within a spatial range
283+
Queries closest point within a spatial range based on meters and a temporal range.
284+
285+
Selects only the points between two Move Dataframes
286+
that have the closest point within a spatial range
276287
based on meters and a temporal range.
277288
278289
Parameters
@@ -295,21 +306,24 @@ def query_all_points_by_range(
295306
a spatial distance and temporal distance equal or smaller
296307
than the minimum distance parameters.
297308
"""
298-
result = pd.DataFrame([]);
309+
if minimum_time is None:
310+
minimum_time = timedelta(minutes=2)
311+
312+
result = pd.DataFrame([])
299313
total = traj1.shape[0]
300314
count = 0
301-
for index, row in traj1.iterrows():
315+
for _, row in traj1.iterrows():
302316
clear_output(wait=True)
303-
print("{} de {}".format(count, total))
304-
print("{:.2f}%".format((count*100/total)))
317+
print('{} de {}'.format(count, total))
318+
print('{:.2f}%'.format((count * 100 / total)))
305319
coinc_points = _meters_filter(row, move_df, minimum_meters)
306320
coinc_points = _datetime_filter(row, coinc_points, minimum_time)
307321
result = coinc_points.append(result)
308-
322+
309323
count += 1
310-
324+
311325
clear_output(wait=True)
312-
print("{} de {}".format(count, total))
313-
print("{:.2f}%".format((count*100/total)))
326+
print('{} de {}'.format(count, total))
327+
print('{:.2f}%'.format((count * 100 / total)))
314328

315329
return result

pymove/tests/test_query.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from pandas import DataFrame, Timestamp, Timedelta
1+
from datetime import timedelta
2+
3+
from pandas import DataFrame, Timedelta, Timestamp
24
from pandas.testing import assert_frame_equal
35

46
from pymove import MoveDataFrame
57
from pymove.query import query
68
from pymove.utils.constants import DATETIME, LATITUDE, LONGITUDE, TRAJ_ID
79

8-
from datetime import timedelta
9-
1010
traj_example = [[16.4, -54.9, Timestamp('2014-10-11 18:00:00'),
1111
' GONZALO'],
1212
[16.4, -55.9, Timestamp('2014-10-12 00:00:00'),
@@ -527,7 +527,7 @@ def test_knn_query():
527527
medt_move_df = query.knn_query(traj_df, move_df, k=2, distance='MEDT')
528528
assert_frame_equal(medt_move_df, expected_medt)
529529

530-
def test__datetime_filter():
530+
def test__datetime_filter():
531531
traj_df = _default_traj_df()
532532
firstpoint = traj_df.iloc[0]
533533
move_df = _default_move_df()
@@ -543,7 +543,7 @@ def test__datetime_filter():
543543
assert_frame_equal(result, expected)
544544

545545

546-
def test__meters_filter():
546+
def test__meters_filter():
547547
traj_df = _default_traj_df()
548548
firstpoint = traj_df.iloc[0]
549549
move_df = _default_move_df()
@@ -571,6 +571,3 @@ def test_query_all_points_by_range():
571571

572572
result = query.query_all_points_by_range(traj_df, move_df, minimum_meters=1900000, minimum_time=timedelta(hours=19000))
573573
assert_frame_equal(result, expected)
574-
575-
576-

0 commit comments

Comments
 (0)