Skip to content

Commit c6ec038

Browse files
committed
changes:example format
1 parent 871d726 commit c6ec038

File tree

1 file changed

+54
-53
lines changed

1 file changed

+54
-53
lines changed

pymove/utils/datetime.py

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ def date_to_str(dt: datetime) -> Text:
6060
6161
Example
6262
-------
63-
>>> import datatime
64-
>>> time_now = datetime.datetime.now()
63+
>>> from datetime import datatime
64+
>>> from pymove.utils.datetime import date_to_str
65+
>>> time_now = datetime.now()
6566
>>> print(time_now)
6667
'2021-04-29 11:01:29.909340'
6768
>>> print(type(time_now))
6869
'<class 'datetime.datetime'>'
6970
>>> print(date_to_str(time_now), type(time_now))
7071
'2021-04-29 <class 'str'>'
71-
7272
"""
7373
return dt.strftime('%Y-%m-%d')
7474

@@ -89,6 +89,7 @@ def str_to_datetime(dt_str: Text) -> datetime:
8989
9090
Example
9191
-------
92+
>>> from pymove.utils.datetime import str_to_datetime
9293
>>> time_1 = '2020-06-29'
9394
>>> time_2 = '2020-06-29 12:45:59'
9495
>>> print(type(time_1), type(time_2))
@@ -122,15 +123,15 @@ def datetime_to_str(dt: datetime) -> Text:
122123
123124
Example:
124125
-------
125-
>>> import datetime
126-
>>> time_now = datetime.datetime.now()
126+
>>> from pymove.utils.datetime import datetime_to_str
127+
>>> from datetime import datetime
128+
>>> time_now = datetime.now()
127129
>>> print(time_now)
128130
'2021-04-29 14:15:29.708113'
129131
>>> print(type(time_now))
130132
'<class 'datetime.datetime'>'
131133
>>> print(datetime_to_str(time_now), type(datetime_to_str(time_now)))
132134
'2021-04-29 14:15:29 <class 'str' >'
133-
134135
"""
135136
return dt.strftime('%Y-%m-%d %H:%M:%S')
136137

@@ -153,14 +154,13 @@ def datetime_to_min(dt: datetime) -> int:
153154
154155
Example
155156
-------
156-
>>> import datetime
157-
158-
>>> time_now = datetime.datetime.now()
157+
>>> from pymove.utils.datetime import datetime_to_min
158+
>>> from datetime import datetime
159+
>>> time_now = datetime.now()
159160
>>> print(type(datetime_to_min(time_now)))
160161
'<class 'int'>'
161162
>>> datetime_to_min(time_now)
162163
'26996497'
163-
164164
"""
165165
# get an integer time slot from a datetime
166166
return int(
@@ -186,9 +186,9 @@ def min_to_datetime(minutes: int) -> datetime:
186186
187187
Example
188188
-------
189+
>>> from pymove.utils.datetime import min_to_datetime
189190
>>> print(min_to_datetime(26996497), type(min_to_datetime(26996497)))
190191
'2021-04-30 13:37:00 <class 'datetime.datetime'>'
191-
192192
"""
193193
return datetime.utcfromtimestamp(minutes * 60)
194194

@@ -216,7 +216,6 @@ def to_day_of_week_int(dt: datetime) -> int:
216216
'0 <class 'int'>'
217217
>>> print(to_day_of_week_int(friday), type(to_day_of_week_int(friday)))
218218
'4 <class 'int'>'
219-
220219
"""
221220
return dt.weekday()
222221

@@ -292,9 +291,9 @@ def now_str() -> Text:
292291
293292
Examples
294293
--------
294+
>>> from pymove.utils.datetime import now_str
295295
>>> now_str()
296296
'2019-09-02 13:54:16'
297-
298297
"""
299298
return datetime_to_str(datetime.now())
300299

@@ -315,6 +314,7 @@ def deltatime_str(deltatime_seconds: float) -> Text:
315314
316315
Examples
317316
--------
317+
>>> from pymove.utils.datetime import deltatime_str
318318
>>> deltatime_str(1082.7180936336517)
319319
'18m:02.718s'
320320
@@ -350,9 +350,9 @@ def timestamp_to_millis(timestamp: Text) -> int:
350350
351351
Examples
352352
--------
353+
>>> from pymove.utils.datetime import timestamp_to_millis
353354
>>> timestamp_to_millis('2015-12-12 08:00:00.123000')
354355
1449907200123 (UTC)
355-
356356
"""
357357
return Timestamp(timestamp).value // 1000000
358358

@@ -373,9 +373,9 @@ def millis_to_timestamp(milliseconds: float) -> Timestamp:
373373
374374
Examples
375375
--------
376+
>>> from pymove.utils.datetime import millis_to_timestamp
376377
>>> millis_to_timestamp(1449907200123)
377378
'2015-12-12 08:00:00.123000'
378-
379379
"""
380380
return Timestamp(milliseconds, unit='ms')
381381

@@ -396,9 +396,9 @@ def time_to_str(time: Timestamp) -> Text:
396396
397397
Examples
398398
--------
399+
>>> from pymove.utils.datetime import time_to_str
399400
>>> time_to_str("2015-12-12 08:00:00.123000")
400401
'08:00:00'
401-
402402
"""
403403
return time.strftime('%H:%M:%S')
404404

@@ -419,9 +419,9 @@ def str_to_time(dt_str: Text) -> datetime:
419419
420420
Examples
421421
--------
422+
>>> from pymove.utils.datetime import str_to_time
422423
>>> str_to_time("08:00:00")
423424
datetime(1900, 1, 1, 8, 0)
424-
425425
"""
426426
return datetime.strptime(dt_str, '%H:%M:%S')
427427

