# Path: protector/query/query.py
# class Query(object):
#     """
#     Common methods for working with InfluxDB Queries
#     """
# 
#     def __init__(self):
#         self.query_type = None
# 
#     def set_type(self, query_type):
#         self.query_type = query_type
# 
#     def get_type(self):
#         return self.query_type
# 
#     def get_resolution(self):
#         """
#         The resolution is the interval given in the the group_by field.
#         (e.g. in the expression "group by time(10s)" it would be 10s)
#         Only Select queries can have a resolution.
#         All others don't, so we set this to None by default.
#         """
#         return None
# 
#     def get_duration(self):
#         """
#         The duration is the timespan to query data for.
#         It can be set in the "where" clause.
#         For instance, in the query:
#         "select * from myseries where time > now() - 24h"
#         the duration would be 24h.
#         Durations can only be given in Select and Delete queries
#         so we set this to None by default.
#         """
#         return None
# 
#     def get_datapoints(self):
#         """
#         Returns an estimate for the number datapoints that this query
#         will return, where datapoints = duration * resolution
#         Datapoints can only occur in Select and Delete queries
#         so we set this to None by default.
#         """
#         return None
# 
# Path: protector/influxdb/keyword.py
# class Keyword:
#     """
#     Valid InfluxDB Keywords
#     """
# 
#     SELECT = 'select'
#     FROM = 'from'
#     WHERE = 'where'
#     LIMIT = 'limit'
#     ORDER = 'order'
#     GROUP_BY = 'group'
#     DROP = 'drop'
#     DELETE = 'delete'
#     LIST = 'list'
#     SERIES = 'series'
# 
#     def __init__(self):
#         pass
# 
# Path: protector/influxdb/time_expression.py
# class TimeExpression(object):
#     # Smallest possible system date.
#     # This is required for the calculation of the max duration between datetime objects.
#     # We use the release day of InfluxDB 0.8 as the epoch
#     # because it is the first official version supported by this tool.
#     INFLUXDB_EPOCH = datetime.strptime('2014-08-22', "%Y-%m-%d")
# 
#     # Full names of all supported relative time units.
#     # Useful for conversions of the internal InfluxDB format to the Python timedelta format.
#     UNIT_NAMES = {
#         'u': 'microseconds',
#         's': 'seconds',
#         'm': 'minutes',
#         'h': 'hours',
#         'd': 'days',
#         'w': 'weeks'
#     }
# 
#     # Conversions of all InfluxDB relative time units to seconds.
#     # Useful for datapoint calculations.
#     UNIT_CONVERSION = {'u': 0.001, 's': 1, 'm': 60, 'h': 3600, 'd': 86400, 'w': 604800}


import datetime
from protector.query.query import Query
from protector.influxdb.keyword import Keyword
from protector.influxdb.time_expression import TimeExpression
        :return:
        """
        if not self.time_overlap:
            return datetime.datetime.now()
        return self.time_overlap.end

    def get_resolution(self):
        return self.resolution

    def get_duration(self):
        return self.duration

    def get_datapoints(self):
        return self.datapoints

    def __str__(self):
        """
        Standard string representation of select query
        """
        # Required parameters
        statements = [
            (Keyword.SELECT, self.select_stmt),
            (Keyword.FROM, self.from_stmt)
        ]
        # Optional parameters
        if self.where_stmt:
            statements.append((Keyword.WHERE, self.where_stmt))
        if self.limit_stmt:
            statements.append((Keyword.LIMIT, self.limit_stmt))
        if self.group_by_stmt:

# Path: protector/query/query.py
# class Query(object):
#     """
#     Common methods for working with InfluxDB Queries
#     """
# 
#     def __init__(self):
#         self.query_type = None
# 
#     def set_type(self, query_type):
#         self.query_type = query_type
# 
#     def get_type(self):
#         return self.query_type
# 
#     def get_resolution(self):
#         """
#         The resolution is the interval given in the the group_by field.
#         (e.g. in the expression "group by time(10s)" it would be 10s)
#         Only Select queries can have a resolution.
#         All others don't, so we set this to None by default.
#         """
#         return None
# 
#     def get_duration(self):
#         """
#         The duration is the timespan to query data for.
#         It can be set in the "where" clause.
#         For instance, in the query:
#         "select * from myseries where time > now() - 24h"
#         the duration would be 24h.
#         Durations can only be given in Select and Delete queries
#         so we set this to None by default.
#         """
#         return None
# 
#     def get_datapoints(self):
#         """
#         Returns an estimate for the number datapoints that this query
#         will return, where datapoints = duration * resolution
#         Datapoints can only occur in Select and Delete queries
#         so we set this to None by default.
#         """
#         return None
# 
# Path: protector/influxdb/keyword.py
# class Keyword:
#     """
#     Valid InfluxDB Keywords
#     """
# 
#     SELECT = 'select'
#     FROM = 'from'
#     WHERE = 'where'
#     LIMIT = 'limit'
#     ORDER = 'order'
#     GROUP_BY = 'group'
#     DROP = 'drop'
#     DELETE = 'delete'
#     LIST = 'list'
#     SERIES = 'series'
# 
#     def __init__(self):
#         pass
# 
# Path: protector/influxdb/time_expression.py
# class TimeExpression(object):
#     # Smallest possible system date.
#     # This is required for the calculation of the max duration between datetime objects.
#     # We use the release day of InfluxDB 0.8 as the epoch
#     # because it is the first official version supported by this tool.
#     INFLUXDB_EPOCH = datetime.strptime('2014-08-22', "%Y-%m-%d")
# 
#     # Full names of all supported relative time units.
#     # Useful for conversions of the internal InfluxDB format to the Python timedelta format.
#     UNIT_NAMES = {
#         'u': 'microseconds',
#         's': 'seconds',
#         'm': 'minutes',
#         'h': 'hours',
#         'd': 'days',
#         'w': 'weeks'
#     }
# 
#     # Conversions of all InfluxDB relative time units to seconds.
#     # Useful for datapoint calculations.
#     UNIT_CONVERSION = {'u': 0.001, 's': 1, 'm': 60, 'h': 3600, 'd': 86400, 'w': 604800}


# Path: protector/query/select.py
import datetime
from protector.query.query import Query
from protector.influxdb.keyword import Keyword
from protector.influxdb.time_expression import TimeExpression

        :return:
        """
        if not self.time_overlap:
            return datetime.datetime.now()
        return self.time_overlap.end

    def get_resolution(self):
        return self.resolution

    def get_duration(self):
        return self.duration

    def get_datapoints(self):
        return self.datapoints

    def __str__(self):
        """
        Standard string representation of select query
        """
        # Required parameters
        statements = [
            (Keyword.SELECT, self.select_stmt),
            (Keyword.FROM, self.from_stmt)
        ]
        # Optional parameters
        if self.where_stmt:
            statements.append((Keyword.WHERE, self.where_stmt))
        if self.limit_stmt:
            statements.append((Keyword.LIMIT, self.limit_stmt))
        if self.group_by_stmt:

            statements.append((Keyword.GROUP_BY, ['by', self.group_by_stmt]))