Giter Site home page Giter Site logo

cadu-leite / networkdays Goto Github PK

View Code? Open in Web Editor NEW
28.0 2.0 8.0 63 KB

Networkdays functions ... including `networkdays` excel like function with no dependencies (no NumPy)

License: Other

Python 100.00%
networkdays bussiness calendar dates scheduler events

networkdays's Introduction

Networkdays

some statistics ...

Pypi Version Doc Status Coverage Downloads
pypi version Documentation Status code coverage Downloads on Pypi

  • Business days calendar.
  • JobSchedule on business days.

Tip

Just Python built-in libs, no dependencies

Networkdays:

Return working days between two dates exclude weekends and holidays.

  • just like spreadsheets networdays function
  • exclude Holidays
  • Exclude "days off" per week.
Job schedule:
Calculate the period for a given job hours, based on Networdays.

Installation

python-networkdays can be installed from PyPI using pip

pip install python-networkdays

Tip

note that the package name is different from the importable name

Page on Pypi: https://pypi.org/project/python-networkdays/

There is no dependencies.

Features

  • Return a list of business days between 2 dates.
  • Exclude weekends by default
  • Custom "days off" may be informed as list like {1,2,3,4,5,6,7}, where 1 is Monday default is {6,7} = (Sat, Sun).
  • How many business days between two dates.
  • How many days off, including holidays and weekends.
  • Return a list of business days for a given number of hours
  • Return a list of Years, months or weeks for a given number of hours
  • No Pandas or NumPy dependencies

Examples

Class Networkdays.networkdays

List business days, weekends and Holidays

In [1]: from networkdays import networkdays

In [2]: import datetime

In [3]: HOLIDAYS = { datetime.date(2020, 12, 25) }  # define a Holidays list

# initiate  class::`networkdays.Networkdays`
In [4]: days = networkdays.Networkdays(
            datetime.date(2020, 12, 15),  # start date
            datetime.date(2020, 12, 31),  # end date
            HOLIDAYS  # list of Holidays
        )

In [5]: days.networkdays()  # return a list os workdays
Out[5]:
[datetime.date(2020, 12, 15),
 datetime.date(2020, 12, 16),
 datetime.date(2020, 12, 17),
 datetime.date(2020, 12, 18),
 datetime.date(2020, 12, 21),
 datetime.date(2020, 12, 22),
 datetime.date(2020, 12, 23),
 datetime.date(2020, 12, 24),
 datetime.date(2020, 12, 28),
 datetime.date(2020, 12, 29),
 datetime.date(2020, 12, 30),
 datetime.date(2020, 12, 31)]

In [6]: days.weekends()  # list os Weekends (default = Saturday ans Sunday)
Out[6]:
[datetime.date(2020, 12, 19),
 datetime.date(2020, 12, 20),
 datetime.date(2020, 12, 26),
 datetime.date(2020, 12, 27)]

In [7]: days.holidays()
Out[7]: [datetime.date(2020, 12, 25)] # list of holidays

class Networkdays.jobschedule

>>> from networkdays import networkdays
>>> import datetime
>>> # Distribute the 600 hrs of effort, starting on december 1, 2020 working 8hrs per day.
>>> jobschedule = networkdays.JobSchedule(600, 8, datetime.date(2020, 12, 1), networkdays=None)
>>> job_dates = jobschedule.job_workdays()
>>> jobschedule.bussines_days
54
>>> jobschedule.total_days
datetime.timedelta(days=73)
>>> jobschedule.prj_starts
'12/01/20'
>>> jobschedule.prj_ends
'02/12/21'
>>> list(jobschedule.years())
[2020, 2021]
>>> list(jobschedule.months())
[12, 1, 2]
>>> list(jobschedule.weeks()) # ISO
[49, 50, 51, 52, 53, 1, 2, 3, 4, 5, 6]
>>> f'days: {list(jobschedule.days())[:2]} ... {list(jobschedule.days())[-2:]}'
'days: [datetime.date(2020, 12, 1), datetime.date(2020, 12, 2)] ... [datetime.date(2021, 2, 11), datetime.date(2021, 2, 12)]'

Other similar projects

When I start to code, I did check for some similar projects.

I knew about python-dateutil, a great project I use for years... I'd like something more straightforward or simpler.

After to publish the python-networkdays on PyPi I found some others 8(

I will try to keep this list updated...

More on ..

https://networkdays.readthedocs.io/index.html

https://libraries.io/pypi/python-networkdays/sourcerank

networkdays's People

Contributors

cadu-leite avatar renzon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

networkdays's Issues

Incompatibility with mypy

hey cadu, how are u doing?

im starting using ur library and just noticed that the code is not being covered by type hintings.

what do u think about we start adding types for the abstraction we already implemented?

im going to open a PR rn adding those type hints

Command line - add funtion to print calendar from command line

like Python calendar function ... but only "networdays"

$>python -m calendar
                                  2020

      January                   February                   March
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                      1  2                         1
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       2  3  4  5  6  7  8
13 14 15 16 17 18 19      10 11 12 13 14 15 16       9 10 11 12 13 14 15
20 21 22 23 24 25 26      17 18 19 20 21 22 23      16 17 18 19 20 21 22
27 28 29 30 31            24 25 26 27 28 29         23 24 25 26 27 28 29
                                                    30 31

It may be easily used on text files ;) .. sphinx, restructuredtext ...

TypeError: unsupported operand type(s) for -: 'NoneType' and 'datetime.date'

Suppose to initiate Networkdays class withou date_end parameter...
Its works but raise exception when call :method:Networkdays.networkdays() method.
trace ...

---> 44         date_diff = self.date_end - self.date_start
     45         dates = {
     46             self.date_start + datetime.timedelta(days=days)

TypeError: unsupported operand type(s) for -: 'NoneType' and 'datetime.date'

ModuleNotFoundError: No module named 'networkdays'

I've installed this on my linux machines and it works well but when i trying it on my Mac it doesn't. Even if its already installed it will always return: ModuleNotFoundError: No module named 'networkdays'.

An option to list month days intead datetime

Networkdays return a llist of datetime objects

For some cases, a nested list of month days number list per month would be desirable.

[[<month days 1>],[<month days 2>],....[<month days 12>]]

Actually its a nested list of month days, grouped by month ;)

[
    [3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31],
    [1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 28],
    [1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 28, 29, 30, 31],
    [1, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29,] 
    [2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 23, 24, 25, 26, 27, 30, 31],
    [1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 27, 28, 29, 30],
    [1, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 25, 26, 27, 28, 29],
    [1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24, 25, 26, 29, 30, 31],
    [1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 26, 27, 28, 29, 30,] 
    [3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31],
    [1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 28, 29, 30],
    [1, 2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 26, 27, 28, 29, 30]
]

JobSchedule e networkdays namespace

For a better namespace or "dot path"...
I believe would be a good idea
take both classes of the networkdays file
and put each one in his own file ...
networkdays

├── networkdays
│   ├── __init__.py
│   ├── networkdays.py

to be ...

├── networkdays
│   ├── __init__.py
│   ├── networkdays.py
│   └── jobschedule.py

and expose both on init.py , to have one less level on namespaces.

remove file: readme_code.ipynb

The file readme_code.ipynb was used to build the first tests for the docs.
Now we have doc tests ... see #8
this file has no need

Add "codecov" badged

Add code below do the readme

.. image:: https://codecov.io/gh/cadu-leite/networkdays/branch/master/graph/badge.svg
     :target: https://codecov.io/gh/cadu-leite/networkdays

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.