#include <iostream>
#include <libpq-fe.h>
#include "CivHydrFuncInter.h"
#include "iostream"
#include "time.h"
#include <time.h>
#include "string.h"
#include "CivTestContext.h"
#include "CivHydrTest.h"
#include <vector>
#include <string>
#include <stdlib.h>

#include <windows.h>
#include <consoleapi2.h>

#include "JsonParseObject.h"

using namespace std;

double random(int min, int max)
{
	double m1 = (double)(rand() % 101) / 101;                        // 计算 0，1之间的随机小数,得到的值域近似为(0,1)
	min++;                                                                             //将 区间变为(min+1,max),
	double m2 = (double)((rand() % (max - min + 1)) + min);    //计算 min+1,max 之间的随机整数，得到的值域为[min+1,max]
	m2 = m2 - 1;       //令值域为[min,max-1]

	double dd = (m1 + m2) * 100;
	double res = (int)dd;
	return res / 100;                                                                //返回值域为(min,max),为所求随机浮点
}
// 测试json解析字符出
void testJson()
{
	std::string jsonstr = "{\"监测点1\":{\"min\":20,\"max\":30},\"监测点2\":{\"min\":28.5,\"max\":32.4},\"雄楚大道\":{\"min\":23,\"max\":31.9}}";
	JsonParseObject parseObj;
	parseObj.parse(jsonstr);

	map<string, vector<double>> resMap;
	parseObj.read(resMap);

	parseObj.clear();
}

int main(int argc, char* argv[])
{
	double res = random(0, 1);
	std::cout<< res <<std::endl;
	// testJson();
	while (true)
	{
		const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
		char* findUri = const_cast<char*>(uri);

		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		cout << "水力模型接口测试，请输入对应的测试号：(输入0退出)\n";
		cout << "\t1.水力接口测试\n";
		cout << "\t2.水质计算接口测试\n";
		cout << "\t3.追踪测试\n";
		cout << "\t4.上游追踪\n";
		cout << "\t5.下游追踪\n";
		cout << "\t6.水源供水范围分析\n";
		cout << "\t7.方案模拟\n";
		cout << "\t8.优化调度测试\n";
		cout << "\t9.余氯分析测试\n";
		cout << "\t10.拓扑维护测试\n";

		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
		int test_no;
		cout << "请输入：";
		cin >> test_no;
		cout << "你选择的测试号是：" << test_no << endl;
		CivTestContext context;

		clock_t start, end;
		start = clock();
		
		switch (test_no)
		{
		case 0://退出
			exit(0);
			break;
		case 1://1.测试水力
			context.setHydrTest(new CivConHydrTest());
			context.contextTest(findUri);
			break;
		case 2://测试水质
			context.setHydrTest(new CivConQuaTest());
			context.contextTest(findUri);
			break;
		case 3://3.测试追踪
			context.setHydrTest(new CivConTrackTest());
			context.contextTest(findUri);
			break;
		case 4://4.测试上游追踪
			context.setHydrTest(new CivUpstreamTrackingTest());
			context.contextTest(findUri);
			break;
		case 5://5.测试下游追踪
			context.setHydrTest(new CivDownStreamTrackingTest());
			context.contextTest(findUri);
			break;
		case 6://6.测试水源供水范围
			context.setHydrTest(new CivWaterSupplyScopeTest());
			context.contextTest(findUri);
			break;

		case 7://6.测试水源供水范围
			context.setHydrTest(new CivProjSimulationTest());
			context.contextTest(findUri);
			break;

		case 8: // 8 优化调度测试
			context.setHydrTest(new CivOptSchedulingTest());
			context.contextTest(findUri);
			break;

		case 9: // 8 优化调度测试
			context.setHydrTest(new CivResdualChrolmeTest());
			context.contextTest(findUri);
			break;

		case 10: // 拓扑维护
			context.setHydrTest(new CivNetTopoTest());
			context.contextTest(findUri);
			break;

		default:
			cout << "输入测试号错误！" << endl;
			break;
		}
		end = clock();
		cout << (end - start)/1000 << endl;
	}


  
    return 0;
}