Skip to main content

Python Gift Exchange Picker

Project description

Python Gift Exchange Picker

The Rest by taleas.com

My wife is in charge of our families' annual Secret Santa Gift Exchange. Because she, unfortunately, knows about my background in math and computer science her requirements have become more extreme. A hat containing folded pieces of paper with hand-written names is no longer sufficient. Python Gift Exchange Picker (pyge) is my third and best implementation of my wife's requirements:

  • It must match each person to a different person.
  • The match should not be in the same household.
  • The match should not be the same gender.
  • The match should not be in the same age group.
  • The match must not happen again for at least three years.

To accomplish this, pyge imports a list of participants along with their feature sets and transforms each participant's feature set into numerical values. Each value is then vectorized and a pairwise euclidean distance between each participant is computed; this can be represented as either a graph or a matrix - I chose a matrix. The distances are then multiplied by a per-participant "qualifier" coefficient and the results are used to build a weighted distribution. The pairs of participants are then randomly matched using the weighted distribution until either all participants have been matched or no matches can be made. If no matches can be made and there are still participants pyge will backtrack until all participants can be successfully matched or it is discovered that it is impossible to match the given set of participants.

If you're interested, you can read a more detailed description here.

Installation

pip install pyge

Basic Usage

Pyge has only one required argument: the path to a csv file containing the people who are participating in the gift exchange. An example csv file, jazz.csv has been provided.

$ pyge /path/to/jazz.csv
Herbie Hancock, Billie Holiday
Ella Fitzgerald, Herbie Hancock
Charlie Parker, Nina Simone
Nina Simone, Bill Evans
Miles Davis, Duke Ellington
John Coltrane, Sarah Vaughan
Sarah Vaughan, Louis Armstrong
Louis Armstrong, Ella Fitzgerald
Billie Holiday, Charlie Parker
Duke Ellington, John Coltrane
Dizzy Gillespie, Miles Davis
Bill Evans, Dizzy Gillespie

Input CSV File Format

name, date of birth, sex, "city, state or province or territory"

Any column containing a comma should be quoted with double-quotes, for example, "Austin, TX".

The Date of Birth field is in MM/DD/YYYY format.

Sex can be M, F or N.

City by default only includes cities in the United States. See Using Other Country Databases for more information on changing the country.

Saving History

Pyge saves a historical list of pairings which is used to ensure participants will not be paired for at a minimum of three exchanges. Saving history can be toggled with the --save-history and --no-history flags. The minimum number of exchanges can be modified with the --history-length argument.

Using Other Country Databases

You can pass a different city weight database file by using the --citydb argument. The city weight database is a csv file in the following format:

city, state or province or territory, normalized latitude, normalized longitude

Where normalized latitude and longitude are the values normalized between -1 and +1 (divided by 180).

Full Usage

usage: pyge [-h] [-s] [-n] [-c citydb] [-l historylength] file

Generates a list of people pairings for a holiday gift exchange.

positional arguments:
  file                  path to the csv containing a list of people who want
                        to be part of the celebration

optional arguments:
  -h, --help            show this help message and exit
  -s, --save-history    save a history file of matches
  -n, --no-history      do not save a history file of matches
  -c citydb, --citydb citydb
                        path to city csv for distance calculations
  -l historylength, --history-length historylength
                        number of cycles before people can be paired again

Cities database provided by https://simplemaps.com/data/us-cities.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyge-1.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

pyge-1.0.2-py3-none-any.whl (389.6 kB view details)

Uploaded Python 3

File details

Details for the file pyge-1.0.2.tar.gz.

File metadata

  • Download URL: pyge-1.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for pyge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1eee23167dc9af1a17ec3615ffafd2e029316e54dbe6b757819e8cc877799b7c
MD5 0fe4978b238f34211a99d2b6d22a130f
BLAKE2b-256 08f6d5c34001f2d5e5a19e9c31db74f5bb7b4f6cc9eb6e2163b5e53ac9bfea59

See more details on using hashes here.

File details

Details for the file pyge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 389.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for pyge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9274c5ae9bc9db3bf7fd34387b20a8c96f0cb95e4adb94007d817eefe82f3229
MD5 b0c7e610da107edd35432c42db7a4e7f
BLAKE2b-256 0781e7695f4de23af366651e6f794e2552b0018999d2ac8482d2926d006cc06f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page