This commit is contained in:
2026-01-22 18:51:58 +01:00
25 changed files with 140 additions and 34 deletions

View File

@@ -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

View File

@@ -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
View 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
View 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

View File

@@ -10,16 +10,58 @@
.. 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
:ivar K(X): Die Säkularzahl :ivar K(X): Die Säkularzahl
@@ -42,7 +84,7 @@ def gaußsche_osterformel(year):
:vartype OE(OG,SZ): int :vartype OE(OG,SZ): int
:ivar OS(OG,OE): Das Datum des Ostersonntags als Märzdatum (32. März = 1. April usw.) :ivar OS(OG,OE): Das Datum des Ostersonntags als Märzdatum (32. März = 1. April usw.)
:vartype OS(OG,OE): int :vartype OS(OG,OE): int
Algorithmus gilt für den Gregorianischen Kalender. Algorithmus gilt für den Gregorianischen Kalender.
source: https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Osterformel 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 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.
: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 :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.
:param year: the year to calculate the Easter Friday :param year: the year to calculate the Easter Friday
:type year: int :type year: int
: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
@@ -90,10 +131,9 @@ def easter_monday(year):
:param year: the year to calculate the Easter Monday :param year: the year to calculate the Easter Monday
:type year: int :type year: int
: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
@@ -102,10 +142,9 @@ def ascension_of_jesus(year):
:param year: the year to calculate the ascension of Jesus :param year: the year to calculate the ascension of Jesus
:type year: int :type year: int
: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
@@ -114,9 +153,32 @@ def pentecost(year):
:param year: the year to calculate the Pentecost :param year: the year to calculate the Pentecost
:type year: int :type year: int
: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