diff --git a/README.md b/README.md index 8a4bb95..f3cdcfa 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -pylib -===== +# Install + +Install in "development mode" so any changes of the program is effective. + + git clone http://weseng.de/daniel/pylib.git + cd pylib + pip install --user -e . + +# Uninstall + + pip uninstall pylib diff --git a/pylib/__init__.py b/pylib/__init__.py deleted file mode 100644 index e946c39..0000000 --- a/pylib/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -import os -import sys - -# Add vendor directory to module search path -project_dir = os.path.abspath(os.path.dirname(__file__)) -parent_dir = os.path.dirname(project_dir) -vendor_dir = os.path.join(parent_dir, 'vendor') - -if vendor_dir not in sys.path: - sys.path.append(vendor_dir) - -# Now you can import any library located in the "vendor" folder! -# import drawille diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..851dd6b --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from os.path import join, dirname +from setuptools import setup, find_packages + +# Utility function to read the README file. Used for the long_description. +def read(fname): + with open(join(dirname(__file__), fname)) as fh: + return fh.read() + +setup( + name="pylib", + version="2021.02.01", + description="python library", + long_description=read("README.md"), + author="Daniel Weschke", + author_email="daniel.weschke@directbox.de", + package_dir={'': 'src'}, + packages=find_packages("src"), + keywords = ['data', 'date', 'draw', 'geometry', 'mathematics', 'numerical', 'time'], + license="MIT", + classifiers=[ + 'Environment :: Console', + 'Intended Audience :: Education', + 'Intended Audience :: End Users/Desktop', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Physics' + ] +) diff --git a/src/pylib/__init__.py b/src/pylib/__init__.py new file mode 100644 index 0000000..e71b082 --- /dev/null +++ b/src/pylib/__init__.py @@ -0,0 +1,13 @@ +import os +import sys + +# Add vendor directory to module search path +_project_dir = os.path.abspath(os.path.dirname(__file__)) +_parent_dir = os.path.dirname(_project_dir) +_vendor_dir = os.path.join(_parent_dir, 'vendor') + +if _vendor_dir not in sys.path: + sys.path.append(_vendor_dir) + +# Now you can import any library located in the "vendor" folder! +# import drawille diff --git a/pylib/data.py b/src/pylib/data.py similarity index 100% rename from pylib/data.py rename to src/pylib/data.py diff --git a/pylib/data_step.py b/src/pylib/data_step.py similarity index 100% rename from pylib/data_step.py rename to src/pylib/data_step.py diff --git a/pylib/data_step_std.py b/src/pylib/data_step_std.py similarity index 100% rename from pylib/data_step_std.py rename to src/pylib/data_step_std.py diff --git a/pylib/date.py b/src/pylib/date.py similarity index 54% rename from pylib/date.py rename to src/pylib/date.py index 4cf20be..ce923b6 100644 --- a/pylib/date.py +++ b/src/pylib/date.py @@ -10,16 +10,58 @@ .. moduleauthor:: Daniel Weschke """ +import datetime +def computus_anonymous_gregorian(year): + """Computus anonymous Gregorian algorithm or Meeus/Jones/Butcher + algorithm. + + :param year: the year to calculate the Easter Sunday + :type year: int + + :returns: the day of Easter Sunday + :rtype: datetime.date + + For Gregorian calendar (1583 and onward) + Works without exeptions. + + Published + 1876 by Anonymous in Nature + 1877 by Samuel Butcher in The Ecclesiastical Calendar + 1916 by Arthur Downing in The Observatory + 1922 by Harold Spencer Jones in General Astronomy + 1988 by Peter Duffett-Smith in Practical Astronomy with your Calculator + 1991 by Jean Meeus in Astronomical Algorithms + + source: https://de.wikipedia.org/wiki/Spencers_Osterformel + source: https://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm + """ + a = year % 19 + b = year // 100 + c = year % 100 + d = b // 4 + e = b % 4 + f = (b + 8) // 25 + g = (b - f + 1) // 3 + h = (19 * a + b - d - g + 15) % 30 + i = c // 4 + k = c % 4 + l = (32 + 2 * e + 2 * i - h - k) % 7 + m = (a + 11 * h + 22 * l) // 451 + n = (h + l - 7 * m + 114) // 31 + o = (h + l - 7 * m + 114) % 31 + return datetime.date(year, n, o + 1) + +# was not correct for 2020 def gaußsche_osterformel(year): """Gaußsche Osterformel. :param year: the year to calculate the Easter Sunday :type year: int - - :returns: the day of Easter Sunday as a day in march. - :rtype: int - + + :returns: the day of Easter Sunday (computed as a day in march). + :rtype: datetime.date + :ivar X: Das Jahr / year :vartype X: int :ivar K(X): Die Säkularzahl @@ -42,7 +84,7 @@ def gaußsche_osterformel(year): :vartype OE(OG,SZ): int :ivar OS(OG,OE): Das Datum des Ostersonntags als Märzdatum (32. März = 1. April usw.) :vartype OS(OG,OE): int - + Algorithmus gilt für den Gregorianischen Kalender. source: https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Osterformel @@ -58,30 +100,29 @@ def gaußsche_osterformel(year): sz = 7 - (x + x // 4 + s) % 7 oe = 7 - (og - sz) % 7 os = og + oe - return os + + march = datetime.date(year, 3, 1) + day = march + datetime.timedelta(days=os) + return day def easter_sunday(year): """Easter Sunday. :param year: the year to calculate the Easter Sunday :type year: int - + :returns: the day of Easter Sunday :rtype: datetime.date""" - import datetime - march = datetime.date(year, 3, 1) - day = march + datetime.timedelta(days=gaußsche_osterformel(year)) - return day + return computus_anonymous_gregorian(year) def easter_friday(year): """Easter Friday. :param year: the year to calculate the Easter Friday :type year: int - + :returns: the day of Easter Friday :rtype: datetime.date""" - import datetime day = easter_sunday(year) + datetime.timedelta(days=-2) return day @@ -90,10 +131,9 @@ def easter_monday(year): :param year: the year to calculate the Easter Monday :type year: int - + :returns: the day of Easter Monday :rtype: datetime.date""" - import datetime day = easter_sunday(year) + datetime.timedelta(days=+1) return day @@ -102,10 +142,9 @@ def ascension_of_jesus(year): :param year: the year to calculate the ascension of Jesus :type year: int - + :returns: the day of ascension of Jesus :rtype: datetime.date""" - import datetime day = easter_sunday(year) + datetime.timedelta(days=+39) return day @@ -114,9 +153,32 @@ def pentecost(year): :param year: the year to calculate the Pentecost :type year: int - + :returns: the day of Pentecost :rtype: datetime.date""" - import datetime day = easter_sunday(year) + datetime.timedelta(days=+49) return day + +def daylist(day, end, excludedweekdays=[], excludeddays=[], inclusive=True): + """Create a list of dates + + :param day: the beginning day for the list + :type day: datetime.date + :param end: the end day of the list + :type end: datetime.date + :param excludedweekdays: list of days of the week to exclude, where + Monday == 1 and Sunday == 7 (ISO weekday, default = []) + :type excludedweekdays: list of int + :param excludeddays: list of days to exclude, e.g. vacation, sick + leaves, trainings (default = []) + :type excludedweekdays: list of datetime.date + :param inclusive: include the end day in the list (default = True) + :type inclusive: bool + """ + # TODO: includeddays: e.g. work on weekend days if using excludedweekdays + result = [] + while day <= end if inclusive else day < end: + if day.isoweekday() not in excludedweekdays and day not in excludeddays: + result.append(day) + day += datetime.timedelta(days=1) + return result diff --git a/pylib/drawblock.py b/src/pylib/drawblock.py similarity index 100% rename from pylib/drawblock.py rename to src/pylib/drawblock.py diff --git a/pylib/function.py b/src/pylib/function.py similarity index 100% rename from pylib/function.py rename to src/pylib/function.py diff --git a/pylib/geometry.py b/src/pylib/geometry.py similarity index 100% rename from pylib/geometry.py rename to src/pylib/geometry.py diff --git a/pylib/geometry2d.py b/src/pylib/geometry2d.py similarity index 100% rename from pylib/geometry2d.py rename to src/pylib/geometry2d.py diff --git a/pylib/geometry2d_plot.py b/src/pylib/geometry2d_plot.py similarity index 100% rename from pylib/geometry2d_plot.py rename to src/pylib/geometry2d_plot.py diff --git a/pylib/geometry_plot.py b/src/pylib/geometry_plot.py similarity index 100% rename from pylib/geometry_plot.py rename to src/pylib/geometry_plot.py diff --git a/pylib/geometry_plot_pylab.py b/src/pylib/geometry_plot_pylab.py similarity index 100% rename from pylib/geometry_plot_pylab.py rename to src/pylib/geometry_plot_pylab.py diff --git a/pylib/helper.py b/src/pylib/helper.py similarity index 100% rename from pylib/helper.py rename to src/pylib/helper.py diff --git a/pylib/mathematics.py b/src/pylib/mathematics.py similarity index 100% rename from pylib/mathematics.py rename to src/pylib/mathematics.py diff --git a/pylib/numerical/__init__.py b/src/pylib/numerical/__init__.py similarity index 100% rename from pylib/numerical/__init__.py rename to src/pylib/numerical/__init__.py diff --git a/pylib/numerical/fit.py b/src/pylib/numerical/fit.py similarity index 100% rename from pylib/numerical/fit.py rename to src/pylib/numerical/fit.py diff --git a/pylib/numerical/integration.py b/src/pylib/numerical/integration.py similarity index 100% rename from pylib/numerical/integration.py rename to src/pylib/numerical/integration.py diff --git a/pylib/numerical/ode.py b/src/pylib/numerical/ode.py similarity index 100% rename from pylib/numerical/ode.py rename to src/pylib/numerical/ode.py diff --git a/pylib/numerical/ode_model.py b/src/pylib/numerical/ode_model.py similarity index 100% rename from pylib/numerical/ode_model.py rename to src/pylib/numerical/ode_model.py diff --git a/pylib/time_of_day.py b/src/pylib/time_of_day.py similarity index 100% rename from pylib/time_of_day.py rename to src/pylib/time_of_day.py diff --git a/pylib/tui.py b/src/pylib/tui.py similarity index 100% rename from pylib/tui.py rename to src/pylib/tui.py diff --git a/vendor/drawille.py b/src/vendor/drawille.py similarity index 100% rename from vendor/drawille.py rename to src/vendor/drawille.py