#!/usr/bin/python
# coding: utf-8
#
# Recount, copyright (c) 2016 Nick Montfort <nickm@nickm.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and
# this notice are preserved. This file is offered as-is, without any warranty.
#
# 24 November 2016
#
# Updated 31 May 2018, changed "print" for Python 2 & 3 compatibility

from random import random, choice, seed

def person():
    n = random()
    if n < .495:
        return ('woman', 'her', 'she')
    if n < .97:
        return ('man', 'his', 'he')
    return ('person not of binary gender', 'their', 'they')

def voted():
    n = random()
    if n < .581:
        return 'voted for ' + vote() + ' for president,'
    else:
        return choice(['decided not to vote,',
              'who was eligible to vote simply didn\'t,',
              'couldn\'t find the time to vote,'])

def vote():
    n = random()
    if n < .455:
        return 'Hillary Clinton'
    if n < .877:
        return 'Donald Trump'
    if n < .924:
        return 'Gary Johnson'
    if n < .943:
        return 'Jill Stein'
    return 'a write-in candidate or no candidate'

def occupation(possessive, subject):
    n = random()
    if n < 9157.5 / 150539.9:
        return 'to ' + possessive + ' corner office and PERT chart'
    if n < 16722.8 / 150539.9:
        return 'to ' + possessive + ' office and spreadsheet'
    if n < 20791.1 / 150539.9:
        return 'to ' + possessive + ' cubicle, ' + possessive + \
        ' code, and all the formulae'
    if n < 23323.8 / 150539.9:
        return choice(['to the office and ' + possessive + ' CAD plans',
        'to the job site, looking over the work being done'])
    if n < 24634.2 / 150539.9:
        return 'to check on ' + possessive + ' experiment and ' + \
        'related research'
    if n < 27099.9 / 150539.9:
        return 'into the community, to visit ' + possessive + ' clients'
    if n < 28368.1 / 150539.9:
        return 'to the law office' + choice(['', '', '', '', '',
               ', and from there to visit a client in jail'])
    if n < 37584.2 / 150539.9:
        return 'to get more materials ready, so that people could ' + \
        'learn from them and use them for study and research'
    if n < 40208.4 / 150539.9:
        return 'to ' + choice(['a coffeehouse to write',
                      possessive + ' studio, to make some more artwork',
                      'the design firm', 'the recording studio',
                      'get ready for tonight\'s game',
                      'the sound stage',
                      'another media-industry meeting'])
    if n < 52682.9 / 150539.9:
        return 'to ' + choice(['the clinic', 'the medical office',
                      'the pharmacy', 'the medical supply store',
                      'the hospital', 'the hospital', 'the hospital'])
    if n < 56126.7 / 150539.9:
        return 'to ' + choice(['the police station',
                      'the security desk', 'the fire station',
                      possessive + ' beat', possessive + ' post',
                      'the military base where ' + subject + \
                      ' was posted'])
    if n < 77594.3 / 150539.9:
        return choice(['to the restaurant and into the kitchen',
                    'to staff the bar',
                    'to the food court and put on a uniform',
                    'to the restaurant to wait on tables',
                    'to the restaurant to bus tables',
                    'to serve coffee'])
    if n < 83211.5 / 150539.9:
        return choice(['to cultivate ' + possessive + \
              ' employer\'s garden', 'to mow the property\'s lawns',
              'to clean the building',
              'to get the trash emptied and taken out'])
    if n < 89217.6 / 150539.9:
        return 'to ' + choice(['the funeral home', 'the salon',
                      'the travel office', 'the gym', 'the resort',
                      'the hotel', 'the motel', 'the tour bus',
                      'the dressing room'])
    if n < 104640.7 / 150539.9:
        return 'to ' + choice(['the shop', 'the store', 'the store',
                      'the boutique', 'the big box store',
                      'the dealership', 'the gallery'])
    if n < 127406.8 / 150539.9:
        return 'to the office'
    if n < 128378.9 / 150539.9:
        return choice(['to the farm', 'to ' + possessive + ' boat',
               'for a day of logging', 'to the farm', 'to the farm'])
    if n < 134880.6 / 150539.9:
        return 'to ' + possessive + ' construction site, in this ' + \
               'case ' + choice(['a massive infrastructural project',
               'a house in a development','an office building',
               'a residential housing project','a high rise building',
               'a new roadway', 'a public building'])
    if n < 140561.1 / 150539.9:
        return 'to ' + possessive + ' truck' + \
               choice([', and then on to a job in a nearby building',
                       ', to wait on call',
                       ', and then on to make repairs'])
    if n < 149791.4 / 150539.9:
        return 'to ' + choice(['the plant', 'the factory'])
    return 'to ' + possessive + ' rig, and kept on'

def returned(possessive, subject):
    n = random()
    if n < .3:
        return choice(['home, to keep on cleaning',
              'home, to watch television',
              'home, to relax',
              'home, to try to get organized',
              'home, to check out the Internet',
              'home, to pursue ' + possessive + ' hobbies',
              'to the retirement home'])
    if n < .35:
        return choice(['to campus and to the weekly schedule',
              'to get some studying done before class',
              'to complete a project for class'])
    return occupation(possessive, subject)

seed(1776)
text = """
# Recount


## Thanksgiving, 2016

## Nick Montfort

See Random Poetry, Michael Murin, 1989, in Slovak, programmed in MUMPS

Also censusAmericans, Jia Zhang, 2015, a Twitter bot (@censusAmericans)

"""
for i in range(300):
    text += '\t'
    for j in range(10):
        noun, possessive, subject = person()
        text += 'A ' + noun + ' ' + voted() + \
        ' and then went back ' + returned(possessive, subject) + '. '
    text += '\n'
print(text)
