Skip to content

Commit 0cb22dd

Browse files
committed
Merge branch 'examples' of github.com:InsightLab/PyMove into examples
2 parents ac51b37 + 30ccf1b commit 0cb22dd

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

pymove/utils/datetime.py

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ def date_to_str(dt: datetime) -> Text:
6363
import datatime
6464
time_now = datetime.datetime.now()
6565
66-
print(time_now)
67-
>>> 2021-04-29 11:01:29.909340
68-
print(type(time_now))
69-
>>> <class 'datetime.datetime'>
70-
71-
print(date_to_str(time_now), type(time_now))
72-
>>> 2021-04-29 <class 'str'>
66+
>>> print(time_now)
67+
2021-04-29 11:01:29.909340
68+
>>> print(type(time_now))
69+
<class 'datetime.datetime'>
70+
>>> print(date_to_str(time_now), type(time_now))
71+
2021-04-29 <class 'str'>
7372
7473
"""
7574
return dt.strftime('%Y-%m-%d')
@@ -94,12 +93,12 @@ def str_to_datetime(dt_str: Text) -> datetime:
9493
time_1 = '2020-06-29'
9594
time_2 = '2020-06-29 12:45:59'
9695
97-
print(type(time_1), type(time_2))
98-
>>> <class 'str'> <class 'str'>
99-
print( str_to_datetime(time_1), type(str_to_datetime(time_1)))
100-
>>> 2020-06-29 00:00:00 <class 'datetime.datetime'>
101-
print(str_to_datetime(time_2), type(str_to_datetime(time_2)))
102-
>>> 2020-06-29 12:45:59 <class 'datetime.datetime'>
96+
>>> print(type(time_1), type(time_2))
97+
<class 'str'> <class 'str'>
98+
>>> print( str_to_datetime(time_1), type(str_to_datetime(time_1)))
99+
2020-06-29 00:00:00 <class 'datetime.datetime'>
100+
>>> print(str_to_datetime(time_2), type(str_to_datetime(time_2)))
101+
2020-06-29 12:45:59 <class 'datetime.datetime'>
103102
104103
105104
"""
@@ -128,13 +127,13 @@ def datetime_to_str(dt: datetime) -> Text:
128127
import datetime
129128
time_now = datetime.datetime.now()
130129
131-
print(time_now)
132-
>>> 2021-04-29 14:15:29.708113
133-
print(type(time_now))
134-
>>> <class 'datetime.datetime'>
130+
>>> print(time_now)
131+
2021-04-29 14:15:29.708113
132+
>>> print(type(time_now))
133+
<class 'datetime.datetime'>
135134
136-
print(data_to_str(time_now), type(data_to_str(time_now)))
137-
>>> 2021-04-29 14:15:29 <class 'str' >
135+
>>> print(data_to_str(time_now), type(data_to_str(time_now)))
136+
2021-04-29 14:15:29 <class 'str' >
138137
139138
"""
140139
return dt.strftime('%Y-%m-%d %H:%M:%S')
@@ -161,10 +160,10 @@ def datetime_to_min(dt: datetime) -> int:
161160
import datetime
162161
163162
time_now = datetime.datetime.now()
164-
print(type(to_min(time_now)))
165-
>>> <class 'int'>
166-
to_min(time_now)
167-
>>> 26996497
163+
>>> print(type(to_min(time_now)))
164+
<class 'int'>
165+
>>> to_min(time_now)
166+
26996497
168167
169168
"""
170169
# get an integer time slot from a datetime
@@ -191,8 +190,8 @@ def min_to_datetime(minutes: int) -> datetime:
191190
192191
Example
193192
-------
194-
print(min_to_datetime(26996497), type(min_to_datetime(26996497)))
195-
>>> 2021-04-30 13:37:00 <class 'datetime.datetime'>
193+
>>> print(min_to_datetime(26996497), type(min_to_datetime(26996497)))
194+
2021-04-30 13:37:00 <class 'datetime.datetime'>
196195
197196
"""
198197
return datetime.utcfromtimestamp(minutes * 60)
@@ -219,10 +218,10 @@ def to_day_of_week_int(dt: datetime) -> int:
219218
monday = str_to_datetime('2021-05-3 12:00:01')
220219
friday = str_to_datetime('2021-05-7 12:00:01')
221220
222-
print(to_day_of_week_int(monday), type(to_day_of_week_int(monday)))
223-
>>> 0 <class 'int'>
224-
print(to_day_of_week_int(friday), type(to_day_of_week_int(friday)))
225-
>>> 4 <class 'int'>
221+
>>> print(to_day_of_week_int(monday), type(to_day_of_week_int(monday)))
222+
0 <class 'int'>
223+
>>> print(to_day_of_week_int(friday), type(to_day_of_week_int(friday)))
224+
4 <class 'int'>
226225
227226
"""
228227
return dt.weekday()
@@ -260,10 +259,14 @@ def working_day(
260259
next_day = str_to_datetime('2021-09-8 12:00:01')
261260
# In Brazil this day is a Wednesday and isn't a holiday
262261
263-
print(working_day(independence_day, 'BR'), type(working_day(independence_day, 'BR')))
264-
>>> False <class 'bool'>
265-
print(working_day(next_day, 'BR'), type(working_day(next_day, 'BR')))
266-
>>> True <class 'bool'>
262+
>>> print(working_day(independence_day, 'BR'))
263+
False
264+
>>> print(type(working_day(independence_day, 'BR')))
265+
<class 'bool'>
266+
>>> print(working_day(next_day, 'BR'))
267+
True
268+
>>> print(type(working_day(next_day, 'BR')))
269+
<class 'bool'>
267270
268271
References
269272
----------
@@ -462,10 +465,10 @@ def elapsed_time_dt(start_time: datetime) -> int:
462465
start_time_1 = datetime(2020, 6, 29, 0, 0)
463466
start_time_2 = str_to_datetime('2020-06-29 12:45:59')
464467
465-
print(elapsed_time_dt(start_time_1))
466-
>>> 26411808666
467-
print(elapsed_time_dt(start_time_2))
468-
>>> 26365849667
468+
>>> print(elapsed_time_dt(start_time_1))
469+
26411808666
470+
>>> print(elapsed_time_dt(start_time_2))
471+
26365849667
469472
"""
470473
return diff_time(start_time, datetime.now())
471474

@@ -496,10 +499,10 @@ def diff_time(start_time: datetime, end_time: datetime) -> int:
496499
start_time_1 = datetime(2020, 6, 29, 0, 0)
497500
start_time_2 = str_to_datetime('2020-06-29 12:45:59')
498501
499-
print(diff_time(start_time_1, time_now))
500-
>>> 26411808665
501-
print(diff_time(start_time_2, time_now))
502-
>>> 26365849665
502+
>>> print(diff_time(start_time_1, time_now))
503+
26411808665
504+
>>> print(diff_time(start_time_2, time_now))
505+
26365849665
503506
"""
504507
return int((end_time - start_time).total_seconds() * 1000)
505508

@@ -588,16 +591,16 @@ def generate_time_statistics(
588591
589592
Example
590593
-------
591-
df
592-
>>> local_label prev_local time_to_prev id
594+
>>> df
595+
local_label prev_local time_to_prev id
593596
0 house None NaN 1
594597
1 market house 720.0 1
595598
2 market market 5.0 1
596599
3 market market 1.0 1
597600
4 school market 844.0 1
598601
599-
generate_time_statistics(df)
600-
>>> local_label prev_local mean std min max sum count
602+
>>> generate_time_statistics(df)
603+
local_label prev_local mean std min max sum count
601604
0 house market 844.0 0.000000 844.0 844.0 844.0 1
602605
1 market house 720.0 0.000000 720.0 720.0 720.0 1
603606
2 market market 3.0 2.828427 1.0 5.0 6.0 2
@@ -636,12 +639,12 @@ def _calc_time_threshold(seg_mean: float, seg_std: float) -> float:
636639
637640
Examples
638641
--------
639-
print(_calc_time_threshold(12.3,2.1))
640-
>>> 14.4
641-
print(_calc_time_threshold(1,1.5))
642-
>>> 2.5
643-
print(_calc_time_threshold(-2,2))
644-
>>> 0.0
642+
>>> print(_calc_time_threshold(12.3,2.1))
643+
14.4
644+
>>> print(_calc_time_threshold(1,1.5))
645+
2.5
646+
>>> print(_calc_time_threshold(-2,2))
647+
0.0
645648
646649
"""
647650
threshold = seg_std + seg_mean
@@ -682,23 +685,23 @@ def threshold_time_statistics(
682685
-------
683686
from pymove.utils.datetime import generate_time_statistics, _calc_time_threshold
684687
685-
df
686-
>>> local_label prev_local time_to_prev id
688+
>>> df
689+
local_label prev_local time_to_prev id
687690
0 house None NaN 1
688691
1 market house 720.0 1
689692
2 market market 5.0 1
690693
3 market market 1.0 1
691694
4 school market 844.0 1
692695
693-
statistics = generate_time_statistics(df)
694-
statistics
695-
>>> local_label prev_local mean std min max sum count
696+
>>> statistics = generate_time_statistics(df)
697+
>>> statistics
698+
local_label prev_local mean std min max sum count
696699
0 house market 844.0 0.000000 844.0 844.0 844.0 1
697700
1 market house 720.0 0.000000 720.0 720.0 720.0 1
698701
2 market market 3.0 2.828427 1.0 5.0 6.0 2
699702
700-
threshold_time_statistics(statistics)
701-
>>> local_label prev_local mean std min max sum count
703+
>>> threshold_time_statistics(statistics)
704+
local_label prev_local mean std min max sum count
702705
0 house market 844.0 0.000000 844.0 844.0 844.0 1
703706
1 market house 720.0 0.000000 720.0 720.0 720.0 1
704707
2 market market 3.0 2.828427 1.0 5.0 6.0 2

0 commit comments

Comments
 (0)