X-Git-Url: http://royale.zerezo.com/git/?p=irssistats;a=blobdiff_plain;f=irssistats.c;h=284dcb9d2b67b2ea8335d8a42382440591afd73d;hp=579fc39d2c99b55cdb92d54aef73473121b45af8;hb=refs%2Ftags%2Fv0.43;hpb=4f1235aec09bf9214b3ed89ed887024c04aea555 diff --git a/irssistats.c b/irssistats.c index 579fc39..284dcb9 100644 --- a/irssistats.c +++ b/irssistats.c @@ -1,12 +1,17 @@ -/* Usage: cat /path/to/file.log | ./irssistats channel maintainer language theme > /path/to/file.html */ +/* Usage: cat /path/to/file.log | ./irssistats \#channel maintainer language theme [nickfile] > /path/to/file.html */ #include #include #include #include +#include + +/* Options */ +#define REFRESH_TIME 3600 +#define W3C_LINK /* Config */ -#define MAXUSERS 5000 +#define MAXUSERS 10000 #define MAXNICKLENGTH 50 #define MAXLINELENGTH 2000 #define MAXQUOTELENGTH 100 @@ -18,7 +23,7 @@ #define MINWORDLENGTH 5 /* irssistats */ -#define VERSION "0.31" +#define VERSION "0.43" #define URL "http://royale.zerezo.com/programmation/irssistats/" /* Counters */ @@ -39,13 +44,13 @@ char *counters[NBCOUNTERS]={"C_SMILE","C_FROWN","C_EXCLAM","C_QUESTION","C_ME","C_TOPIC","C_MODE","C_KICK","C_KICKED","C_URL","C_JOIN","C_NICK","C_MONOLOGUE"}; /* Languages */ -#define NBLANGUAGES 3 +#define NBLANGUAGES 5 #define NBKEYS 38 char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and abbreviation */ { { /* English language */ { "English", "en" }, - { "HEADER", "Statistics for #%s by %s" }, + { "HEADER", "Statistics for %s by %s" }, { "LEGEND", "Legend" }, { "LASTDAYS", "Lastdays statistics" }, { "TOPHOURS", "Hourly statistics" }, @@ -68,7 +73,7 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "OCCURRENCES", "occurrences" }, { "BIGNUMBERS", "Some big numbers..." }, { "NUMBERS", "numbers" }, - { "TIME", "%d lines parsed in %d seconds" }, + { "TIME", "%d lines (%d days) parsed in %d seconds" }, { "FOOTER", "Statistics generated by" }, { "C_SMILE", "is often happy :)" }, { "C_FROWN", "is often sad :(" }, @@ -86,7 +91,7 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab }, { /* French language */ { "Français", "fr" }, - { "HEADER", "Statistiques de #%s par %s" }, + { "HEADER", "Statistiques de %s par %s" }, { "LEGEND", "Légende" }, { "LASTDAYS", "Statistiques des derniers jours" }, { "TOPHOURS", "Statistiques horaires" }, @@ -97,7 +102,7 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "AVGLETTERS", "lettres/lignes" }, { "HOURS", "heures" }, { "QUOTE", "message aléatoire" }, - { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" }, + { "TOPUSERSTIME", "Personnes les plus actives par période de la journée" }, { "RANDTOPICS", "Quelques topics" }, { "CHANGEDBY", "changé par" }, { "NEWTOPIC", "nouveau topic" }, @@ -109,7 +114,7 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "OCCURRENCES", "occurrences" }, { "BIGNUMBERS", "Quelques grands nombres..." }, { "NUMBERS", "nombres" }, - { "TIME", "%d lignes traitées en %d secondes" }, + { "TIME", "%d lignes (%d jours) traitées en %d secondes" }, { "FOOTER", "Statistiques générées par" }, { "C_SMILE", "est souvent heureux :)" }, { "C_FROWN", "est souvent triste :(" }, @@ -125,10 +130,52 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "C_NICK", "change souvent de nick" }, { "C_MONOLOGUE", "parle beaucoup de monologues" } }, + { /* German language */ + /* contributed by Valentin Gelhorn */ + { "German", "de" }, + { "HEADER", "Statistiken für %s von %s" }, + { "LEGEND", "Legende" }, + { "LASTDAYS", "Statistik der letzten Tage" }, + { "TOPHOURS", "Stündliche Statistik" }, + { "TOPUSERS", "Die aktivsten Personen" }, + { "OTHERS", "Es bleiben noch %d uneingetragene" }, + { "NBLINES", "Zeilen" }, + { "NICK", "Nick" }, + { "AVGLETTERS", "Buchstaben/Zeile" }, + { "HOURS", "Stunden" }, + { "QUOTE", "Zufällig ausgewaehlte Zitate" }, + { "TOPUSERSTIME", "Die aktivsten Personen zur bestimmten Tageszeit" }, + { "RANDTOPICS", "Ein paar Topics" }, + { "CHANGEDBY", "Gesetzt von" }, + { "NEWTOPIC", "Neues topic" }, + { "RANDURLS", "Ein paar URLs" }, + { "POSTEDBY", "Geschrieben von" }, + { "POSTEDURL", "URL" }, + { "TOPWORDS", "Am häufigsten benutze Wörter" }, + { "WORD", "Wort" }, + { "OCCURRENCES", "Vorkommen" }, + { "BIGNUMBERS", "Ein paar grosse Zahlen" }, + { "NUMBERS", "Zahlen" }, + { "TIME", "%d Zeilen (%d Tage) analysiert in %d Sekunden" }, + { "FOOTER", "Statistiken wurden erstellt von" }, + { "C_SMILE", "ist oft glüklich :)" }, + { "C_FROWN", "ist oft traurig :(" }, + { "C_EXCLAM", "schreit oft !" }, + { "C_QUESTION", "stellt viele Fragen ?" }, + { "C_ME", "mag /me'en" }, + { "C_TOPIC", "aendert oft das Topico" }, + { "C_MODE", "aendert oft die Modes" }, + { "C_KICK", "mag /kick'en" }, + { "C_KICKED", "wird oft gekickt"}, + { "C_URL", "schreibt viele URLs"}, + { "C_JOIN", "kann sich nicht entscheiden ob er bleiben oder gehen soll" }, + { "C_NICK", "ändert oft seinen Nick" }, + { "C_MONOLOGUE", "spricht oft Monologe" } + }, { /* Spanish language */ - /* Submitted by Alex */ + /* contributed by Alex */ { "Spanish", "es" }, - { "HEADER", "Estadísticas de #%s por %s" }, + { "HEADER", "Estadísticas de %s por %s" }, { "LEGEND", "Leyenda" }, { "LASTDAYS", "Estadísticas de los últimos días" }, { "TOPHOURS", "Estadísticas por horas" }, @@ -151,7 +198,7 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "OCCURRENCES", "Frecuencia" }, { "BIGNUMBERS", "Algunos datos..." }, { "NUMBERS", "Número de veces" }, - { "TIME", "%d lineas procesadas en %d segundos" }, + { "TIME", "%d lineas (%d días) procesadas en %d segundos" }, { "FOOTER", "Estadísticas generadas por" }, { "C_SMILE", "Suele estar felíz :)" }, { "C_FROWN", "Suele estar triste :(" }, @@ -166,6 +213,48 @@ char *keys[NBLANGUAGES][NBKEYS+1][2]= /* first key used for language name and ab { "C_JOIN", "No sabe si irse o quedarse" }, { "C_NICK", "Cambia mucho de nick" }, { "C_MONOLOGUE", "Habla solo" } + }, + { /* Polish language */ + /* contributed by Piotr Jarmuz */ + { "Polish", "pl" }, + { "HEADER", "Statystyki dla %s przez %s" }, + { "LEGEND", "Legenda" }, + { "LASTDAYS", "Statystyki z ostatnich dni" }, + { "TOPHOURS", "Statystyki godzinne" }, + { "TOPUSERS", "Najaktywniejsi ludzie" }, + { "OTHERS", "Zostalo jeszcze %d nie sklasyfikowanych..." }, + { "NBLINES", "linie" }, + { "NICK", "nick" }, + { "AVGLETTERS", "litery/linie" }, + { "HOURS", "godziny" }, + { "QUOTE", "przypadkowa wiadomosc" }, + { "TOPUSERSTIME", "Najaktywniejsi ludzie wedlug czasu dnia" }, + { "RANDTOPICS", "Pare tematow" }, + { "CHANGEDBY", "zmienione przez" }, + { "NEWTOPIC", "nowy temat" }, + { "RANDURLS", "Pare URL-i" }, + { "POSTEDBY", "wyslane przez" }, + { "POSTEDURL", "URL" }, + { "TOPWORDS", "Najczestsze slowa" }, + { "WORD", "slowo" }, + { "OCCURRENCES", "wystapienia" }, + { "BIGNUMBERS", "Pare wielkich liczb..." }, + { "NUMBERS", "liczby" }, + { "TIME", "%d linii (%d dni) sparsowanych w %d sekund" }, + { "FOOTER", "Statystyki wygenerowane przez" }, + { "C_SMILE", "jest czesto szczesliwy :)" }, + { "C_FROWN", "jest czesto smutny :(" }, + { "C_EXCLAM", "duzo krzyczy !" }, + { "C_QUESTION", "zadaje duzo pytan ?" }, + { "C_ME", "lubi /mnie polecenie" }, + { "C_TOPIC", "czesto zmienia temat" }, + { "C_MODE", "czesto zmienia tryb" }, + { "C_KICK", "lubi /kopac" }, + { "C_KICKED", "czesto go wykopuja" }, + { "C_URL", "wysyla duzo URL-i" }, + { "C_JOIN", "nie wie czy zostac czy wyjsc" }, + { "C_NICK", "czesto zmienia swojego nicka" }, + { "C_MONOLOGUE", "czesto mowi monologiem" } } }; @@ -180,7 +269,7 @@ char *L(char *key) } /* Themes */ -#define NBTHEMES 5 +#define NBTHEMES 6 #define NBCOLORS 9 char *colors[NBTHEMES][NBCOLORS+1][2]= /* first key used for theme name/description and abbreviation */ { @@ -243,6 +332,18 @@ char *colors[NBTHEMES][NBCOLORS+1][2]= /* first key used for theme name/descript { "TITLE2", "#FF7700" }, { "BGTABLE", "#FFEEEE" }, { "BGTITLE", "#FF7700" } + }, + { /* Blue theme */ + { "Blue theme...", "blue" }, + { "BGCOLOR", "#FFFFFF" }, + { "TEXT", "#000000" }, + { "LINK", "#4444FF" }, + { "VLINK", "#8888FF" }, + { "ALINK", "#CCCCFF" }, + { "TITLE1", "#8888FF" }, + { "TITLE2", "#AAAAFF" }, + { "BGTABLE", "#EEEEFF" }, + { "BGTITLE", "#CCCCFF" } } }; @@ -269,6 +370,7 @@ struct int hours[4]; char quote[MAXQUOTELENGTH+1]; int counters[NBCOUNTERS]; + int temp; } users[MAXUSERS]; int nbusers=0; @@ -396,6 +498,7 @@ int dichotomic(char *nick) for (j=0;j<4;j++) users[i].hours[j]=users[i-1].hours[j]; strcpy(users[i].quote,users[i-1].quote); for (j=0;j6)) { - fprintf(stderr,"Usage: cat /path/to/file.log | ./irssistats channel maintainer language theme > /path/to/file.html\n\n"); + fprintf(stderr,"Usage: cat /path/to/file.log | ./irssistats \\#channel maintainer language theme [nickfile] > /path/to/file.html\n\n"); fprintf(stderr,"Version :\nirssistats %s\n\n",VERSION); fprintf(stderr,"Supported languages :\n"); for (i=0;i=MAXLINELENGTH) { fprintf(stderr,"line too long\n"); exit(1); } + if (pos>=MAXLINELENGTH) { fprintf(stderr,"line %d is too long\n",totallines); exit(1); } if (c=='\n') { line[pos-1]='\0'; @@ -471,12 +577,10 @@ int main(int argc,char *argv[]) for (j=0;j<4;j++) lastdays[0].hours[j]=0; days++; } - else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by Nick(, Nick2, Nick3...) */ + else if (strncmp("-!- mode/",&line[6],9)==0) /* 00:00 -!- mode/#channel [...] by (Nick, Nick2, )Nick3 */ { - for (i=15;(line[i]!=']')||(line[i+1]!=' ');i++); - nick=&line[i+5]; - for (i=0;(nick[i]!='\0')&&(nick[i]!=',');i++); - nick[i]='\0'; + for (i=strlen(line);line[i]!=' ';i--); + nick=&line[i+1]; users[dichotomic(nick)].counters[D_MODE]++; } else if (strncmp("-!-",&line[6],3)==0) /* 00:00 -!- Nick something... */ @@ -531,9 +635,11 @@ int main(int argc,char *argv[]) message=&line[i+1]; } else if (line[7]=='>') /* 00:00 <>>>?Nick<<<> the personal message */ + /* 00:00 <>>?Nick<<> the personal message */ { - for (i=11;line[i]!='<';i++); - nick=&line[11]; + for (i=10;line[i]!='<';i++); + nick=&line[10]; + if (line[9]=='>') nick++; message=&line[i+5]; } else /* 00:00 the message */ @@ -590,85 +696,131 @@ int main(int argc,char *argv[]) pos=0; } } - fprintf(stderr,"done\n"); + fprintf(stderr," done\n"); bestwords(words,0); + /*** ALIAS ***/ + + if (argc==6) + { + for (i=0;i=0)) + { + if (users[i].temp>users[user].temp) /* for nick alias, keep the random quote of the most used nick */ + { + strcpy(users[user].quote,users[i].quote); + users[user].temp=users[i].temp; + } + users[user].lines+=users[i].lines; + users[user].letters+=users[i].letters; + for (j=0;j<4;j++) users[user].hours[j]+=users[i].hours[j]; + for (j=0;j"); + users[i].lines=-1; + users[i].letters=-1; + for (j=0;j<4;j++) users[i].hours[j]=-1; + for (j=0;j\n\n"); printf("\n\n",VERSION,URL); - printf("\n\n\n\n"); + printf("<html>\n\n<head>\n<title>"); printf(L("HEADER"),channel,maintainer); - printf("\n\n\n"); - printf("\n\n
\n\n

