Last active
January 22, 2020 04:21
-
-
Save eddieantonio/b754b398f53ac82727f840f0f2099385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: UTF-8 -*- | |
""" | |
Creates (dumb) rainfall data. | |
Usage: | |
python3 create-data.py > rainfall.txt | |
""" | |
from random import choice, gauss, random, shuffle | |
MAX_CITIES = 100 | |
suffixes = ["town", "ville", "ton", "burg", " City"] | |
prefixes = ["New ", "The ", "St. ", "Santa ", "San "] | |
with open("/usr/share/dict/words", encoding="UTF-8") as f: | |
words = f.read().splitlines() | |
shuffle(words) | |
words = words[:MAX_CITIES] | |
for word in words: | |
city = word.capitalize() | |
if choice((True, False)): | |
decay = 1.0 | |
if random() < 0.50: | |
city = city + choice(suffixes) | |
decaye = 0.25 | |
if random() * decay < 0.50: | |
city = choice(prefixes) + city | |
rainfall = gauss(75.0, 10.0) | |
print(f"{city}\t{rainfall:1.2f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[50-60) | |
SAN CLAYEN 55.93 | |
SANTA BESPRENT 55.95 | |
THE LYMPHATION 58.41 | |
KERRITE 59.24 | |
NONRETENTION 59.87 | |
[60-70) | |
ST. ORTHOGRAPH 63.03 | |
PLAGIOCLASITE 63.46 | |
ST. ACER 63.89 | |
NOTIFY 64.10 | |
SWORDSMITH 65.75 | |
SAN TEMPOROSPHENOID 65.84 | |
ZYGOBRANCHIA 66.10 | |
MONATOMICITY 66.39 | |
VARIEGATION 67.02 | |
PRESOCIAL 68.03 | |
UNDISROBED 68.45 | |
AMPHODIPLOPIA CITY 69.80 | |
[70-80) | |
HOMOTYPICAL 70.13 | |
ST. MARSHALVILLE 70.76 | |
ENCRIMSON 70.83 | |
SANTA TWAETOWN 70.88 | |
ST. AXSTONETON 71.08 | |
ST. SINOGRAM 71.46 | |
SOTNIA 71.62 | |
UPAS 74.05 | |
ST. LARYNGOPHARYNGITIS 74.22 | |
DAYSTREAK 76.41 | |
LACTARIUSVILLE 76.82 | |
LABARA 77.09 | |
NUTCRACKER 77.19 | |
SEPIUM 77.29 | |
EPIPLASMIC 78.68 | |
[80-90) | |
ST. ASPARAGUSVILLE 80.74 | |
SAN OWENITEVILLE 81.45 | |
CYCLOHEXANOL 81.82 | |
SEPTIFOLIOUSBURG 81.89 | |
BASIOPHTHALMITE 82.13 | |
IDGAH 82.74 | |
DECANT 82.93 | |
REDOUBTABLY 84.06 | |
THE PENNYWINKLETOWN 84.90 | |
ST. CHAOTICNESS 85.93 | |
THE BRAKELESS 87.28 | |
PRIAPULIDAE 87.83 | |
PYTHIUSTON 87.96 | |
SPORTFULNESS 88.10 | |
SANTA ICHTHYOIDTON 89.02 | |
THE PRECOMPOSEBURG 89.10 | |
[90-100) | |
OUTCUT 93.43 | |
[100-110) | |
THE CATECHISTICAL 100.61 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: UTF-8 -*- | |
from collections import defaultdict | |
# Read the rainfall. | |
with open("rainfall.tsv", "r", encoding="UTF-8") as rainfall_file: | |
rainfall_contents = rainfall_file.read() | |
# Populate the rainfall dictionary | |
rainfall = {} | |
for line in rainfall_contents.splitlines(): | |
city, rain_str = line.split("\t") | |
rainfall[city] = float(rain_str) | |
# Figure out which cities go in what intervals | |
intervals = defaultdict(list) | |
for city, avg_rain in rainfall.items(): | |
# Figure out the lower bound: | |
# * Integer divide it by 10 to get drop the last digit, and everything | |
# after the decimal point, | |
# * then multiply it by 10 again to get it back to scale. | |
lower_bound = int(avg_rain // 10) * 10 | |
upper_bound = lower_bound + 10 | |
intervals[lower_bound, upper_bound].append(city) | |
def by_average_rainfall(city_name): | |
"Returns the rainfall of a city. Use this as a sort key." | |
return rainfall[city_name] | |
# Print the results, by interval. | |
for lower_bound, upper_bound in sorted(intervals): | |
cities = intervals[lower_bound, upper_bound] | |
cities.sort(key=by_average_rainfall) | |
print(f"[{lower_bound}-{upper_bound})") | |
for city in cities: | |
display_name = city.upper() | |
avg_rain = rainfall[city] | |
print(f"{display_name:^50s} {avg_rain:3.2f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Homotypical | 70.13 | |
---|---|---|
Epiplasmic | 78.68 | |
Kerrite | 59.24 | |
Santa Besprent | 55.95 | |
St. Marshalville | 70.76 | |
St. Orthograph | 63.03 | |
Idgah | 82.74 | |
The Precomposeburg | 89.10 | |
Sportfulness | 88.10 | |
Plagioclasite | 63.46 | |
Nutcracker | 77.19 | |
The Lymphation | 58.41 | |
Cyclohexanol | 81.82 | |
St. Axstoneton | 71.08 | |
St. Laryngopharyngitis | 74.22 | |
Upas | 74.05 | |
The Catechistical | 100.61 | |
The Brakeless | 87.28 | |
Priapulidae | 87.83 | |
Daystreak | 76.41 | |
San Oweniteville | 81.45 | |
Lactariusville | 76.82 | |
San Clayen | 55.93 | |
Labara | 77.09 | |
Decant | 82.93 | |
Santa Ichthyoidton | 89.02 | |
Nonretention | 59.87 | |
Presocial | 68.03 | |
Variegation | 67.02 | |
Basiophthalmite | 82.13 | |
Swordsmith | 65.75 | |
Zygobranchia | 66.10 | |
Undisrobed | 68.45 | |
Outcut | 93.43 | |
San Temporosphenoid | 65.84 | |
Sepium | 77.29 | |
Notify | 64.10 | |
St. Asparagusville | 80.74 | |
Santa Twaetown | 70.88 | |
St. Sinogram | 71.46 | |
Redoubtably | 84.06 | |
Encrimson | 70.83 | |
St. Acer | 63.89 | |
St. Chaoticness | 85.93 | |
Septifoliousburg | 81.89 | |
The Pennywinkletown | 84.90 | |
Sotnia | 71.62 | |
Monatomicity | 66.39 | |
Amphodiplopia City | 69.80 | |
Pythiuston | 87.96 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
homotypical | |
epiplasmic | |
kerrite | |
besprent | |
marshal | |
orthograph | |
idgah | |
precompose | |
sportfulness | |
plagioclasite | |
nutcracker | |
lymphation | |
cyclohexanol | |
axstone | |
laryngopharyngitis | |
upas | |
catechistical | |
brakeless | |
Priapulidae | |
daystreak | |
Owenite | |
Lactarius | |
clayen | |
labara | |
decant | |
ichthyoid | |
nonretention | |
presocial | |
variegation | |
basiophthalmite | |
swordsmith | |
Zygobranchia | |
undisrobed | |
outcut | |
temporosphenoid | |
sepium | |
notify | |
asparagus | |
twae | |
Sinogram | |
redoubtably | |
encrimson | |
Acer | |
chaoticness | |
septifolious | |
pennywinkle | |
sotnia | |
monatomicity | |
amphodiplopia | |
Pythius |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment