Automatically disambiguate location identifiers
authorPetr Viktorin <encukou@gmail.com>
Mon, 11 Apr 2011 21:43:03 +0000 (00:43 +0300)
committerPetr Viktorin <encukou@gmail.com>
Tue, 12 Apr 2011 04:23:11 +0000 (07:23 +0300)
See the script docstring for what was done

Victory Roads and Halls of Origin should probably be hand-tuned later

pokedex/data/csv/locations.csv
scripts/disambiguate-location-identifiers.py [new file with mode: 0644]

index 8021d36..bf11a66 100644 (file)
@@ -3,7 +3,7 @@ id,region_id,identifier
 2,4,eterna-city
 3,4,pastoria-city
 4,4,sunyshore-city
-5,4,pokemon-league
+5,4,sinnoh-pokemon-league
 6,4,oreburgh-mine
 7,4,valley-windworks
 8,4,eterna-forest
@@ -11,7 +11,7 @@ id,region_id,identifier
 10,4,mt-coronet
 11,4,great-marsh
 12,4,solaceon-ruins
-13,4,victory-road
+13,4,sinnoh-victory-road
 14,4,ravaged-path
 15,4,oreburgh-gate
 16,4,stark-mountain
@@ -28,40 +28,40 @@ id,region_id,identifier
 28,4,lake-acuity
 29,4,valor-lakefront
 30,4,acuity-lakefront
-31,4,route-201
-32,4,route-202
-33,4,route-203
-34,4,route-204
-35,4,route-205
-36,4,route-206
-37,4,route-207
-38,4,route-208
-39,4,route-209
+31,4,sinnoh-route-201
+32,4,sinnoh-route-202
+33,4,sinnoh-route-203
+34,4,sinnoh-route-204
+35,4,sinnoh-route-205
+36,4,sinnoh-route-206
+37,4,sinnoh-route-207
+38,4,sinnoh-route-208
+39,4,sinnoh-route-209
 40,4,lost-tower
-41,4,route-210
-42,4,route-211
-43,4,route-212
-44,4,route-213
-45,4,route-214
-46,4,route-215
-47,4,route-216
-48,4,route-217
-49,4,route-218
-50,4,route-219
-51,4,route-221
-52,4,route-222
-53,4,route-224
-54,4,route-225
-55,4,route-227
-56,4,route-228
-57,4,route-229
+41,4,sinnoh-route-210
+42,4,sinnoh-route-211
+43,4,sinnoh-route-212
+44,4,sinnoh-route-213
+45,4,sinnoh-route-214
+46,4,sinnoh-route-215
+47,4,sinnoh-route-216
+48,4,sinnoh-route-217
+49,4,sinnoh-route-218
+50,4,sinnoh-route-219
+51,4,sinnoh-route-221
+52,4,sinnoh-route-222
+53,4,sinnoh-route-224
+54,4,sinnoh-route-225
+55,4,sinnoh-route-227
+56,4,sinnoh-route-228
+57,4,sinnoh-route-229
 58,4,twinleaf-town
 59,4,celestic-town
 60,4,resort-area
-61,4,sea-route-220
-62,4,sea-route-223
-63,4,sea-route-226
-64,4,sea-route-230
+61,4,sinnoh-sea-route-220
+62,4,sinnoh-sea-route-223
+63,4,sinnoh-sea-route-226
+64,4,sinnoh-sea-route-230
 65,2,blackthorn-city
 66,2,burned-tower
 67,1,celadon-city
@@ -85,53 +85,53 @@ id,region_id,identifier
 85,2,olivine-city
 86,1,pallet-town
 87,1,rock-tunnel