",T("BGCOLOR"),T("TEXT"),T("LINK"),T("VLINK"),T("ALINK"),T("TITLE1")); + printf("\n\n"); +#ifdef REFRESH_TIME + printf("\n",REFRESH_TIME); +#endif + printf("\n\n\n"); + printf("\n\n
\n\n",T("BGCOLOR"),T("TEXT"),T("LINK"),T("VLINK"),T("ALINK"),T("TITLE1")); printf(L("HEADER"),channel,maintainer); - printf("

\n%s
\n

\n\n",ctime(&debut)); + printf("


\n%s
\n

\n\n",ctime(&debut)); /* legend */ - printf("

%s

\n\n\n",T("TITLE2"),L("LEGEND"),T("BGTABLE")); - for (i=0;i<4;i++) printf("\n",i+1,L("HOURS"),i*6,i*6+5); + printf("%s

\n
: %s %d-%d
\n\n",T("TITLE2"),L("LEGEND"),T("BGTABLE")); + for (i=0;i<4;i++) printf("\n",i+1,L("HOURS"),i*6,i*6+5); printf("\n
\"\" : %s %d-%d
\n

\n\n"); /* last days */ - printf("

%s

\n\n\n",T("TITLE2"),L("LASTDAYS")); + printf("%s

\n
\n\n",T("TITLE2"),L("LASTDAYS")); max=-1; for (i=30;i>=0;i--) if (lastdays[i].lines>max) max=lastdays[i].lines; for (i=30;i>=0;i--) { printf("\n"); } printf("\n\n"); for (i=30;i>=0;i--) - printf("\n",T("BGTABLE"),i); + printf("\n",T("BGTABLE"),i); printf("\n
%d
",lastdays[i].lines); - for (j=0;j<4;j++) if (lastdays[i].hours[j]!=0) printf("
",j+1,150*lastdays[i].hours[j]/max); + for (j=0;j<4;j++) if (lastdays[i].hours[j]!=0) printf("\"\"
",j+1,150*lastdays[i].hours[j]/max); printf("
%d%d
\n

