Skip to content
Code from the book Fighting Churn With Data
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is code for the (forthcoming) book "Fighting Churn With Data: The Subscribed Institute Guide to Data Driven Customer Engagement". See for more information.

Getting Started


  • Python 3 and the required packages (requirements.txt)
  • Postgres

Python 3

If you need help installing Python 3, you can refer to this page for Mac:

(If you are on linux I'm going to assume you know how to install your own python...)


To install Postgres for Mac following these instructions:

I also recommend installing installing pgAdmin to make it easier to import and export data, and run adhoc queries.
Follow the instructions here:


You will need to create a schema with the tables in the schema folder - you can use any tool or method you prefer. After that you need to load subscription and event data into those tables. For details on the subscription data see the blog posts on for more information:

Running the Code

Generating Artificial Data

Code for generating artificial data to run the code is in the directory data-generation. Details to come...

Book Examples

You can run the book examples with the project under examples.


Currently everything is hard coded. If you want to run just one example or chapter you can uncomment the variables one_chapter and/or one_example. Command line parameters coming soon...

Metric Calculation

First you need to configure some metrics specifically for your event data in a configuration file for your schema. See the examples metric-example/conf/x_metrics.json where the "x" is replaced with your schema name. Then running in the metric-framework folder will 1) truncate the metrics in the metric table and 2) insert new metrics defined by whatever is in the file metric-example/conf/yourschema_metrics.json.

Currently everything is hard coded, so you must set the postgres connection string, the schema, and date range in the file.


If you want to run just one metric you can uncomment the variable one_metric. Note that when running one metric currently you need to take care of deleting values yourself (if you find yourself running the same metric again after changes.)

Command line parameters coming soon...

Event QA

Details coming soon...


Metric QA

Details coming soon...




This project is licensed under the MIT License - see the file for details


  • Coming soon
You can’t perform that action at this time.