diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-01-08 02:52:44 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-01-08 02:52:44 +0100 |
commit | e3ecfb708fa6f868fd15a34ac74cad17082c9e7a (patch) | |
tree | 02af333ef9253d1798fa0ded145b430d8ac42f30 | |
parent | 3f0b80bb129aedd41ee09dccf45c532caf28a854 (diff) |
Implemented monolog counters.
-rw-r--r-- | config.c | 4 | ||||
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | export_xml.c | 4 | ||||
-rw-r--r-- | parsing.c | 19 | ||||
-rw-r--r-- | user.c | 2 | ||||
-rw-r--r-- | user.h | 2 |
6 files changed, 30 insertions, 3 deletions
@@ -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"); @@ -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); @@ -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. */ @@ -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; @@ -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; }; |