示例#1
0
feature feat_trade_region(vec_t trade_list)
{
	feature feat;
	if (trade_list.size() > 0)
		feat.push_back(trade_list[trade_list.size() - 1].timeStamp - trade_list[0].timeStamp);
	else
		feat.push_back(0);
	return feat;
}
示例#2
0
feature feat_trade_distglobal_total(vec_t trade_list)
{
	feature feat;
	size_t len = trade_list.size();
	double sum = 0;
	for (size_t i = 0; i + 1 < len; ++i)
		sum += dist_global(trade_list[i].addr, trade_list[i + 1].addr);
	feat.push_back(sum);
	return feat;
}
示例#3
0
feature feat_trade_distglobal_max(vec_t trade_list)
{
	feature feat;
	size_t len = trade_list.size();
	double maxDist = 0;
	for (size_t i = 0; i + 1 < len; ++i)
		for (size_t j = i + 1; j < len; ++j)
			if (dist_global(trade_list[i].addr, trade_list[j].addr) > maxDist)
				maxDist = dist_global(trade_list[i].addr, trade_list[j].addr);
	feat.push_back(maxDist);
	return feat;
}
    void reportAction()
    {
    	/*
    	1. Todos los trenes que tienen cierta falla.
		2. Todos los trenes que tienen cierto accidente.
		3. Todas las fallas de una formacion determinada.
		4. Todos los accidentes de una formacion determinada.
		5. Todas las fallas.
		6. Todas las formaciones.
		7. Todas las lineas.
		8. Todos los accidentes
		*/
		
		std::map< std::string, unsigned > available_reports;
		
		available_reports["trenesxfalla"] = 1;
		available_reports["trenesxaccidente"] = 2;
		available_reports["fallasxformacion"] = 3;
		available_reports["accidentesxformacion"] = 4;
		available_reports["fallas"] = 5;
		available_reports["formaciones"] = 6;
		available_reports["lineas"] = 7;
		available_reports["accidentes"] = 8;
		
		if (args.size() == 0) {
			std::cerr << "No se especificó el tipo de reporte" << std::endl;
			return;
		}
		
		if (available_reports.find(args[0]) == available_reports.end()) {
			std::cerr << "No se encontró el reporte especificado" << std::endl;
			return;
		}
		
		Query * q = new Query();
		QueryBuilder builder;
		builder.setQuery(q);
		std::vector< std::string > headers;
		std::vector< unsigned > fields;
		
		switch (available_reports[args[0]]) {
			case 1:
				if (args.size() < 2) {
					std::cerr << "No se especificó la falla" << std::endl;
					delete q;
					return;				
				}
				
				builder.parse("falla=" + args[1]);
				
				headers.push_back("Línea");
				headers.push_back("Formación");
				
				fields.push_back(LINEA);
				fields.push_back(FORMACION);
				
				break;
			case 2:
				if (args.size() < 2) {
					std::cerr << "No se especificó el accidente" << std::endl;
					delete q;
					return;				
				}
				
				builder.parse("accidente=" + args[1]);
				
				headers.push_back("Línea");
				headers.push_back("Formación");
				
				fields.push_back(LINEA);
				fields.push_back(FORMACION);
				
				break;

			case 3:
				if (args.size() < 2) {
					std::cerr << "No se especificó la línea ni la formación" << std::endl;
					delete q;
					return;				
				}
				
				if (args.size() < 3) {
					std::cerr << "No se especificó la formación" << std::endl;
					delete q;
					return;				
				}
				
				builder.parse("linea=" + args[1]);
				builder.parse("formacion=" + args[2]);
				
				headers.push_back("Línea");
				headers.push_back("Formación");
				headers.push_back("Falla");
				
				fields.push_back(LINEA);
				fields.push_back(FORMACION);
				fields.push_back(FALLA);
				
				break;

			case 4:
				if (args.size() < 2) {
					std::cerr << "No se especificó la línea ni la formación" << std::endl;
					delete q;
					return;				
				}
				
				if (args.size() < 3) {
					std::cerr << "No se especificó la formación" << std::endl;
					delete q;
					return;				
				}
				
				builder.parse("linea=" + args[1]);
				builder.parse("formacion=" + args[2]);
				
				headers.push_back("Línea");
				headers.push_back("Formación");
				headers.push_back("Accidente");
				
				fields.push_back(LINEA);
				fields.push_back(FORMACION);
				fields.push_back(ACCIDENTE);
				
				break;
				
			case 5:
				headers.push_back("Falla");
				fields.push_back(FALLA);
				
				break;
			
			case 6:
				headers.push_back("Línea");
				headers.push_back("Formacion");
				fields.push_back(LINEA);
				fields.push_back(FORMACION);
				
				break;
				
			case 7:
				headers.push_back("Línea");
				fields.push_back(LINEA);
				
				break;
				
			case 8:
				headers.push_back("Accidente");
				fields.push_back(ACCIDENTE);
				
				break;
				
			default: 
				std::cerr << "Ha ocurrido un error" << std::endl;
				return;
		}
		
		KDtree * tree = new KDtree(DIMENSIONS, new FileBlocks(path.c_str(), blockSize));
		std::vector< Record * > result = tree->find(q);
		
		if (result.size() == 0) {
			std::cout << "No se encontraron registros" << std::endl;
		} else {
			std::cout << std::endl;

			for(int i = 0; i < headers.size(); i++) {
				std::cout << headers[i];
				std::cout << "\t\t";
			}
			
			std::cout << std::endl;
			std::cout << std::endl;
		
			std::vector<Key*> shownKeys;

			for (int i = 0; i < result.size(); i++) {
				for (int f = 0; f < fields.size(); f++) {
					if ((!shown(result[i]->getID()->getKey(fields[f]), shownKeys)) || (fields.size()>1)){
						result[i]->getID()->getKey(fields[f])->dump();
						shownKeys.push_back(result[i]->getID()->getKey(fields[f]));
						std::cout << "\t\t";
						if((fields.size()==1))std::cout << std::endl;
					}
				}
				if((fields.size()>1))std::cout << std::endl;
			}


		}
		
		delete tree;
    }
示例#5
0
feature get_basic_feature(customer x)
{
	feature feat;
	feat.push_back(x.id);
	feat.push_back(x.gender);
	feat.push_back(type2int[x.type]);
	if (x.birth.isVailed())
	{
		int year, month, day;
		x.birth.get_date(year, month, day);
		for (int i = 1; i < 13; ++i)
		{
			if (i == month)
				feat.push_back(1);
			else
				feat.push_back(-1);
		}
		for (int i = 0; i < 4; ++i)
			if (i * 3 < month && month <= (i * 3 + 3))
				feat.push_back(1);
			else
				feat.push_back(-1);
		// month
		for (int k = 0; k < 10; ++k)
			for (int i = 1910; i + k <= 2012; ++i)
				if (i <= year && year <= i + k)
					feat.push_back(1);
				else
					feat.push_back(-1);
	}
	else
	{
		for (int i = 1; i < 13; ++i)
			feat.push_back(0);
		for (int i = 0; i < 4; ++i)
			feat.push_back(0);
		for (int k = 0; k < 10; ++k)
			for (int i = 1930; i + k <= 2012; ++i)
				feat.push_back(0);
	}
	//histogram of month and year;
	for (int i = 0; i < 35; ++i)
		if (x.addr.get_province() == i)
			feat.push_back(+1);
		else feat.push_back(-1);
	return feat;
}
示例#6
0
feature feat_trade_amount(vec_t trade_list)
{
	feature feat;
	feat.push_back(trade_list.size());
	return feat;
}