summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-10-04 09:50:48 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-10-04 09:50:48 +0800
commit6353dfdb305068cd9b3be2a28501e2d362a58efe (patch)
treeb3b3ea408b69c3688e179f9cfb1097a482f64266
parenta817b4f057ef097e8d5928300afb067d52039806 (diff)
downloadpttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar.gz
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar.bz2
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar.lz
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar.xz
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.tar.zst
pttbbs-6353dfdb305068cd9b3be2a28501e2d362a58efe.zip
Split 'users today' and 'history' update into seperate functions
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5105 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/util/account.c204
1 files changed, 116 insertions, 88 deletions
diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c
index 99dbacb5..309c3fb0 100644
--- a/pttbbs/util/account.c
+++ b/pttbbs/util/account.c
@@ -138,15 +138,123 @@ parse_usies(const char *fn, struct tm *ptime, int act[27])
return 0;
}
+static int
+output_today(struct tm *ptime, int act[27], int peak_hour_login, int day_login)
+{
+ char buf[256];
+ int item = peak_hour_login / ACCOUNT_MAX_LINE + 1;
+ int per_hour_unit = 100;
+ int i, j;
+ FILE *fp;
+
+ if ((fp = fopen("etc/today", "w")) == NULL) {
+ printf("can't open etc/today\n");
+ return 1;
+ }
+
+ fprintf(fp, "\t\t\t" ANSI_COLOR(1;33;46) "–Ω参璸 [%02d/%02d/%02d] " ANSI_COLOR(40) "\n\n",
+ ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
+
+ for (i = ACCOUNT_MAX_LINE + 1; i > 0; i--) {
+ strcpy(buf, " ");
+
+ for (j = 0; j < 24; j++) {
+ int hour_count = act[j];
+ int max = item * i;
+ if (hour_count && (hour_count < max) && (max <= hour_count + item)) {
+ my_outs(fp, buf, '3');
+ fprintf(fp, "%-3d", hour_count / per_hour_unit);
+ } else if (max <= hour_count) {
+ my_outs(fp, buf, '4');
+ fprintf(fp, " ");
+ } else
+ strcat(buf, " ");
+ }
+
+ fprintf(fp, "\n");
+ }
+
+ fprintf(fp, " " ANSI_COLOR(32)
+ "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n\n"
+ "\t " ANSI_COLOR(34) "虫: " ANSI_COLOR(37) "%d" ANSI_COLOR(34) " ", per_hour_unit);
+ fprintf(fp, " 羆Ω" ANSI_COLOR(37) "%-7d" ANSI_COLOR(34) "キАㄏノ计" ANSI_COLOR(37) "%d\n",
+ day_login, day_login / 24);
+ fclose(fp);
+
+ return 0;
+}
+
+static int
+update_history(struct tm *ptime, int peak_hour, int peak_hour_login, int day_login)
+{
+ int max_hour_login = 0, max_day_login = 0, max_reg = 0, max_online = 0;
+ int peak_online;
+ FILE *fp, *fp1;
+ time_t t;
+ struct tm tm;
+
+ if ((fp = fopen("etc/history.data", "r+")) == NULL)
+ return 1;
+
+ /* 程絬 */
+ if (fscanf(fp, "%d %d %d %d", &max_day_login, &max_hour_login, &max_reg, &max_online) != 4)
+ goto out;
+
+ if ((fp1 = fopen("etc/history", "a")) == NULL)
+ goto out;
+
+ resolve_fcache();
+ peak_online = SHM->max_user;
+ printf("琿程絬:%d 筁:%d\n", peak_online, max_online);
+
+ if (peak_online > max_online) {
+ localtime4_r(&SHM->max_time, &tm);
+ fprintf(fp1, "》 %02d/%02d/%02d %02d:%02d"
+ ANSI_COLOR(32) "ず计" ANSI_RESET "Ω笷 " ANSI_COLOR(1;36) "%d" ANSI_RESET " Ω\n",
+ tm.tm_mon + 1, tm.tm_mday, tm.tm_year % 100, tm.tm_hour, tm.tm_min, peak_online);
+ max_online = peak_online;
+ }
+
+ t = mktime(ptime) + ADJUST_M * 60;
+ localtime_r(&t, &tm);
+
+ if (tm.tm_hour == 0) {
+ if (peak_hour_login > max_hour_login) {
+ fprintf(fp1, "『 %02d/%02d/%02d %02d "
+ ANSI_COLOR(1;32) "虫絬Ω" ANSI_RESET "Ω笷 " ANSI_COLOR(1;35) "%d" ANSI_RESET " Ω\n",
+ ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, peak_hour, peak_hour_login);
+ max_hour_login = peak_hour_login;
+ }
+ if (day_login > max_day_login) {
+ fprintf(fp1, "』 %02d/%02d/%02d "
+ ANSI_COLOR(1;32) "虫ら絬Ω" ANSI_RESET "Ω笷 " ANSI_COLOR(1;33) "%d" ANSI_RESET " Ω\n",
+ ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, day_login);
+ max_day_login = day_login;
+ }
+ if (SHM->number > max_reg + max_reg / 10) {
+ fprintf(fp1, "」 %02d/%02d/%02d "
+ ANSI_COLOR(1;32) "羆爹计" ANSI_RESET "矗ど " ANSI_COLOR(1;31) "%d" ANSI_RESET " \n",
+ ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, SHM->number);
+ max_reg = SHM->number;
+ }
+ }
+
+ fclose(fp1);
+
+out:
+ rewind(fp);
+ fprintf(fp, "%d %d %d %d", max_day_login, max_hour_login, max_reg, peak_online);
+ fclose(fp);
+
+ return 0;
+}
+
int
main(int argc, char **argv)
{
int i, j;
- int item, mo, da, peak_hour_login = 0,
- max_reg = 0, peak_hour = 0;
- int day_login, max_day_login;
- int max_hour_login;
- int max_online;
+ int mo, da;
+ int peak_hour_login, peak_hour, day_login;
const char const log_file[] = "usies";
const char const wday_str[] = "UMTWRFS";
char buf[256], buf1[256];
@@ -154,7 +262,6 @@ main(int argc, char **argv)
int act[27]; /* Ω计/仓璸丁/pointer */
time4_t now;
struct tm *ptime;
- int per_hour_unit = 100;
attach_SHM();
nice(10);
@@ -167,7 +274,7 @@ main(int argc, char **argv)
printf("Ω计/仓璸丁\n");
parse_usies(log_file, ptime, act);
- peak_hour_login = 0;
+ peak_hour_login = peak_hour = 0;
day_login = 0;
for (i = 0; i < 24; i++) {
day_login += act[i];
@@ -176,7 +283,6 @@ main(int argc, char **argv)
peak_hour = i;
}
}
- item = peak_hour_login / ACCOUNT_MAX_LINE + 1;
if (!ptime->tm_hour) {
keeplog("etc/today", BN_RECORD, "Ω参璸", NULL);
@@ -188,62 +294,12 @@ main(int argc, char **argv)
/* -------------------------------------------------------------- */
printf("Ω参璸\n");
- if ((fp = fopen("etc/today", "w")) == NULL) {
- printf("cann't open etc/today\n");
- return 1;
- }
- fprintf(fp, "\t\t\t –Ω参璸 [%02d/%02d/%02d] \n\n",
- ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
- for (i = ACCOUNT_MAX_LINE + 1; i > 0; i--) {
- strcpy(buf, " ");
- for (j = 0; j < 24; j++) {
- int hour_count = act[j];
- int max = item * i;
- if (hour_count && (hour_count < max) && (max <= hour_count + item)) {
- my_outs(fp, buf, '3');
- fprintf(fp, "%-3d", hour_count / per_hour_unit);
- } else if (max <= hour_count) {
- my_outs(fp, buf, '4');
- fprintf(fp, " ");
- } else
- strcat(buf, " ");
- }
- fprintf(fp, "\n");
- }
- fprintf(fp, " "
- "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n\n"
- "\t 虫: %d ", per_hour_unit);
- fprintf(fp, " 羆Ω%-7dキАㄏノ计%d\n", day_login, day_login / 24);
- fclose(fp);
+ output_today(ptime, act, peak_hour_login, day_login);
/* -------------------------------------------------------------- */
printf("菌ㄆン矪瞶\n");
/* Ptt 菌ㄆン矪瞶 */
- if ((fp = fopen("etc/history.data", "r"))) { /* 程絬 */
- if (fscanf(fp, "%d %d %d %d", &max_day_login, &max_hour_login, &max_reg, &max_online) == 4) {
- int peak_online;
- resolve_fcache();
- peak_online = SHM->max_user;
- printf("琿程絬:%d 筁:%d\n", peak_online, max_online);
- fclose(fp);
- if (peak_online > max_online) {
- ptime = localtime4(&SHM->max_time);
- if ((fp1 = fopen("etc/history", "a"))) {
- fprintf(fp1,
- "》 %02d/%02d/%02d %02d:%02d"
- "ず计Ω笷 %d Ω\n",
- ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100,
- ptime->tm_hour, ptime->tm_min, peak_online);
- fclose(fp1);
- }
- if ((fp = fopen("etc/history.data", "w"))) {
- fprintf(fp, "%d %d %d %d", max_day_login, max_hour_login, max_reg, peak_online);
- fclose(fp);
- }
- }
- } else
- fclose(fp);
- }
+ update_history(ptime, peak_hour, peak_hour_login, day_login);
now += ADJUST_M * 60; /* back to future */
ptime = localtime4(&now);
@@ -286,34 +342,6 @@ main(int argc, char **argv)
gzip(log_file, "usies", buf);
printf("溃罽ㄏノ絬菏北\n");
- if ((fp = fopen("etc/history.data", "r"))) { /* 虫ら程ΩΩ,絬,爹 */
- if (fscanf(fp, "%d %d %d %d", &max_day_login, &max_hour_login, &max_reg, &max_online) == 4) {
- fp1 = fopen("etc/history", "a");
- if (peak_hour_login > max_hour_login) {
- fprintf(fp1, "『 %02d/%02d/%02d %02d "
- "虫絬ΩΩ笷 %d Ω \n"
- ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, peak_hour, peak_hour_login);
- max_hour_login = peak_hour_login;
- }
- if (day_login > max_day_login) {
- fprintf(fp1, "』 %02d/%02d/%02d "
- "虫ら絬ΩΩ笷 %d Ω \n"
- ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, day_login);
- max_day_login = day_login;
- }
- if (SHM->number > max_reg + max_reg / 10) {
- fprintf(fp1, "」 %02d/%02d/%02d "
- "羆爹计矗ど %d  \n"
- ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, SHM->number);
- max_reg = SHM->number;
- }
- fclose(fp1);
- }
- fclose(fp);
- fp = fopen("etc/history.data", "w");
- fprintf(fp, "%d %d %d %d", max_day_login, max_hour_login, max_reg, max_online);
- fclose(fp);
- }
now += ADJUST_M * 60; /* back to future */
ptime = localtime4(&now);