Merge branch 'master' of https://gitea.weseng.de/daniel/pylib
This commit is contained in:
13
README.md
13
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
|
||||||
|
|||||||
@@ -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
|
|
||||||
35
setup.py
Normal file
35
setup.py
Normal file
@@ -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'
|
||||||
|
]
|
||||||
|
)
|
||||||
13
src/pylib/__init__.py
Normal file
13
src/pylib/__init__.py
Normal file
@@ -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
|
||||||
@@ -10,15 +10,57 @@
|
|||||||
|
|
||||||
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
||||||
"""
|
"""
|
||||||
|
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):
|
def gaußsche_osterformel(year):
|
||||||
"""Gaußsche Osterformel.
|
"""Gaußsche Osterformel.
|
||||||
|
|
||||||
:param year: the year to calculate the Easter Sunday
|
:param year: the year to calculate the Easter Sunday
|
||||||
:type year: int
|
:type year: int
|
||||||
|
|
||||||
:returns: the day of Easter Sunday as a day in march.
|
:returns: the day of Easter Sunday (computed as a day in march).
|
||||||
:rtype: int
|
:rtype: datetime.date
|
||||||
|
|
||||||
:ivar X: Das Jahr / year
|
:ivar X: Das Jahr / year
|
||||||
:vartype X: int
|
:vartype X: int
|
||||||
@@ -58,7 +100,10 @@ def gaußsche_osterformel(year):
|
|||||||
sz = 7 - (x + x // 4 + s) % 7
|
sz = 7 - (x + x // 4 + s) % 7
|
||||||
oe = 7 - (og - sz) % 7
|
oe = 7 - (og - sz) % 7
|
||||||
os = og + oe
|
os = og + oe
|
||||||
return os
|
|
||||||
|
march = datetime.date(year, 3, 1)
|
||||||
|
day = march + datetime.timedelta(days=os)
|
||||||
|
return day
|
||||||
|
|
||||||
def easter_sunday(year):
|
def easter_sunday(year):
|
||||||
"""Easter Sunday.
|
"""Easter Sunday.
|
||||||
@@ -68,10 +113,7 @@ def easter_sunday(year):
|
|||||||
|
|
||||||
:returns: the day of Easter Sunday
|
:returns: the day of Easter Sunday
|
||||||
:rtype: datetime.date"""
|
:rtype: datetime.date"""
|
||||||
import datetime
|
return computus_anonymous_gregorian(year)
|
||||||
march = datetime.date(year, 3, 1)
|
|
||||||
day = march + datetime.timedelta(days=gaußsche_osterformel(year))
|
|
||||||
return day
|
|
||||||
|
|
||||||
def easter_friday(year):
|
def easter_friday(year):
|
||||||
"""Easter Friday.
|
"""Easter Friday.
|
||||||
@@ -81,7 +123,6 @@ def easter_friday(year):
|
|||||||
|
|
||||||
:returns: the day of Easter Friday
|
:returns: the day of Easter Friday
|
||||||
:rtype: datetime.date"""
|
:rtype: datetime.date"""
|
||||||
import datetime
|
|
||||||
day = easter_sunday(year) + datetime.timedelta(days=-2)
|
day = easter_sunday(year) + datetime.timedelta(days=-2)
|
||||||
return day
|
return day
|
||||||
|
|
||||||
@@ -93,7 +134,6 @@ def easter_monday(year):
|
|||||||
|
|
||||||
:returns: the day of Easter Monday
|
:returns: the day of Easter Monday
|
||||||
:rtype: datetime.date"""
|
:rtype: datetime.date"""
|
||||||
import datetime
|
|
||||||
day = easter_sunday(year) + datetime.timedelta(days=+1)
|
day = easter_sunday(year) + datetime.timedelta(days=+1)
|
||||||
return day
|
return day
|
||||||
|
|
||||||
@@ -105,7 +145,6 @@ def ascension_of_jesus(year):
|
|||||||
|
|
||||||
:returns: the day of ascension of Jesus
|
:returns: the day of ascension of Jesus
|
||||||
:rtype: datetime.date"""
|
:rtype: datetime.date"""
|
||||||
import datetime
|
|
||||||
day = easter_sunday(year) + datetime.timedelta(days=+39)
|
day = easter_sunday(year) + datetime.timedelta(days=+39)
|
||||||
return day
|
return day
|
||||||
|
|
||||||
@@ -117,6 +156,29 @@ def pentecost(year):
|
|||||||
|
|
||||||
:returns: the day of Pentecost
|
:returns: the day of Pentecost
|
||||||
:rtype: datetime.date"""
|
:rtype: datetime.date"""
|
||||||
import datetime
|
|
||||||
day = easter_sunday(year) + datetime.timedelta(days=+49)
|
day = easter_sunday(year) + datetime.timedelta(days=+49)
|
||||||
return day
|
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
|
||||||
Reference in New Issue
Block a user