From e3ecfb708fa6f868fd15a34ac74cad17082c9e7a Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 8 Jan 2010 02:52:44 +0100 Subject: Implemented monolog counters. --- config.c | 4 ++++ config.h | 2 +- export_xml.c | 4 ++++ parsing.c | 19 +++++++++++++++++++ user.c | 2 +- user.h | 2 +- 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index b9123b8..0ae6beb 100644 --- a/config.c +++ b/config.c @@ -31,6 +31,10 @@ int cfg_init() { ircstats_config.threads = 1; } + if(!config_lookup_int(&config, "monolog_min", &ircstats_config.monolog_min)) { + ircstats_config.monolog_min = 5; + } + config_setting_t *regexes_setting = config_lookup(&config, "regexes"); if(!config_setting_is_aggregate(regexes_setting)) { fprintf(stderr, "Setting \"regexes\" must be an aggregate type.\n"); diff --git a/config.h b/config.h index b5b9874..3b42ee8 100644 --- a/config.h +++ b/config.h @@ -5,7 +5,7 @@ int cfg_init(); void cfg_free(); struct ircstats_config_t { - long int threads; + long int threads, monolog_min; }; extern struct ircstats_config_t ircstats_config; diff --git a/export_xml.c b/export_xml.c index f7509c3..1bacc5c 100644 --- a/export_xml.c +++ b/export_xml.c @@ -53,6 +53,10 @@ int export_xml(struct channel_t *channel, struct user_t *users) { xmlNewChild(user_node, NULL, "kicks", s); snprintf(s, 0xf, "%d", user->kicked); xmlNewChild(user_node, NULL, "kicked", s); + snprintf(s, 0xf, "%d", user->monolog_lines); + xmlNewChild(user_node, NULL, "monolog_lines", s); + snprintf(s, 0xf, "%d", user->monologs); + xmlNewChild(user_node, NULL, "monologs", s); /* Add lines for this user. */ xmlNodePtr lines_node = xmlNewChild(user_node, NULL, "lines", NULL); diff --git a/parsing.c b/parsing.c index 58a5303..e554907 100644 --- a/parsing.c +++ b/parsing.c @@ -9,6 +9,7 @@ #include "user.h" #include "word.h" #include "export_xml.h" +#include "config.h" #define NICK_BUFFER_SIZE 0x100 #define TEXT_BUFFER_SIZE 0x400 @@ -19,6 +20,9 @@ pthread_mutex_t user_mutex, word_mutex; static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *rs) { char line[LINE_BUFFER_SIZE]; + struct user_t *last_user = NULL; + int in_monolog = 0, monolog_len = 0;; + while(fgets(line, LINE_BUFFER_SIZE, f)) { int rc; int ovector[30]; @@ -32,6 +36,21 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t * pcre_copy_named_substring(rs->text, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE); pthread_mutex_lock(&user_mutex); struct user_t *user = user_get(nick); + if(user == last_user) { + monolog_len++; + if(!in_monolog && monolog_len >= ircstats_config.monolog_min) { + in_monolog = 1; + user->monologs++; + /* Count first lines. */ + user->monolog_lines += monolog_len; + } else if(in_monolog) { + user->monolog_lines++; + } + } else { + last_user = user; + in_monolog = 0; + monolog_len = 1; + } pthread_mutex_unlock(&user_mutex); /* Calculate array index for lines. */ diff --git a/user.c b/user.c index dc4b5ed..de10e1c 100644 --- a/user.c +++ b/user.c @@ -32,7 +32,7 @@ struct user_t *user_get(char *nick) { user->hash = hash; user->nick = strdup(nick); memset(user->lines, 0, 24*4 * sizeof(unsigned long)); - user->words = user->characters = user->kicks = user->kicked = 0; + user->words = user->characters = user->kicks = user->kicked = user->monolog_lines = user->monologs = 0; user->next = NULL; char *_nick = nick_get(nick); user->real_user = strcmp(nick, _nick) ? user_get(_nick) : NULL; diff --git a/user.h b/user.h index d2cb180..b08dd36 100644 --- a/user.h +++ b/user.h @@ -7,7 +7,7 @@ struct user_t { unsigned long hash; char *nick; unsigned long lines[24*4]; - unsigned long long words, characters, kicks, kicked; + unsigned long long words, characters, kicks, kicked, monolog_lines, monologs; struct user_t *real_user, *next; }; -- cgit v1.2.3