2 nterfacer newserv chanstats module
3 Copyright (C) 2004 Chris Porter.
6 #include "../chanstats/chanstats.h"
7 #include "../core/error.h"
8 #include "../lib/version.h"
11 #include "nterfacer_control.h"
15 int handle_chanstats(struct rline
*li
, int argc
, char **argv
);
16 static struct handler
*hl
= NULL
;
20 Error("nterfacer_chanstats", ERR_ERROR
, "Unable to register chanstats as nterfacer_control isn't loaded!");
23 hl
= register_handler(n_node
, "chanstats", 1, handle_chanstats
);
28 deregister_handler(hl
);
31 int handle_chanstats(struct rline
*li
, int argc
, char **argv
) {
39 cip
=findchanindex(argv
[0]);
42 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
47 return ri_error(li
, ERR_CHANSTATS_STATS_NOT_FOUND
, "Stats not found");
54 for(i
=0;i
<SAMPLEHISTORY
;i
++) {
55 tot
+=csp
->lastsamples
[i
];
56 if (csp
->lastsamples
[i
]==0) {
60 details
[0] = tot
/SAMPLEHISTORY
;
61 details
[1] = emp
/SAMPLEHISTORY
* 100;
65 details
[2] = csp
->todayusers
/todaysamples
;
66 details
[3] = ((float)(todaysamples
-csp
->todaysamples
)/todaysamples
)*100;
67 details
[4] = csp
->todaymax
;
69 themax
=csp
->lastmax
[0];
71 details
[5] = csp
->lastdays
[0]/10;
72 details
[6] = ((float)(lastdaysamples
[0]-csp
->lastdaysamples
[0])/lastdaysamples
[0])*100;
79 k
+=csp
->lastdaysamples
[i
];
81 if (csp
->lastmax
[i
]>themax
) {
82 themax
=csp
->lastmax
[i
];
87 details
[9] = ((l
-k
)*100)/l
;
90 /* 14-day average: continuation of last loop */
93 k
+=csp
->lastdaysamples
[i
];
95 if (csp
->lastmax
[i
]>themax
) {
96 themax
=csp
->lastmax
[i
];
101 details
[12] = ((l
-k
)*100)/l
;
102 details
[13] = themax
;
104 ri_append(li
, "%.1f", details
[0]);
105 ri_append(li
, "%.1f%%", details
[1]);
107 ri_append(li
, "%.1f", details
[j
++]);
108 ri_append(li
, "%.1f%%", details
[j
++]);
109 ri_append(li
, "%f%%", details
[j
++]);