• 沒有找到結果。

Statistic Module

4. 監控系統之設計

4.1 轉信機制

4.2.4. 系統核心之設計

4.2.4.3. Statistic Module

4.2.4.3. Statistic Module

在此定義系統所使用的討論串的資料結構如 Code Seg. # 2。Thread 結構中 的變數 title 為儲存討論串的標題,hours[24]為記錄此討論串 24 小時的文章,

artlist 為儲存該 thread 所有文章 ID 之 hash 資料結構,利用 hash 的方式儲存 文章 ID 可以避免因為時間誤差所產生重複取得相同文章的情形發生。Obs_hour 中記錄討論串超過該小時的 theta_hour/2 的時間。Alert_hour 與 Alert_day 表 示該討論串是某應被視為異常。

While(1) // infinite loop {

time = get_local_time;

Sleep(180); // wait 3 minute Connect to newserver:nntp Get new article from time;

}

Code Seg. # 2 Thread Structure

在統計時,會利用 hash 的方式儲存 thread 資料結構,其 key 為回應文章的 標題,value 則為對應此標題的 thread 資料結構。當一回應文章被系統讀入時,

若此回應文章的標題在 hash 中找不到時,表示此文章為一新 thread,否則,從 hash 中取出對應該回應文章的 thread 資料結構,並修改該 thread 的資訊,將 該回應文章加進 thread 結構裡的 artlist 中,如 Code Seg. # 3 的 01~11 行。

在每一篇新回應文章讀進來時,也可以記錄目前該小時的最熱門討論串,並計算 過去 24 小時內的最熱門討論串,如 Code Seg. # 3 的 12~18 行,除此之外,若 此 thread 的回應文章數目超過篩選值時,則必須立即輸出,如 Code Seg. # 3 的 19~36 行。

Struct Thread {

String Title // Thread title

Int hours[24]; // Number of articles in each hour Hash artlist; // contains artid

int obs_hour // contain the time # of articles exceed // theta_hour/2 first

Bool alert_hour // indicate # of articles in this hour exceed // theta_hour or exceed theta_hour/2 twice

Bool alert_day // indicate # of articles in this day exceed // theta_day

}

31 Code Seg. # 3 Statistic Module

01 IF article.title can be found in Thread_hash // indicate thread exist 02 THEN

03 1. Get the thread structure from Thread_hash 04 2. Add this article to thread.artlist

05 3. thread.hour[this_hour] plus 1 06 ELSE

07 1. Create a newthread structure 08 2. Add this article to newthread.artlist 09 3. newthread.hour[this_hour] plus 1 10

11 Store the thread to the Thread_hash

12 IF thread.hour[this_hour] > HotThreadOfHour.hour[this_hour]

13 THEN

14 HotThreadOfHour = thread

15 IF SUM(thread.hour) > SUM(HotThreadOfDay.hour) 16 THEN

17 HotThreadOfDay = thread 18

19 IF # of articles in this hours] >Θhour/2 20 THEN

21 For each thread in this hour

22 IF thread.hour[this_hour] >Θhour, 23 THEN

24 Add thread to monitor-list 25 Mail this article

26 ELSEIF thread is already in candidate-list AND # of articles >Θhour/2 27 THEN

28 Add thread to monitor-list 29 Mail this article

30 ELSEIF thread.hour[this_hour] >Θhour/2 31 THEN

32 Add thread to candidate-list 33 IF SUM(thread.hour) >Θday

34 THEN

35 Add thread to monitor list 36 Mail this article

系統預設會參考前一個月份的回應文章來計算篩選值,因此為了計算篩選用 的Θhour與Θday我們利用兩個 array:hourstat[24][30]與 daystat[30],以儲存 計算篩選值所需的數值。Housrstat[24][30]為儲存各小時過去 30 天的文章量,

daystat[30]則是儲存過去 30 天的最熱門討論串的文章量(從早上八點到隔天早 上七點)。篩選值的計算方法如 Code Seg. # 4,先取平均值再取標準差,之後 計算 theta_hour 與 theta_day。

Code Seg. # 4 篩選之 Algorithm

在每一個小時開始統計前,都會將 Thread_hash 中所有 thread 該小時文章 量歸零,藉由此歸零的動作,每個小時開始統計前都可以檢查 Thread_hash 中的 所有 thread 其 thread.hour 是否均為零,若全為零則表示此 Thread 已沒人注 意,可從 Thread_hash 中將此 thread 移除。除此之外,每一小時會將前一個小 時的統計資料更新,並重新計算前一個小時的 theta_hour,並將統計結果輸出,

包括該小時回應文章量最多的討論串、過去 24 小時中累積回應文章量最多的討 論串,如 Code Seg. # 5 的 01~10 行;若此小時為早上八點時,則會紀錄過去

00 Calculate_theta_hour(hour) 01 {

02 For index = 1 to 30

03 totalsum = totalsum + hourstat[hour][index]

04 End For

05 average = totalsum / 30 06

07 For index = 1 to 30

08 Variance = Variance + (hourstat[hour][index] – average)^ 2 09 End For

10 Theta_hour[hour] = 2*sqrt(Variance / 30) + average 11 }

12 Calculate_theta_day 13 {

14 For index = 1 to 30

15 totalsum = totalsum + daystat[index]

16 End For

17 average = totalsum / 30 18

19 For index = 1 to 30

20 Variance = Variance + (daystat[index] – average)^ 2 21 End For

22 Theta_day = 2*sqrt(Variance/30) + average 23 }

33

24 小時累計文章量最多的討論串,並重新計算 theta_day,如 Code Seg. # 5 的 11~14 行。

Code Seg. # 5 更新篩選值之 Algorithm

相關文件