# Path: moira/graphite/attime.py
# def parseATTime(s, tzinfo=None):
#     if tzinfo is None:
#         tzinfo = pytz.utc
#     s = s.strip().lower().replace('_', '').replace(',', '').replace(' ', '')
#     if s.isdigit():
#         if len(s) == 8 and int(s[:4]) > 1900 and int(
#                 s[4:6]) < 13 and int(s[6:]) < 32:
#             pass  # Fall back because its not a timestamp, its YYYYMMDD form
#         else:
#             return datetime.fromtimestamp(int(s), tzinfo)
#     elif ':' in s and len(s) == 13:
#         return tzinfo.localize(datetime.strptime(s, '%H:%M%Y%m%d'), daylight)
#     if '+' in s:
#         ref, offset = s.split('+', 1)
#         offset = '+' + offset
#     elif '-' in s:
#         ref, offset = s.split('-', 1)
#         offset = '-' + offset
#     else:
#         ref, offset = s, ''
#     return (
#         parseTimeReference(ref) +
#         parseTimeOffset(offset)).astimezone(tzinfo)


from moira.graphite.util import epoch
from moira.graphite.attime import parseATTime
from twisted.internet import defer

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""


db = None


def createRequestContext(fromTime, endTime, allowRealTimeAlerting):
    return {'startTime': parseATTime(fromTime),
            'endTime': parseATTime(endTime),
            'bootstrap': False,
            'allowRealTimeAlerting': allowRealTimeAlerting,
            'localOnly': False,
            'template': None,
            'graphite_patterns': {},
            'metrics': set()}


class TimeSeries(list):

    def __init__(self, name, start, end, step, values, consolidate='average'):
        list.__init__(self, values)
        self.name = name
        self.start = start
        self.end = end
        self.step = step

# Path: moira/graphite/attime.py
# def parseATTime(s, tzinfo=None):
#     if tzinfo is None:
#         tzinfo = pytz.utc
#     s = s.strip().lower().replace('_', '').replace(',', '').replace(' ', '')
#     if s.isdigit():
#         if len(s) == 8 and int(s[:4]) > 1900 and int(
#                 s[4:6]) < 13 and int(s[6:]) < 32:
#             pass  # Fall back because its not a timestamp, its YYYYMMDD form
#         else:
#             return datetime.fromtimestamp(int(s), tzinfo)
#     elif ':' in s and len(s) == 13:
#         return tzinfo.localize(datetime.strptime(s, '%H:%M%Y%m%d'), daylight)
#     if '+' in s:
#         ref, offset = s.split('+', 1)
#         offset = '+' + offset
#     elif '-' in s:
#         ref, offset = s.split('-', 1)
#         offset = '-' + offset
#     else:
#         ref, offset = s, ''
#     return (
#         parseTimeReference(ref) +
#         parseTimeOffset(offset)).astimezone(tzinfo)


# Path: moira/graphite/datalib.py
from moira.graphite.util import epoch
from moira.graphite.attime import parseATTime
from twisted.internet import defer


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""


db = None


def createRequestContext(fromTime, endTime, allowRealTimeAlerting):
    return {'startTime': parseATTime(fromTime),
            'endTime': parseATTime(endTime),
            'bootstrap': False,
            'allowRealTimeAlerting': allowRealTimeAlerting,
            'localOnly': False,
            'template': None,
            'graphite_patterns': {},
            'metrics': set()}


class TimeSeries(list):

    def __init__(self, name, start, end, step, values, consolidate='average'):
        list.__init__(self, values)
        self.name = name
        self.start = start
        self.end = end
        self.step = step

        self.consolidationFunc = consolidate