Exemplo n.º 1
0
def bootstrap(command, conf, vars):
    """Place any commands to setup outages here"""

    #Kill the scheduler
    tgscheduler.stop_scheduler()

    root_node = LocationNode(id=0, name="RootNode", location_level="ROOTNODE")

    DBSession.add(root_node)
    DBSession.flush()

    transaction.commit()
Exemplo n.º 2
0
def populate(data, parent, utility):
    loc_qual = get_location_qualifier(data.location_level)
    loc_filter = LocationNode.query.filter(and_(
        LocationNode.name==data.name,
        LocationNode.location_level==loc_qual))

    if loc_filter.count():
        #Object exists, lets grab it
        loc = loc_filter.one()
    else:
        loc = LocationNode()
        loc.name = data.name
        loc.parent = parent
        loc.location_level = loc_qual
        loc.total_customers = data.total_customers
        loc.update_time = data.update_time
        DBSession.add(loc)
        DBSession.flush()

    for child_loc in data.locations:
        populate(child_loc, loc, utility)

    if data.outage:
        if not loc.outages:
            outage = Outage()
            outage.location = loc
            outage.utility = utility
            outage.affected_customers = data.outage.affected_customers
            outage.proposed_end_time = data.outage.proposed_end_time
            DBSession.add(outage)
            DBSession.flush()

    transaction.commit()
Exemplo n.º 3
0
def update_geo_locations():
    # Process the Location
    for obj in LocationNode.query.filter(LocationNode.location_level==LOCATION_CHAIN[0]):
        if obj.lat is None and obj.lng is None:
            chain = build_geo_chain(obj)
            # Get a lat/lng from Google
            lat, lng = get_lat_long(', '.join(chain))

            # Update object
            if lat is not None and lng is not None:
                obj.lat = str(lat)
                obj.lng = str(lng)

    DBSession.flush()
    transaction.commit()
Exemplo n.º 4
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Exemplo n.º 5
0
def scrape_omni_outages_url(service):
    #TODO: Pull this out to generic it
    # Get the utility entry, else create one if it's missing
    utility = None
    utility_query = Utility.query.filter(Utility.key==service['key'])
    if utility_query.count():
        utility = utility_query.one()
    else:
        # Doesn't exist, add new utility
        utility = Utility()
        utility.key = service['key']
        utility.name = service['name']
        DBSession.add(utility)
        DBSession.flush()


    # Clear all outages
    for o_obj in Outage.query.all():
        if o_obj.utility is utility:
            DBSession.delete(o_obj)

    # Get data from Omni
    scraper = OmniScraper(service['base'])

    outage_data = scraper.start(service['base'])
    
    # Setup the root Location as the State
    outage_data.name = service['state']
    outage_data.location_level = 'state'
    
    tot_custs = 0
    for child in outage_data.locations:
        if not outage_data.update_time:
            outage_data.update_time = child.update_time
        tot_custs = tot_custs + child.total_customers
    
    outage_data.total_customers = tot_custs

    populate_database(outage_data, utility)
Exemplo n.º 6
0
def scrape_natgrid_outages_url(service):
    #TODO: Pull this out to generic it
    # Get the utility entry, else create one if it's missing
    utility = None
    utility_query = Utility.query.filter(Utility.key==service['key'])
    if utility_query.count():
        utility = utility_query.one()
    else:
        # Doesn't exist, add new utility
        utility = Utility()
        utility.key = service['key']
        utility.name = service['name']
        DBSession.add(utility)
        DBSession.flush()


    # Clear all outages
    for o_obj in Outage.query.all():
        if o_obj.utility is utility:
            DBSession.delete(o_obj)

    # Get data from NatGrid
    scraper = NationalGridScraper()

    outage_data = scraper.start(service['base'])

    # First layer is always garbage   
    outage_data = outage_data.locations[0]

    tot_custs = 0
    for child in outage_data.locations:
        if not outage_data.update_time:
            outage_data.update_time = child.update_time
        tot_custs = tot_custs + child.total_customers
    
    outage_data.total_customers = tot_custs

    populate_database(outage_data, utility)
Exemplo n.º 7
0
 def test_query_obj(self):
     """Model objects can be queried"""
     obj = DBSession.query(self.klass).one()
     for key, value in self.attrs.iteritems():
         assert_equals(getattr(obj, key), value)
Exemplo n.º 8
0
 def tearDown(self):
     """Finish model test fixture."""
     DBSession.rollback()