aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-11-23 23:34:13 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-11-23 23:34:13 +0000
commit2defb0b8d12f20542b34c31f3761b66c8e0fd868 (patch)
tree8e0d4c24faeda5f84a80176529dd3990e5d07aa2
parent5baa70c552a6a262a86d07cb3f600f83db4c0fed (diff)
downloadtagr-2defb0b8d12f20542b34c31f3761b66c8e0fd868.tar.gz
tagr-2defb0b8d12f20542b34c31f3761b66c8e0fd868.tar.bz2
(convert_stats): Rewritten
git-svn-id: file:///svnroot/tagr/trunk@73 7c378d0d-a4e4-4a64-9229-dfce8bfd23d4
-rw-r--r--stat.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/stat.c b/stat.c
index 63f87fa..3cb4b23 100644
--- a/stat.c
+++ b/stat.c
@@ -166,23 +166,64 @@ update_stats (SD *sd, struct traffic_record *tr)
#define hist_rec last_sample
static void
+_convert (struct traffic_record *tr, struct hist_rec *hp, size_t count,
+ int sample)
+{
+ size_t i;
+
+ tr->last.time = hp[count-1].time - sample;
+ for (i = count - 1; i+1 > 0; i--)
+ {
+ SD sd;
+
+ sd.t = hp[i].time;
+ sd.in = hp[i].in;
+ sd.out = hp[i].out;
+ verbose (3, "Data %lu %lu %lu", sd.t, sd.in, sd.out);
+ update_stats (&sd, tr);
+ }
+}
+
+static void
+convert_yearly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+{
+ _convert (tr, hp, YEAR_COUNT + 1, YEAR_SAMPLE);
+}
+
+static void
+convert_monthly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+{
+ if (count > MONTH_COUNT+1)
+ convert_yearly (tr, hp + MONTH_COUNT + 1, count - (MONTH_COUNT + 1));
+ _convert (tr, hp, MONTH_COUNT + 1, MONTH_SAMPLE);
+}
+
+static void
+convert_weekly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+{
+ if (count > WEEK_COUNT+1)
+ convert_monthly (tr, hp + WEEK_COUNT + 1, count - (WEEK_COUNT + 1));
+ _convert (tr, hp, WEEK_COUNT + 1, WEEK_SAMPLE);
+}
+
+static void
+convert_daily (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+{
+ if (count > DAY_COUNT+1)
+ convert_weekly (tr, hp + DAY_COUNT + 1, count - (DAY_COUNT + 1));
+ _convert (tr, hp, DAY_COUNT + 1, DAY_SAMPLE);
+}
+
+static void
convert_stats (SD *sd, struct hist_rec *last,
struct hist_rec *hp, size_t count)
{
- size_t i;
struct traffic_record *trp, tr;
memset (&tr, 0, sizeof tr);
tr_init (&tr);
- tr.last.time = hp[count-1].time - 300;
- for (i = count - 1; i+1 > 0; i--)
- {
- sd->t = hp[i].time;
- sd->in = hp[i].in;
- sd->out = hp[i].out;
- verbose (3, "Data %lu %lu %lu", sd->t, sd->in, sd->out);
- update_stats (sd, &tr);
- }
+
+ convert_daily (&tr, hp, count);
read_db (sd, &trp);
*trp = tr;

Return to:

Send suggestions and report system problems to the System administrator.