Commit aafa2bec authored by 刘乐's avatar 刘乐

1, 最新版

parent 73a9973d
......@@ -24,7 +24,7 @@ void CivConTrackTest::test(char* uri)
char result[1024 * 512];
char sn[64];
strcpy_s(sn, "ffd0f63d-b8c3-4354-aea5-aedc52cb8e16");
strcpy_s(sn, "5fbaaf9e-dfcf-4e97-9fb1-31d03293f654");
int succ = trackingSimulation(uri, sn, 6, result);
......@@ -36,7 +36,7 @@ void CivUpstreamTrackingTest::test(char* uri)
{
// 追踪节点编号
char sn[64];
strcpy(sn, "ffd0f63d-b8c3-4354-aea5-aedc52cb8e16");
strcpy(sn, "5fbaaf9e-dfcf-4e97-9fb1-31d03293f654");
char result[1024 * 128];
......@@ -54,7 +54,7 @@ void CivDownStreamTrackingTest::test(char* uri)
{
// 追踪节点编号
char sn[64];
strcpy(sn, "3997f59b-91ae-44e1-be89-c23b6b330909");
strcpy(sn, "5fbaaf9e-dfcf-4e97-9fb1-31d03293f654");
char result[1024 * 512];
......
......@@ -22,8 +22,8 @@ int main(int argc, char* argv[])
context.contextTest(findUri);*/
// 测试水质
CivTestContext context(new CivConQuaTest());
context.contextTest(findUri);
/*CivTestContext context(new CivConQuaTest());
context.contextTest(findUri);*/
// 测试追踪分析
......@@ -35,8 +35,8 @@ int main(int argc, char* argv[])
context.contextTest(findUri);*/
// 下游追踪
/*CivTestContext context(new CivDownStreamTrackingTest());
context.contextTest(findUri);*/
CivTestContext context(new CivDownStreamTrackingTest());
context.contextTest(findUri);
// 水源供水范围分析
......
......@@ -188,6 +188,108 @@ bool CivHydrCompute::hdyrCompute()
return true;
}
bool CivHydrCompute::chlorineCompute()
{
// 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置
long t(0), tstep(0);
int iTime(0);
int errcode = 0;
char inpFile[128];
strcpy_s(inpFile, mInFile.c_str());
char rptFile[128];
strcpy_s(rptFile, mRptFile.c_str());
char binFile[128];
strcpy_s(binFile, mBinFile.c_str());
CivSysLog::getInstance()->info("打开inp文件", "CivHydrCompute", __FUNCTION__);
errcode = ENopen(inpFile, rptFile, binFile);
if (errcode > 0)
{
CivSysLog::getInstance()->error("ENopen 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
if (ENopenH() > 0)
{
CivSysLog::getInstance()->error("ENopenH 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
if (ENinitH(EN_SAVE) > 0)
{
CivSysLog::getInstance()->error("ENinitH 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
do
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
/*for (int i = 1; i <= nLinkCount; i++)
{
int linkType;
char id[128] = "";
ENgetlinktype(i, &linkType);
ENgetlinkid(i, id);
}*/
errcode = ENrunH(&t); // errcode > 100 是错误
if (errcode > 100)
{
ENcloseH();
ENclose();
return false;
}
ENnextH(&tstep);
iTime++;
} while (tstep > 0);
ENcloseH();
// 进行水质分析
ENopenQ();
ENinitQ(1);
t = 0;
tstep = 0;
iTime = 0;
do
{
errcode = ENrunQ(&t); // errcode > 100 是错误
if (errcode > 100)
{
ENcloseQ();
ENclose();
return false;
}
iTime++;
// 获取水质模拟结果
getNodeChlorine(iTime);
getLinkChlorine(iTime);
ENstepQ(&tstep);
} while (tstep > 0);
ENcloseQ();
ENclose();
CivSysLog::getInstance()->info("ENclose", "CivHydrCompute", __FUNCTION__);
return true;
}
void CivHydrCompute::dateAndTime(int time,std::string& nowDate,std::string& nowTime)
{
CivDate civDate;
......@@ -219,7 +321,7 @@ void CivHydrCompute::getNodeResult(short time)
// 计算节点
int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount);
//int* typeCode = (int*)malloc(sizeof(int));
int* typeCode = (int*)malloc(sizeof(int));
std::string nowDate;
std::string nowTime;
......@@ -227,37 +329,25 @@ void CivHydrCompute::getNodeResult(short time)
for (int i = 1; i <= nNodeCount; i++)
{
//ENgetlinktype(i, typeCode);
//if (*typeCode == EN_TANK || *typeCode== EN_RESERVOIR)
//{
// TankResultItem tankItem;
//
// ENgetnodeid(i, tankItem.szNo);// 编号
// ENgetnodevalue(i, EN_TANKVOLUME, &tankItem.dTankVolume); // 水池容量
// ENgetnodevalue(i, EN_MAXVOLUME, &tankItem.dTankMaxVolume); // 水池最大容量
// ENgetnodevalue(i, EN_TANKLEVEL, &tankItem.dTankLevel); // 液位高度
// tankItem.dDate = nowDate;
// tankItem.dTime = nowTime;
// tankItem.dModifyTime = CurrentTime;
//}
//else
//{
NodeResultItem nodeItem;
ENgetnodeid(i, nodeItem.szNo);// 编号
ENgetnodevalue(i, EN_HEAD, &nodeItem.dHead);// 水头
ENgetnodevalue(i, EN_PRESSURE, &nodeItem.dPressure); // 压力
ENgetnodevalue(i, EN_ELEVATION, &nodeItem.dElevation);// 标高
ENgetnodevalue(i, EN_DEMAND, &nodeItem.dDemand);// 实际需水量
nodeItem.dDate = nowDate;
nodeItem.dTime = nowTime;
nodeItem.dModifyTime = CurrentTime;
mResultCache.addNodeItems(time,nodeItem);
// }
ENgetnodetype(i, typeCode);
if (*typeCode != EN_JUNCTION)
continue;
NodeResultItem nodeItem;
ENgetnodeid(i, nodeItem.szNo);// 编号
ENgetnodevalue(i, EN_HEAD, &nodeItem.dHead);// 水头
ENgetnodevalue(i, EN_PRESSURE, &nodeItem.dPressure); // 压力
ENgetnodevalue(i, EN_ELEVATION, &nodeItem.dElevation);// 标高
ENgetnodevalue(i, EN_DEMAND, &nodeItem.dDemand);// 实际需水量
nodeItem.dDate = nowDate;
nodeItem.dTime = nowTime;
nodeItem.dModifyTime = CurrentTime;
mResultCache.addNodeItems(time, nodeItem);
}
// free(typeCode);
free(typeCode);
}
void CivHydrCompute::getLinkResult(short time)
......@@ -305,17 +395,22 @@ void CivHydrCompute::getNodeQuality(short time)
int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount);
float* quality = (float*)malloc(sizeof(float));
int* typeCode = (int*)malloc(sizeof(int));
for (int i = 1; i <= nNodeCount; i++)
{
char No[35];
ENgetnodeid(i, No);// 编号
ENgetnodevalue(i, EN_QUALITY, quality); // 水质
ENgetnodetype(i, typeCode);
if (*typeCode == EN_JUNCTION)
{
char No[35];
ENgetnodeid(i, No);// 编号
float quality;
ENgetnodevalue(i, EN_QUALITY, &quality); // 水质
mResultCache.addNodeQuality(*quality, time, No);
mResultCache.addNodeQuality(quality, time, No);
}
}
free(quality);
free(typeCode);
}
void CivHydrCompute::getLinkQuality(short time)
......@@ -339,6 +434,51 @@ void CivHydrCompute::getLinkQuality(short time)
free(typeCode);
}
void CivHydrCompute::getNodeChlorine(short time)
{
int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount);
int* typeCode = (int*)malloc(sizeof(int));
for (int i = 1; i <= nNodeCount; i++)
{
ENgetnodetype(i, typeCode);
if (*typeCode != EN_JUNCTION)
continue;
char No[35];
ENgetnodeid(i, No);// 编号
float quality;
ENgetnodevalue(i, EN_QUALITY, &quality); // 水质
mResultCache.addNodeChlorine(quality, time, No);
}
free(typeCode);
}
void CivHydrCompute::getLinkChlorine(short time)
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
int* typeCode = (int*)malloc(sizeof(int));
for (int i = 1; i <= nLinkCount; i++)
{
ENgetlinktype(i, typeCode);
if (*typeCode != EN_PIPE)
continue;
char lnkNo[35];
ENgetlinkid(i, lnkNo);// 编号
float quality;
ENgetlinkvalue(i, EN_LINKQUAL, &quality);// 水质
mResultCache.addLinkChlorine(quality, time, lnkNo);
}
free(typeCode);
}
void CivHydrCompute::saveResult(const std::string& uri)
{
......
......@@ -15,6 +15,7 @@ public:
*/
bool qualityCompute();
bool chlorineCompute();
/**
*@brief 水力计算
*/
......@@ -36,9 +37,12 @@ private:
void getLinkResult(short time);
void getNodeQuality(short time);
void getLinkQuality(short time);
void getNodeChlorine(short time);
void getLinkChlorine(short time);
void dateAndTime(int time, std::string& date, std::string& nowtime);
CivSimulResultCache mResultCache;
std::string mInFile;
std::string mRptFile;
std::string mBinFile;
......
......@@ -34,7 +34,11 @@ bool CivHydrSimulation::qualitySimulation()
{
CivSysLog::getInstance()->info("开始水质模拟", "CivSysLog", __FUNCTION__);
CivSysLog::getInstance()->info("开始转inp文件", "CivSysLog", __FUNCTION__);
CivInpConvertor convertor(mUri);
// convertor.maintainTopo();
std::string inpFileS = convertor.convertBaseInp();
if (inpFileS.empty() || inpFileS == "")
{
......@@ -54,6 +58,19 @@ bool CivHydrSimulation::qualitySimulation()
CivSysLog::getInstance()->info("计算成功", "CivSysLog", __FUNCTION__);
// 余氯计算
inpFileS = convertor.convertResidualInp();
if (inpFileS.empty() || inpFileS == "")
{
CivSysLog::getInstance()->error("转inp文件失败", "CivSysLog", __FUNCTION__);
return false;
}
if (!mHydrCompute.chlorineCompute())
{
CivSysLog::getInstance()->error("计算失败", "CivSysLog", __FUNCTION__);
return false;
}
mHydrCompute.saveResult(mUri);
return true;
......@@ -62,6 +79,7 @@ bool CivHydrSimulation::qualitySimulation()
bool CivHydrSimulation::trackingSimulation(char* snNode, int hours,std::string& jsonResult)
{
CivInpConvertor convertor(mUri);
std::string inpFileS = convertor.convertTrackInp(snNode, std::to_string(hours));
if (inpFileS.empty())
return false;
......
......@@ -80,6 +80,11 @@ void CivInpBuilder::setQuality(const std::string& name, const std::string& val)
mInitQuality.addItem({ name ,val });
}
void CivInpBuilder::setQualityType(CivInpHelperAbs::QualityType type)
{
mHelper->setQualityType(type);
}
void CivInpBuilder::buildCurves()
{
}
......
......@@ -34,6 +34,7 @@ public:
void setReaction(const std::string& name, const std::string& val);
void setQuality(const std::string& name, const std::string& val);
void setQualityType(CivInpHelperAbs::QualityType type);
void resetAllToZero();
/**
*@brief 返回装成的inp文件名
......
......@@ -16,16 +16,20 @@ CivInpConvertor::~CivInpConvertor()
}
std::string CivInpConvertor::convertPorjInp(
const std::string& projCode,
const std::string& start)
bool CivInpConvertor::maintainTopo()
{
CivHydrTableHelper helper(mUri);
if (!helper.mainTain())
{
return "";
return false;
}
return true;
}
std::string CivInpConvertor::convertPorjInp(
const std::string& projCode,
const std::string& start)
{
CivProjInpBuilder* builder = new CivProjInpBuilder(mUri);
builder->setProjCode(projCode);
builder->setTimes("Duration", "0");
......@@ -48,11 +52,6 @@ std::string CivInpConvertor::convertPorjInp(
std::string CivInpConvertor::convertBaseInp()
{
CivHydrTableHelper helper(mUri);
if (!helper.mainTain())
{
return "";
}
CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
CivInpDirector director;
......@@ -74,10 +73,10 @@ std::string CivInpConvertor::convertTrackInp(const std::string& sn,
const std::string& hours)
{
CivHydrTableHelper helper(mUri);
if (!helper.mainTain())
{
return "";
}
//if (!helper.mainTain())
//{
// return "";
//}
std::string codeTosn;
helper.getCodeToSn(sn, codeTosn);
......@@ -104,14 +103,30 @@ std::string CivInpConvertor::convertTrackInp(const std::string& sn,
std::string CivInpConvertor::convertAnalysisInp()
{
CivHydrTableHelper helper(mUri);
if (!helper.mainTain())
CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
builder->setTimes("Duration", "1");
CivInpDirector director;
director.setBuilder(builder);
director.create();
std::string inpFile = CivCommonUtils::getExePath() + "\\test.inp";
if (!builder->getNewInp(inpFile))
{
delete builder;
return "";
}
delete builder;
return inpFile;
}
std::string CivInpConvertor::convertResidualInp()
{
CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
builder->setTimes("Duration", "1");
builder->setQualityType(CivInpHelperAbs::Chlorine);
builder->setOption("Quality", "Chlorine mg/L");
CivInpDirector director;
director.setBuilder(builder);
......
......@@ -12,6 +12,8 @@ public:
explicit CivInpConvertor(const std::string& uri);
~CivInpConvertor();
bool maintainTopo();
/**
*@brief 转成方案模拟的inp文件
*@param projCode 方案编码
......@@ -34,6 +36,11 @@ public:
std::string convertAnalysisInp();
/**
* 余氯分析
*/
std::string convertResidualInp();
private:
std::string mUri;
};
\ No newline at end of file
......@@ -116,3 +116,27 @@ void CivSimulResultCache::getCodeToSnMap(const std::string& uri)
helper.getNodeCodeSnMap(mNodeCodeSnMap);
helper.getLinCodeSnMap(mLineCodeSnMap);
}
void CivSimulResultCache::addNodeChlorine(float quality, int interval, const string& sNo)
{
if (mNodeItemsMap.find(interval) == mNodeItemsMap.end())
return;
auto nodeMap = mNodeItemsMap.find(interval)->second;
if (nodeMap.find(sNo) == nodeMap.end())
return;
mNodeItemsMap[interval][sNo].dChlorine = quality;
}
void CivSimulResultCache::addLinkChlorine(float quality, int interval, const string& sNo)
{
if (mLinkItemsMap.find(interval) == mLinkItemsMap.end())
return;
auto linkMap = mLinkItemsMap.find(interval)->second;
if (linkMap.find(sNo) == linkMap.end())
return;
mLinkItemsMap[interval][sNo].dChlorine = quality;
}
......@@ -29,6 +29,11 @@ public:
*/
void addLinkQuality(float quality, int interval, const string& sNo);
void addNodeChlorine(float quality, int interval, const string& sNo);
void addLinkChlorine(float quality, int interval, const string& sNo);
/**
*@brief 缓存节点水力模拟情况
*@param nodeItem:节点水力结果值
......
......@@ -29,9 +29,8 @@ bool CivConnection::update(const std::string& table,
}
sql = sql.substr(0, sql.length() - 1);
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
if (!execSql(utf8Sql))
if (!execSql(sql))
return false;
return true;
......@@ -43,8 +42,8 @@ bool CivConnection::del(const std::string& table, const std::string& where)
return false;
std::string sql = "delete from "+table +" where "+where;
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
if (!execSql(utf8Sql))
if (!execSql(sql))
return false;
return true;
......@@ -86,9 +85,9 @@ bool CivConnection::insertBulk(const std::string& table,
}
sql = sql.substr(0, sql.length() - 1);
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
//2 执行插入操作
if (!execSql(utf8Sql))
if (!execSql(sql))
return false;
return true;
......@@ -121,9 +120,9 @@ bool CivConnection::insert(const std::string& table,
sql.append(") VALUES");
sql.append(vals);
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
//2 执行插入操作
if (!execSql(utf8Sql))
if (!execSql(sql))
return false;
return true;
......@@ -156,9 +155,9 @@ bool CivConnection::query(const std::string& table,
sql.append(where);
}
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
// 2 执行sql语句
if (!execSql(utf8Sql))
if (!execSql(sql))
{
return false;
}
......
......@@ -20,7 +20,7 @@ CivHydrTableHelper::~CivHydrTableHelper()
bool CivHydrTableHelper::mainTain()
{
unTopoMaintain();
//unTopoMaintain();
// 节点
updateAssem(TABLE_NODE, std::string("本点号"), "JD");
updateAssem(TABLE_PIPE, std::string("编号"), "GD");
......@@ -79,20 +79,12 @@ bool CivHydrTableHelper::topoMaintain()
topoMainTable(TABLE_PIPE, TABLE_NODE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(TABLE_PIPE, TABLE_RESERVOIR, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, TABLE_TANK, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, TABLE_VALVEE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, TABLE_VALVEE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoValve(std::string("起始节点"),std::string("from_code"),std::string("to_code"));
topoValve(std::string("终止节点"), std::string("to_code"), std::string("from_code"));
std::string delSql = std::string("update \"管段\" \
set \"起始节点\" = null,\"终止节点\" = null \
from \"阀门\" t1 where\
\"to_code\" = t1.\"code\" or \"from_code\" = t1.\"code\"");
std::string utfsql = CivCommonUtils::string_To_UTF8(delSql);
if (mConn && !mConn->execSql(utfsql))
{
mErrInfo = mConn->getLastError();
return false;
}
return true;
}
......@@ -118,8 +110,7 @@ bool CivHydrTableHelper::topoMainTable(const std::string& sourceTable,
\""+sourceTable+"\".\"" + code + "\" = cqt.\"code\"";
std::string utfsql = CivCommonUtils::string_To_UTF8(sql);
if (mConn && !mConn->execSql(utfsql))
if (mConn && !mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return false;
......@@ -141,9 +132,7 @@ bool CivHydrTableHelper::topoValve(const std::string& sn,
where \"code\" = dd.\"vacode\"");
std::string utfsql = CivCommonUtils::string_To_UTF8(sql);
if (mConn && !mConn->execSql(utfsql))
if (mConn && !mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return false;
......@@ -169,8 +158,8 @@ bool CivHydrTableHelper::unTopoTable(const std::string& table, const std::vector
}
sql = sql.substr(0, sql.length() - 1);
std::string utfsql = CivCommonUtils::string_To_UTF8(sql);
if (mConn && !mConn->execSql(utfsql))
if (mConn && !mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return false;
......@@ -182,8 +171,8 @@ bool CivHydrTableHelper::unTopoTable(const std::string& table, const std::vector
void CivHydrTableHelper::getCodeToSn(const std::string& code, std::string& sn)
{
std::string sql = "select \"本点号\" from 节点 where code = '" + code+"'";
std::string utfsql = CivCommonUtils::string_To_UTF8(sql);
if (mConn && !mConn->execSql(utfsql))
if (mConn && !mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return;
......
......@@ -48,7 +48,78 @@ bool CivInpDbHelper::getNode(CivNode& node)
bool CivInpDbHelper::getPipe(CivPipe& pipes)
{
PipeTable pipeTable;
PipeTable pipeTable;
// 注意去重
// 查找与阀门像连的管段
std::string sql = "select pipe.\"编号\",pipe.\"起始节点\",pipe.\"终止节点\", \
pipe.\"管长\", pipe.\"管径\",pipe.\"摩阻系数\",pipe.\"局损系数\",pipe.\"初始状态\",va.\"本点号\", pipe.\"code\",\
va.\"类型\" from \"管段\" as pipe, \"阀门\" as va where pipe.\"起始节点\" = va.\"本点号\" \
or pipe.\"终止节点\" = va.\"本点号\" order by \"本点号\"";
if (!mDbConn->execSql(sql))
{
return false;
}
std::vector<std::map<std::string, std::string>> resultMap;
mDbConn->queryResult(resultMap);
int toal = resultMap.size();
std::string repeatSn;
std::string repeatVaType;
std::string starNode;
std::string endNode;
// 存储已拼接的管段CODE,为下面去重
std::set<std::string> filterSet;
for (int i = 0; i < toal; i++)
{
std::map<std::string, std::string> tempMap = resultMap[i];
std::string sn = tempMap.find("本点号")->second;
std::string vaType = tempMap.find("类型")->second;
std::string pipeCode = tempMap.find(pipeTable.code)->second;
filterSet.insert(pipeCode);
if (sn == repeatSn && repeatVaType == vaType && repeatVaType == "BV")
{
CivPipe::PipesTable pipe;
pipe.ID = tempMap.find(pipeTable.snNo)->second;
std::string secondStartNode = tempMap.find(pipeTable.startPoint)->second;
std::string secondEndNode = tempMap.find(pipeTable.endPoint)->second;
if (starNode == repeatSn)
{
pipe.Node1 = secondStartNode;
pipe.Node2 = endNode;
}
else if(endNode == repeatSn)
{
pipe.Node1 = starNode;
pipe.Node2 = secondEndNode;
}
pipe.Length = tempMap.find(pipeTable.length)->second;
pipe.Diameter = tempMap.find(pipeTable.diameter)->second;
pipe.Roughness = tempMap.find(pipeTable.friction)->second;
pipe.MinorLoss = tempMap.find(pipeTable.localLoss)->second;
pipe.Status = tempMap.find(pipeTable.status)->second;
pipes.addItem(pipe);
}
repeatVaType = vaType;
repeatSn = sn;
starNode = tempMap.find(pipeTable.startPoint)->second;
endNode = tempMap.find(pipeTable.endPoint)->second;
}
std::vector<std::string> fields = {
pipeTable.snNo,
......@@ -63,7 +134,18 @@ bool CivInpDbHelper::getPipe(CivPipe& pipes)
};
std::vector<std::map<std::string, std::string>> resultVector;
mDbConn->query(PIPELINE, fields, resultVector, mCondtion);
std::string condition = " \"code\" not in (";
for (auto iter = filterSet.begin(); iter != filterSet.end(); iter++)
{
std::string code = *iter;
condition.append("'"+code+"'");
condition.append(",");
}
condition = condition.substr(0, condition.length() - 1);
condition.append(")");
mDbConn->query(PIPELINE, fields, resultVector, condition);
size_t total = resultVector.size();
for (int i = 0; i < total; i++)
......@@ -146,6 +228,10 @@ bool CivInpDbHelper::getValve(CivValve& valves)
CivValve::ValveTable vave;
std::map<std::string, std::string> map = resultVector[i];
std::string vaType = map.find(vaveTable.type)->second;
if (vaType == "BV")
continue;
vave.ID = map.find(vaveTable.sn)->second;
vave.Node1 = map.find(vaveTable.startPoint)->second;
vave.Node2 = map.find(vaveTable.endPoint)->second;
......@@ -259,8 +345,6 @@ bool CivInpDbHelper::getCoordinates(CivCoordinates& coord)
return true;
}
bool CivInpDbHelper::getQuality(CivQuality& quality)
{
JunctionTable nodeTable;
......@@ -268,7 +352,8 @@ bool CivInpDbHelper::getQuality(CivQuality& quality)
std::vector<std::string> fields =
{
nodeTable.sn,
nodeTable.initQuality
nodeTable.initQuality ,
nodeTable.chlorine
};
std::vector<std::map<std::string, std::string>> resultVector;
......@@ -282,8 +367,18 @@ bool CivInpDbHelper::getQuality(CivQuality& quality)
CivQuality::QualityTable quliTable;
std::map<std::string, std::string> map = resultVector[i];
quliTable.ID = map.find(fields[0])->second;
quliTable.InitQuality = map.find(fields[1])->second;;
quliTable.ID = map.find(nodeTable.sn)->second;
switch (mQualityType)
{
case Chlorine:
quliTable.InitQuality = map.find(nodeTable.chlorine)->second;
break;
case Age:
default:
quliTable.InitQuality = map.find(nodeTable.initQuality)->second;
break;
}
quality.addItem(quliTable);
}
......
......@@ -7,6 +7,7 @@ CivInpHelperAbs::CivInpHelperAbs(const std::string& uri)
{
mDbConn = new CivPgDbConnection();
mDbConn->connect(uri);
mQualityType = Age;
}
CivInpHelperAbs::~CivInpHelperAbs()
......@@ -180,3 +181,8 @@ void CivInpHelperAbs::getSnToCode(std::map<std::string, std::string>& coord)
}
void CivInpHelperAbs::setQualityType(QualityType qualiType)
{
mQualityType = qualiType;
}
......@@ -10,6 +10,13 @@ class CivConnection;
class INPDLLEXPORT CivInpHelperAbs
{
public:
// 水质模拟时间
enum QualityType
{
Age, // 水龄
Chlorine // 余氯
};
explicit CivInpHelperAbs(const std::string& uri);
virtual ~CivInpHelperAbs();
......@@ -36,7 +43,8 @@ public:
bool getMixing(CivMixing& mixing);
bool getParameter(std::vector<CivParameter>& param);
bool getEmitters(CivEmitters& emitter);
void setQualityType(QualityType qualiType);
protected:
QualityType mQualityType;
CivConnection* mDbConn;
};
......@@ -58,15 +58,18 @@ bool CivPgDbConnection::queryResult(std::vector<std::map<std::string,std::string
bool CivPgDbConnection::execSql(const std::string& sql)
{
if (!mConn)
if (!mConn || sql.empty() )
return false;
mResult = PQexec(mConn, sql.c_str());
std::string utf8Sql = CivCommonUtils::string_To_UTF8(sql);
mResult = PQexec(mConn, utf8Sql.c_str());
std::string errorStr = PQresultErrorMessage(mResult);
if (!errorStr.empty())
{
mLastError = errorStr;
std::cout << mLastError << std::endl;
PQclear(mResult);
return false;
}
......
......@@ -2,6 +2,13 @@
#include<string>
#include<map>
// 水质模拟时间
enum QualityType
{
Age, // 水龄
Chlorine // 余氯
};
struct ResultItem
{
std::string code;
......@@ -9,6 +16,7 @@ struct ResultItem
std::string dDate;
std::string dTime;
float dQuality;
float dChlorine;
std::string dModifyTime;
};
......
......@@ -20,7 +20,8 @@ CivSimulResDbHelper::CivSimulResDbHelper(const std::string& uri)
tableFields.dHead,
tableFields.dDate,
tableFields.dInterval,
tableFields.dModifyTime
tableFields.dModifyTime,
tableFields.chlorine
};
//
......@@ -35,7 +36,8 @@ CivSimulResDbHelper::CivSimulResDbHelper(const std::string& uri)
pipeFields.szStatus,
pipeFields.dDate,
pipeFields.dInterval,
pipeFields.dModifyTime
pipeFields.dModifyTime,
pipeFields.chlorine
};
}
......@@ -63,7 +65,7 @@ bool CivSimulResDbHelper::insertNodes(const NodeResultItems& nodeitems)
vecRes.push_back("\'" + nodeItem.dDate + "\'");
vecRes.push_back("\'" + nodeItem.dTime + "\'");
vecRes.push_back("\'" + CurrentTime + "\'");
vecRes.push_back(std::to_string(nodeItem.dChlorine));
vecVec.push_back(vecRes);
condition = "\'" + nodeItem.dTime + "\'";
}
......@@ -86,18 +88,19 @@ bool CivSimulResDbHelper::insertLinks(const LinkResultItems& linkMap)
LinkResultItem linkItem = iter->second;
std::string sn = linkItem.code;
std::string status = linkItem.szStatus;
std::vector<std::string> vecRes =
{
"\'"+ sn +"\'",
std::to_string(linkItem.dFlow),
std::to_string(linkItem.dVelocity),
std::to_string(linkItem.dHeadloss),
std::to_string(linkItem.dQuality),
"\'"+ status + "\'",
"\'" + linkItem.dDate + "\'",
"\'" + linkItem.dTime + "\'",
"\'" + CurrentTime + "\'"
};
std::vector<std::string> vecRes;
vecRes.push_back("\'" + sn + "\'");
vecRes.push_back(std::to_string(linkItem.dFlow));
vecRes.push_back(std::to_string(linkItem.dVelocity));
vecRes.push_back(std::to_string(linkItem.dHeadloss));
vecRes.push_back(std::to_string(linkItem.dQuality));
vecRes.push_back("\'" + status + "\'");
vecRes.push_back("\'" + linkItem.dDate + "\'");
vecRes.push_back("\'" + linkItem.dTime + "\'");
vecRes.push_back("\'" + CurrentTime + "\'");
vecRes.push_back(std::to_string(linkItem.dChlorine));
vecVec.push_back(vecRes);
condition = "\'" + linkItem.dTime + "\'";
}
......
......@@ -54,6 +54,7 @@ typedef struct JunctionTableFileds
Str totalHead = "水头";
Str pressure = "压力";
Str quality = "水质";
Str chlorine = "余氯";
}JunctionTable;
/**
......@@ -84,6 +85,7 @@ typedef struct PipeTableFields
Str status = "状态";
Str quality = "水质";
Str leakWater = "漏水量";
Str chlorine = "余氯";
}PipeTable;
/**
......@@ -157,6 +159,7 @@ typedef struct ResourcesTableFileds
Str flow = "流量";
Str totalHead = "总水头";
Str quality = "水质";
Str chlorine = "余氯";
}ResourcesTable;
/**
......@@ -194,6 +197,7 @@ typedef struct NodeResultTableField
Str dDate = "日期";
Str dInterval = "时间点";
Str dModifyTime = "修改时间";
Str chlorine = "余氯";
} NodeResultTable;
/**
......@@ -211,6 +215,7 @@ typedef struct PipeResultTableField
Str dDate = "日期";
Str dInterval = "时间点";
Str dModifyTime = "修改时间";
Str chlorine = "余氯";
}PipeResultTable;
......
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