# Path: randtalkbot/errors.py
# class StrangerSenderServiceError(Exception):
#     pass
# 
# Path: randtalkbot/stats.py
# class Stats(Model):
#     data_json = TextField()
#     created = DateTimeField(default=datetime.datetime.utcnow, index=True)
# 
#     class Meta:
#         database = DATABASE_PROXY
# 
#     def __init__(self, *args, **kwargs):
#         super(Stats, self).__init__(*args, **kwargs)
#         self._data_cache = None
# 
#     def get_data(self):
#         if self._data_cache is None:
#             self._data_cache = json.loads(self.data_json)
# 
#         return self._data_cache
# 
#     def set_data(self, data):
#         self._data_cache = data
#         self.data_json = json.dumps(data)
# 
#     def get_sex_ratio(self):
#         """https://en.wikipedia.org/wiki/Human_sex_ratio
# 
#         Returns:
#             float: Ratio of males over the females.
# 
#         """
#         try:
#             sex_data = self.get_data()['sex_distribution']
#         except (KeyError, TypeError):
#             return 1
# 
#         males_count = sex_data.get('male', 0)
#         females_count = sex_data.get('female', 0)
# 
#         if males_count > 0 and females_count > 0:
#             return males_count / females_count
#         elif males_count > 0:
#             return RATIO_MAX
#         elif females_count > 0:
#             return 1 / RATIO_MAX
# 
#         return 1


import asyncio
import datetime
import logging
from peewee import DoesNotExist
from .errors import StrangerSenderServiceError
from .stats import Stats
        from .stranger_service import StrangerService
        from .stranger_sender_service import StrangerSenderService
        from .talk import Talk
        'count': count,
        }

def increment(dictionary, key):
    try:
        dictionary[key] += 1
    except KeyError:
        dictionary[key] = 1

def increment_distribution(dictionary, value, intervals):
    for interval in intervals:
        if value <= interval:
            break
    else:
        interval = 'more'

    dictionary[interval] += 1

def first(iterable):
    return iterable[0]

def second(iterable):
    return iterable[1]

class StatsService:
    INTERVAL = datetime.timedelta(hours=4)

    def __init__(self):
        type(self)._instance = self
        try:

# Path: randtalkbot/errors.py
# class StrangerSenderServiceError(Exception):
#     pass
# 
# Path: randtalkbot/stats.py
# class Stats(Model):
#     data_json = TextField()
#     created = DateTimeField(default=datetime.datetime.utcnow, index=True)
# 
#     class Meta:
#         database = DATABASE_PROXY
# 
#     def __init__(self, *args, **kwargs):
#         super(Stats, self).__init__(*args, **kwargs)
#         self._data_cache = None
# 
#     def get_data(self):
#         if self._data_cache is None:
#             self._data_cache = json.loads(self.data_json)
# 
#         return self._data_cache
# 
#     def set_data(self, data):
#         self._data_cache = data
#         self.data_json = json.dumps(data)
# 
#     def get_sex_ratio(self):
#         """https://en.wikipedia.org/wiki/Human_sex_ratio
# 
#         Returns:
#             float: Ratio of males over the females.
# 
#         """
#         try:
#             sex_data = self.get_data()['sex_distribution']
#         except (KeyError, TypeError):
#             return 1
# 
#         males_count = sex_data.get('male', 0)
#         females_count = sex_data.get('female', 0)
# 
#         if males_count > 0 and females_count > 0:
#             return males_count / females_count
#         elif males_count > 0:
#             return RATIO_MAX
#         elif females_count > 0:
#             return 1 / RATIO_MAX
# 
#         return 1


# Path: randtalkbot/stats_service.py
import asyncio
import datetime
import logging
from peewee import DoesNotExist
from .errors import StrangerSenderServiceError
from .stats import Stats
        from .stranger_service import StrangerService
        from .stranger_sender_service import StrangerSenderService
        from .talk import Talk

        'count': count,
        }

def increment(dictionary, key):
    try:
        dictionary[key] += 1
    except KeyError:
        dictionary[key] = 1

def increment_distribution(dictionary, value, intervals):
    for interval in intervals:
        if value <= interval:
            break
    else:
        interval = 'more'

    dictionary[interval] += 1

def first(iterable):
    return iterable[0]

def second(iterable):
    return iterable[1]

class StatsService:
    INTERVAL = datetime.timedelta(hours=4)

    def __init__(self):
        type(self)._instance = self
        try:

            self._stats = Stats.select().order_by(Stats.created.desc()).get()