Methods for handling time range overlaps for scheduling, taxes, and physics applications.
- Free software: GNU General Public License v3
- Documentation: https://time-range.readthedocs.io.
import time_range as tr
Specify a year
year = 2017
For this year, define all your trips by defining where they are and when the trip started. This is an ordered list so the end date is inferred from the next trip in the list. For the start date, the first number is month, the second is the day, the third is the hour, and so forth.
trips = ({'country': 'NL', 'start': (1, 1)},
{'country': 'ES', 'start': (3, 4, 14, 0)},
{'country': 'NL', 'start': (4, 11, 19, 50)},
{'country': 'US', 'start': (5, 22, 12), 'state': 'NJ'},
{'country': 'US', 'start': (6, 30, 12, 30), 'state': 'TX'},
{'country': 'US', 'start': (7, 3, 16, 28), 'state': 'NJ'})
Determine your time distribution over the year as follows for just working days:
series = tr.time_distribution(trips=trips, year=2004)
series
working_day 251.0 (NL, NL) 73.0 (ES, ES) 26.0 (US, NJ) 150.0 (US, TX) 2.0 dtype: float64
And your fraction of income in each place as follows:
tr.fraction_of_year(trips=trips, year=2004, income=100000)
.dataframe thead tr:only-child th {
text-align: right;
}
.dataframe thead th {
text-align: left;
}
.dataframe tbody tr th {
vertical-align: top;
}
days | fraction_of_year | income | |
---|---|---|---|
working_day | 251.0 | 1.000000 | 100000.000000 |
(NL, NL) | 73.0 | 0.290837 | 29083.665339 |
(ES, ES) | 26.0 | 0.103586 | 10358.565737 |
(US, NJ) | 150.0 | 0.597610 | 59760.956175 |
(US, TX) | 2.0 | 0.007968 | 796.812749 |
Lastly, if you're just curious about the working days of that year:
tr.get_working_days(2013).head()
.dataframe thead tr:only-child th {
text-align: right;
}
.dataframe thead th {
text-align: left;
}
.dataframe tbody tr th {
vertical-align: top;
}
working_day | |
---|---|
2013-01-01 | False |
2013-01-02 | True |
2013-01-03 | True |
2013-01-04 | True |
2013-01-05 | False |
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.