回精華區
作者qazq.bbs@bbs.cs.nchu.edu.tw (按~煩死了.....) 看板: plan
標題[功能] 當日文章數據統計。
時間中興資科 (Fri, 28 Nov 2003 11:23:15 +0800 (CST)) Updated: 2003/11/30
    1. 統計當日發表文章的總時間(秒)、字元數、獲得錢幣。

    2. 統計當日的文章灌水王。

    3. 每天 0:00 自動產生在 record 板。

    4. 在 精華公佈欄 也可以直接閱讀。

==============================================================================

: src/include/global.h

#define FN_RUN_POST "run/post"  /* 文章篇數統計 */
#define FN_RUN_POST_LOG "run/post.log"  /* 文章篇數統計 */
+#define FN_TOTAL_POST_GOLD  "run/var/post_gold.log" /* 當日文章各項數據 */
+#define FN_RUN_POSTNUMS_TOP "run/postnums_top.log"  /* 當日灌水王 */



: src/include/struct.h      加入下面的結構

typedef struct
{
  time_t spendtime;
  int wordsnum;
  int gold;
} POSTGOLD;     /* 統計全站當日的文章價值 */


: src/maple/post.c:do_post()        //每發表一篇就記錄一次該篇文章的數據。

    else
    {
+     POSTGOLD PostGold;

      mode = BMIN(wordsnum, spendtime) / 10;    /* 每十字/秒 一元 */
      prints("這是您的第 %d 篇文章,得 %d 銀。", ++cuser.numposts, mode);
      cuser.money += mode;
      /* itoc.010408: 依文章長度/所費時間來決定要給多少錢 */
      /* itoc.註解: 錢要難賺,幣制才會有意義 */

+     PostGold.spendtime = spendtime;   /* 統計全站當日的文章價值 */
+     PostGold.wordsnum = wordsnum;
+     PostGold.gold = mode;

+     rec_add(FN_TOTAL_POST_GOLD, &PostGold, sizeof(POSTGOLD));
    }



: src/util/poststat.c

+#define MAX_NUM 5       /* 本日灌水王統計名次 */


: poststat.c:post_author()      //把當日發表篇數前幾名抓出來寫入檔案。

  /* report */

  if (fp = fopen(FN_RUN_POST_LOG, "w"))
  {
+   FILE *fp2;
+   int i = 1;

+   fp2 = fopen(FN_RUN_POSTNUMS_TOP, "w");

!   pa_out(patop, fp, fp2, i);
    fclose(fp);
+   fclose(fp2);
  }
}


: poststat.c:pa_out()

static void
!pa_out(top, fp, fp2, i)
  SplayNode *top;
  FILE *fp;
+ FILE *fp2;
+ int i;
{

  .....
  .....

  if (top == NULL)
    return;

! pa_out(top->left, fp, fp2, i);

  .....
  .....

  fprintf(fp, "\n>%6d %s\n", pa->count, pa->author);

+ if (i <= MAX_NUM)
+ {
+   fprintf(fp2, "%d %s\n", pa->count, pa->author);
+   i++;
+ }

  for (text = pa->text; text; text = text->ptnext)
  {
    fprintf(fp, "%7d %.70s\n", text->count, text->title);
  }

! pa_out(top->right, fp, fp2, i);
}


: src/util/account.c:main()     每天產生檔案在 record 板。

+   sprintf(title, "%s文章數據統計", date);
+   keeplog("gem/@/@-poststat", NULL, title, 0);      

    if (fp = fopen(fn_yesday, "w"))
    {
      f_suck(fp, fn_today);
      fclose(fp);
    }
    sprintf(title, "%s上站人次統計", date);
    keeplog(fn_today, NULL, title, 1);



: src/util/post-gold.c      加入下面整支程式
                    檔案可在這取得:http://140.120.13.11/~qazq/bbs/post-gold.c

/*-------------------------------------------------------*/
/* util/post-gold.c ( NTHU CS MapleBBS Ver 3.00 )        */
/*-------------------------------------------------------*/
/* target : 文章數據統計                                 */
/* create : 03/11/27                                     */
/* update :   /  /                                       */
/* modify : qazq.bbs@csNCHU.twbbs.org                    */
/*-------------------------------------------------------*/

#include "bbs.h"

#define FN_TOTAL_POST_GOLD_OLD  "run/var/post_gold.old"
#define OUTPUT_POSTSTAT     BBSHOME"/gem/@/@-poststat"

#define MAX_NUM 5   /* 本日灌水王統計名次 */

static void
postnum_top(OutPut_fp)
  FILE *OutPut_fp;
{
  FILE *fp;
  int i = 0;
  int postnums[MAX_NUM] = {0};
  char userid[MAX_NUM][13] = {0};

  if (fp = fopen(FN_RUN_POSTNUMS_TOP, "r"))
  {
    while (i <= MAX_NUM - 1)
    {
      fscanf(fp, "%d%s", &postnums[i], userid[i]);
      i++;
    }
    fclose(fp);
  }

  i = 0;

  while (postnums[i] != 0 && i <= MAX_NUM - 1)
  {
    fprintf(OutPut_fp, "  \033[1;3%dm第 %d 名:%-13s 發表 %d 篇\033[m\n",
      i <= 2 ? i + 1 : 7, i + 1, userid[i], postnums[i]);
    i++;
  }
}