-88,1,route-1
-89,1,route-10
-90,1,route-11
-91,1,route-12
-92,1,route-13
-93,1,route-14
-94,1,route-15
-95,1,route-16
-96,1,route-17
-97,1,route-18
-98,1,sea-route-19
-99,1,route-2
-100,1,sea-route-20
-101,1,sea-route-21
-102,1,route-22
-103,1,route-24
-104,1,route-25
-105,1,route-26
-106,1,route-27
-107,1,route-28
-108,2,route-29
-109,1,route-3
-110,2,route-30
-111,2,route-31
-112,2,route-32
-113,2,route-33
-114,2,route-34
-115,2,route-35
-116,2,route-36
-117,2,route-37
-118,2,route-38
-119,2,route-39
-120,1,route-4
-121,2,sea-route-40
-122,2,sea-route-41
-123,2,route-42
-124,2,route-43
-125,2,route-44
-126,2,route-45
-127,2,route-46
-128,2,route-47
-129,2,route-48
-130,1,route-5
-131,1,route-6
-132,1,route-7
-133,1,route-8
-134,1,route-9
+88,1,kanto-route-1
+89,1,kanto-route-10
+90,1,kanto-route-11
+91,1,kanto-route-12
+92,1,kanto-route-13
+93,1,kanto-route-14
+94,1,kanto-route-15
+95,1,kanto-route-16
+96,1,kanto-route-17
+97,1,kanto-route-18
+98,1,kanto-sea-route-19
+99,1,kanto-route-2
+100,1,kanto-sea-route-20
+101,1,kanto-sea-route-21
+102,1,kanto-route-22
+103,1,kanto-route-24
+104,1,kanto-route-25
+105,1,kanto-route-26
+106,1,kanto-route-27
+107,1,kanto-route-28
+108,2,johto-route-29
+109,1,kanto-route-3
+110,2,johto-route-30
+111,2,johto-route-31
+112,2,johto-route-32
+113,2,johto-route-33
+114,2,johto-route-34
+115,2,johto-route-35
+116,2,johto-route-36
+117,2,johto-route-37
+118,2,johto-route-38
+119,2,johto-route-39
+120,1,kanto-route-4
+121,2,johto-sea-route-40
+122,2,johto-sea-route-41
+123,2,johto-route-42
+124,2,johto-route-43
+125,2,johto-route-44
+126,2,johto-route-45
+127,2,johto-route-46
+128,2,johto-route-47
+129,2,johto-route-48
+130,1,kanto-route-5
+131,1,kanto-route-6
+132,1,kanto-route-7
+133,1,kanto-route-8
+134,1,kanto-route-9
 135,2,ruins-of-alph
 136,1,seafoam-islands
 137,2,slowpoke-well
@@ -144,17 +144,17 @@ id,region_id,identifier
 149,2,unknown-all-rattata
 150,2,unknown-all-bugs
 151,1,vermilion-city
-152,1,victory-road
+152,1,kanto-victory-road-1
 153,2,violet-city
 154,1,viridian-city
 155,1,viridian-forest
 156,2,whirl-islands
-157,1,route-23
+157,1,kanto-route-23
 158,1,power-plant
-159,1,victory-road
+159,1,kanto-victory-road-2
 160,1,pokemon-tower
 161,1,pokemon-mansion
-162,1,safari-zone
+162,1,kanto-safari-zone
 163,4,sandgem-town
 164,4,floaroma-town
 165,4,solaceon-town
@@ -178,8 +178,8 @@ id,region_id,identifier
 185,4,fight-area
 186,4,survival-area
 187,4,seabreak-path
-188,4,hall-of-origin
-189,4,hall-of-origin
+188,4,sinnoh-hall-of-origin-1
+189,4,sinnoh-hall-of-origin-2
 190,4,verity-cavern
 191,4,valor-cavern
 192,4,acuity-cavern
@@ -188,21 +188,21 @@ id,region_id,identifier
 195,4,gts
 196,4,trainers-school
 197,4,mining-museum
-198,4,flower-shop
-199,4,cycle-shop
+198,4,sinnoh-flower-shop
+199,4,sinnoh-cycle-shop
 200,4,contest-hall
 201,4,poffin-house
-202,4,foreign-building
+202,4,sinnoh-foreign-building
 203,4,pokemon-day-care
 204,4,veilstone-store
-205,4,game-corner
+205,4,sinnoh-game-corner
 206,4,canalave-library
 207,4,vista-lighthouse
 208,4,sunyshore-market
 209,4,footstep-house
-210,4,cafe
+210,4,sinnoh-cafe
 211,4,grand-lake
-212,4,restaurant
+212,4,sinnoh-restaurant
 213,4,battle-park
 214,4,battle-frontier
 215,4,battle-factory
@@ -210,8 +210,8 @@ id,region_id,identifier
 217,4,battle-arcade
 218,4,battle-hall
 219,4,distortion-world
-220,4,global-terminal
-221,4,villa
+220,4,sinnoh-global-terminal
+221,4,sinnoh-villa
 222,4,battleground
 223,4,rotoms-room
 224,4,tg-eterna-bldg
@@ -225,7 +225,7 @@ id,region_id,identifier
 232,2,lavender-town
 233,2,indigo-plateau
 234,2,saffron-city
