summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-08-17 13:53:58 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2009-08-17 13:53:58 +0200
commit44f3e1486fb5fd45644683af83aaaf27047e4250 (patch)
treef46347575a37a90234233fd504f9a8173811d57d
parent27bf4f8c64eac6d969116e4c6ed8584b52badb46 (diff)
Count lines per quarter hour for channels and users.
-rw-r--r--channel.c1
-rw-r--r--channel.h2
-rw-r--r--main.c16
-rw-r--r--user.c3
-rw-r--r--user.h2
5 files changed, 20 insertions, 4 deletions
diff --git a/channel.c b/channel.c
index 45bbb71..c69cf2b 100644
--- a/channel.c
+++ b/channel.c
@@ -23,6 +23,7 @@ struct channel_t *channel_add(const char *name) {
struct channel_t *channel = &channels[channel_count-1];
channel->name = strdup(name);
channel->files = NULL;
+ memset(channel->hours, 0, 24*4 * sizeof(unsigned long));
return channel;
}
diff --git a/channel.h b/channel.h
index 73f2dde..0335782 100644
--- a/channel.h
+++ b/channel.h
@@ -12,6 +12,8 @@ struct channel_file_t {
struct channel_t {
char *name;
struct channel_file_t *files;
+
+ unsigned long hours[24*4];
};
void channel_init();
diff --git a/main.c b/main.c
index d32b091..8175dbe 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -11,6 +12,7 @@
#define NICK_BUFFER_SIZE 0x100
#define TEXT_BUFFER_SIZE 0x400
#define LINE_BUFFER_SIZE 0x400
+#define TIME_BUFFER_SIZE 0xf
int main(int argc, char **argv) {
/* Regex sets must be initialized before config. */
@@ -48,11 +50,21 @@ int main(int argc, char **argv) {
rc = pcre_exec(rs->text, rs->text_e, line, strlen(line), 0, 0, ovector, 30);
if(rc > 0) {
- char nick[NICK_BUFFER_SIZE], text[TEXT_BUFFER_SIZE];
+ char nick[NICK_BUFFER_SIZE], text[TEXT_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
pcre_copy_named_substring(rs->text, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
pcre_copy_named_substring(rs->text, line, ovector, rc, "text", text, TEXT_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->text, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->text, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
struct user_t *user = user_get(nick);
- user->lines++;
+
+ /* Calculate array index for lines. */
+ int hour, min, time_i;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+ time_i = hour*4 + min / 15;
+
+ user->lines[time_i]++;
+ channel->hours[time_i]++;
/* Count words. */
char word[TEXT_BUFFER_SIZE];
diff --git a/user.c b/user.c
index a9e2927..aed1ea6 100644
--- a/user.c
+++ b/user.c
@@ -30,7 +30,8 @@ struct user_t *user_get(char *nick) {
if(!user->nick) {
user->hash = hash;
user->nick = strdup(nick);
- user->lines = user->words = 0;
+ memset(user->lines, 0, 24*4 * sizeof(unsigned long));
+ user->words = 0;
user->next = NULL;
}
diff --git a/user.h b/user.h
index 0bf3686..042eb32 100644
--- a/user.h
+++ b/user.h
@@ -6,7 +6,7 @@
struct user_t {
unsigned long hash;
char *nick;
- unsigned long lines;
+ unsigned long lines[24*4];
unsigned long long words;
struct user_t *next;
};