]>
Commit | Line | Data |
---|---|---|
504f62c7 CP |
1 | /* |
2 | nterfacer newserv chanstats module | |
3 | Copyright (C) 2004 Chris Porter. | |
4 | */ | |
5 | ||
6 | #include "../chanstats/chanstats.h" | |
16d29ce2 | 7 | #include "../core/error.h" |
87698d77 | 8 | #include "../lib/version.h" |
504f62c7 CP |
9 | |
10 | #include "library.h" | |
11 | #include "nterfacer_control.h" | |
12 | ||
70b0a4e5 | 13 | MODULE_VERSION(""); |
87698d77 | 14 | |
504f62c7 | 15 | int handle_chanstats(struct rline *li, int argc, char **argv); |
4e4920a4 | 16 | static struct handler *hl = NULL; |
504f62c7 CP |
17 | |
18 | void _init(void) { | |
16d29ce2 CP |
19 | if(!n_node) { |
20 | Error("nterfacer_chanstats", ERR_ERROR, "Unable to register chanstats as nterfacer_control isn't loaded!"); | |
21 | return; | |
22 | } | |
504f62c7 CP |
23 | hl = register_handler(n_node, "chanstats", 1, handle_chanstats); |
24 | } | |
25 | ||
26 | void _fini(void) { | |
27 | if(hl) | |
28 | deregister_handler(hl); | |
29 | } | |
30 | ||
31 | int handle_chanstats(struct rline *li, int argc, char **argv) { | |
32 | chanstats *csp; | |
33 | chanindex *cip; | |
34 | int i,j,k,l; | |
35 | int tot,emp; | |
36 | int themax; | |
0555113a | 37 | float details[14]; |
504f62c7 CP |
38 | |
39 | cip=findchanindex(argv[0]); | |
40 | ||
41 | if (cip==NULL) | |
42 | return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found"); | |
43 | ||
44 | csp=cip->exts[csext]; | |
45 | ||
46 | if (csp==NULL) | |
47 | return ri_error(li, ERR_CHANSTATS_STATS_NOT_FOUND, "Stats not found"); | |
48 | ||
49 | if (uponehour==0) { | |
50 | details[0] = -1; | |
51 | details[1] = -1; | |
52 | } else { | |
53 | tot=0; emp=0; | |
54 | for(i=0;i<SAMPLEHISTORY;i++) { | |
55 | tot+=csp->lastsamples[i]; | |
56 | if (csp->lastsamples[i]==0) { | |
57 | emp++; | |
58 | } | |
59 | } | |
60 | details[0] = tot/SAMPLEHISTORY; | |
61 | details[1] = emp/SAMPLEHISTORY * 100; | |
62 | ||
63 | } | |
64 | ||
65 | details[2] = csp->todayusers/todaysamples; | |
66 | details[3] = ((float)(todaysamples-csp->todaysamples)/todaysamples)*100; | |
67 | details[4] = csp->todaymax; | |
68 | ||
69 | themax=csp->lastmax[0]; | |
70 | ||
71 | details[5] = csp->lastdays[0]/10; | |
72 | details[6] = ((float)(lastdaysamples[0]-csp->lastdaysamples[0])/lastdaysamples[0])*100; | |
73 | details[7] = themax; | |
74 | ||
75 | /* 7-day average */ | |
76 | j=k=l=0; | |
77 | for (i=0;i<7;i++) { | |
78 | j+=csp->lastdays[i]; | |
79 | k+=csp->lastdaysamples[i]; | |
80 | l+=lastdaysamples[i]; | |
81 | if (csp->lastmax[i]>themax) { | |
82 | themax=csp->lastmax[i]; | |
83 | } | |
84 | } | |
85 | ||
86 | details[8] = j/70; | |
87 | details[9] = ((l-k)*100)/l; | |
88 | details[10] = themax; | |
89 | ||
90 | /* 14-day average: continuation of last loop */ | |
91 | for (;i<14;i++) { | |
92 | j+=csp->lastdays[i]; | |
93 | k+=csp->lastdaysamples[i]; | |
94 | l+=lastdaysamples[i]; | |
95 | if (csp->lastmax[i]>themax) { | |
96 | themax=csp->lastmax[i]; | |
97 | } | |
98 | } | |
99 | ||
100 | details[11] = j/140; | |
101 | details[12] = ((l-k)*100)/l; | |
102 | details[13] = themax; | |
103 | ||
104 | ri_append(li, "%.1f", details[0]); | |
105 | ri_append(li, "%.1f%%", details[1]); | |
106 | for(j=2;j<14;) { | |
107 | ri_append(li, "%.1f", details[j++]); | |
108 | ri_append(li, "%.1f%%", details[j++]); | |
16739dbe | 109 | ri_append(li, "%f%%", details[j++]); |
504f62c7 CP |
110 | } |
111 | ||
112 | return ri_final(li); | |
113 | } |