//std::string CAlarmHandler::MTBF()
//{
//	// Need to maintain this in memory better
//	CsvArchiver csv;
//	std::vector<std::string> faultfields; 
//	std::vector<DataDictionary>  faultdatum;
//	std::string filename=_archivepath+this->_sMachine+"AlarmHistory.csv";
//	csv.read(filename, faultfields, _historicalfaultdatum);
//	std::vector<std::string> tbfs = DataDictionary().Column<std::string>( _historicalfaultdatum, "RaisedAt");
//	std::vector<ptime> ptbfs;
//	std::vector<double> dtbfs;
//	for(int i=0; i< tbfs.size(); i++)
//	{
//		ptbfs.push_back(GetDateTime(tbfs[i]));
//	}
//	if(ptbfs.size() < 2)
//		return "";  // time since last fail - from start, from yesterday?
//	for(int i=1; i< ptbfs.size(); i++)
//	{
//		time_duration duration = ptbfs[i] - ptbfs[i-1];
//		dtbfs.push_back(duration.total_seconds());
//	}
//	std::vector<double> ds;
//	srand ( 1 );
//	for(int i=1; i< 100; i++)
//	{
//		int n = rand() % dtbfs.size();
//		ds.push_back(dtbfs[n] /60.0);
//	}
//
//	StatFitting statfit;
//	Distribution dist = statfit.BestFit(ds); // dtbfs);
//	return dist.ToString();
//}
//std::string CAlarmHandler::MTTR()
//{
//
//}
bool CAlarmHandler::CalculateMeanTimes(std::string &mtbf, std::string &mttr)
{	// Need to maintain this in memory better
	CsvArchiver csv;
	std::vector<std::string> faultfields; 
	std::vector<DataDictionary>  faultdatum;
	std::string filename=_archivepath+this->_sMachine+"AlarmHistory.csv";
	csv.read(filename, faultfields, _historicalfaultdatum);

	std::vector<double> ttrs = DataDictionary().Column<double>( _historicalfaultdatum, "TTR");
	std::vector<double> tbfs = DataDictionary().Column<double>( _historicalfaultdatum, "TBF");
	//std::vector<double> dtbrs, dttrs;
	mtbf.clear(); mttr.clear();
	if(ttrs.size() < 2)
		return false;  // time since last fail - from start, from yesterday?
	if(ttrs.size() > 100)
	{
		random_unique(tbfs.begin(), tbfs.end(), 100);
		random_unique(ttrs.begin(), ttrs.end(), 100);
		tbfs.erase(tbfs.begin()+100, tbfs.end());
		ttrs.erase(ttrs.begin()+100, ttrs.end());
	}
	StatFitting statfit;
	Distribution dist1 = statfit.BestFit(ttrs);
	Distribution dist2 = statfit.BestFit(tbfs);
	mttr=dist1.ToString();
	mtbf=dist2.ToString();
	return true;

}
예제 #2
0
int ZHTgetLocations(ZHTClient_c zhtClient, struct comLocations * loc){
	//This makes a connection to ZHT to get the memberlist and picks blocksNumber locations to store our files.
	ZHTClient * zhtcppClient = (ZHTClient *) zhtClient;

	int blocksNumber = loc->locationsNumber;
	
	vector<struct HostEntity> potentialLoc(zhtcppClient->memberList); //we need to pick here :) Maybe need to include zht_util to decrypt HostEntity

	if(potentialLoc.size() < blocksNumber){
		loc->locationsNumber = potentialLoc.size();
	}
	
	//This allows to pick n random different members in the vector ---------
	//Laziness: http://ideone.com/3A3cv and http://stackoverflow.com/questions/9345087/choose-m-elements-randomly-from-a-vector-containing-n-elements
	random_unique(potentialLoc.begin(), potentialLoc.end(), blocksNumber);
    
    
	int currentLocationsNumber = 0;
	int i;
	
	int FFSNETSHIFT = 9000;
	
	struct comTransfer * prev = NULL;
	struct comTransfer * current;
	
	
    for(int i=0; i<blocksNumber; ++i) {
        //std::cout << a[i] << '\n';
              
        current = (struct comTransfer *) malloc(sizeof(struct comTransfer));
	
		current->hostName = (char *) malloc(potentialLoc[i].host.size()+1);
		strcpy(current->hostName,potentialLoc[i].host.c_str());
		
		current->port = potentialLoc[i].port + FFSNETSHIFT;
		
	
		currentLocationsNumber++;
		current->next = prev;
		prev = current;

        
    }
	loc->transfers = current;

	return 0;
}