diff --git a/ebdjango/management/commands/create_indexes.py b/ebdjango/management/commands/create_indexes.py index ee195703405e344be6abfb0f3812d2e5d8252b88..b6b25c26c77c734c486ddcea5404bf4192d0e83e 100644 --- a/ebdjango/management/commands/create_indexes.py +++ b/ebdjango/management/commands/create_indexes.py @@ -18,4 +18,16 @@ class Command(BaseCommand): self.stdout.write("Creating index nyc.address_text") db.nyc.create_index([("address", "text")], name="address_text") + self.stdout.write("Creating index nyc.bbl") + db.nyc.create_index([("bbl", pymongo.ASCENDING)], name="bbl_asc") + + self.stdout.write("Creating index roc.bbl") + db.roc.create_index([("bbl", pymongo.ASCENDING)], name="bbl_asc") + + self.stdout.write("Creating index nyc.properties.program") + db.nyc.create_index([("properties.program", pymongo.ASCENDING)], name="properties_program_asc") + + self.stdout.write("Creating index roc.properties.program") + db.roc.create_index([("properties.program", pymongo.ASCENDING)], name="properties_program_asc") + self.stdout.write(self.style.SUCCESS('Finished creating indexes.')) diff --git a/ebdjango/management/commands/update_cbra.py b/ebdjango/management/commands/update_cbra.py new file mode 100644 index 0000000000000000000000000000000000000000..5985d111fbe36741f9d1b4596061115465094004 --- /dev/null +++ b/ebdjango/management/commands/update_cbra.py @@ -0,0 +1,34 @@ +from django.core.management.base import BaseCommand, CommandError +from django.conf import settings +import pymongo +from pymongo import MongoClient +from pymongo.errors import BulkWriteError +import pprint + +class Command(BaseCommand): + help = 'Update CBRA properties' + + def handle(self, *args, **options): + db = MongoClient(settings.MONGO_DB_URI)[settings.MONGO_CLIENT] + + for area in ("roc", "nyc"): + self.stdout.write("Cleaning up existing proprties in %s marked as CBRA." % area) + bulk_op = db[area].initialize_unordered_bulk_op() + bulk_op.find({"properties.program": "CBRA"}).update({"$set": {"properties.program": ""}}) + bulk_op.execute() + + i = 0 + bulk_op = db[area].initialize_unordered_bulk_op() + self.stdout.write("Updating %d records" % db.cbra.count()) + + for doc in db.cbra.find(): + i += 1 + self.stdout.write("Adding bbl: %d %d" % (i, doc['BBL'])) + bulk_op.find({"bbl": doc['BBL']}).update({"$set": {"properties.program": "CBRA"}}) + + self.stdout.write("Executing bulk update.") + try: + bulk_op.execute() + self.stdout.write(self.style.SUCCESS('Finished updating records.')) + except BulkWriteError as bwe: + pprint(bwe.details)