Commit 2dd32d84 authored by 刘乐's avatar 刘乐

阀门处理方式更改

parent d6aa5e6c
......@@ -175,5 +175,7 @@ bool PANDANALYSIS_API residualChlorineAnalysis(char* uri, char* conditionMap,cha
std::string uriStr = uri;
std::string conditionMapStr = conditionMap;
return true;
}
\ No newline at end of file
......@@ -149,36 +149,6 @@ bool CivInpDbHelper::getValve(CivValve& valves)
{
valves.addItem(mValuvesVec[i]);
}
/*ValveTable vaTable;
std::vector<std::string> fields;
fields.push_back(vaTable.sn);
fields.push_back(vaTable.startPoint);
fields.push_back(vaTable.endPoint);
fields.push_back(vaTable.length);
fields.push_back(vaTable.type);
fields.push_back(vaTable.setting);
fields.push_back(vaTable.lossCoeff);
std::vector<std::map<std::string, std::string>> resultVector;
mDbConn->query(VALVE, fields, resultVector, mCondtion);
size_t totals = resultVector.size();
for (int i = 0; i < totals; i++)
{
CivValve::ValveTable pump;
std::map<std::string, std::string> map = resultVector[i];
pump.ID = map.find(vaTable.sn)->second;
pump.Node1 = map.find(vaTable.startPoint)->second;
pump.Node2 = map.find(vaTable.endPoint)->second;
pump.Diameter =map.find(vaTable.length)->second;
pump.Type = map.find(vaTable.type)->second;
pump.Setting = map.find(vaTable.setting)->second;
pump.MinorLoss = map.find(vaTable.lossCoeff)->second;
valves.addItem(pump);
}*/
return true;
}
......@@ -350,252 +320,224 @@ void CivInpDbHelper::handlePump()
}
void CivInpDbHelper::handleValve()
bool CivInpDbHelper::handleValves2()
{
//阀门的下游管段
std::string dwPipeSql = "select pipe.\"编号\", ('UP' || pipe.\"起始节点\") as \"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\",\
pipe.\"摩阻系数\" ,pipe.\"局损系数\" from \"管段\" as pipe where pipe.\"from_layer\" = '阀门'";
if (!mDbConn->execSql(dwPipeSql))
return;
std::vector<std::map<std::string, std::string>> upPipes;
mDbConn->queryResult(upPipes);
size_t total = upPipes.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> pipe = upPipes[i];
CivPipe::Table pipeStruct;
pipeStruct.ID = pipe.find("编号")->second;
if(pipe.find("code") != pipe.end())
pipeStruct.code = pipe.find("code")->second;
pipeStruct.Node1 = pipe.find("起始节点")->second;
pipeStruct.Node2 = pipe.find("终止节点")->second;
pipeStruct.Length = pipe.find("管长")->second;
pipeStruct.Diameter = pipe.find("管径")->second;
pipeStruct.Roughness = pipe.find("摩阻系数")->second;
pipeStruct.Status = "Open";
pipeStruct.MinorLoss = pipe.find("局损系数")->second;
mPipesVec.push_back(pipeStruct);
}
// 阀门的上游管段
std::string upPipeSql = "select pipe.\"编号\", pipe.\"起始节点\", ('DW' || pipe.\"终止节点\") as \"终止节点\", pipe.\"管长\", pipe.\"管径\", \
pipe.\"摩阻系数\",pipe.\"局损系数\" from \"管段\" as pipe where pipe.\"to_layer\" = '阀门'";
if (!mDbConn->execSql(upPipeSql))
return;
std::vector<std::map<std::string, std::string>> downPipes;
mDbConn->queryResult(downPipes);
size_t dtotal = downPipes.size();
for (int i = 0; i < dtotal; i++)
{
std::map<std::string, std::string> pipe = downPipes[i];
CivPipe::Table pipeStruct;
auto iterEnd = pipe.end();
if(pipe.find("编号") != iterEnd)
pipeStruct.ID = pipe.find("编号")->second;
if(pipe.find("code")!= iterEnd)
pipeStruct.code = pipe.find("code")->second;
if(pipe.find("起始节点")!= iterEnd)
pipeStruct.Node1 = pipe.find("起始节点")->second;
if (pipe.find("终止节点") != iterEnd)
pipeStruct.Node2 = pipe.find("终止节点")->second;
if (pipe.find("管长") != iterEnd)
pipeStruct.Length = pipe.find("管长")->second;
if (pipe.find("管径") != iterEnd)
pipeStruct.Diameter = pipe.find("管径")->second;
if (pipe.find("摩阻系数") != iterEnd)
pipeStruct.Roughness = pipe.find("摩阻系数")->second;
pipeStruct.Status = "Open";
if (pipe.find("局损系数") != iterEnd)
pipeStruct.MinorLoss = pipe.find("局损系数")->second;
mPipesVec.push_back(pipeStruct);
}
//-- 阀门信息--
// 构造阀门起始节点
std::string vaStartSql = "SELECT \
'UP' || va.\"本点号\" AS \"本点号\", vnode.\"高程\", vnode.\"基本需水量\", vnode.\"需水量模式\" \
, (va.\"横坐标\" - 1) AS \"横坐标\", (va.\"纵坐标\" - 1) AS \"纵坐标\", va.\"本点号\" as \"阀门本点号\",\
va.\"类型\" as \"阀门类型\", ('UP' || va.\"本点号\") as \"阀门起始节点\", \
va.\"直径\" as \"阀门直径\",va.\"固定状态\" as \"阀门状态\",va.\"设置\" as \"阀门设置\",va.\"水损系数\"\
FROM \"阀门\" va, ( \
SELECT node.\"本点号\", node.\"高程\", node.\"基本需水量\", node.\"需水量模式\", node.\"横坐标\"\
, node.\"纵坐标\", va.\"终止节点\"\
FROM \"节点\" node, (\
SELECT pipe.\"编号\", pipe.\"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\"\
, pipe.\"摩阻系数\"\
FROM \"管段\" pipe\
WHERE pipe.\"to_layer\" = '阀门'\
) va\
WHERE node.\"本点号\" = va.\"起始节点\"\
) vnode \
WHERE vnode.\"终止节点\" = va.\"本点号\"";
if (!mDbConn->execSql(vaStartSql))
return;
std::vector<std::map<std::string, std::string>> valvesVec;
mDbConn->queryResult(valvesVec);
std::map<std::string, CivValve::ValveTable> valveTableMap;
std::map<std::string, CivPipe::PipesTable> pipeTableMap;
size_t valvsSize = valvesVec.size();
for (int i = 0; i < valvsSize; i++)
{
std::map<std::string, std::string> valveMap = valvesVec[i];
// 构造节点
CivNode::NodeTable nodeTable;
std::string szNo = valveMap.find("本点号")->second;
nodeTable.ID = szNo;
nodeTable.Elev = valveMap.find("高程")->second;
std::string patternID = valveMap.find("需水量模式")->second;
std::string demand = valveMap.find("基本需水量")->second;
handleDelayPattern(demand, patternID, nodeTable.Demand, nodeTable.PatternId);
mNodeVec.push_back(nodeTable);
// 节点坐标
CivCoordinates::CoordTable coordTable;
coordTable.ID = szNo;
coordTable.XCoord = valveMap.find("横坐标")->second;
coordTable.YCoord = valveMap.find("纵坐标")->second;
mCoords.push_back(coordTable);
std::string valveSn = valveMap.find("阀门本点号")->second;
std::string valveType = valveMap.find("阀门类型")->second;
if (valveType == "BV") // 止回阀,转成管段
{
CivPipe::Table pipeStruct;
pipeStruct.ID = valveSn;
pipeStruct.Node1 = szNo;
pipeStruct.Length = "2";
pipeStruct.Diameter = valveMap.find("阀门直径")->second;
pipeStruct.Roughness =std::string("130");//valveMap.find("摩阻系数")->second;
pipeStruct.Status = (valveMap.find("阀门状态")->second == "Open")?"Open":"CV";
pipeStruct.MinorLoss = "0";
auto pter = std::make_pair(valveSn, pipeStruct);
pipeTableMap.insert(pter);
}
else
{
// 阀门
CivValve::ValveTable valveTable;
valveTable.ID = valveSn;
valveTable.Node1 = szNo;
valveTable.Diameter = valveMap.find("阀门直径")->second;
valveTable.Type = valveType;
valveTable.Setting = valveMap.find("阀门设置")->second;
valveTable.MinorLoss = valveMap.find("水损系数")->second;
valveTableMap.insert(std::make_pair(szNo, valveTable));
// 阀门状态组件
CivStatus::StatusTable statusTable;
statusTable.ID = valveSn;
statusTable.Setting = valveMap.find("固定状态")->second;
mStatusVec.push_back(statusTable);
}
}
//--构造阀门终止节点
std::string vaEndSql = "SELECT\
'DW' || va.\"本点号\" AS \"本点号\", vnode.\"高程\", vnode.\"基本需水量\", vnode.\"需水量模式\"\
, (va.\"横坐标\" + 1) AS \"横坐标\", (va.\"纵坐标\" + 1) AS \"纵坐标\", va.\"本点号\" as \"阀门本点号\",\
va.\"类型\" as \"阀门类型\", ('DW' || va.\"本点号\") as \"阀门终止节点\"\
FROM \"阀门\" va, (\
SELECT node.\"本点号\", node.\"高程\", node.\"基本需水量\", node.\"需水量模式\", node.\"横坐标\"\
, node.\"纵坐标\", va.\"起始节点\"\
FROM \"节点\" node, (\
SELECT pipe.\"编号\", pipe.\"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\"\
, pipe.\"摩阻系数\"\
FROM \"管段\" pipe\
WHERE pipe.\"from_layer\" = '阀门'\
) va\
WHERE node.\"本点号\" = va.\"终止节点\"\
) vnode\
WHERE vnode.\"起始节点\" = va.\"本点号\"";
if (!mDbConn->execSql(vaEndSql))
return;
std::vector<std::map<std::string, std::string>> valvesEndVec;
mDbConn->queryResult(valvesEndVec);
size_t endVecSize = valvesEndVec.size();
for (int i = 0; i < endVecSize; i++)
std::string sql = "SELECT A.*,B.* FROM\
(\
SELECT\
node.\"本点号\",\
node.\"横坐标\" AS 阀门横坐标,\
node.\"纵坐标\" AS 阀门纵坐标,\
node.\"固定状态\" AS 阀门固定状态,\
node.\"类型\" AS 阀门类型,\
node.\"设置\" AS 阀门设置,\
node.\"水损系数\" AS 阀门水损系数,\
pipe.编号 AS 上游管段编号,\
pipe.\"管长\" AS 上游管长,\
pipe.\"管径\" AS 上游管径,\
pipe.\"摩阻系数\" AS 上游管段摩阻系数,\
junc.\"本点号\" AS 上游节点,\
junc.\"code\" AS 上游节点code,\
junc.\"高程\" AS 上游节点高程,\
junc.\"需水量模式\" AS 上游节点蓄水量模式,\
junc.\"基本需水量\" as 上游节点基本需水量,\
junc.\"横坐标\" AS 上游节点横坐标,\
junc.\"纵坐标\" AS 上游节点纵坐标,\
junc.\"初始水质\" AS 上游节点初始水质\
FROM\
阀门 AS node, 管段 AS pipe, 节点 as junc\
WHERE\
pipe.\"from_code\" = node.\"code\" AND pipe.\"to_code\" = junc.\"code\"\
) A,\
(\
SELECT\
pipe.编号 AS 下游管段编号,\
pipe.\"管长\" AS 下游管段管长,\
pipe.\"管径\" AS 下游管段管径,\
pipe.\"摩阻系数\" AS 下游管段摩阻系数,\
node.\"本点号\",\
junc.\"本点号\" AS 下游节点,\
junc.\"code\" AS 上游节点code,\
junc.\"高程\" AS 下游节点高程,\
junc.\"需水量模式\" AS 下游节点蓄水量模式,\
junc.\"基本需水量\" as 下游节点基本需水量,\
junc.\"横坐标\" AS 下游节点横坐标,\
junc.\"纵坐标\" AS 下游节点纵坐标,\
junc.\"初始水质\" AS 下游节点初始水质\
FROM\
阀门 AS node, 管段 AS pipe, 节点 as junc\
WHERE\
pipe.\"to_code\" = node.\"code\" AND pipe.\"from_code\" = junc.\"code\"\
) B\
WHERE\
A.\"本点号\" = b.\"本点号\"";
if (!mDbConn->execSql(sql))
{
std::map<std::string, std::string> valveMap = valvesEndVec[i];
// 构造节点
CivNode::NodeTable nodeTable;
std::string szNo = valveMap.find("本点号")->second;
nodeTable.ID = szNo;
nodeTable.Elev = valveMap.find("高程")->second;
std::string error = mDbConn->getLastError();
return false;
}
std::string patternID = valveMap.find("需水量模式")->second;
std::string demand = valveMap.find("基本需水量")->second;
handleDelayPattern(demand, patternID, nodeTable.Demand, nodeTable.PatternId);
// 查询与阀门关联的管段,和节点
std::vector<std::map<std::string, std::string>> valvesPipes;
mDbConn->queryResult(valvesPipes);
mNodeVec.push_back(nodeTable);
// 总个数
size_t total = valvesPipes.size();
for (int i = 0; i < total; i++)
{
std::map<std::string,std::string> valvePipe = valvesPipes[i];
std::string vaSzNo = valvePipe.find("本点号")->second;
std::string vaXcoord = valvePipe.find("阀门横坐标")->second;
std::string vaYcoord = valvePipe.find("阀门纵坐标")->second;
std::string vaStatus = valvePipe.find("阀门固定状态")->second;
std::string vaType = valvePipe.find("阀门类型")->second;
std::string vaSetting = valvePipe.find("阀门设置")->second;
std::string vaLoss = valvePipe.find("阀门水损系数")->second;
std::string upperPipeSzNo = valvePipe.find("上游管段编号")->second;
std::string upperPipeCode = valvePipe.find("上游管段code")->second;
std::string upperPipeLength = valvePipe.find("上游管长")->second;
std::string upperPipeDiametor = valvePipe.find("上游管径")->second;
std::string upperPipeFriction = valvePipe.find("下游管段摩阻系数")->second;
std::string upperNodeSz = valvePipe.find("上游节点")->second;
std::string upperNodeHeight = valvePipe.find("上游节点高程")->second;
std::string upperNodePattern = valvePipe.find("上游节点蓄水量模式")->second;
std::string upperNodeDemand = valvePipe.find("上游节点基本需水量")->second;
std::string upperNodeXcoord = valvePipe.find("上游节点横坐标")->second;
std::string upperNodeYcoord = valvePipe.find("上游节点纵坐标")->second;
std::string upperNodeQuality = valvePipe.find("上游节点初始水质")->second;
std::string donwPipeSz = valvePipe.find("下游管段编号")->second;
std::string donwPipeCode = valvePipe.find("下游管段code")->second;
std::string donwPipeLength = valvePipe.find("下游管段管长")->second;
std::string donwPipeDiametor = valvePipe.find("下游管段管径")->second;
std::string downPipeFraction = valvePipe.find("下游管段摩阻系数")->second;
std::string donwNodeSz = valvePipe.find("下游节点")->second;
std::string donwNodeHeight = valvePipe.find("下游节点高程")->second;
std::string donwNodePattern = valvePipe.find("下游节点蓄水量模式")->second;
std::string donwNodeDemand = valvePipe.find("下游节点基本需水量")->second;
std::string donwNodeXcoord = valvePipe.find("下游节点横坐标")->second;
std::string donwNodeYcoord = valvePipe.find("下游节点纵坐标")->second;
std::string donwNodeQuality = valvePipe.find("下游节点初始水质")->second;
// 判断阀门类型
std::string upperVaType = vaType;
std::transform(vaType.begin(), vaType.begin(), vaType.end(), ::toupper);
// 阀门需要构造两个虚拟节点,两个节点尽可能接近
CivNode::NodeTable startNodeTable;
CivCoordinates::CoordTable startNodeCoord; // 节点坐标
// 节点信息
startNodeTable.ID = "VUP"+vaSzNo;
startNodeTable.Elev = upperNodeHeight;
startNodeTable.Demand = "0";
// 两点之间直线
double vupperXcoord = (atof(upperNodeXcoord.c_str()) - atof(vaXcoord.c_str()))/5+atof(vaXcoord.c_str());
double vupperYcoord = (atof(upperNodeYcoord.c_str()) - atof(vaYcoord.c_str()))/5 + atof(vaYcoord.c_str());
// 节点坐标
CivCoordinates::CoordTable coordTable;
coordTable.ID = szNo;
coordTable.XCoord = valveMap.find("横坐标")->second;
coordTable.YCoord = valveMap.find("纵坐标")->second;
mCoords.push_back(coordTable);
std::string valveSn = valveMap.find("阀门本点号")->second;
std::string valveType = valveMap.find("阀门类型")->second;
if (valveType == "BV") // 止回阀,转成管段
startNodeCoord.ID = "VUP" + vaSzNo;
startNodeCoord.XCoord = std::to_string(vupperXcoord);
startNodeCoord.YCoord = std::to_string(vupperYcoord);
// 终止节点构造
CivNode::NodeTable endNodeTable; // 终止节点
CivCoordinates::CoordTable endNodeCoord; // 终止节点坐标
// 终止节点信息
endNodeTable.ID = "VDW" + vaSzNo;
endNodeTable.Elev = upperNodeHeight;
endNodeTable.Demand = "0";
mNodeVec.push_back(startNodeTable);
mCoords.push_back(startNodeCoord);
// 两点之间直线
double vdownXcoord = (atof(donwNodeXcoord.c_str()) - atof(vaXcoord.c_str())) / 5 + atof(vaXcoord.c_str());
double vdownYcoord = (atof(donwNodeYcoord.c_str()) - atof(vaYcoord.c_str())) / 5 + atof(vaYcoord.c_str());
// 终止节点坐标信息
endNodeCoord.ID = "VDW" + vaSzNo;
endNodeCoord.XCoord = std::to_string(vdownXcoord);
endNodeCoord.YCoord = std::to_string(vdownYcoord);
mNodeVec.push_back(endNodeTable);
mCoords.push_back(endNodeCoord);
// 构造上游管段的
CivPipe::PipesTable upperPipeTable;
CivPipe::PipesTable downPipeTable;
// 上游管段属性
upperPipeTable.code = upperPipeCode;
upperPipeTable.ID = upperPipeSzNo;
upperPipeTable.Node1 = upperNodeSz;
upperPipeTable.Node2 = startNodeTable.ID;
upperPipeTable.Length = upperPipeLength;
upperPipeTable.Diameter = upperPipeDiametor;
upperPipeTable.Roughness = upperPipeFriction;
upperPipeTable.Status = "Open";
upperPipeTable.MinorLoss = vaLoss;
// 下游管段属性
downPipeTable.code = donwPipeCode;
downPipeTable.ID = donwPipeSz;
downPipeTable.Node1 = endNodeTable.ID;
downPipeTable.Node2 = donwNodeSz;
downPipeTable.Length = donwPipeLength;
downPipeTable.Diameter = donwPipeDiametor;
downPipeTable.Roughness = upperPipeFriction;
downPipeTable.Status = "Open";
downPipeTable.MinorLoss = vaLoss;
mPipesVec.push_back(downPipeTable);
mPipesVec.push_back(upperPipeTable);
// 普通阀门等效于管段
if (upperVaType == "BV")
{
auto iter = pipeTableMap.find(valveSn);
if (iter != pipeTableMap.end())
{
pipeTableMap[valveSn].Node2 = szNo;
mPipesVec.push_back(iter->second);
}
// 构造一条虚拟管段
CivPipe::PipesTable vPipeTable;
vPipeTable.ID = "VG"+vaSzNo;
vPipeTable.Node1 = startNodeTable.ID;
vPipeTable.Node2 = endNodeTable.ID;
vPipeTable.Length = donwPipeLength;
vPipeTable.Diameter = donwPipeDiametor;
vPipeTable.Roughness = upperPipeFriction;
vPipeTable.Status = vaStatus;
vPipeTable.MinorLoss = vaLoss;
mPipesVec.push_back(vPipeTable);
}
else
{
// 阀门
auto iter = valveTableMap.find(valveSn);
if (iter != valveTableMap.end())
{
valveTableMap[valveSn].Node2 = szNo;
mValuvesVec.push_back(iter->second);
}
CivValve::ValveTable valveTable;
valveTable.ID = vaSzNo;
valveTable.Node1 = startNodeTable.ID;
valveTable.Node2 = endNodeTable.ID;
valveTable.Diameter = upperPipeDiametor;
valveTable.Type = vaType;
valveTable.Setting =vaSetting;
valveTable.MinorLoss = vaLoss;
mValuvesVec.push_back(valveTable);
// 阀门状态组件
CivStatus::StatusTable statusTable;
statusTable.ID = vaSzNo;
statusTable.Setting = vaStatus;
mStatusVec.push_back(statusTable);
}
}
}
void CivInpDbHelper::handleValve()
{
handleValves2();
return;
}
\ No newline at end of file
......@@ -25,4 +25,7 @@ public:
bool getQuality(CivQuality& quality) override;
bool getStatus(CivStatus& status) override;
private:
bool handleValves2();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment