/*This is the object for keep track of the statistics in the lewontin model.*/

#pragma once

#include "LewObjects.h"
#include "plotting.h"

#define NUM_LONGE_GROUPS 101
#define NUM_MUTAT_GROUPS 101
#define NUM_AGE_GROUPS 11


#if __cplusplus
class cStats  
#else
class cStats : indirect
#endif
{
	FILE *logfp;
	double ave_longe;
	double ave_mutat;
	double ave_age;
	int max_fitness;
	int min_fitness;
	
	/*These should be changed to cHistograms.*/
	unsigned int longevities[NUM_LONGE_GROUPS];
	unsigned int mutations[NUM_MUTAT_GROUPS];
	unsigned int ages[NUM_AGE_GROUPS];
	cHistogram *longeHist;
/*	cHistogram *mutatHist;
	cHistogram *agesHist;
*/	
	
	public:
		cStats();  /*constructor*/
		~cStats(); /*destructor*/
		void setup(int popsize); /*sets up the histograms.*/
		void open_file(char logfile[]);
		void close_file();
		/*Takes the population and gathers the stats.*/	
		void gather_pop(cPopulation *pop);	
		void record_state(cPopulation *pop, cContext *context);
		void display();  /*Plots the histograms of the stats.*/
		
	protected:
		void calc_ave_longe(cOrganism **orgs, int popsize);
		void calc_ave_mutat(cOrganism **orgs, int popsize);
		void calc_ave_age(cOrganism **orgs, int popsize);
		void get_fitness_bounds(cOrganism **orgs, int popsize);
		
		void gather_longes(cOrganism **orgs);
		void gather_mutats(cOrganism **orgs);
		void gather_ages(cOrganism **orgs);
};