supporters/python
Denver Gingerich 4d3b8b0673 models: flexible returning supporter mth count API
Rename months_expired() to months_expired_at_return() and have the
method return an integer representing the month count rather than an
enum-like so that the API user has more flexibility with respect to
what they then do with the result.  Thanks to Brett for the review
that suggested this, and for much of the clever math in this change.

The results produced by returning_report.py (which is updated here to
use the new API) are almost identical to the results produced before
the change.  In rare cases (about 2-5% of the time) a supporter's
lapsed month count will fall into an adjacent bucket instead of the
one it fell into before, usually because the previous result was wrong
to begin with (due to the ugly days-per-3-months table that we used
previously, which this change thankfully eliminates).
2018-01-25 17:03:09 -05:00
..
supporters models: flexible returning supporter mth count API 2018-01-25 17:03:09 -05:00
load_ledger.py python: Initial documentation. 2017-01-25 15:35:10 -05:00
manage.py python: Start Django project. 2017-01-24 13:31:30 -05:00
README.rst README: Update database migration method for Django 1.10. 2018-01-22 10:15:30 -05:00
returning_report.py models: flexible returning supporter mth count API 2018-01-25 17:03:09 -05:00
status_report.py python models: Add Date.strptime constructor. 2017-02-17 11:41:39 -05:00
TODO.rst python: Initial documentation. 2017-01-25 15:35:10 -05:00

Python Supporter Database
=========================

This directory contains a Python module and set of scripts to load Supporter payment information into a database, and query that information using consistent business logic.

As of today it only imports payment information from Ledger.  It doesn't know about the supplemental Supporter database with contact information, requests, etc.  For that, use the Perl module.

Getting Started
---------------

You'll need Python 3, Django, and Ledger::

  # apt install python3 python3-django ledger

Create the database::

  $ ./manage.py makemigrations supporters
  $ ./manage.py migrate

Load data from Ledger.  Depending on how you've configured Ledger, you may need to tell it where to find the books with Supporter payments.  You can pass additional arguments to configure how the import is done; run the script with the ``--help`` flag for details.  A typical first import looks like::

  $ ./load_ledger.py -- --file /path/to/supporters.ledger

Importing More Data
~~~~~~~~~~~~~~~~~~~

If you run ``load_ledger.py`` multiple times, each run will add the imported transactions to the database each time.  It doesn't know how to import "new" data only yet.

If you can specify what "new" data is with Ledger search criteria, you can use those to add new payments to the database.  For example, if you have all payments through 2016, and now you want to import payments from 2017, you might run::

  $ ./load_ledger.py -- --begin 2017-01-01

If you're unsure, you can just remove the ``db.sqlite3`` file, then recreate the database following the steps in the `Getting Started`_ section.

Reports
-------

Other scripts in this directory generate reports from the payment database.  You can run any script with the ``--help`` flag to learn more about what it does and how to run it.