\n\n"); /* top hours */ - printf("

%s

\n\n\n",T("TITLE2"),L("TOPHOURS")); + printf("%s

\n
\n\n",T("TITLE2"),L("TOPHOURS")); max=-1; for (i=0;i<24;i++) if (hours[i]>max) max=hours[i]; for (i=0;i<24;i++) { printf("\n"); } printf("\n\n"); for (i=0;i<24;i++) - printf("\n",T("BGTABLE"),i); + printf("\n",T("BGTABLE"),i); printf("\n
%.1f%%
",lines!=0?(float)100*hours[i]/lines:0); - if (hours[i]!=0) printf("
",i/6+1,150*hours[i]/max); + if (hours[i]!=0) printf("\"\"
",i/6+1,150*hours[i]/max); printf("
%d%d
\n

\n\n"); /* top users */ - printf("

%s

\n",T("TITLE2"),L("TOPUSERS")); + printf("%s

\n",T("TITLE2"),L("TOPUSERS")); printf("\n\n",T("BGTITLE"),L("NICK"),T("BGTITLE"),L("NBLINES"),T("BGTITLE"),L("HOURS"),T("BGTITLE"),L("AVGLETTERS"),T("BGTITLE"),L("QUOTE")); for (i=1;i<=NBUSERS;i++) { user=-1; - max=-1; + max=0; for (j=0;jmax) max=users[user=j].lines; if (user!=-1) { printf("\n"); users[user].lines=-1; } } printf("
%s%s%s%s%s
%d%s%d",T("BGTABLE"),i,T("BGTABLE"),users[user].nick,T("BGTABLE"),users[user].lines,T("BGTABLE")); - for (j=0;j<4;j++) if (users[user].hours[j]!=0) printf("",j+1,100*users[user].hours[j]/users[user].lines); - printf("%d\"",T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE")); + for (j=0;j<4;j++) if (users[user].hours[j]!=0) printf("\"\"",j+1,100*users[user].hours[j]/users[user].lines); + printf("%d\"\"\"",T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE"),users[user].lines!=0?users[user].letters/users[user].lines:0,T("BGTABLE")); printhtml(users[user].quote); printf("\"
\n"); - if (nbusers>NBUSERS) + temp=0; + for (i=0;i<=nbusers;i++) if (users[i].lines>=0) temp++; + if (temp>0) { printf("
"); - printf(L("OTHERS"),nbusers-50); + printf(L("OTHERS"),temp); printf("
\n"); } printf("

\n\n"); /* top users by time */ - printf("

%s

\n",T("TITLE2"),L("TOPUSERSTIME")); + printf("%s

\n",T("TITLE2"),L("TOPUSERSTIME")); printf("\n"); for (i=0;i<4;i++) printf("",T("BGTITLE"),L("HOURS"),i*6,i*6+5); printf("\n"); @@ -678,7 +830,7 @@ int main(int argc,char *argv[]) for (j=0;j<4;j++) { user=-1; - max=-1; + max=0; for (k=0;kmax) max=users[user=k].hours[j]; if (user!=-1) { @@ -692,7 +844,7 @@ int main(int argc,char *argv[]) printf("
%s %d-%d
\n

\n\n"); /* random topics */ - printf("

%s

\n",T("TITLE2"),L("RANDTOPICS")); + printf("%s

\n",T("TITLE2"),L("RANDTOPICS")); printf("\n\n",T("BGTITLE"),L("CHANGEDBY"),T("BGTITLE"),L("NEWTOPIC")); for (i=nbtopics=0;i--) { @@ -703,25 +855,27 @@ int main(int argc,char *argv[]) printf("
%s%s
\n

\n\n"); /* random urls */ - printf("

%s

\n",T("TITLE2"),L("RANDURLS")); + printf("%s

\n",T("TITLE2"),L("RANDURLS")); printf("\n\n",T("BGTITLE"),L("POSTEDBY"),T("BGTITLE"),L("POSTEDURL")); for (i=nburls=0;i--) { - printf("\n"); } printf("
%s%s
%s\"",T("BGTABLE"),urls[i].nick,T("BGTABLE"),urls[i].url); + printf("
%s\""); printhtml(urls[i].shorturl); printf("\"
\n

\n\n"); /* top words */ - printf("

%s

\n",T("TITLE2"),L("TOPWORDS")); + printf("%s

\n",T("TITLE2"),L("TOPWORDS")); printf("\n\n",T("BGTITLE"),L("WORD"),T("BGTITLE"),L("OCCURRENCES")); for (i=0;i\n",T("BGTABLE"),i+1,T("BGTABLE"),topwords[i].word,T("BGTABLE"),topwords[i].nb); printf("
%s%s
%d\"%s\"%d
\n

\n\n"); /* big numbers */ - printf("

%s

\n",T("TITLE2"),L("BIGNUMBERS")); + printf("%s

\n",T("TITLE2"),L("BIGNUMBERS")); printf("\n\n",T("BGTITLE"),L("NICK"),T("BGTITLE"),L("NUMBERS"),T("BGTITLE"),L("NBLINES")); for (i=0;i\n

\n\n"); /* footer */ - printf(L("TIME"),totallines,(int)(time(NULL)-debut)); + printf(L("TIME"),totallines,days,(int)(time(NULL)-debut)); printf("
\n%s irssistats %s",L("FOOTER"),URL,VERSION); +#ifdef W3C_LINK + printf("

\n\n"); +#endif printf("\n\n\n\n\n\n\n"); return(0);
%s%s%s