-236,2,lighthouse
+236,2,johto-lighthouse
 237,2,team-rocket-hq
 238,2,goldenrod-tunnel
 239,2,mt-silver-cave
@@ -331,8 +331,8 @@ id,region_id,identifier
 341,,concert-event
 342,,mr-pokemon
 343,,primo
-344,5,mystery-zone
-345,5,faraway-place
+344,5,unova-mystery-zone
+345,5,unova-faraway-place
 346,5,nuvema-town
 347,5,accumula-town
 348,5,striaton-city
@@ -343,24 +343,24 @@ id,region_id,identifier
 353,5,mistralton-city
 354,5,icirrus-city
 355,5,opelucid-city
-356,5,route-1
-357,5,route-2
-358,5,route-3
-359,5,route-4
-360,5,route-5
-361,5,route-6
-362,5,route-7
-363,5,route-8
-364,5,route-9
-365,5,route-10
-366,5,route-11
-367,5,route-12
-368,5,route-13
-369,5,route-14
-370,5,route-15
-371,5,route-16
-372,5,route-17
-373,5,route-18
+356,5,unova-route-1
+357,5,unova-route-2
+358,5,unova-route-3
+359,5,unova-route-4
+360,5,unova-route-5
+361,5,unova-route-6
+362,5,unova-route-7
+363,5,unova-route-8
+364,5,unova-route-9
+365,5,unova-route-10
+366,5,unova-route-11
+367,5,unova-route-12
+368,5,unova-route-13
+369,5,unova-route-14
+370,5,unova-route-15
+371,5,unova-route-16
+372,5,unova-route-17
+373,5,unova-route-18
 374,5,dreamyard
 375,5,pinwheel-forest
 376,5,desert-resort
@@ -369,11 +369,11 @@ id,region_id,identifier
 379,5,chargestone-cave
 380,5,twist-mountain
 381,5,dragonspiral-tower
-382,5,victory-road
+382,5,unova-victory-road
 383,5,lacunosa-town
 384,5,undella-town
 385,5,anville-town
-386,5,pokemon-league
+386,5,unova-pokemon-league
 387,5,ns-castle
 388,5,royal-unova
 389,5,gear-station
@@ -387,7 +387,7 @@ id,region_id,identifier
 397,5,rumination-field
 398,5,celestial-tower
 399,5,moor-of-icirrus
-400,5,shopping-mall
+400,5,unova-shopping-mall
 401,5,challengers-cave
 402,5,poke-transfer-lab
 403,5,giant-chasm
@@ -431,53 +431,53 @@ id,region_id,identifier
 441,3,mt-pyre
 442,3,seafloor-cavern
 443,3,cave-of-origin
-444,3,victory-road
+444,3,hoenn-victory-road
 445,3,shoal-cave
 446,3,new-mauville
 447,3,abandoned-ship
 448,3,sky-pillar
-449,3,route-101
-450,3,route-102
-451,3,route-103
-452,3,route-104
-453,3,route-105
-454,3,route-106
-455,3,route-107
-456,3,route-108
-457,3,route-109
-458,3,route-110
-459,3,route-111
-460,3,route-112
-461,3,route-113
-462,3,route-114
-463,3,route-115
-464,3,route-116
-465,3,route-117
-466,3,route-118
-467,3,route-119
-468,3,route-120
-469,3,route-121
-470,3,route-122
-471,3,route-123
-472,3,route-124
-473,3,route-125
-474,3,route-126
-475,3,route-127
-476,3,route-128
-477,3,route-129
-478,3,route-130
-479,3,route-131
-480,3,route-132
-481,3,route-133
-482,3,route-134
-483,3,safari-zone
+449,3,hoenn-route-101
+450,3,hoenn-route-102
+451,3,hoenn-route-103
+452,3,hoenn-route-104
+453,3,hoenn-route-105
+454,3,hoenn-route-106
+455,3,hoenn-route-107
+456,3,hoenn-route-108
+457,3,hoenn-route-109
+458,3,hoenn-route-110
+459,3,hoenn-route-111
+460,3,hoenn-route-112
+461,3,hoenn-route-113
+462,3,hoenn-route-114
+463,3,hoenn-route-115
+464,3,hoenn-route-116
+465,3,hoenn-route-117
+466,3,hoenn-route-118
+467,3,hoenn-route-119
+468,3,hoenn-route-120
+469,3,hoenn-route-121
+470,3,hoenn-route-122
+471,3,hoenn-route-123
+472,3,hoenn-route-124
+473,3,hoenn-route-125
+474,3,hoenn-route-126
+475,3,hoenn-route-127
+476,3,hoenn-route-128
+477,3,hoenn-route-129
+478,3,hoenn-route-130
+479,3,hoenn-route-131
+480,3,hoenn-route-132
+481,3,hoenn-route-133
+482,3,hoenn-route-134
+483,3,hoenn-safari-zone
 484,3,dewford-town
 485,3,pacifidlog-town
 486,3,magma-hideout
 487,3,mirage-tower
 488,3,desert-underpass
 489,3,artisan-cave
