// stats.C: the Statistics class.

#include <iostream.h>
#include "supermarket.h"
#include "stats.h"


void Statistics::accumSale (double items) {
   customersServed += 1;
   totalItemsSold += items;
}

void Statistics::accumServiceTime (double interval) {
   totalServiceTime += interval;
}

void Statistics::accumWaitingTime (double interval) {
   totalWaitingTime += interval;
}

void Statistics::countArrival () {
   totalArrivals += 1;
}

// printHeaders: print column titles for the statistics summaries.
void Statistics::printHeaders () {

   // CODE: this headers show which statistics to collect in snapshot
   cout<< "\n(Times are reported in minutes)\n";
   cout<<"CstArrv: total number of customers that arrived so far\n";
   cout<<"CstServ: total number of customers that were served so far\n";
   cout<<"CS/min:  average number of customers served per minute\n";
   cout<<"Its/min: average number of items sold per minute\n";
   cout<<"MaxWait: maximum waiting time among all customers served so far\n";
   cout<<"AvgWait: average waiting time among customers\n";
   cout<<"AvgServ: average service time among customers\n";
   cout<<"AvgTime: average time among customers (waiting+service)\n";
   cout<< "\n(Times are reported in minutes)\n";
   // current time
   cout.width(8); cout << " Time";
   // Total number of customers that arrived so far 
   cout.width(8); cout << " CstArrv";
   // Total number of customers that were served so far 
   cout.width(8); cout << " CstServ";
   // Average number of customers served per minute
   cout.width(8); cout << " CS/min" ;
   // Average number of items sold per minute
   cout.width(8); cout << " Its/min";
   // Maximum waiting time among all customers served so far 
   cout.width(8); cout << " MaxWait";
   // Average waiting time among customers
   cout.width(8); cout << " AvgWait";
   // Average service time among customers
   cout.width(8); cout << " AvgServ";
   // Average Total time among customers (Total=waiting+service)
   cout.width(8); cout << " AvgTime\n";

   for (int i = 0; i < 79; i++)
      cout << "-";
   cout << "\n";
   cout.precision(5);
}

void Statistics::snapshot () {

   // CODE: appropriate stats must be print 
   // (see printHeaders above to see which quantities should be printed where)
   // ( now is printing zeroes for most outputs)

   double time = sim->getTime()/60;
   cout.width(8); 
   cout<<time; // this is already done 
                                 // (note seconds being converted to minutes)
   cout.width(8);
   cout<<totalArrivals; // another already done for you
   cout.width(8);
   cout<< customersServed;
   cout.width(8);
   cout << customersServed/time;
   cout.width(8);
   cout << totalItemsSold/time; 
   cout.width(8);
   cout << 0;
   cout.width(8);
   cout << totalWaitingTime/customersServed;
   cout.width(8);
   cout << totalServiceTime/customersServed;
   cout.width(8);
   cout << ( totalWaitingTime + totalServiceTime ) / customersServed <<"\n";
}