@@ -521,19 +521,20 @@ def create_time_slot_in_minute(
521521
522522
Examples
523523
--------
524+
>>> from pymove.utils.datetime import create_time_slot_in_minute
524525
>>> from pymove import datetime
525526
>>> data
526-
' lat lon datetime id'
527-
'0 39.984094 116.319236 2008-10-23 05:44:05 1'
528-
'1 39.984198 116.319322 2008-10-23 05:56:06 1'
529-
'2 39.984224 116.319402 2008-10-23 05:56:11 1'
530-
'3 39.984224 116.319402 2008-10-23 06:10:15 1'
527+
lat lon datetime id
528+
0 39.984094 116.319236 2008-10-23 05:44:05 1
529+
1 39.984198 116.319322 2008-10-23 05:56:06 1
530+
2 39.984224 116.319402 2008-10-23 05:56:11 1
531+
3 39.984224 116.319402 2008-10-23 06:10:15 1
531532
>>> datetime.create_time_slot_in_minute(data, inplace=False)
532-
' lat lon datetime id time_slot'
533-
'0 39.984094 116.319236 2008-10-23 05:44:05 1 22'
534-
'1 39.984198 116.319322 2008-10-23 05:56:06 1 23'
535-
'2 39.984224 116.319402 2008-10-23 05:56:11 1 23'
536-
'3 39.984224 116.319402 2008-10-23 06:10:15 1 24'
533+
lat lon datetime id time_slot
534+
0 39.984094 116.319236 2008-10-23 05:44:05 1 22
535+
1 39.984198 116.319322 2008-10-23 05:56:06 1 23
536+
2 39.984224 116.319402 2008-10-23 05:56:11 1 23
537+
3 39.984224 116.319402 2008-10-23 06:10:15 1 24
537538
538539
"""
539540
if data.dtypes[label_datetime] != 'datetime64[ns]':
@@ -570,19 +571,19 @@ def generate_time_statistics(
570571
571572
Example
572573
-------
574+
>>> from pymove.utils.datetime import generate_time_statistics
573575
>>> df
574-
' local_label prev_local time_to_prev id'
575-
'0 house NaN NaN 1'
576-
'1 market house 720.0 1'
577-
'2 market market 5.0 1'
578-
'3 market market 1.0 1'
579-
'4 school market 844.0 1'
580-
576+
local_label prev_local time_to_prev id
577+
0 house NaN NaN 1
578+
1 market house 720.0 1
579+
2 market market 5.0 1
580+
3 market market 1.0 1
581+
4 school market 844.0 1
581582
>>> generate_time_statistics(df)
582-
' local_label prev_local mean std min max sum count'
583-
'0 house market 844.0 0.000000 844.0 844.0 844.0 1'
584-
'1 market house 720.0 0.000000 720.0 720.0 720.0 1'
585-
'2 market market 3.0 2.828427 1.0 5.0 6.0 2'
583+
local_label prev_local mean std min max sum count
584+
0 house market 844.0 0.000000 844.0 844.0 844.0 1
585+
1 market house 720.0 0.000000 720.0 720.0 720.0 1
586+
2 market market 3.0 2.828427 1.0 5.0 6.0 2
586587
"""
587588
df_statistics = data.groupby(
588589
[local_label, PREV_LOCAL]
@@ -618,6 +619,7 @@ def _calc_time_threshold(seg_mean: float, seg_std: float) -> float:
618619
619620
Examples
620621
--------
622+
>>> from pymove.utils.datetime import _calc_time_threshold
621623
>>> print(_calc_time_threshold(12.3,2.1))
622624
14.4
623625
>>> print(_calc_time_threshold(1,1.5))
@@ -665,24 +667,23 @@ def threshold_time_statistics(
665667
>>> from pymove.utils.datetime import generate_time_statistics
666668
667669
>>> df
668-
' local_label prev_local time_to_prev id'
669-
'0 house NaN NaN 1'
670-
'1 market house 720.0 1'
671-
'2 market market 5.0 1'
672-
'3 market market 1.0 1'
673-
'4 school market 844.0 1'
674-
670+
local_label prev_local time_to_prev id
671+
0 house NaN NaN 1
672+
1 market house 720.0 1
673+
2 market market 5.0 1
674+
3 market market 1.0 1
675+
4 school market 844.0 1
675676
>>> statistics = generate_time_statistics(df)
676677
>>> statistics
677-
' local_label prev_local mean std min max sum count'
678-
'0 house market 844.0 0.000000 844.0 844.0 844.0 1'
679-
'1 market house 720.0 0.000000 720.0 720.0 720.0 1'
680-
'2 market market 3.0 2.828427 1.0 5.0 6.0 2'
678+
local_label prev_local mean std min max sum count
679+
0 house market 844.0 0.000000 844.0 844.0 844.0 1
680+
1 market house 720.0 0.000000 720.0 720.0 720.0 1
681+
2 market market 3.0 2.828427 1.0 5.0 6.0 2
681682
>>> threshold_time_statistics(statistics)
682-
' local_label prev_local mean std min max sum count threshold'
683-
'0 house market 844.0 0.000000 844.0 844.0 844.0 1 844.0'
684-
'1 market house 720.0 0.000000 720.0 720.0 720.0 1 720.0'
685-
'2 market market 3.0 2.828427 1.0 5.0 6.0 2 5.8'
683+
local_label prev_local mean std min max sum count threshold
684+
0 house market 844.0 0.000000 844.0 844.0 844.0 1 844.0
685+
1 market house 720.0 0.000000 720.0 720.0 720.0 1 720.0
686+
2 market market 3.0 2.828427 1.0 5.0 6.0 2 5.8
686687
687688
"""
688689
if not inplace:

0 commit comments

Comments
 (0)