-490,3,altering-cave
+490,3,hoenn-altering-cave
 491,1,monean-chamber
 492,1,liptoo-chamber
 493,1,weepth-chamber
@@ -486,7 +486,7 @@ id,region_id,identifier
 496,1,rixy-chamber
 497,1,viapos-chamber
 498,1,ss-anne
-499,1,victory-road
+499,1,kanto-victory-road-3
 500,1,mt-ember
 501,1,berry-forest
 502,1,icefall-cave
@@ -509,12 +509,12 @@ id,region_id,identifier
 519,1,canyon-entrance
 520,1,sevault-canyon
 521,1,tanoby-ruins
-522,1,route-19
-523,1,route-20
-524,1,route-21
+522,1,kanto-route-19
+523,1,kanto-route-20
+524,1,kanto-route-21
 525,1,vermillion-city
 526,1,one-island
 527,1,four-island
 528,1,five-island
-529,1,altering-cave
-530,1,victory-road
+529,1,kanto-altering-cave
+530,1,kanto-victory-road-4
diff --git a/scripts/disambiguate-location-identifiers.py b/scripts/disambiguate-location-identifiers.py
new file mode 100644 (file)
index 0000000..fdc0ca7
--- /dev/null
@@ -0,0 +1,80 @@
+# Encoding: UTF-8
+"""Automatically disambiguate location identifiers
+
+This is an unmaintained one-shot script, only included in the repo for reference.
+
+
+Disambiguates identifiers that aren't unique, Routes and Sea Routes, and
+generic names like 'villa' or 'game corner' that could appear in future
+generations again.
+
+Does this by prepending the region name, and if that isn't enough, appends
+numbers.
+"""
+
+import sys
+import re
+from collections import defaultdict
+
+from pokedex.db import connect, tables
+
+ambiguous_re = re.compile(r'^(sea-)?route-\d+$')
+
+ambiguous_set = set('foreign-building game-corner global-terminal lighthouse '
+    'restaurant flower-shop cycle-shop cafe shopping-mall villa'.split())
+
+def main(*argv):
+    session = connect()
+
+    location_dict = defaultdict(list)
+    for location in session.query(tables.Location).order_by(tables.Location.id):
+        location_dict[location.identifier].append(location)
+
+    changes = False
+    for identifier, locations in sorted(location_dict.items()):
+        disambiguate = any((
+                len(locations) > 1,
+                ambiguous_re.match(identifier),
+                identifier in ambiguous_set,
+            ))
+        print len(locations), ' *'[disambiguate], identifier,
+        if disambiguate:
+            changes = True
+            print u'→'.encode('utf-8'),
+            by_region = defaultdict(list)
+            for location in locations:
+                if location.region:
+                    by_region[location.region.identifier].append(location)
+                else:
+                    by_region[None].append(location)
+            for region_identifier, region_locations in by_region.items():
+                if region_identifier:
+                    new_identifier = '%s-%s' % (region_identifier, identifier)
+                else:
+                    # No change
+                    new_identifier = identifier
+                if len(region_locations) == 1:
+                    location = region_locations[0]
+                    # The region was enough
+                    print new_identifier,
+                    location.identifier = new_identifier
+                else:
+                    # Need to number the locations :(
+                    for i, location in enumerate(region_locations, start=1):
+                        numbered_identifier = '%s-%s' % (new_identifier, i)
+                        print numbered_identifier,
+                        location.identifier = numbered_identifier
+        print
+
+    if changes:
+        if argv and argv[0] == '--commit':
+            session.commit()
+            print 'Committed'
+        else:
+            print 'Run with --commit to commit changes'
+    else:
+        print 'No changes needed'
+
+
+if __name__ == '__main__':
+    main(*sys.argv[1:])
\ No newline at end of file