int
main()
{
  FILE *fp;
  FILE *OutPut_fp;
  POSTGOLD *PostGolds;
  int i ,total;
  int total_spendtime = 0, total_wordsnum = 0, total_gold = 0;

  chdir(BBSHOME);

  if (fp = fopen(FN_TOTAL_POST_GOLD, "r"))
  {
    total = rec_num(FN_TOTAL_POST_GOLD, sizeof(POSTGOLD));
    PostGolds = malloc(total * sizeof(POSTGOLD));

    for (i = 0; i <= total - 1; i++)
      fread(&PostGolds[i], sizeof(POSTGOLD), 1, fp);

    fclose(fp);
  }
  else
    return 0;

  for (i = 0; i <= total - 1; i++)
  {
    total_spendtime += PostGolds[i].spendtime;
    total_wordsnum += PostGolds[i].wordsnum;
    total_gold += PostGolds[i].gold;
  }

  if (OutPut_fp = fopen(OUTPUT_POSTSTAT, "w"))
  {
    int average_spendtime, average_wordsnum, average_gold;
    time_t now;
    struct tm *ptime;

    average_spendtime = total_spendtime / total;
    average_wordsnum = total_wordsnum / total;
    average_gold = total_gold / total;

    time(&now);
    ptime = localtime(&now);

    fprintf(OutPut_fp, "\n        ┤\033[1;41m        本日文章所得        \033[m├"
      "        \033[33m統計日期: \033[36m%d 月 %d 日\033[m\n\n",
      ptime->tm_mon + 1, ptime->tm_mday);

    fprintf(OutPut_fp,
      "  文章發表\033[31m總篇數:\033[1;31m%d 篇\033[m\n\n"
      "  發文耗費\033[36m總時數:\033[1;36m%d 秒 \033[0;36m(%d 時 %d 分 %d 秒)\033[m\n"
      "      文章\033[32m總字數:\033[1;32m%d 個字元 \033[0;32m(%d 頁 %d 行 %d 個字元)\033[m\n"
      "      文章\033[33m總價值:\033[1;33m%d 金\033[m\n\n",
      total, total_spendtime, total_spendtime / 3600, (total_spendtime % 3600) / 60, total_spendtime % 60,
      total_wordsnum, total_wordsnum / 1840, (total_wordsnum % 1840) / 80, total_wordsnum % 80,
      total_gold);
    fprintf(OutPut_fp,
      "    平均耗費時數:\033[1m%d 秒 (%d 分 %d秒)\033[m\n"
      "    平均總字元數:\033[1m%d 個字元 (%d 行 %d 個字元)\033[m\n"
      "    平均文章價值:\033[1m%d 金\033[m\n\n",
      average_spendtime, average_spendtime / 60, average_spendtime % 60,
      average_wordsnum, average_wordsnum / 80, average_wordsnum % 80,
      average_gold);

    fprintf(OutPut_fp, "\n        ┤\033[1;41m        本日灌水王        \033[m├\n\n");

    postnum_top(OutPut_fp);
    fclose(OutPut_fp);

    rename(FN_TOTAL_POST_GOLD, FN_TOTAL_POST_GOLD_OLD);
    //unlink(FN_TOTAL_POST_GOLD);
  }

  free(PostGolds);
  return 0;
}

: src/util/MakeFile

! ..... poststat post-gold reaper ....

==============================================================================

    最後在 crontab 加入

# 每天 23:55 做當然文章數據統計
55 23 * * * bin/post-gold > /dev/null 2>&1


    在 (A)nnounce  ξ 精華公佈欄 ξ 加入資料

    檔名為 -poststat

==============================================================================

    真是不怎麼起眼的功能....

    不過就是浪費一下系統資源....^^a

    而且...還不怎麼準勒~

    像是....文章總字元....換算成X頁X行X個字元.....

    還有什麼可以加在這個統計裡面的嗎?

    我能力可及都寫了....呵呵~

    好晚了....明天在PO程式碼好了....

==============================================================================



        ┤        本日文章所得        統計日期: 11 月 27 日

  文章發表總篇數:65 篇

  發文耗費總時數:26270 秒 (7 時 17 分 50 秒)
      文章總字數:14317 個字元 (7 頁 17 行 77 個字元)
      文章總價值:2654 金

    平均耗費時數:404 秒 (6 分 44秒)
    平均總字元數:220 個字元 (2 行 60 個字元)
    平均文章價值:40 金        本日灌水王        第 1 名:Ramanujan     發表 9 篇
  第 2 名:bug           發表 6 篇
  第 3 名:qazq          發表 6 篇
  第 4 名:[不告訴你]    發表 5 篇
  第 5 名:johnson       發表 5 篇   


--
  Author:  中興資科˙中興資科 e資獨秀  csNCHU.twbbs.org 
  Origin: qazq 61-217-232-237.HINET-IP.hinet.net 發表
精華選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