Index: branches/eam_branches/ipp-20101205/tools/czarpoll.pl
===================================================================
--- branches/eam_branches/ipp-20101205/tools/czarpoll.pl	(revision 29959)
+++ branches/eam_branches/ipp-20101205/tools/czarpoll.pl	(revision 30102)
@@ -108,50 +108,51 @@
     my $newState = undef;
     my $nsStatus = undef;
-    my $lastDay = strftime('%Y-%m-%d', localtime);
     my $today = undef;
-    my $doneMetricsToday = 1;
-
+    my $yesterday = undef;
+    my $newDayTime = "18:00";
+    my $lastDayDailyTasks = "2010-01-01";
+
+    # main polling loop
     while (1) {
 
-        # check whether day has changed. if so, cleanup tables from previous day and optimize
+        # sort out times
         $today = strftime('%Y-%m-%d', localtime);
-        if ($czarDb->isBefore($lastDay, $today)) {
-        
+        $yesterday = $czarDb->subtractInterval($today, "1 DAY");
+        $end = $czarDb->getNowTimestamp();
+
+        # if before 18:00 today, then start plots from 18:00 yesterday
+        if ($czarDb->isBefore($end, "$today $newDayTime")) {$begin = "$yesterday $newDayTime";}
+        # if after 18:00 today, then perform some daily tasks and start plots from 18:00 today
+        else {
+            
+            $begin = "$today $newDayTime";
+
+            # check whether yesterday was cleaned. if not, cleanup tables and optimize
+            if ($lastDayDailyTasks ne $yesterday) {
+   
+                print "* performing daily tasks (clean-up, metrics)";
+
+                # create metrics for last 24 hours
+                print "* Creating metrics for last 24 hours\n";
+                # TODO hardcoded path needs to be in config
+                my $dayMetrics = new czartool::DayMetrics($gpc1Db, 
+                        $czarDb, 
+                        "/data/ipp004.0/ipp/ippMetrics/", 
+                        1, 0, $today); 
+                $dayMetrics->writeHTML();
+
+                # now update metrics index page
+                my $metricsIndex = new czartool::MetricsIndex($gpc1Db, 
+                        $czarDb, 
+                        "/data/ipp004.0/ipp/ippMetrics/", 
+                        1, 0); 
+                $metricsIndex->writeHTML();
+
+                # now cleanup tables from yesterday and optimize
                 print "* New day - performing cleanup\n";
-                $czarDb->cleanupDateRange($lastDay, $lastDay, "30 MINUTE");
+                $czarDb->cleanupDateRange($yesterday, $yesterday, "30 MINUTE");
                 $czarDb->optimize();
-                $lastDay = $today;
-                $doneMetricsToday = 0;
-        }
-
-        # sort out times
-        $begin = strftime('%Y-%m-%d 06:30', localtime);
-        $end = $czarDb->getNowTimestamp();
-
-        # if time now is after 06:35am, then create metrics for past 24 hours
-        if (!$doneMetricsToday && $czarDb->isBefore($begin, $end)) {
-        
-            # create metrics for last 24 hours
-            print "* Creating metrics for last 24 hours\n";
-            my $yesterday = $czarDb->subtractInterval($today, "1 DAY");
-            # TODO hardcoded path needs to be in config
-            my $dayMetrics = new czartool::DayMetrics($gpc1Db, 
-                    $czarDb, 
-                    "/data/ipp004.0/ipp/ippMetrics/", 
-                    1, 0, $yesterday); 
-            $dayMetrics->writeHTML();
-            $doneMetricsToday = 1;
-
-            # now update metrics index page
-            my $metricsIndex = new czartool::MetricsIndex($gpc1Db, 
-                    $czarDb, 
-                    "/data/ipp004.0/ipp/ippMetrics/", 
-                    1, 0); 
-        }
-
-        # if time now is before 06:35am, include data from previous day
-        if ($czarDb->isBefore($end, $begin)) {
-
-            $begin = $czarDb->subtractInterval($begin, "1 DAY");
+                $lastDayDailyTasks = $yesterday;
+            }
         }
 
@@ -247,5 +248,5 @@
 
         $plotter->createLogAndLinearTimeSeries($allServerLabels,  $stage, $begin, $end); # TODO must be a neater way...
-        $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
+            $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
     }
 }
@@ -271,5 +272,5 @@
     my $server = undef;
     my $state = undef;
-    
+
     foreach $stage (@stages) {
 
