diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f093a1a..8699410 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,8 +10,6 @@ on: pull_request: branches: - '*' - schedule: - - cron: '59 23 * * *' workflow_dispatch: inputs: version: diff --git a/docs/source/conf.py b/docs/source/conf.py index 36a3600..c104a91 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,8 +25,8 @@ author = 'Qing Yu' # The full version, including alpha/beta/rc tags -release = '0.4.14' -version = '0.4.14' +release = '0.4.15' +version = '0.4.15' html_logo = "_static/logo-wordmark-light.png" html_favicon = '_static/logo2.ico' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 7148068..d0f25e3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="transbigdata", - version="0.4.14", + version="0.4.15", author="Qing Yu", author_email="yuq@sustech.edu.cn", description="A Python package developed for transportation spatio-temporal big data processing and analysis.", diff --git a/src/transbigdata/__init__.py b/src/transbigdata/__init__.py index dae5238..8612373 100644 --- a/src/transbigdata/__init__.py +++ b/src/transbigdata/__init__.py @@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ -__version__ = '0.4.14' +__version__ = '0.4.15' __author__ = 'Qing Yu ' # module level doc-string diff --git a/src/transbigdata/mobilephonedata.py b/src/transbigdata/mobilephonedata.py index 128434f..4a50404 100644 --- a/src/transbigdata/mobilephonedata.py +++ b/src/transbigdata/mobilephonedata.py @@ -33,7 +33,7 @@ import pandas as pd import numpy as np from .grids import GPS_to_grid, grid_to_centre - +import warnings def mobile_stay_move(data, params, col=['ID', 'dataTime', 'longitude', 'latitude'], @@ -81,6 +81,8 @@ def mobile_stay_move(data, params, stay['duration'] = (pd.to_datetime(stay['etime']) - pd.to_datetime(stay['stime'])).dt.total_seconds() stay = stay[stay['duration'] >= activitytime].copy() + stay = stay[[uid, 'stime','LONCOL', 'LATCOL','etime','lon','lat', 'duration']] + ''' # Renumber the status stay['status_id'] = ((stay['LONCOL'] != stay['LONCOL'].shift()) | (stay['LATCOL'] != stay['LATCOL'].shift()) | @@ -96,6 +98,7 @@ def mobile_stay_move(data, params, [stay['LONCOL'], stay['LATCOL']], params) stay['duration'] = (pd.to_datetime(stay['etime']) - pd.to_datetime(stay['stime'])).dt.total_seconds() + ''' # Identify move move = stay.copy() move['stime_next'] = move['stime'].shift(-1) @@ -118,7 +121,7 @@ def mobile_stay_move(data, params, return stay, move -def mobile_stay_dutation(staydata, col=['stime', 'etime'], start_hour=8, end_hour=20): +def mobile_stay_duration(staydata, col=['stime', 'etime'], start_hour=8, end_hour=20): ''' Input the stay point data to identify the duration during night and day time. @@ -177,6 +180,10 @@ def mobile_stay_dutation(staydata, col=['stime', 'etime'], start_hour=8, end_hou return duration_night, duration_day +def mobile_stay_dutation(*args, **kwargs): + warnings.warn("This method is renamed as transbigdata.mobile_stay_duration") # pragma: no cover + return mobile_stay_duration(*args, **kwargs) # pragma: no cover + def mobile_identify_home(staydata, col=['uid','stime', 'etime','LONCOL', 'LATCOL'], start_hour=8, end_hour=20 ): ''' Identify home location from mobile phone stay data. The rule is to identify the locations with longest @@ -202,7 +209,7 @@ def mobile_identify_home(staydata, col=['uid','stime', 'etime','LONCOL', 'LATCOL etime = col[2] stay = staydata.copy() if ('duration_night' not in stay.columns) | ('duration_day' not in stay.columns): - stay['duration_night'], stay['duration_day'] = mobile_stay_dutation( + stay['duration_night'], stay['duration_day'] = mobile_stay_duration( stay, col = [stime,etime],start_hour=start_hour, end_hour=end_hour) # 夜晚最常停留地 home = stay.groupby([col[0],*col[3:]])['duration_night'].sum().reset_index() @@ -253,7 +260,7 @@ def mobile_identify_work(staydata, col=['uid', 'stime', 'etime', 'LONCOL', 'LATC stay_workdays['nextday'] = pd.to_datetime( stay_workdays[stime].dt.date+pd.Timedelta(1, unit='days')) stay_workdays[etime] = stay_workdays[[etime, 'nextday']].min(axis=1) - stay_workdays['duration_night'], stay_workdays['duration_day'] = mobile_stay_dutation( + stay_workdays['duration_night'], stay_workdays['duration_day'] = mobile_stay_duration( stay_workdays, col = [stime,etime],start_hour=start_hour, end_hour=end_hour) # 白天最常活动地 @@ -275,8 +282,9 @@ def mobile_identify_work(staydata, col=['uid', 'stime', 'etime', 'LONCOL', 'LATC return work + def mobile_plot_activity(data, col=['stime', 'etime', 'LONCOL', 'LATCOL'], - figsize=(10, 5), dpi=250): + figsize=(10, 5), dpi=250,shuffle=True): ''' Plot the activity plot of individual @@ -286,6 +294,11 @@ def mobile_plot_activity(data, col=['stime', 'etime', 'LONCOL', 'LATCOL'], activity information of one person col : List The column name.[starttime,endtime,LONCOL,LATCOL] of activities + figsize : List + The figure size + dpi : Number + shuffle : bool + Whether to shuffle the activity ''' stime, etime, LONCOL, LATCOL = col activity = data.copy() @@ -314,10 +327,11 @@ def mobile_plot_activity(data, col=['stime', 'etime', 'LONCOL', 'LATCOL'], time.strptime(x, '%Y-%m-%d %H:%M:%S'))).astype('int64') activityinfo = activity[[LONCOL, LATCOL]].drop_duplicates() indexs = list(range(1, len(activityinfo)+1)) - np.random.shuffle(indexs) + if shuffle: + np.random.shuffle(indexs) activityinfo['index'] = indexs import matplotlib as mpl - norm = mpl.colors.Normalize(vmin=0, vmax=len(activityinfo)) + norm = mpl.colors.Normalize(vmin=1, vmax=len(activityinfo)+1) from matplotlib.colors import ListedColormap import seaborn as sns cmap = ListedColormap(sns.hls_palette( diff --git a/src/transbigdata/tests/test_getbusdata.py b/src/transbigdata/tests/test_getbusdata.py index 5cc44f6..1e82c97 100644 --- a/src/transbigdata/tests/test_getbusdata.py +++ b/src/transbigdata/tests/test_getbusdata.py @@ -21,13 +21,16 @@ def test_getadmin(self): admin = 0 t = 0 - while (type(admin)==int)&(t<5): + while (type(admin)==int)&(t<10): try: admin, _ = tbd.getadmin( - '深圳市', ak='2305ee7c82c147f11aac58fcc5bb7f19',jscode = '694338a096c6c50b74e5d74f411c9ab5', subdistricts=True) + '深圳市', + ak='2305ee7c82c147f11aac58fcc5bb7f19', + jscode = '694338a096c6c50b74e5d74f411c9ab5', + subdistricts=True) except: # pragma: no cover t+=1 # pragma: no cover - assert '深圳市' in admin['name'].sum() + assert '深圳市' in list(admin['name']) def test_getisochrone(self):