#!/usr/bin/perl -w

use warnings;
use strict;

use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
use POSIX qw/strftime/;
use CGI::Pretty qw[:standard];

use czartool::CzarDb;
use czartool::Gpc1Db;
use czartool::Plotter;
use czartool::StageMetrics;
use czartool::Metrics;


package czartool::MultiDayMetrics;
our @ISA = qw(czartool::Metrics);    # inherits from Metrics class

###########################################################################
#
# Constructor (overrides superclass)
#
###########################################################################
sub new {
    my ($class) = @_;

    # Call the constructor of the parent class
    my $self = $class->SUPER::new(
            $_[1],  # config object 
            $_[2],  # verbose
            $_[3]   # save_temps
            );

    $self->{startDay} = $_[4];
    $self->{endDay} = $_[5];

    # sort out times
    $self->{begin} =  "$self->{startDay} " . $self->{config}->getMetricsStartTime();
    $self->{end} =  "$self->{endDay} " . $self->{config}->getMetricsStartTime();

    # create path, dir and html file
    $self->{path} = "$self->{baseDir}/$self->{startDay}_$self->{endDay}";
    rmdir($self->{path});
    mkdir($self->{path}, 0777);
    $self->{plotter}->setOutputPath($self->{path});

    if ($self->{verbose}) {print "* Creating metrics for $self->{startDay} to $self->{endDay}\n";}

    bless $self, $class;

    return $self;
}

###########################################################################
#
# Writes HTML document
#
###########################################################################
sub writeHTML {
    my ($self) = @_;

    $self->createHtml("IPP Metrics for $self->{startDay} to $self->{endDay}");
    my $htmlFile = $self->{htmlFile};

    print $htmlFile "<h5  align=\"middle\"><a href=\"../index.html\">all</a><br> </h5>";

    # summary plots
    $self->createSummaryPlots();

    # magic mask plots
    $self->createMaskPlots($self->{startDay}, $self->{endDay});

    $self->finishHtml();
}
1;
