{ "cells": [ { "cell_type": "code", "execution_count": 45, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import random\n", "import re\n", "import uuid" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def cap_after_hyphen(string):\n", " return re.sub(r'\\-(?P[a-z])', \n", " lambda m: '-' + m.group('first').upper(), \n", " string) " ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Aalborg',\n", " 'Nullarbor',\n", " 'Morgantown',\n", " 'Estacada',\n", " 'Almaty',\n", " 'Tambon-Pa-Fa',\n", " 'Lemnos',\n", " 'Sofia',\n", " 'Puente-Laguna-Garzonkuala-Penyu',\n", " 'Hajnowski',\n", " 'Karlukovo',\n", " 'Mamula',\n", " 'Stonington-Island',\n", " 'Grimsey-Island',\n", " 'Uzupis',\n", " 'Sukhumi',\n", " 'Ijsseloog',\n", " 'Giessenmestia',\n", " 'Nordkapp',\n", " 'Gorongosa',\n", " 'Brorfelde',\n", " 'Parowan',\n", " 'Tubakuba',\n", " 'Geoje-Si',\n", " 'Mora',\n", " 'Holmegaard',\n", " 'Jayuya',\n", " 'Zhangye-Shi',\n", " 'Luoyang']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "destination_names = ('Aalborg Nullarbor MORGANTOWN ESTACADA ALMATY TAMBON-PA-FA Lemnos Sofia Puente-Laguna-Garzon' +\n", "'KUALA-PENYU HAJNOWSKI KARLUKOVO Mamula STONINGTON-ISLAND Grimsey-Island Uzupis SUKHUMI IJsseloog GIESSEN' +\n", "'MESTIA NORDKAPP GORONGOSA Brorfelde PAROWAN Tubakuba GEOJE-SI MORA HOLMEGAARD JAYUYA ZHANGYE-SHI LUOYANG')\n", "destination_names = destination_names.lower().split()\n", "destination_names = [n[0].upper() + n[1:] for n in destination_names]\n", "destination_names = [cap_after_hyphen(n) for n in destination_names]\n", "\n", "destination_names" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Aalborg': 1,\n", " 'Almaty': 1,\n", " 'Brorfelde': 1,\n", " 'Estacada': 1,\n", " 'Geoje-Si': 1,\n", " 'Giessenmestia': 1,\n", " 'Gorongosa': 1,\n", " 'Grimsey-Island': 1,\n", " 'Hajnowski': 1,\n", " 'Holmegaard': 1,\n", " 'Ijsseloog': 1,\n", " 'Jayuya': 1,\n", " 'Karlukovo': 1,\n", " 'Lemnos': 1,\n", " 'Luoyang': 1,\n", " 'Mamula': 1,\n", " 'Mora': 1,\n", " 'Morgantown': 1,\n", " 'Nordkapp': 1,\n", " 'Nullarbor': 1,\n", " 'Parowan': 1,\n", " 'Puente-Laguna-Garzonkuala-Penyu': 1,\n", " 'Sofia': 1,\n", " 'Stonington-Island': 1,\n", " 'Sukhumi': 1,\n", " 'Tambon-Pa-Fa': 1,\n", " 'Tubakuba': 1,\n", " 'Uzupis': 1,\n", " 'Zhangye-Shi': 1}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "destination_scores = {n: 1 for n in destination_names}\n", "destination_scores" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Aalborg': 1,\n", " 'Almaty': 2.0,\n", " 'Brorfelde': 0.9,\n", " 'Estacada': 0.4,\n", " 'Geoje-Si': 1,\n", " 'Giessenmestia': 1,\n", " 'Gorongosa': 1,\n", " 'Grimsey-Island': 1,\n", " 'Hajnowski': 1,\n", " 'Holmegaard': 1,\n", " 'Ijsseloog': 1,\n", " 'Jayuya': 0.6,\n", " 'Karlukovo': 2.2,\n", " 'Lemnos': 1,\n", " 'Luoyang': 1,\n", " 'Mamula': 1,\n", " 'Mora': 1,\n", " 'Morgantown': 2.9,\n", " 'Nordkapp': 1.5,\n", " 'Nullarbor': 2.2,\n", " 'Parowan': 1,\n", " 'Puente-Laguna-Garzonkuala-Penyu': 0.4,\n", " 'Sofia': 1,\n", " 'Stonington-Island': 1,\n", " 'Sukhumi': 1,\n", " 'Tambon-Pa-Fa': 1,\n", " 'Tubakuba': 1,\n", " 'Uzupis': 0.9,\n", " 'Zhangye-Shi': 1}" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "adjust = random.sample(destination_names, 10)\n", "inc_names = adjust[:5]\n", "dec_names = adjust[5:]\n", "for n in inc_names:\n", " destination_scores[n] = float(random.randint(11, 30)) / 10\n", "for n in dec_names:\n", " destination_scores[n] = float(random.randint(3, 9)) / 10 \n", "destination_scores" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": true }, "outputs": [], "source": [ "destination_scores = {'Aalborg': 1, 'Almaty': 2.0, 'Brorfelde': 0.9, 'Estacada': 0.4, 'Geoje-Si': 1,\n", " 'Giessenmestia': 1, 'Gorongosa': 1, 'Grimsey-Island': 1, 'Hajnowski': 1, 'Holmegaard': 1, 'Ijsseloog': 1,\n", " 'Jayuya': 0.6, 'Karlukovo': 2.2, 'Lemnos': 1, 'Luoyang': 1, 'Mamula': 1, 'Mora': 1, 'Morgantown': 2.9,\n", " 'Nordkapp': 1.5, 'Nullarbor': 2.2, 'Parowan': 1, 'Puente-Laguna-Garzonkuala-Penyu': 0.4, 'Sofia': 1,\n", " 'Stonington-Island': 1, 'Sukhumi': 1, 'Tambon-Pa-Fa': 1, 'Tubakuba': 1, 'Uzupis': 0.9, 'Zhangye-Shi': 1}" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "collapsed": true }, "outputs": [], "source": [ "destination_score_exceptions = {'Almaty': 2.0, 'Brorfelde': 0.9, 'Estacada': 0.4, 'Jayuya': 0.6, 'Karlukovo': 2.2, 'Morgantown': 2.9,\n", " 'Nordkapp': 1.5, 'Nullarbor': 2.2, 'Puente-Laguna-Garzonkuala-Penyu': 0.4, 'Uzupis': 0.9}" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "| Destination | Score |\n", "|-------------|-------|\n", "| Almaty | 2.0 |\n", "| Brorfelde | 0.9 |\n", "| Estacada | 0.4 |\n", "| Jayuya | 0.6 |\n", "| Karlukovo | 2.2 |\n", "| Morgantown | 2.9 |\n", "| Nordkapp | 1.5 |\n", "| Nullarbor | 2.2 |\n", "| Puente-Laguna-Garzonkuala-Penyu | 0.4 |\n", "| Uzupis | 0.9 |\n" ] } ], "source": [ "print('| Destination | Score |')\n", "print('|-------------|-------|')\n", "for n in sorted(destination_scores):\n", " if destination_scores[n] != 1:\n", " print('|', n, '|', destination_scores[n], '|')" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def make_holiday(name=None):\n", " if not name:\n", " name = random.choice(destination_names)\n", " days = random.choice([3, 7, 7, 7, 10, 14, 14, 14, 14, 21, 21])\n", " price = 0\n", " for _ in range(4):\n", " price += random.randint(100, 500)\n", " hol_id = str(uuid.uuid4())\n", " return hol_id, price, name, days" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('4615dad7-f5ab-4c9b-8028-b3e5c676ff24', 1046, 'Almaty', 14)" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_holiday()" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('3c425201-5538-4a3f-bfd7-1219137c9d63', 1147, 'Aalborg', 21),\n", " ('5913e357-dc18-49c5-850d-aa0172041cc4', 1398, 'Nullarbor', 3),\n", " ('bc966859-49ad-4c26-b36e-94251b0a29b5', 1064, 'Morgantown', 7),\n", " ('ab1d0a54-41bc-4351-beb8-f6e5fd4f07f0', 1722, 'Estacada', 14),\n", " ('b5efba4e-373d-4a15-b048-8fcb3169c441', 1132, 'Almaty', 7),\n", " ('bd1ff2b9-5b97-4a13-9d8a-601faea40e9c', 1085, 'Tambon-Pa-Fa', 14),\n", " ('5b9df004-a8b7-4c28-a27e-21e24cd566b5', 1264, 'Lemnos', 7),\n", " ('5951de60-9e98-471f-a917-74e3c8a3457a', 938, 'Sofia', 14),\n", " ('c6a4cad7-cd9a-4e05-bd16-92305c933269',\n", " 922,\n", " 'Puente-Laguna-Garzonkuala-Penyu',\n", " 14),\n", " ('9527ee0b-4bcd-4a1f-95fd-b3a627eacf02', 1071, 'Hajnowski', 14),\n", " ('82b6adfb-f09d-420f-bbf9-ea90450d21f6', 734, 'Karlukovo', 3),\n", " ('7b08192c-5e30-45dc-bb31-2da61861c0ac', 1692, 'Mamula', 21),\n", " ('5abbe3e4-7d2e-404c-9ce2-27083f95c140', 1277, 'Stonington-Island', 7),\n", " ('b3f517ca-2a07-427d-8531-81227468b611', 1280, 'Grimsey-Island', 3),\n", " ('f1fa90d2-0f58-480f-80c0-0fddb845b71a', 1225, 'Uzupis', 7),\n", " ('330e4f58-31d2-474f-8e23-654224689a18', 1016, 'Sukhumi', 14),\n", " ('a6837ba1-42aa-488d-b39a-5b49422ce165', 966, 'Ijsseloog', 21),\n", " ('a7e4161a-0435-4915-961e-8c204e527a4b', 1465, 'Giessenmestia', 21),\n", " ('633be2e4-a719-496e-9987-d5ea8b6ab428', 1256, 'Nordkapp', 3),\n", " ('bd83d3e3-6134-4511-918c-a94338ffb0c8', 1508, 'Gorongosa', 7),\n", " ('05ed4593-3582-4fde-8958-a63274507344', 1099, 'Brorfelde', 7),\n", " ('b8361d0a-7f23-4491-9450-c28917807a68', 1364, 'Parowan', 7),\n", " ('dc7f49c2-672e-4abc-a58a-4e8b45e786d7', 1491, 'Tubakuba', 14),\n", " ('b709a89e-e5c5-4a60-97ca-55ad350fa7f1', 1373, 'Geoje-Si', 7),\n", " ('18888ae2-e410-4430-87af-1d07ba9b25bb', 1317, 'Mora', 3),\n", " ('b08ebc25-7d02-4973-8e28-fa3b75ed4e29', 1483, 'Holmegaard', 14),\n", " ('d3519dde-9a15-4982-b1ed-1dd6dbecc2c1', 653, 'Jayuya', 21),\n", " ('fa882848-1787-424a-90c3-8593bb91f174', 1027, 'Zhangye-Shi', 10),\n", " ('21d2fcc8-f528-467d-b0ba-a6748933a4a8', 1261, 'Luoyang', 14)]" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "holidays = []\n", "for n in destination_names:\n", " holidays += [make_holiday(n)]\n", "holidays" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": true }, "outputs": [], "source": [ "for _ in range(95):\n", " holidays += [make_holiday()]" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "random.shuffle(holidays)\n", "with open('01-holidays.txt', 'w') as f:\n", " for hid, price, name, days in holidays:\n", " f.write('{} {} {} {}\\n'.format(hid[-10:], price, name, days))" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['5f12ce1b86', '1192', 'Sukhumi', '14'],\n", " ['0279c8a91b', '1008', 'Estacada', '14'],\n", " ['1faea40e9c', '1085', 'Tambon-Pa-Fa', '14']]" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with open('01-holidays.txt') as f:\n", " hols = [h.split() for h in f.readlines()]\n", "hols[:3]" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "collapsed": true }, "outputs": [], "source": [ "assert len(set(h[0] for h in hols)) == len(hols)" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('6138068a-3c16-4f7f-8dc6-a1199608abc5', 1209, 'Nordkapp', 21),\n", " ('eafb15a4-1839-4fb5-be9b-d8389018bd07', 1052, 'Estacada', 21),\n", " ('ab659b71-347d-45dc-9416-34def36ffc7d', 1514, 'Giessenmestia', 21),\n", " ('bb8d5034-49ce-483d-ab6c-d16caf2584a5', 724, 'Stonington-Island', 14),\n", " ('7476b214-8b55-47f6-833e-dfa487c4270a', 782, 'Geoje-Si', 14),\n", " ('f2ffe169-7cc5-42e1-9b46-8cdb61bb906d', 769, 'Morgantown', 3),\n", " ('2e6a6d6d-6c08-4021-b99f-05202c898b5f', 1184, 'Morgantown', 21)]" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_holidays = []\n", "names = random.sample(destination_score_exceptions.keys(), 2) + random.sample(destination_names, 4)\n", "names += [names[-1]]\n", "example_holidays = [make_holiday(n) for n in names]\n", "example_holidays" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('f2ffe169-7cc5-42e1-9b46-8cdb61bb906d', 769, 'Morgantown', 3),\n", " ('2e6a6d6d-6c08-4021-b99f-05202c898b5f', 1184, 'Morgantown', 21),\n", " ('ab659b71-347d-45dc-9416-34def36ffc7d', 1514, 'Giessenmestia', 21),\n", " ('eafb15a4-1839-4fb5-be9b-d8389018bd07', 1052, 'Estacada', 21),\n", " ('7476b214-8b55-47f6-833e-dfa487c4270a', 782, 'Geoje-Si', 14),\n", " ('bb8d5034-49ce-483d-ab6c-d16caf2584a5', 724, 'Stonington-Island', 14),\n", " ('6138068a-3c16-4f7f-8dc6-a1199608abc5', 1209, 'Nordkapp', 21)]" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.shuffle(example_holidays)\n", "example_holidays" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "collapsed": true }, "outputs": [], "source": [ "example_holidays = [('f2ffe169-7cc5-42e1-9b46-8cdb61bb906d', 769, 'Morgantown', 3),\n", " ('2e6a6d6d-6c08-4021-b99f-05202c898b5f', 1284, 'Morgantown', 21),\n", " ('ab659b71-347d-45dc-9416-34def36ffc7d', 1514, 'Giessenmestia', 21),\n", " ('eafb15a4-1839-4fb5-be9b-d8389018bd07', 1052, 'Estacada', 21),\n", " ('7476b214-8b55-47f6-833e-dfa487c4270a', 782, 'Geoje-Si', 14),\n", " ('bb8d5034-49ce-483d-ab6c-d16caf2584a5', 724, 'Stonington-Island', 14),\n", " ('6138068a-3c16-4f7f-8dc6-a1199608abc5', 1209, 'Nordkapp', 21)]" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "db61bb906d 769 Morgantown 3\n", "202c898b5f 1284 Morgantown 21\n", "def36ffc7d 1514 Giessenmestia 21\n", "389018bd07 1052 Estacada 21\n", "a487c4270a 782 Geoje-Si 14\n", "6caf2584a5 724 Stonington-Island 14\n", "199608abc5 1209 Nordkapp 21\n" ] } ], "source": [ "for hid, price, name, days in example_holidays:\n", " print('{} {} {} {}'.format(hid[-10:], price, name, days))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2+" } }, "nbformat": 4, "nbformat_minor": 2 }