Пример #1
0
def ch_stats_freq(channel, window=10):
    """
    Counts frequencies of channel messages

    # TODO: Change freq counting type
    !!! This type of freq. counting is not good as it depends on the window.
    !!! e.g. if the window big enough but there are now messages such old, then freq is low
    !!! But for an example it should be OK.

    :param channel: string, channel name
    :param window: period of time in minutes in which we select messages
    :return: freq, messages per min and per sec
    """
    if window == 0:
        window = 10

    msg_num = Chat.get_messages_cnt(channel, window=window)

    return jsonify({
        'messages per minute': msg_num / window,
        'messages per second': msg_num / window / 60
    })