# Path: surveilr/utils.py
# def truncate(number, rounding_factor):
# def generate_key():
# def enhance_data_point(data_point):


from riakalchemy import RiakObject
from riakalchemy.types import Integer, String, Dict, RelatedObjects
from surveilr import utils
"""



class Service(RiakObject):
    """A service that is referenced by many LogEntry's

    If the same logical service gets information from multiple sources,
    it needs separate Service objects. However, if several metrics are
    provided for a single service in each log entry, only one Service
    is needed"""
    bucket_name = 'services'
    searchable = True

    name = String()
    user = RelatedObjects(backref=True)
    plugins = Dict()


class User(RiakObject):
    """A user of the service"""
    bucket_name = 'users'

    api_key = String()
    credentials = Dict()
    messaging_driver = String()
    messaging_address = String()

    def pre_save(self):
        if not hasattr(self, 'api_key'):

# Path: surveilr/utils.py
# def truncate(number, rounding_factor):
# def generate_key():
# def enhance_data_point(data_point):


# Path: surveilr/models.py
from riakalchemy import RiakObject
from riakalchemy.types import Integer, String, Dict, RelatedObjects
from surveilr import utils

"""



class Service(RiakObject):
    """A service that is referenced by many LogEntry's

    If the same logical service gets information from multiple sources,
    it needs separate Service objects. However, if several metrics are
    provided for a single service in each log entry, only one Service
    is needed"""
    bucket_name = 'services'
    searchable = True

    name = String()
    user = RelatedObjects(backref=True)
    plugins = Dict()


class User(RiakObject):
    """A user of the service"""
    bucket_name = 'users'

    api_key = String()
    credentials = Dict()
    messaging_driver = String()
    messaging_address = String()

    def pre_save(self):
        if not hasattr(self, 'api_key'):

            self.api_key = utils.generate_key()