// CLEAN
// LISTCLEAN

/***************************************************************************
                          row.h  -  description
                             -------------------
    begin                : Wed Jul 10 2002
    copyright            : (C) 2002 by Ross Andrews
    email                : randrews@geekfu.org
 ***************************************************************************/


#ifndef ROW_H
#define ROW_H

#include "station.h"
#include "resultset.h"
#include <string>
#include <vector>

using namespace std;

/**
  *@author Ross Andrews
  */

#define NUMMODS 12

// All the columns in the output table
struct columns{
  double power_ttl_mod[NUMMODS],power_xcd_mod[NUMMODS],power_ttl,power_xcd; //25
  double energy_ttl_mod[NUMMODS],energy_xcd_mod[NUMMODS],energy_ttl,energy_xcd; //25
  double energy_crewtend_ttl_mod[NUMMODS],energy_crewtend_xcd_mod[NUMMODS],energy_crewtend_ttl,energy_crewtend_xcd; //26
  double MTL_ttl_mod[NUMMODS],MTL_xcd_mod[NUMMODS],MTL_xcd; //25
  double LTL_ttl_mod[NUMMODS],LTL_xcd_mod[NUMMODS],LTL_xcd; //25
  double MTL_ttl_simul_mod[NUMMODS],MTL_xcd_simul_mod[NUMMODS],MTL_simul_xcd; //25
  double LTL_ttl_simul_mod[NUMMODS],LTL_xcd_simul_mod[NUMMODS],LTL_simul_xcd; //25
  double MTL_crewtend_ttl_mod[NUMMODS],MTL_crewtend_xcd_mod[NUMMODS],MTL_crewtend_xcd;
  double LTL_crewtend_ttl_mod[NUMMODS],LTL_crewtend_xcd_mod[NUMMODS],LTL_crewtend_xcd; //50
  double acoustics_ttl_mod[NUMMODS],acoustics_xcd_mod[NUMMODS],acoustics_xcd;
  double acoustics_ttl_simul_mod[NUMMODS],acoustics_xcd_simul_mod[NUMMODS],acoustics_xcd_simul; //50
  double acoustics_crewtend_ttl_mod[NUMMODS],acoustics_crewtend_xcd_mod[NUMMODS],acoustics_crewtend_xcd; //25
  double keepalive_ttl,keepalive_xcd;
  double middecks_ttl,middecks_xcd;
  double stowage_ttl,stowage_xcd;
  double upmass_ttl,upmass_xcd;
  double crewtrng_ttl,crewtrng_xcd;
  double crewtime_ttl,crewtime_xcd;
  
  double nominal_uplink,peak_uplink,peak_uplink_duration;
  double nominal_uplink_xcd,peak_uplink_xcd,peak_uplink_duration_xcd;
  double nominal_downlink,peak_downlink,peak_downlink_duration;
  double nominal_downlink_xcd,peak_downlink_xcd,peak_downlink_duration_xcd;
  double nominal_ethernet,peak_ethernet,peak_ethernet_duration;
  double nominal_ethernet_xcd,peak_ethernet_xcd,peak_ethernet_duration_xcd;
  double nominal_1553,peak_1553,peak_1553_duration;
  double nominal_1553_xcd,peak_1553_xcd,peak_1553_duration_xcd;
  double nominal_HRL,peak_HRL,peak_HRL_duration;
  double nominal_HRL_xcd,peak_HRL_xcd,peak_HRL_duration_xcd;
  double video_uplink,video_downlink,video_rate;
  double video_uplink_xcd,video_downlink_xcd,video_rate_xcd;

  double cs_p4_asc_ttl,cs_p4_orb_ttl,cs_p4_desc_ttl;
  double cs_m20_asc_ttl,cs_m20_orb_ttl,cs_m20_desc_ttl;
  double cs_m80_asc_ttl,cs_m80_orb_ttl,cs_m80_desc_ttl;
  double cs_m180_asc_ttl,cs_m180_orb_ttl,cs_m180_desc_ttl;

  double cs_p4_asc_xcd,cs_p4_orb_xcd,cs_p4_desc_xcd;
  double cs_m20_asc_xcd,cs_m20_orb_xcd,cs_m20_desc_xcd;
  double cs_m80_asc_xcd,cs_m80_orb_xcd,cs_m80_desc_xcd;
  double cs_m180_asc_xcd,cs_m180_orb_xcd,cs_m180_desc_xcd;

  double runtime_ttl;
  
  double any_exceeded_inc,any_exceeded_simul; //26

  vector<double> sums_ttl;
  vector<int> sums_xcd;
};

// The columns in runs that are the parameters for a run
struct runparams{
  double MLE,stowage,upmass,bulk,rack_overhead,
    crewtrng,crewtime,power,keepalive,
    avg_uplink,avg_ethernet,avg_1553,avg_HRL,avg_downlink,
    peak_uplink,peak_ethernet,peak_1553,peak_HRL,peak_downlink,
    peak_uplink_duration,peak_ethernet_duration,peak_1553_duration,peak_HRL_duration,peak_downlink_duration,
    video_uplink,video_downlink,video_rate,
    hskpg,inclength,middeckmass,ku_power,
    pl_power,sams_power,stowage_MLEs;

  double cs_p4_asc,cs_p4_orb,cs_p4_desc;
  double cs_m20_asc,cs_m20_orb,cs_m20_desc;
  double cs_m80_asc,cs_m80_orb,cs_m80_desc;
  double cs_m180_asc,cs_m180_orb,cs_m180_desc;

  int newsams,samsmod,needssams;
  string tblname;
  int ignore;
  vector<double> limits;
};

class row {
private:
	row();
/////////////////////
	MYSQL conn;
	station *stn;
	columns cols;
	ostream* outputstream;
	string separator;
/////////////////////
	int findsams(string);
/////////////////////
	void calc_power();
	void calc_energy();
	void calc_energy_crewtend();
	void calc_MTL();
	void calc_LTL();
	void calc_MTL_simul();
	void calc_LTL_simul();
	void calc_MTL_crewtend();
	void calc_LTL_crewtend();
	void calc_acoustics();
	void calc_acoustics_simul();
	void calc_acoustics_crewtend();
	void calc_keepalive();
	void calc_middecks();
	void calc_stowage();
	void calc_upmass();
	void calc_crewtrng();
	void calc_crewtime();
	void calc_networking();
	void calc_coldStowage();
	void calc_runtime();
	void calc_sums();
	void calc_any();
/////////////////////
	void generic_print(double,double,double*,double*,string);
	void print_MTL();
	void print_LTL();
	void print_MTL_simul();
	void print_LTL_simul();
	void print_MTL_crewtend();
	void print_LTL_crewtend();
	void print_acoustics();
	void print_acoustics_simul();
	void print_acoustics_crewtend();
	void print_keepalive();
	void print_middecks();
	void print_stowage();
	void print_upmass();
	void print_crewtrng();
	void print_crewtime();
	void print_networking();
	void print_coldStowage();
	void print_runtime();
	void print_sums();
	void print_any();
/////////////////////
public:
///////////////////// Public Data
	runparams run;
///////////////////// Constructors
	row(MYSQL,int,string);
	row(const row&);
	const row& operator=(const row&);
	~row();
/////////////////////
	void calc();
	void store(int,string);
	void dump(ostream&);
/////////////////////
	void addcombo(vector<rack>);
	void addkeepalivecombo(vector<rack>);
};

#endif
