provost 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of provost might be problematic. Click here for more details.
- provost/__init__.py +84 -0
- provost/__main__.py +6 -0
- provost/attendance.py +75 -0
- provost/cli.py +118 -0
- provost/giving.py +73 -0
- provost/io.py +43 -0
- provost/membership.py +70 -0
- provost/metrics.py +91 -0
- provost/models.py +75 -0
- provost/py.typed +0 -0
- provost-0.1.0.dist-info/METADATA +173 -0
- provost-0.1.0.dist-info/RECORD +16 -0
- provost-0.1.0.dist-info/WHEEL +5 -0
- provost-0.1.0.dist-info/entry_points.txt +2 -0
- provost-0.1.0.dist-info/licenses/LICENSE +21 -0
- provost-0.1.0.dist-info/top_level.txt +1 -0
provost/__init__.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""provost — simple, transparent data automation for church administration.
|
|
2
|
+
|
|
3
|
+
``provost`` helps church and congregation administrators turn the CSV exports
|
|
4
|
+
their management software already produces into plain-English summaries:
|
|
5
|
+
attendance trends, giving analytics and membership lifecycle metrics.
|
|
6
|
+
|
|
7
|
+
Design principles:
|
|
8
|
+
|
|
9
|
+
* **Standard library only.** No third-party runtime dependencies.
|
|
10
|
+
* **No side effects.** Nothing here touches the network, reads the system
|
|
11
|
+
clock implicitly, or executes anything from the data it reads.
|
|
12
|
+
* **Explainable maths.** Every metric is a short, auditable function.
|
|
13
|
+
|
|
14
|
+
Example
|
|
15
|
+
-------
|
|
16
|
+
>>> from provost import read_attendance, attendance_summary
|
|
17
|
+
>>> records = read_attendance("attendance.csv")
|
|
18
|
+
>>> attendance_summary(records)["mean"] # doctest: +SKIP
|
|
19
|
+
182.5
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from .io import read_attendance, read_giving, read_members
|
|
25
|
+
from .models import AttendanceRecord, GivingRecord, Member
|
|
26
|
+
from . import attendance, giving, membership, metrics
|
|
27
|
+
from .attendance import (
|
|
28
|
+
attendance_summary,
|
|
29
|
+
forecast_next,
|
|
30
|
+
rolling_average,
|
|
31
|
+
weekly_totals,
|
|
32
|
+
year_over_year,
|
|
33
|
+
)
|
|
34
|
+
from .giving import (
|
|
35
|
+
average_gift,
|
|
36
|
+
giving_by_fund,
|
|
37
|
+
giving_by_member,
|
|
38
|
+
giving_summary,
|
|
39
|
+
recurring_donors,
|
|
40
|
+
total_giving,
|
|
41
|
+
)
|
|
42
|
+
from .membership import (
|
|
43
|
+
active_members,
|
|
44
|
+
net_growth,
|
|
45
|
+
new_members,
|
|
46
|
+
retention_rate,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__version__ = "0.1.0"
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"__version__",
|
|
53
|
+
# io
|
|
54
|
+
"read_attendance",
|
|
55
|
+
"read_giving",
|
|
56
|
+
"read_members",
|
|
57
|
+
# models
|
|
58
|
+
"AttendanceRecord",
|
|
59
|
+
"GivingRecord",
|
|
60
|
+
"Member",
|
|
61
|
+
# submodules
|
|
62
|
+
"attendance",
|
|
63
|
+
"giving",
|
|
64
|
+
"membership",
|
|
65
|
+
"metrics",
|
|
66
|
+
# attendance
|
|
67
|
+
"attendance_summary",
|
|
68
|
+
"forecast_next",
|
|
69
|
+
"rolling_average",
|
|
70
|
+
"weekly_totals",
|
|
71
|
+
"year_over_year",
|
|
72
|
+
# giving
|
|
73
|
+
"average_gift",
|
|
74
|
+
"giving_by_fund",
|
|
75
|
+
"giving_by_member",
|
|
76
|
+
"giving_summary",
|
|
77
|
+
"recurring_donors",
|
|
78
|
+
"total_giving",
|
|
79
|
+
# membership
|
|
80
|
+
"active_members",
|
|
81
|
+
"net_growth",
|
|
82
|
+
"new_members",
|
|
83
|
+
"retention_rate",
|
|
84
|
+
]
|
provost/__main__.py
ADDED
provost/attendance.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Attendance analytics.
|
|
2
|
+
|
|
3
|
+
Turns a list of :class:`~provost.models.AttendanceRecord` into weekly totals,
|
|
4
|
+
rolling averages, year-over-year comparisons and a naive next-period forecast.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections import defaultdict
|
|
10
|
+
from datetime import date
|
|
11
|
+
from typing import Sequence
|
|
12
|
+
|
|
13
|
+
from .metrics import moving_average, summarize
|
|
14
|
+
from .models import AttendanceRecord
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def weekly_totals(records: Sequence[AttendanceRecord]) -> dict[date, int]:
|
|
18
|
+
"""Sum attendance per ISO-week, keyed by that week's Monday.
|
|
19
|
+
|
|
20
|
+
Every service on the same date is combined, then dates are grouped into
|
|
21
|
+
their week. The result is ordered oldest-first.
|
|
22
|
+
"""
|
|
23
|
+
by_week: dict[date, int] = defaultdict(int)
|
|
24
|
+
for record in records:
|
|
25
|
+
monday = record.date.fromordinal(
|
|
26
|
+
record.date.toordinal() - record.date.weekday()
|
|
27
|
+
)
|
|
28
|
+
by_week[monday] += record.count
|
|
29
|
+
return dict(sorted(by_week.items()))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def rolling_average(
|
|
33
|
+
records: Sequence[AttendanceRecord], window: int = 4
|
|
34
|
+
) -> list[tuple[date, float]]:
|
|
35
|
+
"""Rolling average of weekly totals over ``window`` weeks.
|
|
36
|
+
|
|
37
|
+
Returns ``(week_start, average)`` pairs. An empty list is returned when
|
|
38
|
+
there are fewer weeks of data than ``window``.
|
|
39
|
+
"""
|
|
40
|
+
weeks = weekly_totals(records)
|
|
41
|
+
if len(weeks) < window:
|
|
42
|
+
return []
|
|
43
|
+
starts = list(weeks.keys())
|
|
44
|
+
counts = list(weeks.values())
|
|
45
|
+
averages = moving_average(counts, window)
|
|
46
|
+
return list(zip(starts[window - 1 :], averages))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def year_over_year(records: Sequence[AttendanceRecord]) -> dict[int, int]:
|
|
50
|
+
"""Total attendance grouped by calendar year, ordered oldest-first."""
|
|
51
|
+
by_year: dict[int, int] = defaultdict(int)
|
|
52
|
+
for record in records:
|
|
53
|
+
by_year[record.date.year] += record.count
|
|
54
|
+
return dict(sorted(by_year.items()))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def forecast_next(records: Sequence[AttendanceRecord], window: int = 4) -> float:
|
|
58
|
+
"""Naive forecast for the next week: the mean of the last ``window`` weeks.
|
|
59
|
+
|
|
60
|
+
This is deliberately simple and explainable — it is a baseline, not a
|
|
61
|
+
statistical model. Raises ``ValueError`` when there is no data.
|
|
62
|
+
"""
|
|
63
|
+
weeks = weekly_totals(records)
|
|
64
|
+
if not weeks:
|
|
65
|
+
raise ValueError("no attendance data to forecast from")
|
|
66
|
+
recent = list(weeks.values())[-window:]
|
|
67
|
+
return sum(recent) / len(recent)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def attendance_summary(records: Sequence[AttendanceRecord]) -> dict[str, float]:
|
|
71
|
+
"""Descriptive statistics of weekly attendance totals."""
|
|
72
|
+
weeks = weekly_totals(records)
|
|
73
|
+
if not weeks:
|
|
74
|
+
raise ValueError("no attendance data to summarize")
|
|
75
|
+
return summarize(weeks.values())
|
provost/cli.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Command-line interface for provost.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
provost attendance path/to/attendance.csv
|
|
6
|
+
provost giving path/to/giving.csv
|
|
7
|
+
provost members path/to/members.csv
|
|
8
|
+
|
|
9
|
+
Each command prints a human-readable summary to stdout. The CLI reads only the
|
|
10
|
+
file you point it at and writes only to stdout.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import sys
|
|
17
|
+
from typing import Sequence
|
|
18
|
+
|
|
19
|
+
from . import __version__
|
|
20
|
+
from .attendance import attendance_summary, forecast_next, year_over_year
|
|
21
|
+
from .giving import (
|
|
22
|
+
average_gift,
|
|
23
|
+
giving_by_fund,
|
|
24
|
+
recurring_donors,
|
|
25
|
+
total_giving,
|
|
26
|
+
)
|
|
27
|
+
from .io import read_attendance, read_giving, read_members
|
|
28
|
+
from .membership import active_members
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _money(value: float) -> str:
|
|
32
|
+
return f"{value:,.2f}"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _cmd_attendance(path: str) -> int:
|
|
36
|
+
records = read_attendance(path)
|
|
37
|
+
if not records:
|
|
38
|
+
print("No attendance records found.")
|
|
39
|
+
return 0
|
|
40
|
+
stats = attendance_summary(records)
|
|
41
|
+
print(f"Attendance summary for {path}")
|
|
42
|
+
print(f" weeks recorded : {int(stats['count'])}")
|
|
43
|
+
print(f" mean / week : {stats['mean']:.1f}")
|
|
44
|
+
print(f" median / week : {stats['median']:.1f}")
|
|
45
|
+
print(f" best week : {int(stats['max'])}")
|
|
46
|
+
print(f" quietest week : {int(stats['min'])}")
|
|
47
|
+
print(f" next-week est. : {forecast_next(records):.1f}")
|
|
48
|
+
print(" by year:")
|
|
49
|
+
for year, total in year_over_year(records).items():
|
|
50
|
+
print(f" {year}: {total}")
|
|
51
|
+
return 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _cmd_giving(path: str) -> int:
|
|
55
|
+
records = read_giving(path)
|
|
56
|
+
if not records:
|
|
57
|
+
print("No giving records found.")
|
|
58
|
+
return 0
|
|
59
|
+
print(f"Giving summary for {path}")
|
|
60
|
+
print(f" gifts recorded : {len(records)}")
|
|
61
|
+
print(f" total given : {_money(total_giving(records))}")
|
|
62
|
+
print(f" average gift : {_money(average_gift(records))}")
|
|
63
|
+
print(" by fund:")
|
|
64
|
+
for fund, amount in giving_by_fund(records).items():
|
|
65
|
+
print(f" {fund}: {_money(amount)}")
|
|
66
|
+
recurring = recurring_donors(records)
|
|
67
|
+
print(f" recurring donors (3+ months): {len(recurring)}")
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _cmd_members(path: str) -> int:
|
|
72
|
+
members = read_members(path)
|
|
73
|
+
if not members:
|
|
74
|
+
print("No member records found.")
|
|
75
|
+
return 0
|
|
76
|
+
active = active_members(members)
|
|
77
|
+
print(f"Membership summary for {path}")
|
|
78
|
+
print(f" members on file : {len(members)}")
|
|
79
|
+
print(f" currently active: {len(active)}")
|
|
80
|
+
return 0
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
84
|
+
parser = argparse.ArgumentParser(
|
|
85
|
+
prog="provost",
|
|
86
|
+
description="Simple data automation for church administration.",
|
|
87
|
+
)
|
|
88
|
+
parser.add_argument("--version", action="version", version=f"provost {__version__}")
|
|
89
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
90
|
+
|
|
91
|
+
for name, help_text in (
|
|
92
|
+
("attendance", "Summarise an attendance CSV."),
|
|
93
|
+
("giving", "Summarise a giving CSV."),
|
|
94
|
+
("members", "Summarise a members CSV."),
|
|
95
|
+
):
|
|
96
|
+
p = sub.add_parser(name, help=help_text)
|
|
97
|
+
p.add_argument("path", help="Path to the CSV file.")
|
|
98
|
+
|
|
99
|
+
return parser
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
103
|
+
parser = build_parser()
|
|
104
|
+
args = parser.parse_args(argv)
|
|
105
|
+
handlers = {
|
|
106
|
+
"attendance": _cmd_attendance,
|
|
107
|
+
"giving": _cmd_giving,
|
|
108
|
+
"members": _cmd_members,
|
|
109
|
+
}
|
|
110
|
+
try:
|
|
111
|
+
return handlers[args.command](args.path)
|
|
112
|
+
except (OSError, ValueError) as exc:
|
|
113
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
114
|
+
return 1
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__": # pragma: no cover
|
|
118
|
+
raise SystemExit(main())
|
provost/giving.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Giving / contribution analytics.
|
|
2
|
+
|
|
3
|
+
Summaries over a list of :class:`~provost.models.GivingRecord`: totals, splits
|
|
4
|
+
by fund and by member, average gift size and identification of recurring
|
|
5
|
+
donors. All figures are computed directly from the records passed in.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections import defaultdict
|
|
11
|
+
from typing import Sequence
|
|
12
|
+
|
|
13
|
+
from .metrics import summarize
|
|
14
|
+
from .models import GivingRecord
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def total_giving(records: Sequence[GivingRecord]) -> float:
|
|
18
|
+
"""Sum of all gift amounts."""
|
|
19
|
+
return sum(record.amount for record in records)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def giving_by_fund(records: Sequence[GivingRecord]) -> dict[str, float]:
|
|
23
|
+
"""Total given to each fund, ordered largest-first."""
|
|
24
|
+
by_fund: dict[str, float] = defaultdict(float)
|
|
25
|
+
for record in records:
|
|
26
|
+
by_fund[record.fund] += record.amount
|
|
27
|
+
return dict(sorted(by_fund.items(), key=lambda kv: kv[1], reverse=True))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def giving_by_member(records: Sequence[GivingRecord]) -> dict[str, float]:
|
|
31
|
+
"""Total given by each member, ordered largest-first."""
|
|
32
|
+
by_member: dict[str, float] = defaultdict(float)
|
|
33
|
+
for record in records:
|
|
34
|
+
by_member[record.member_id] += record.amount
|
|
35
|
+
return dict(sorted(by_member.items(), key=lambda kv: kv[1], reverse=True))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def average_gift(records: Sequence[GivingRecord]) -> float:
|
|
39
|
+
"""Mean gift amount. Raises ``ValueError`` when there are no records."""
|
|
40
|
+
if not records:
|
|
41
|
+
raise ValueError("no giving records")
|
|
42
|
+
return total_giving(records) / len(records)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def recurring_donors(
|
|
46
|
+
records: Sequence[GivingRecord], min_months: int = 3
|
|
47
|
+
) -> list[str]:
|
|
48
|
+
"""Members who gave in at least ``min_months`` distinct calendar months.
|
|
49
|
+
|
|
50
|
+
Returns member ids ordered by their number of active months, most
|
|
51
|
+
frequent first.
|
|
52
|
+
"""
|
|
53
|
+
months: dict[str, set[tuple[int, int]]] = defaultdict(set)
|
|
54
|
+
for record in records:
|
|
55
|
+
months[record.member_id].add((record.date.year, record.date.month))
|
|
56
|
+
qualifying = {
|
|
57
|
+
member: len(active)
|
|
58
|
+
for member, active in months.items()
|
|
59
|
+
if len(active) >= min_months
|
|
60
|
+
}
|
|
61
|
+
return [
|
|
62
|
+
member
|
|
63
|
+
for member, _ in sorted(
|
|
64
|
+
qualifying.items(), key=lambda kv: kv[1], reverse=True
|
|
65
|
+
)
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def giving_summary(records: Sequence[GivingRecord]) -> dict[str, float]:
|
|
70
|
+
"""Descriptive statistics of individual gift amounts."""
|
|
71
|
+
if not records:
|
|
72
|
+
raise ValueError("no giving records to summarize")
|
|
73
|
+
return summarize(record.amount for record in records)
|
provost/io.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""CSV loading helpers.
|
|
2
|
+
|
|
3
|
+
Reads use the standard-library :mod:`csv` module and never touch the network
|
|
4
|
+
or execute anything from the files they read. A CSV is only ever parsed as
|
|
5
|
+
data.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import csv
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Callable, TypeVar
|
|
13
|
+
|
|
14
|
+
from .models import AttendanceRecord, GivingRecord, Member
|
|
15
|
+
|
|
16
|
+
T = TypeVar("T")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _read_records(path: str | Path, factory: Callable[[dict[str, str]], T]) -> list[T]:
|
|
20
|
+
records: list[T] = []
|
|
21
|
+
with open(path, newline="", encoding="utf-8") as handle:
|
|
22
|
+
reader = csv.DictReader(handle)
|
|
23
|
+
for line_no, row in enumerate(reader, start=2):
|
|
24
|
+
try:
|
|
25
|
+
records.append(factory(row))
|
|
26
|
+
except (KeyError, ValueError) as exc:
|
|
27
|
+
raise ValueError(f"{path}: could not parse row {line_no}: {exc}") from exc
|
|
28
|
+
return records
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def read_attendance(path: str | Path) -> list[AttendanceRecord]:
|
|
32
|
+
"""Load attendance records from a CSV with ``date,service,count`` columns."""
|
|
33
|
+
return _read_records(path, AttendanceRecord.from_row)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def read_giving(path: str | Path) -> list[GivingRecord]:
|
|
37
|
+
"""Load giving records from a CSV with ``date,member_id,amount[,fund,method]``."""
|
|
38
|
+
return _read_records(path, GivingRecord.from_row)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def read_members(path: str | Path) -> list[Member]:
|
|
42
|
+
"""Load members from a CSV with ``member_id,join_date[,status,left_date]``."""
|
|
43
|
+
return _read_records(path, Member.from_row)
|
provost/membership.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Membership lifecycle analytics.
|
|
2
|
+
|
|
3
|
+
Works out active headcount, new joiners, leavers and simple retention from a
|
|
4
|
+
list of :class:`~provost.models.Member` records.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from datetime import date
|
|
10
|
+
from typing import Sequence
|
|
11
|
+
|
|
12
|
+
from .models import Member
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def active_members(members: Sequence[Member], as_of: date | None = None) -> list[Member]:
|
|
16
|
+
"""Members who had joined by ``as_of`` and had not left by then.
|
|
17
|
+
|
|
18
|
+
``as_of`` defaults to the latest join or leave date found in the data, so
|
|
19
|
+
the function is deterministic and never reads the system clock.
|
|
20
|
+
"""
|
|
21
|
+
if as_of is None:
|
|
22
|
+
as_of = _latest_date(members)
|
|
23
|
+
if as_of is None:
|
|
24
|
+
return []
|
|
25
|
+
return [
|
|
26
|
+
member
|
|
27
|
+
for member in members
|
|
28
|
+
if member.join_date <= as_of
|
|
29
|
+
and (member.left_date is None or member.left_date > as_of)
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def new_members(members: Sequence[Member], start: date, end: date) -> list[Member]:
|
|
34
|
+
"""Members who joined within the inclusive ``[start, end]`` window."""
|
|
35
|
+
return [m for m in members if start <= m.join_date <= end]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def leavers(members: Sequence[Member], start: date, end: date) -> list[Member]:
|
|
39
|
+
"""Members who left within the inclusive ``[start, end]`` window."""
|
|
40
|
+
return [
|
|
41
|
+
m for m in members if m.left_date is not None and start <= m.left_date <= end
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def net_growth(members: Sequence[Member], start: date, end: date) -> int:
|
|
46
|
+
"""Joiners minus leavers over the inclusive ``[start, end]`` window."""
|
|
47
|
+
return len(new_members(members, start, end)) - len(leavers(members, start, end))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def retention_rate(members: Sequence[Member], start: date, end: date) -> float:
|
|
51
|
+
"""Fraction of members active at ``start`` who are still active at ``end``.
|
|
52
|
+
|
|
53
|
+
Returns ``0.0`` when nobody was active at ``start``.
|
|
54
|
+
"""
|
|
55
|
+
active_at_start = active_members(members, start)
|
|
56
|
+
if not active_at_start:
|
|
57
|
+
return 0.0
|
|
58
|
+
ids_at_start = {m.member_id for m in active_at_start}
|
|
59
|
+
still_active = {m.member_id for m in active_members(members, end)}
|
|
60
|
+
retained = ids_at_start & still_active
|
|
61
|
+
return len(retained) / len(ids_at_start)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _latest_date(members: Sequence[Member]) -> date | None:
|
|
65
|
+
dates: list[date] = []
|
|
66
|
+
for member in members:
|
|
67
|
+
dates.append(member.join_date)
|
|
68
|
+
if member.left_date is not None:
|
|
69
|
+
dates.append(member.left_date)
|
|
70
|
+
return max(dates) if dates else None
|
provost/metrics.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""General-purpose numeric helpers used across provost.
|
|
2
|
+
|
|
3
|
+
Everything here operates on plain Python numbers and lists using only the
|
|
4
|
+
standard library, so the results are easy to audit and there are no hidden
|
|
5
|
+
side effects.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import statistics
|
|
11
|
+
from typing import Iterable, Sequence
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def moving_average(values: Sequence[float], window: int) -> list[float]:
|
|
15
|
+
"""Return the simple moving average of ``values``.
|
|
16
|
+
|
|
17
|
+
The output has ``len(values) - window + 1`` elements. Raises
|
|
18
|
+
``ValueError`` if ``window`` is smaller than 1 or larger than the number
|
|
19
|
+
of values supplied.
|
|
20
|
+
"""
|
|
21
|
+
if window < 1:
|
|
22
|
+
raise ValueError("window must be >= 1")
|
|
23
|
+
if window > len(values):
|
|
24
|
+
raise ValueError("window is larger than the number of values")
|
|
25
|
+
result: list[float] = []
|
|
26
|
+
running = sum(values[:window])
|
|
27
|
+
result.append(running / window)
|
|
28
|
+
for i in range(window, len(values)):
|
|
29
|
+
running += values[i] - values[i - window]
|
|
30
|
+
result.append(running / window)
|
|
31
|
+
return result
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def growth_rate(previous: float, current: float) -> float:
|
|
35
|
+
"""Fractional growth from ``previous`` to ``current``.
|
|
36
|
+
|
|
37
|
+
Returns e.g. ``0.1`` for a 10% increase. Raises ``ValueError`` if
|
|
38
|
+
``previous`` is zero, where a growth rate is undefined.
|
|
39
|
+
"""
|
|
40
|
+
if previous == 0:
|
|
41
|
+
raise ValueError("growth rate is undefined when previous is zero")
|
|
42
|
+
return (current - previous) / previous
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def cagr(begin_value: float, end_value: float, periods: float) -> float:
|
|
46
|
+
"""Compound annual (or per-period) growth rate.
|
|
47
|
+
|
|
48
|
+
``periods`` is the number of periods between the two values.
|
|
49
|
+
"""
|
|
50
|
+
if begin_value <= 0:
|
|
51
|
+
raise ValueError("begin_value must be positive")
|
|
52
|
+
if periods <= 0:
|
|
53
|
+
raise ValueError("periods must be positive")
|
|
54
|
+
return (end_value / begin_value) ** (1 / periods) - 1
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def percentile(values: Sequence[float], p: float) -> float:
|
|
58
|
+
"""Linear-interpolation percentile, with ``p`` in the range [0, 100]."""
|
|
59
|
+
if not values:
|
|
60
|
+
raise ValueError("cannot compute a percentile of no values")
|
|
61
|
+
if not 0 <= p <= 100:
|
|
62
|
+
raise ValueError("p must be between 0 and 100")
|
|
63
|
+
ordered = sorted(values)
|
|
64
|
+
if len(ordered) == 1:
|
|
65
|
+
return float(ordered[0])
|
|
66
|
+
rank = (p / 100) * (len(ordered) - 1)
|
|
67
|
+
low = int(rank)
|
|
68
|
+
high = min(low + 1, len(ordered) - 1)
|
|
69
|
+
frac = rank - low
|
|
70
|
+
return ordered[low] + (ordered[high] - ordered[low]) * frac
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def summarize(values: Iterable[float]) -> dict[str, float]:
|
|
74
|
+
"""Return a small dictionary of descriptive statistics.
|
|
75
|
+
|
|
76
|
+
Keys: ``count``, ``sum``, ``mean``, ``median``, ``min``, ``max`` and
|
|
77
|
+
``stdev`` (population-sample standard deviation, ``0.0`` for a single
|
|
78
|
+
value).
|
|
79
|
+
"""
|
|
80
|
+
data = list(values)
|
|
81
|
+
if not data:
|
|
82
|
+
raise ValueError("cannot summarize an empty sequence")
|
|
83
|
+
return {
|
|
84
|
+
"count": float(len(data)),
|
|
85
|
+
"sum": float(sum(data)),
|
|
86
|
+
"mean": statistics.fmean(data),
|
|
87
|
+
"median": statistics.median(data),
|
|
88
|
+
"min": float(min(data)),
|
|
89
|
+
"max": float(max(data)),
|
|
90
|
+
"stdev": statistics.stdev(data) if len(data) > 1 else 0.0,
|
|
91
|
+
}
|
provost/models.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Lightweight record types for the data provost works with.
|
|
2
|
+
|
|
3
|
+
These are plain dataclasses. They carry no behaviour beyond parsing helpers,
|
|
4
|
+
which keeps the data model transparent and trivial to serialise.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from datetime import date, datetime
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def parse_date(value: str | date) -> date:
|
|
14
|
+
"""Parse an ISO ``YYYY-MM-DD`` string (or pass through a ``date``)."""
|
|
15
|
+
if isinstance(value, date):
|
|
16
|
+
return value
|
|
17
|
+
return datetime.strptime(value.strip(), "%Y-%m-%d").date()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class AttendanceRecord:
|
|
22
|
+
"""A count of people attending a single service on a given date."""
|
|
23
|
+
|
|
24
|
+
date: date
|
|
25
|
+
service: str
|
|
26
|
+
count: int
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def from_row(cls, row: dict[str, str]) -> "AttendanceRecord":
|
|
30
|
+
return cls(
|
|
31
|
+
date=parse_date(row["date"]),
|
|
32
|
+
service=row.get("service", "").strip() or "main",
|
|
33
|
+
count=int(row["count"]),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True)
|
|
38
|
+
class GivingRecord:
|
|
39
|
+
"""A single financial gift or contribution."""
|
|
40
|
+
|
|
41
|
+
date: date
|
|
42
|
+
member_id: str
|
|
43
|
+
amount: float
|
|
44
|
+
fund: str = "general"
|
|
45
|
+
method: str = "unspecified"
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_row(cls, row: dict[str, str]) -> "GivingRecord":
|
|
49
|
+
return cls(
|
|
50
|
+
date=parse_date(row["date"]),
|
|
51
|
+
member_id=row["member_id"].strip(),
|
|
52
|
+
amount=float(row["amount"]),
|
|
53
|
+
fund=row.get("fund", "").strip() or "general",
|
|
54
|
+
method=row.get("method", "").strip() or "unspecified",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class Member:
|
|
60
|
+
"""A congregation member and their lifecycle dates."""
|
|
61
|
+
|
|
62
|
+
member_id: str
|
|
63
|
+
join_date: date
|
|
64
|
+
status: str = "active"
|
|
65
|
+
left_date: date | None = None
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def from_row(cls, row: dict[str, str]) -> "Member":
|
|
69
|
+
left = row.get("left_date", "").strip()
|
|
70
|
+
return cls(
|
|
71
|
+
member_id=row["member_id"].strip(),
|
|
72
|
+
join_date=parse_date(row["join_date"]),
|
|
73
|
+
status=row.get("status", "").strip() or "active",
|
|
74
|
+
left_date=parse_date(left) if left else None,
|
|
75
|
+
)
|
provost/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: provost
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple, dependency-free data automation for church administration (attendance, giving and membership analytics).
|
|
5
|
+
Author-email: Martin Gallagher <martinjgallagher@icloud.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MartinGallagher-code/provost
|
|
8
|
+
Project-URL: Repository, https://github.com/MartinGallagher-code/provost
|
|
9
|
+
Project-URL: Documentation, https://github.com/MartinGallagher-code/provost/tree/main/docs
|
|
10
|
+
Project-URL: Issues, https://github.com/MartinGallagher-code/provost/issues
|
|
11
|
+
Keywords: church,congregation,administration,attendance,giving,membership,analytics,csv
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Religion
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Office/Business
|
|
24
|
+
Classifier: Topic :: Religion
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# provost
|
|
38
|
+
|
|
39
|
+
[](https://pypi.org/project/provost/)
|
|
40
|
+
[](https://pypi.org/project/provost/)
|
|
41
|
+
[](https://github.com/MartinGallagher-code/provost/blob/main/LICENSE)
|
|
42
|
+
[](https://github.com/MartinGallagher-code/provost/actions/workflows/ci.yml)
|
|
43
|
+
[](https://pypi.org/project/provost/)
|
|
44
|
+
[](https://pypi.org/project/provost/)
|
|
45
|
+
|
|
46
|
+
**Simple, dependency-free data automation for church administration.**
|
|
47
|
+
|
|
48
|
+
`provost` helps church and congregation administrators turn the CSV exports
|
|
49
|
+
their management software already produces into plain-English summaries:
|
|
50
|
+
attendance trends, giving analytics and membership lifecycle metrics — without
|
|
51
|
+
a spreadsheet wrestling match.
|
|
52
|
+
|
|
53
|
+
The name is a nod to the traditional role of a *provost*: the person who keeps
|
|
54
|
+
the day-to-day administration of a church running.
|
|
55
|
+
|
|
56
|
+
📚 **Full documentation** lives in [`docs/`](docs/index.md) and builds into a
|
|
57
|
+
searchable site with MkDocs (`pip install ".[docs]" && mkdocs serve`).
|
|
58
|
+
|
|
59
|
+
## Why provost?
|
|
60
|
+
|
|
61
|
+
- **No third-party runtime dependencies.** It is built entirely on the Python
|
|
62
|
+
standard library, so it installs instantly and audits easily.
|
|
63
|
+
- **No surprises.** It reads only the CSV files you point it at and writes only
|
|
64
|
+
to stdout. It never touches the network, phones home, collects telemetry, or
|
|
65
|
+
runs anything at install time. What you see in the source is all it does.
|
|
66
|
+
- **Explainable maths.** Every metric is a short, readable function you can
|
|
67
|
+
check yourself. No black boxes.
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install provost
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Python 3.9 or newer.
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
### As a command-line tool
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
provost attendance attendance.csv
|
|
83
|
+
provost giving giving.csv
|
|
84
|
+
provost members members.csv
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Example output:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Attendance summary for attendance.csv
|
|
91
|
+
weeks recorded : 12
|
|
92
|
+
mean / week : 182.5
|
|
93
|
+
median / week : 180.0
|
|
94
|
+
best week : 240
|
|
95
|
+
quietest week : 150
|
|
96
|
+
next-week est. : 188.0
|
|
97
|
+
by year:
|
|
98
|
+
2024: 2190
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### As a library
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from provost import read_attendance, attendance_summary, forecast_next
|
|
105
|
+
|
|
106
|
+
records = read_attendance("attendance.csv")
|
|
107
|
+
print(attendance_summary(records)) # mean, median, min, max, stdev...
|
|
108
|
+
print(forecast_next(records)) # naive next-week estimate
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from provost import read_giving, giving_by_fund, recurring_donors
|
|
113
|
+
|
|
114
|
+
gifts = read_giving("giving.csv")
|
|
115
|
+
print(giving_by_fund(gifts)) # {"general": 12450.0, "building": 3200.0}
|
|
116
|
+
print(recurring_donors(gifts)) # members who gave in 3+ distinct months
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from provost import read_members, active_members, retention_rate
|
|
121
|
+
from datetime import date
|
|
122
|
+
|
|
123
|
+
members = read_members("members.csv")
|
|
124
|
+
print(len(active_members(members)))
|
|
125
|
+
print(retention_rate(members, date(2023, 1, 1), date(2024, 1, 1)))
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Expected CSV formats
|
|
129
|
+
|
|
130
|
+
**Attendance** — `date,service,count` (`service` optional, defaults to `main`):
|
|
131
|
+
|
|
132
|
+
```csv
|
|
133
|
+
date,service,count
|
|
134
|
+
2024-01-07,morning,182
|
|
135
|
+
2024-01-07,evening,64
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Giving** — `date,member_id,amount` (plus optional `fund`, `method`):
|
|
139
|
+
|
|
140
|
+
```csv
|
|
141
|
+
date,member_id,amount,fund,method
|
|
142
|
+
2024-01-07,M001,100.00,general,card
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Members** — `member_id,join_date` (plus optional `status`, `left_date`):
|
|
146
|
+
|
|
147
|
+
```csv
|
|
148
|
+
member_id,join_date,status,left_date
|
|
149
|
+
M001,2019-03-01,active,
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Sample files live in [`examples/`](examples/).
|
|
153
|
+
|
|
154
|
+
## What's included
|
|
155
|
+
|
|
156
|
+
| Module | Highlights |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| `provost.attendance` | weekly totals, rolling average, year-over-year, naive forecast |
|
|
159
|
+
| `provost.giving` | totals, split by fund/member, average gift, recurring donors |
|
|
160
|
+
| `provost.membership` | active members, joiners, leavers, net growth, retention |
|
|
161
|
+
| `provost.metrics` | moving average, growth rate, CAGR, percentile, summary stats |
|
|
162
|
+
| `provost.io` | tolerant CSV loaders with clear per-row error messages |
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pip install -e ".[dev]"
|
|
168
|
+
pytest
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
provost/__init__.py,sha256=rltMOKMr1SvhMUDfnaT2jMaPJnsELYM8jPL4UheBKLI,2037
|
|
2
|
+
provost/__main__.py,sha256=oYuPMJ53ufYd9WR4N02jygHr1bjJ1rQEAiAPGoHdTgQ,116
|
|
3
|
+
provost/attendance.py,sha256=rmXHIkYt8alIfSHgIKXQQTMKDB3hw30u-fYSXNjm-Ms,2629
|
|
4
|
+
provost/cli.py,sha256=q8ojrz7xQq63ZttI89JlfU-peolrvXWndCBwPs0gF3c,3564
|
|
5
|
+
provost/giving.py,sha256=3MaRPHZZ1rGpGdwueSYidu8JEd4wAn0K-jsDiIXCOu0,2507
|
|
6
|
+
provost/io.py,sha256=PaJ-AzavCK3DKMKdO007p6W9aMJEF8XVUJDGILfuqSA,1462
|
|
7
|
+
provost/membership.py,sha256=Sw4Igm351AnmVpfl-9N4DM9PzoGGmT2ff0LsUopJhSM,2415
|
|
8
|
+
provost/metrics.py,sha256=qXhVCPEdZdui3sv8crDSP0y_xtBlMFEazUdn6wudei4,3136
|
|
9
|
+
provost/models.py,sha256=S3U4nk0eodnVMnzUXdGdFivFG0jHoUSlvGn51SUBIHs,2123
|
|
10
|
+
provost/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
provost-0.1.0.dist-info/licenses/LICENSE,sha256=HdV2oyF96eYrFTYdfFqVRHyze9hjI_OIDkmUWBWvj2g,1073
|
|
12
|
+
provost-0.1.0.dist-info/METADATA,sha256=ef2iTyqvvxx_XJrUZYdRmJ8dMNxKAZXKc_L2QNRF3m8,5810
|
|
13
|
+
provost-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
14
|
+
provost-0.1.0.dist-info/entry_points.txt,sha256=PdW3-SZen3G6hZRQwUy7CMu9MxL-CwUZ5TczucaytZo,45
|
|
15
|
+
provost-0.1.0.dist-info/top_level.txt,sha256=clsMcOzC2aBz5acf2S0WBr8JVXKPNR9zEw7cwmYYky0,8
|
|
16
|
+
provost-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Martin Gallagher
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
provost
|