# Path: dcmetrometrics/common/utils.py
# def gen_days(s, e):
#     """Generate days between start_day s and end_day e (exclusive)"""
#     d = s
#     while d < e:
#         yield d
#         d = d + timedelta(days = 1)
# 
# Path: dcmetrometrics/common/dbGlobals.py
# class _DBGlobals(object):
#     def __init__(self):
#     def update(self):
#     def getEscalatorIds(self):
#     def getElevatorIds(self):
#     def getUnitIds(self):
#     def getDB(self):
# def getDB():
# def connect():
# def G():
# _G = None # Global object
#     _G = _DBGlobals()


from mongoengine import *
from operator import attrgetter
from ..common.metroTimes import TimeRange, UTCToLocalTime, toUtc, tzny, utcnow, dateToOpen
from ..common.WebJSONMixin import WebJSONMixin
from ..common.DataWriteable import DataWriteable
from ..common.utils import gen_days
from .defs import symptomToCategory, SYMPTOM_CHOICES
from ..common import dbGlobals
from .misc_utils import *
from .StatusGroup import StatusGroup
from datetime import timedelta, datetime, date
import sys
import logging
    Add a unit to the database if it does not already exist.
    If the unit is being added for the first time, create an initial
    operational UnitStatus entry.

    If the unit already exists and a status already exists,
    do nothing.
    """
    unit_id = kwargs['unit_id']

    try:

      unit = Unit.objects.get(unit_id = unit_id)

    except DoesNotExist:
      logger.info("Adding Unit to DB: " + unit_id)
      unit = cls(**kwargs)
      unit.save()

    # Add a new entry to the escalator_statuses collection if necessary
    status_count = UnitStatus.objects(unit = unit).count()
    has_key_statuses = unit.key_statuses is not None
    has_performance_summary = unit.performance_summary is not None

    updated_unit = False

    if status_count == 0:

        if curTime is None:
          curTime = datetime.now() 


# Path: dcmetrometrics/common/utils.py
# def gen_days(s, e):
#     """Generate days between start_day s and end_day e (exclusive)"""
#     d = s
#     while d < e:
#         yield d
#         d = d + timedelta(days = 1)
# 
# Path: dcmetrometrics/common/dbGlobals.py
# class _DBGlobals(object):
#     def __init__(self):
#     def update(self):
#     def getEscalatorIds(self):
#     def getElevatorIds(self):
#     def getUnitIds(self):
#     def getDB(self):
# def getDB():
# def connect():
# def G():
# _G = None # Global object
#     _G = _DBGlobals()


# Path: dcmetrometrics/eles/models.py
from mongoengine import *
from operator import attrgetter
from ..common.metroTimes import TimeRange, UTCToLocalTime, toUtc, tzny, utcnow, dateToOpen
from ..common.WebJSONMixin import WebJSONMixin
from ..common.DataWriteable import DataWriteable
from ..common.utils import gen_days
from .defs import symptomToCategory, SYMPTOM_CHOICES
from ..common import dbGlobals
from .misc_utils import *
from .StatusGroup import StatusGroup
from datetime import timedelta, datetime, date
import sys
import logging

    Add a unit to the database if it does not already exist.
    If the unit is being added for the first time, create an initial
    operational UnitStatus entry.

    If the unit already exists and a status already exists,
    do nothing.
    """
    unit_id = kwargs['unit_id']

    try:

      unit = Unit.objects.get(unit_id = unit_id)

    except DoesNotExist:
      logger.info("Adding Unit to DB: " + unit_id)
      unit = cls(**kwargs)
      unit.save()

    # Add a new entry to the escalator_statuses collection if necessary
    status_count = UnitStatus.objects(unit = unit).count()
    has_key_statuses = unit.key_statuses is not None
    has_performance_summary = unit.performance_summary is not None

    updated_unit = False

    if status_count == 0:

        if curTime is None:
          curTime = datetime.now() 


        G = dbGlobals.G()