From e2ceaedb78d2a1f223981640c1a28bf322e8760f Mon Sep 17 00:00:00 2001 From: Justin Kitzes Date: Mon, 12 Nov 2012 21:43:36 -0800 Subject: [PATCH] Notebook to create animal sighting files --- python/make_animals.ipynb | 129 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 python/make_animals.ipynb diff --git a/python/make_animals.ipynb b/python/make_animals.ipynb new file mode 100644 index 0000000..f75a2e8 --- /dev/null +++ b/python/make_animals.ipynb @@ -0,0 +1,129 @@ +{ + "metadata": { + "name": "make_animals" + }, + "nbformat": 2, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": true, + "input": [ + "animals = ('Moose', 'Elk', 'Fox', 'Owl', 'Wolf', 'Muskox', 'Ptarmigan', 'Grizzly', 'Wolverine')" + ], + "language": "python", + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "import datetime as dt", + "import random" + ], + "language": "python", + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "def make_animals(filename, lines=100):", + " date = dt.date(2011, 4, 22)", + " one_day = dt.timedelta(days=1)", + "", + " f = open(filename, 'w')", + "", + " f.write('Date,Time,Animal,Count\\n')", + " for _ in xrange(lines):", + " animal = random.choice(animals)", + " hour = random.randint(0, 23)", + " minute = random.randint(0, 59)", + " number = random.randint(1, 42)", + " ", + " date_str = '{}-{:02d}-{:02d}'.format(date.year, date.month, date.day)", + " ", + " time_str = '{:02d}:{:02d}'.format(hour, minute)", + " ", + " line = '{},{},{},{}\\n'.format(date_str, time_str, animal, number)", + " ", + " f.write(line)", + " ", + " if random.choice((True, False)):", + " date = date + one_day", + " ", + " f.close()" + ], + "language": "python", + "outputs": [], + "prompt_number": 31 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "def make_animals_unstruct(filename, lines=100):", + " date = dt.date(2011, 4, 22)", + " one_day = dt.timedelta(days=1)", + "", + " f = open(filename, 'w')", + "", + " for i in range(lines):", + " animal = random.choice(animals)", + " hour = random.randint(0, 23)", + " minute = random.randint(0, 59)", + " number = random.randint(1, 42)", + " ", + " date_str = '{}-{:02d}-{:02d}'.format(date.year, date.month, date.day)", + " ", + " time_str = '{:02d}:{:02d}'.format(hour, minute)", + " ", + " line = '{} {{\\nDate: {}\\nTime: {}\\nAnimal: {}\\nCount: {}\\n}}\\n\\n'.format(i, date_str, time_str, animal, number)", + " ", + " f.write(line)", + " ", + " if random.choice((True, False)):", + " date = date + one_day", + " ", + " f.close() " + ], + "language": "python", + "outputs": [], + "prompt_number": 32 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "make_animals('sightings_tab_sm.csv', 5)", + "#make_animals_unstruct('sightings_recs_sm.txt', 3)" + ], + "language": "python", + "outputs": [], + "prompt_number": 33 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "make_animals('sightings_tab_lg.csv', 200)", + "make_animals_unstruct('sightings_recs_lg.txt', 200)" + ], + "language": "python", + "outputs": [], + "prompt_number": 34 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "outputs": [] + } + ] + } + ] +} \ No newline at end of file -- 2.26.2