Commit d85a6654 authored by 刘乐's avatar 刘乐

1, 修改

parent 69423e9b
......@@ -102,7 +102,7 @@
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectName)_d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>..\..\hModelProgram\lib\</OutDir>
<OutDir>$(ProjectDir)..\libs\x64\</OutDir>
<IntDir>$(ProjectDir)..\tmp\$(PlatformName)\$(ProjectName)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
......
......@@ -81,3 +81,17 @@ void CivWaterSupplyScopeTest::test(char* uri)
std::cout << result << std::endl;
std::cout << "测试结果:" << isSucc << std::endl;
}
void CivProjSimulationTest::test(char* uri)
{
// 追踪节点编号
char projCode[512];
strcpy(projCode, "57cae198-838d-4776-8ec1-c195df12b00b");
char time[512];
strcpy(time, "2020-09-16 09:00:00");
bool isSucc = projSimulation(uri, projCode, time);
std::cout << "测试结果:" << isSucc << std::endl;
}
......@@ -64,3 +64,12 @@ class CivWaterSupplyScopeTest :public CivHydrTest
public:
virtual void test(char* uri);
};
/**
方案模拟接口
*/
class CivProjSimulationTest :public CivHydrTest
{
public:
virtual void test(char* uri);
};
\ No newline at end of file
......@@ -130,7 +130,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;PANDANALYSIS_DLL;PANDANALYSIS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(OUTDIR)..\include</AdditionalIncludeDirectories>
</ClCompile>
......@@ -139,7 +139,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>pandaAnalysis.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>pandaAnalysis.lib;pandaLog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
......
......@@ -9,16 +9,15 @@
#include "CivHydrTest.h"
#include <vector>
#include <string>
#include <windows.h>
#include <consoleapi2.h>
using namespace std;
int main(int argc, char* argv[])
{
while (true)
{
const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
......@@ -32,6 +31,7 @@ int main(int argc, char* argv[])
cout << "\t4.上游追踪\n";
cout << "\t5.下游追踪\n";
cout << "\t6.水源供水范围分析\n";
cout << "\t7.方案模拟\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
int test_no;
......@@ -72,6 +72,10 @@ int main(int argc, char* argv[])
context.setHydrTest(new CivWaterSupplyScopeTest());
context.contextTest(findUri);
break;
case 7://6.测试水源供水范围
context.setHydrTest(new CivProjSimulationTest());
context.contextTest(findUri);
break;
default:
cout << "输入测试号错误!" << endl;
break;
......
[2020-09-15 17:13:46][Info] CivSimulResultCache::save 开始存入数据
[2020-09-15 17:16:52][Info] CivSimulResultCache::save 开始存入数据
......@@ -17,6 +17,12 @@ CivBaseInpBuilder::~CivBaseInpBuilder()
delete mHelper;
}
void CivBaseInpBuilder::preHandleLikelyPipe()
{
mHelper->handleValve();
mHelper->handlePump();
}
void CivBaseInpBuilder::buildNode()
{
CivNode node;
......
......@@ -10,6 +10,7 @@ public:
explicit CivBaseInpBuilder(const std::string& uri);
~CivBaseInpBuilder();
virtual void preHandleLikelyPipe();
virtual void buildNode();
virtual void buildPipe();
virtual void buildTank();
......
......@@ -8,7 +8,6 @@
#define OUT
#define INOUT
#define ALGRAPHEXPORT __declspec(dllexport)
class CivDbConn;
......
......@@ -481,7 +481,6 @@ void CivHydrCompute::getLinkChlorine(short time)
void CivHydrCompute::saveResult(const std::string& uri)
{
mResultCache.save(uri);
}
......
......@@ -32,6 +32,7 @@ public:
void getNodeItemByInterval(int time, NodeResultItems& nodeItem);
void getPipeItemByInterval(int time, LinkResultItems& linkItem);
private:
void getNodeResult(short time);
void getLinkResult(short time);
......
......@@ -3,20 +3,21 @@
#include "CivHydrSimulation.h"
#include "CivTrackingAnalysis.h"
#include "CivProjSimulation.h"
bool FUNEXPORT hdyrSimulation(char* uri)
bool PANDANALYSIS_API hdyrSimulation(char* uri)
{
CivHydrSimulation simulation(uri);
return simulation.hdyrSimulation();
}
bool FUNEXPORT qualitySimulation(char* uri)
bool PANDANALYSIS_API qualitySimulation(char* uri)
{
CivHydrSimulation simulation(uri);
return simulation.qualitySimulation();
}
bool FUNEXPORT trackingSimulation(char* uri, char* sN, int hours, char* result)
bool PANDANALYSIS_API trackingSimulation(char* uri, char* sN, int hours, char* result)
{
CivHydrSimulation simulation(uri);
......@@ -29,7 +30,7 @@ bool FUNEXPORT trackingSimulation(char* uri, char* sN, int hours, char* result)
return true;
}
bool FUNEXPORT upstreamTracking(char* uri, char* sn, char* result)
bool PANDANALYSIS_API upstreamTracking(char* uri, char* sn, char* result)
{
CivTrackingAnalysis track(uri);
track.createGraphFrom();
......@@ -43,7 +44,7 @@ bool FUNEXPORT upstreamTracking(char* uri, char* sn, char* result)
return true;
}
bool FUNEXPORT downstreamTracking(char* uri, char* sn, char* result)
bool PANDANALYSIS_API downstreamTracking(char* uri, char* sn, char* result)
{
CivTrackingAnalysis track(uri);
track.createGraphFrom();
......@@ -56,13 +57,18 @@ bool FUNEXPORT downstreamTracking(char* uri, char* sn, char* result)
return true;
}
bool FUNEXPORT waterSupplyScopeAnalysis(char* uri, char* sn, char* result)
bool PANDANALYSIS_API waterSupplyScopeAnalysis(char* uri, char* sn, char* result)
{
return true;
}
bool FUNEXPORT projSimulation(char* uri, char* projCode, char* time)
bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time)
{
CivProjSimulation projSimulation(uri);
if (!projSimulation.simulationProj(projCode, time))
return false;
return true;
}
\ No newline at end of file
#ifndef CIVHYDRFUNCINTER_H
#define CIVHYDRFUNCINTER_H
#define FUNEXPORT __declspec(dllexport)
#include "pandaAnalysis.h"
#if defined(__cplusplus)
extern "C" {
......@@ -12,7 +11,7 @@ extern "C" {
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool FUNEXPORT upstreamTracking(char* uri, char* sn, char* result);
bool PANDANALYSIS_API upstreamTracking(char* uri, char* sn, char* result);
/**
*@brief 下游追踪
......@@ -20,7 +19,7 @@ extern "C" {
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool FUNEXPORT downstreamTracking(char* uri, char* sn, char* result);
bool PANDANALYSIS_API downstreamTracking(char* uri, char* sn, char* result);
/**
*@brief 供水范围追踪
......@@ -28,21 +27,21 @@ extern "C" {
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool FUNEXPORT waterSupplyScopeAnalysis(char* uri, char* sn, char* result);
bool PANDANALYSIS_API waterSupplyScopeAnalysis(char* uri, char* sn, char* result);
/**
*@brief 水力计算服务
*@param uri:数据库连接地址
*@return 1:成功,其他值失败
*/
bool FUNEXPORT hdyrSimulation(char* uri);
bool PANDANALYSIS_API hdyrSimulation(char* uri);
/**
*@brief 水质计算
*@param uri:数据库连接地址
*@return 1:成功,其他值失败
*/
bool FUNEXPORT qualitySimulation(char* uri);
bool PANDANALYSIS_API qualitySimulation(char* uri);
/**
*@brief 水质追踪分析,扩散分析
......@@ -52,7 +51,7 @@ extern "C" {
*@param result:输出结果:json字符串
*@return 1:成功,其他值失败
*/
bool FUNEXPORT trackingSimulation(char* uri, char* sN, int hours,char* result);
bool PANDANALYSIS_API trackingSimulation(char* uri, char* sN, int hours,char* result);
/**
*@brief 方案模拟
......@@ -60,7 +59,7 @@ extern "C" {
*@param sN:追踪节点
*@param time:追踪小时
*/
bool FUNEXPORT projSimulation(char* uri, char* projCode, char* time);
bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time);
#if defined(__cplusplus)
......
......@@ -69,10 +69,6 @@ void CivInpBuilder::buildParamter()
}
}
void CivInpBuilder::resetAllToZero()
{
mResetToZero = true;
}
void CivInpBuilder::setQuality(const std::string& name, const std::string& val)
{
......@@ -107,3 +103,13 @@ void CivInpBuilder::buildVertices()
{
}
void CivInpBuilder::setPatternTime(const std::string& patternTime)
{
mHelper->setPatternTime(patternTime);
}
void CivInpBuilder::isDelayTimeSmuli(bool isDelay)
{
mHelper->isDelayTimeSimul(isDelay);
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#define _CIVINPEXPOTER_H
#include "CivNewInp.h"
#include "CivInpHelperAbs.h"
#include "pandaAnalysis.h"
#define ASSERT(A,B) if ((A) == nullptr || (B) == nullptr) return
/**
......@@ -23,6 +24,11 @@ public:
*/
void setTimes(const std::string& name, const std::string& val);
/**
*@brief 是否延时模拟
*/
void isDelayTimeSmuli(bool isDelay);
/**
*@brief 设置输出报告选项
*/
......@@ -35,7 +41,10 @@ public:
void setQuality(const std::string& name, const std::string& val);
void setQualityType(CivInpHelperAbs::QualityType type);
void resetAllToZero();
void resetAllToZero() { mResetToZero = true; }
void setPatternTime(const std::string& patternTime);
/**
*@brief 返回装成的inp文件名
*/
......@@ -48,6 +57,8 @@ public:
virtual void buildLabels();
virtual void buildVertices();
// 预处理,阀门,水泵等类管段类型的组件
virtual void preHandleLikelyPipe() = 0;
virtual void buildNode()=0;
virtual void buildPipe()=0;
virtual void buildTank()=0;
......@@ -64,9 +75,7 @@ public:
virtual void buildControls()=0;
virtual void buildRules()=0;
virtual void buildDemands()=0;
protected:
CivParameter mOptions;
CivParameter mTimes;
CivParameter mReactions;
......@@ -76,7 +85,10 @@ protected:
CivNewInp* mNewInp;
CivInpHelperAbs* mHelper;
std::string mPattenTime;
bool mResetToZero = false;
std::string mUri;
};
......
......@@ -26,21 +26,22 @@ bool CivInpConvertor::maintainTopo()
return true;
}
std::string CivInpConvertor::convertPorjInp(
const std::string& projCode,
const std::string& start)
std::string CivInpConvertor::convertPorjInp(const std::string& projCode, const std::string& start)
{
CivProjInpBuilder* builder = new CivProjInpBuilder(mUri);
builder->setProjCode(projCode);
builder->setTimes("Duration", "0");
builder->setTimes("Start Clocktime", start);
builder->isDelayTimeSmuli(false);
builder->setPatternTime(start);
CivInpDirector director;
director.setBuilder(builder);
director.create();
std::string inpFile = CivCommonUtils::getExePath() + "\\test.inp";
if (builder->getNewInp(inpFile))
std::string inpFile = CivCommonUtils::getExePath() + "\\ptest.inp";
if (!builder->getNewInp(inpFile))
{
delete builder;
return "";
......@@ -52,7 +53,6 @@ std::string CivInpConvertor::convertPorjInp(
std::string CivInpConvertor::convertBaseInp()
{
CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
CivInpDirector director;
director.setBuilder(builder);
......@@ -69,14 +69,10 @@ std::string CivInpConvertor::convertBaseInp()
return inpFile;
}
std::string CivInpConvertor::convertTrackInp(const std::string& sn,
const std::string& hours)
std::string CivInpConvertor::convertTrackInp(const std::string& sn, const std::string& hours)
{
CivHydrTableHelper helper(mUri);
//if (!helper.mainTain())
//{
// return "";
//}
std::string codeTosn;
helper.getCodeToSn(sn, codeTosn);
......@@ -142,3 +138,27 @@ std::string CivInpConvertor::convertResidualInp()
delete builder;
return inpFile;
}
std::string CivInpConvertor::convertNotPorjInp(const std::string& simulTime)
{
CivInpBuilder* builder = new CivBaseInpBuilder(mUri);
builder->setTimes("Duration", "0");
builder->setTimes("Start Clocktime", simulTime);
builder->isDelayTimeSmuli(false);
builder->setPatternTime(simulTime);
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;
}
\ No newline at end of file
......@@ -8,19 +8,23 @@
class CivInpConvertor
{
public:
explicit CivInpConvertor(const std::string& uri);
~CivInpConvertor();
bool maintainTopo();
/**
*@brief 转成方案模拟的inp文件
*@param projCode 方案编码
*@param startTime 模拟时间
*/
std::string convertPorjInp(const std::string& projCode,
const std::string& startTime);
std::string convertPorjInp(const std::string& projCode, const std::string& startTime);
/**
*@brief 根据模拟的时刻值转inp文件
*@param [std::string] simulTime 模拟时间
*/
std::string convertNotPorjInp(const std::string& simulTime);
/**
*@brief 转成方案普通inp
......@@ -32,7 +36,7 @@ public:
*@param sn 追踪的节点
*@param hours 追踪小时数
*/
std::string convertTrackInp(const std::string& sn,const std::string& hours);
std::string convertTrackInp(const std::string& sn, const std::string& hours);
std::string convertAnalysisInp();
......
......@@ -12,14 +12,15 @@ void CivInpDirector::create()
if (mBuilder == NULL)
return;
mBuilder->preHandleLikelyPipe(); // 增加预处理阀门,水泵等类管网类型
mBuilder->buildTank();
mBuilder->buildReservoir();
mBuilder->buildPatterns();
mBuilder->buildNode();
mBuilder->buildPipe();
mBuilder->buildPump();
mBuilder->buildVavle();
mBuilder->buildEmitter();
mBuilder->buildPatterns();
mBuilder->buildParamter();
mBuilder->buildCoordnates();
mBuilder->buildVertices();
......
......@@ -230,3 +230,9 @@ void CivProjInpBuilder::setProjCode(const std::string& projCode)
if (helper != nullptr)
helper->setProjCode(projCode);
}
void CivProjInpBuilder::preHandleLikelyPipe()
{
mHelper->handleValve();
mHelper->handlePump();
}
......@@ -4,7 +4,7 @@
/**
方案模拟转inp文件构造器
*/
class CivProjInpBuilder:public CivInpBuilder
class CivProjInpBuilder: public CivInpBuilder
{
public:
explicit CivProjInpBuilder(const std::string& uri);
......@@ -12,7 +12,8 @@ public:
/**/
void setProjCode(const std::string& projCode);
// 预处理,阀门,水泵等类管段类型的组件
void preHandleLikelyPipe() override;
void buildNode() override;
void buildPipe()override;
void buildTank()override;
......
#include "CivProjSimulation.h"
#include "CivCommonUtils.h"
#include "epanet2.h"
#include "CivInpConvertor.h"
#include "CivHydrTableHelper.h"
CivProjSimulation::CivProjSimulation()
CivProjSimulation::CivProjSimulation(const std::string& uri):mUri(uri)
{
mRptFile = CivCommonUtils::getExePath() + "\\test.rpt";
mBinFile = CivCommonUtils::getExePath() + "\\test.bin";
}
CivProjSimulation::~CivProjSimulation()
......@@ -10,7 +15,284 @@ CivProjSimulation::~CivProjSimulation()
}
bool CivProjSimulation::simulationProj()
bool CivProjSimulation::simulationProj(const std::string& projCode, const std::string& time)
{
mSimulTime = time;
mProjCode = projCode;
// 转inp之前先拓扑维护
CivHydrTableHelper helper(mUri);
if (!helper.mainTain())
return false;
// 缓存编码和code的映射
mProjCache.getCodeToSnMap(mUri);
// 转普通inp文件
CivInpConvertor conventor(mUri);
std::string baseInp = conventor.convertNotPorjInp(time);
// 转方案inp文件
std::string projInp = conventor.convertPorjInp(projCode, time);
char baseInpFile[256];
strcpy(baseInpFile, baseInp.c_str());
char projInpFile[256];
strcpy(projInpFile, projInp.c_str());
if (!projBeforeHydrCompute(baseInpFile))
return false;
if (!projHydrCompute(projInpFile))
return false;
if (!saveToDb())
return false;
return true;
}
bool CivProjSimulation::saveToDb()
{
return mProjCache.saveToUri(mUri,mSimulTime,mProjCode);
}
bool CivProjSimulation::projBeforeHydrCompute(char* inp)
{
short hydCode = 1;
long t(0), tstep(0);
int iTime(0);
int errcode = 0;
char rptFile[128];
strcpy_s(rptFile, mRptFile.c_str());
char binFile[128];
strcpy_s(binFile, mBinFile.c_str());
errcode = ENopen(inp, rptFile, binFile);
if (errcode > 0)
{
ENclose();
return false;
}
if (ENopenH() > 0)
{
ENclose();
return false;
}
if (ENinitH(0) > 0)
{
ENclose();
return false;
}
float dHStep;
ENGetVal(4, &dHStep);
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);
}*/
if (ENrunH(&t) > 100) // errcode > 100 是错误
{
ENclose();
return false;
}
// 获取计算结果
getNodeResult();
getLinkResult();
ENnextH(&tstep);
iTime++;
} while (tstep > 0);
ENcloseH();
ENclose();
return true;
}
bool CivProjSimulation::projHydrCompute(char* inp)
{
short hydCode = 1;
long t(0), tstep(0);
int iTime(0);
int errcode = 0;
char rptFile[128];
strcpy_s(rptFile, mRptFile.c_str());
char binFile[128];
strcpy_s(binFile, mBinFile.c_str());
errcode = ENopen(inp, rptFile, binFile);
if (errcode > 0)
{
ENclose();
return false;
}
if (ENopenH() > 0)
{
ENclose();
return false;
}
if (ENinitH(0) > 0)
{
ENclose();
return false;
}
float dHStep;
ENGetVal(4, &dHStep);
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);
}*/
if (ENrunH(&t) > 100) // errcode > 100 是错误
{
ENclose();
return false;
}
// 存储方案模拟结果数据
getProjNodeResult();
getProjLinkResult();
ENnextH(&tstep);
iTime++;
} while (tstep > 0);
ENcloseH();
ENclose();
return true;
}
void CivProjSimulation::getProjNodeResult()
{
// 计算节点
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;
NodeResultItem nodeItem;
ENgetnodeid(i, nodeItem.szNo);// 编号
ENgetnodevalue(i, EN_HEAD, &nodeItem.dHead);// 水头
mProjCache.addProjNodeHead(nodeItem.szNo, nodeItem.dHead);
ENgetnodevalue(i, EN_PRESSURE, &nodeItem.dPressure); // 压力
mProjCache.addProjNodePressure(nodeItem.szNo, nodeItem.dPressure);
}
free(typeCode);
}
void CivProjSimulation::getProjLinkResult()
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
int* typeCode = (int*)malloc(sizeof(int));
for (int i = 1; i <= nLinkCount; i++)
{
LinkResultItem linkItem;
ENgetlinktype(i, typeCode);
if (*typeCode != EN_PIPE)
continue;
ENgetlinkid(i, linkItem.szNo); // 编号
ENgetlinkvalue(i, EN_FLOW, &linkItem.dFlow);// 流量
mProjCache.addProjPipeFlow(linkItem.szNo, linkItem.dFlow);
ENgetlinkvalue(i, EN_VELOCITY, &linkItem.dVelocity);// 流速
mProjCache.addProjPipeVelcoity(linkItem.szNo, linkItem.dVelocity);
ENgetlinkvalue(i, EN_HEADLOSS, &linkItem.dHeadloss);// 水头损失
mProjCache.addPipeHeadLoss(linkItem.szNo, linkItem.dHeadloss);
}
free(typeCode);
}
void CivProjSimulation::getNodeResult()
{
// 计算节点
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;
ProjNodeResultItem nodeItem;
ENgetnodeid(i, nodeItem.szNo);// 编号
ENgetnodevalue(i, EN_HEAD, &nodeItem.dHead);// 水头
ENgetnodevalue(i, EN_PRESSURE, &nodeItem.dPressure); // 压力
nodeItem.dDateTime =CivCommonUtils::currentTime(); // 当前时间
nodeItem.dTime = mSimulTime;
nodeItem.projCode = mProjCode;
mProjCache.addNodeItem(nodeItem);
}
free(typeCode);
}
void CivProjSimulation::getLinkResult()
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
int* typeCode = (int*)malloc(sizeof(int));
for (int i = 1; i <= nLinkCount; i++)
{
PorjPipeResultItem linkItem;
ENgetlinktype(i, typeCode);
if (*typeCode != EN_PIPE)
continue;
ENgetlinkid(i, linkItem.szNo); // 编号
ENgetlinkvalue(i, EN_FLOW, &linkItem.dFlow);// 流量
ENgetlinkvalue(i, EN_VELOCITY, &linkItem.dVelocity);// 流速
ENgetlinkvalue(i, EN_HEADLOSS, &linkItem.dHeadLoss);// 水头损失
linkItem.dDateTime = CivCommonUtils::currentTime(); // 当前时间
linkItem.dTime =mSimulTime ;
linkItem.projCode = mProjCode;
mProjCache.addPipeItem(linkItem);
}
free(typeCode);
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include <map>
#include <vector>
#include <string>
#include "CivProjSmulResultCache.h"
/**
方案模拟
......@@ -9,14 +10,49 @@
class CivProjSimulation
{
public:
explicit CivProjSimulation();
explicit CivProjSimulation(const std::string& uri);
~CivProjSimulation();
/**
*@brief 方案模拟
*@param [std::string] projCode 方案编码
*@param [std::string] time 模拟的时段
*/
bool simulationProj(const std::string& projCode,const std::string& time);
bool simulationProj();
/**
*@brief 计算数据刷进数据库
*/
bool saveToDb();
private:
/**
*@brief 不加方案的水力计算
*@param [char*] inp 计算inp格式文件
*/
bool projBeforeHydrCompute(char* inp);
/**
*@brief 方案的水力计算
*@param [char*] inp 计算inp格式文件
*/
bool projHydrCompute(char* inp);
void getNodeResult();
void getLinkResult();
void getProjNodeResult();
void getProjLinkResult();
private:
std::map<std::string, std::string> m;
std::string mUri;
CivProjSmulResultCache mProjCache; //方案模拟结果缓存
std::string mRptFile;
std::string mBinFile;
std::string mSimulTime; // 模拟的时刻
std::string mProjCode; // 方案编码
};
#include "CivProjSmulResultCache.h"
#include "CIvProjSimulResHelper.h"
CivProjSmulResultCache::CivProjSmulResultCache()
{
}
CivProjSmulResultCache::~CivProjSmulResultCache()
{
}
void CivProjSmulResultCache::addNodeItem(ProjNodeResultItem& nodeItem)
{
std::map<std::string, std::string>::iterator iter = mNodeCodeSnMap.find(nodeItem.szNo);
if (iter == mNodeCodeSnMap.end())
return;
std::string code = iter->second;
nodeItem.code = code;
mNodeCache.insert(std::pair<std::string, ProjNodeResultItem>(code,nodeItem));
}
void CivProjSmulResultCache::addPipeItem(PorjPipeResultItem& pipeItem)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeItem.szNo);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
pipeItem.code = code;
mPipeCache.insert(std::pair<std::string, PorjPipeResultItem>(code, pipeItem));
}
bool CivProjSmulResultCache::saveToUri(const std::string& dbUri,const std::string& time,const std::string& projCode)
{
CIvProjSimulResHelper simulResHelper(dbUri);
simulResHelper.deleteByTimeAndPorjcode(time, projCode);
std::vector< ProjNodeResultItem> nodeVec;
for (auto iter = mNodeCache.begin(); iter != mNodeCache.end(); iter++)
{
ProjNodeResultItem nodeItem = iter->second;
nodeVec.push_back(nodeItem);
}
std::vector<PorjPipeResultItem> pipeVec;
for (auto iter = mPipeCache.begin(); iter != mPipeCache.end(); iter++)
{
PorjPipeResultItem pipeItem = iter->second;
pipeVec.push_back(pipeItem);
}
simulResHelper.saveNodeToDb(nodeVec);
simulResHelper.savePipeToDb(pipeVec);
return true;
}
void CivProjSmulResultCache::addNodeHead(const std::string& nodeCode, float head)
{
std::map<std::string, std::string>::iterator iter = mNodeCodeSnMap.find(nodeCode);
if (iter == mNodeCodeSnMap.end())
return;
std::string code = iter->second;
mNodeCache[code].dHead = head;
}
void CivProjSmulResultCache::addNodePressure(const std::string& nodeCode, float pressure)
{
std::map<std::string, std::string>::iterator iter = mNodeCodeSnMap.find(nodeCode);
if (iter == mNodeCodeSnMap.end())
return;
std::string code = iter->second;
mNodeCache[code].dPressure = pressure;
}
void CivProjSmulResultCache::addPipeFlow(const std::string& pipeSn, float flow)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dFlow = flow;
}
void CivProjSmulResultCache::addPipeVelcoity(const std::string& pipeSn, float velcocity)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dVelocity = velcocity;
}
void CivProjSmulResultCache::addPipeHeadLoss(const std::string& pipeSn, float headLoss)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dHeadLoss = headLoss;
}
void CivProjSmulResultCache::addProjNodeHead(const std::string& nodeCode, float head)
{
std::map<std::string, std::string>::iterator iter = mNodeCodeSnMap.find(nodeCode);
if (iter == mNodeCodeSnMap.end())
return;
std::string code = iter->second;
mNodeCache[code].dProjHead = head;
}
void CivProjSmulResultCache::addProjNodePressure(const std::string& nodeCode, float pressure)
{
std::map<std::string, std::string>::iterator iter = mNodeCodeSnMap.find(nodeCode);
if (iter == mNodeCodeSnMap.end())
return;
std::string code = iter->second;
mNodeCache[code].dProjPressure = pressure;
}
void CivProjSmulResultCache::addProjPipeFlow(const std::string& pipeSn, float flow)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dProjFlow = flow;
}
void CivProjSmulResultCache::addProjPipeVelcoity(const std::string& pipeSn, float velcocity)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dProjVelocity = velcocity;
}
void CivProjSmulResultCache::addProjPipeHeadLoss(const std::string& pipeSn, float headLoss)
{
std::map<std::string, std::string>::iterator iter = mLineCodeSnMap.find(pipeSn);
if (iter == mLineCodeSnMap.end())
return;
std::string code = iter->second;
mPipeCache[code].dPorjHeadLoss = headLoss;
}
void CivProjSmulResultCache::getCodeToSnMap(const std::string& uri)
{
CivSimulResHelperAbs* helper = new CIvProjSimulResHelper(uri);
helper->getNodeCodeSnMap(mNodeCodeSnMap);
helper->getLinCodeSnMap(mLineCodeSnMap);
delete helper;
}
\ No newline at end of file
#pragma once
#include<string>
#include "CivSimuResStruct.h"
/**
*@brief 方案模拟结果缓存
*/
class CivProjSmulResultCache
{
public:
CivProjSmulResultCache();
~CivProjSmulResultCache();
void setProjCode(const std::string& projCode) { mProjCode = projCode; }
void addNodeHead(const std::string& nodeCode, float head);
void addNodePressure(const std::string& nodeCode, float pressure);
void addPipeFlow(const std::string& pipeSn, float flow);
void addPipeVelcoity(const std::string& pipeSn, float velcocity);
void addPipeHeadLoss(const std::string& pipeSn, float headLoss);
void addProjNodeHead(const std::string& nodeCode, float head);
void addProjNodePressure(const std::string& nodeCode, float pressure);
void addProjPipeFlow(const std::string& pipeSn, float flow);
void addProjPipeVelcoity(const std::string& pipeSn, float velcocity);
void addProjPipeHeadLoss(const std::string& pipeSn, float headLoss);
void addNodeItem(ProjNodeResultItem& nodeItem);
void addPipeItem(PorjPipeResultItem& pipeItem);
bool saveToUri(const std::string& dbUri, const std::string& time, const std::string& projCode);
// 缓存code到sn的映射
void getCodeToSnMap(const std::string& uri);
private:
std::string mProjCode; // 方案编码
std::map<std::string, ProjNodeResultItem> mNodeCache;
std::map<std::string, PorjPipeResultItem> mPipeCache;
std::map<std::string, std::string> mNodeCodeSnMap;
std::map<std::string, std::string> mLineCodeSnMap;
};
......@@ -5,9 +5,9 @@
#include <string>
#include <map>
#define ALGORITHMEXPORT __declspec(dllexport)
#include "pandaAnalysis.h"
class ALGORITHMEXPORT CivTrackingAnalysis
class CivTrackingAnalysis
{
public:
explicit CivTrackingAnalysis(const std::string& uri);
......
#pragma once
#if defined(PANDANALYSIS_DLL)
#if defined(PANDANALYSIS_EXPORTS)
#if defined(_MSC_VER)
#define PANDANALYSIS_API __declspec(dllexport)
#else
#define PANDADBMANAGER_API
#endif
#else
#if defined(_MSC_VER)
#define PANDADBMANAGER_API __declspec(dllimport)
#else
#define PANDADBMANAGER_API
#endif
#endif
#else
#define PANDADBMANAGER_API
#endif
......@@ -133,7 +133,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;NDEBUG;PANDANALYSIS_DLL;PANDANALYSIS_EXPORTS;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)pandaDbManager;$(OUTDIR)..\include</AdditionalIncludeDirectories>
<Optimization>Disabled</Optimization>
......@@ -148,7 +148,8 @@
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
</Link>
<PostBuildEvent>
<Command>copy CivHydrFuncInter.h $(OutDir)..\include /y</Command>
<Command>copy CivHydrFuncInter.h $(OutDir)..\include /y
copy pandaAnalysis.h $(OutDir)..\include /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
......@@ -168,6 +169,7 @@
<ClCompile Include="CivProjInpBuilder.cpp" />
<ClCompile Include="CivProjManager.cpp" />
<ClCompile Include="CivProjSimulation.cpp" />
<ClCompile Include="CivProjSmulResultCache.cpp" />
<ClCompile Include="CivSimulResultCache.cpp" />
<ClCompile Include="CivStopWaterAnalysis.cpp" />
<ClCompile Include="CivTrackingAnalysis.cpp" />
......@@ -190,9 +192,11 @@
<ClInclude Include="CivProjInpBuilder.h" />
<ClInclude Include="CivProjManager.h" />
<ClInclude Include="CivProjSimulation.h" />
<ClInclude Include="CivProjSmulResultCache.h" />
<ClInclude Include="CivSimulResultCache.h" />
<ClInclude Include="CivStopWaterAnalysis.h" />
<ClInclude Include="CivTrackingAnalysis.h" />
<ClInclude Include="pandaAnalysis.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -72,6 +72,9 @@
<ClCompile Include="CivStopWaterAnalysis.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivProjSmulResultCache.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivHydrFuncInter.h">
......@@ -134,5 +137,11 @@
<ClInclude Include="CivBreakPipeAnalysis.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivProjSmulResultCache.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pandaAnalysis.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#include "CIvProjSimulResHelper.h"
#include "CivPgDbConnection.h"
CIvProjSimulResHelper::CIvProjSimulResHelper(const std::string& uri)
{
mConn = new CivPgDbConnection();
mConn->connect(uri);
mPreNodeSQL = "insert into \"方案模拟点表\"(\"code\",\"方案编码\",\"时间点\",\"水头\",\"压力\",\"方案水头\",\"方案压力\",\"修改时间\")";
mPrePipeSQL = "insert into \"方案模拟线表\" (\"code\",\"方案编码\",\"时间点\",\"流量\",\"流速\",\"单位水损\",\"方案流量\",\"方案流速\",\"方案单位水损\",\"修改时间\")";
}
CIvProjSimulResHelper::~CIvProjSimulResHelper()
{
mConn->disconnect();
delete mConn;
}
void CIvProjSimulResHelper::saveNodeToDb(const std::vector<ProjNodeResultItem>& nodeItems)
{
size_t total = nodeItems.size();
std::string nodeSql;
nodeSql.append(" values");
for (int i = 0; i < total; i++)
{
ProjNodeResultItem nodeItem = nodeItems[i];
if (nodeItem.dProjHead == 0 && nodeItem.dProjPressure == 0)
continue;
nodeSql.append("('");
nodeSql.append(nodeItem.code);
nodeSql.append("','");
nodeSql.append(nodeItem.projCode);
nodeSql.append("','");
nodeSql.append(nodeItem.dTime);
nodeSql.append("',");
nodeSql.append(std::to_string(nodeItem.dHead));
nodeSql.append(",");
nodeSql.append(std::to_string(nodeItem.dPressure));
nodeSql.append(",");
nodeSql.append(std::to_string(nodeItem.dProjHead));
nodeSql.append(",");
nodeSql.append(std::to_string(nodeItem.dProjPressure));
nodeSql.append(",'");
nodeSql.append(nodeItem.dDateTime);
nodeSql.append("'),");
}
nodeSql = nodeSql.substr(0, nodeSql.length() - 1);
std::string finalSql = mPreNodeSQL + nodeSql;
if (!mConn->execSql(finalSql))
return;
}
void CIvProjSimulResHelper::savePipeToDb(const std::vector<PorjPipeResultItem>& pipeItems)
{
std::string pipeSql;
pipeSql.append(" values");
size_t total = pipeItems.size();
for (int i = 0; i < total; i++)
{
PorjPipeResultItem pipItem = pipeItems[i];
if (pipItem.dProjFlow == 0 && pipItem.dProjVelocity == 0)
continue;
pipeSql.append("('");
pipeSql.append(pipItem.code);
pipeSql.append("','");
pipeSql.append(pipItem.projCode);
pipeSql.append("','");
pipeSql.append(pipItem.dTime);
pipeSql.append("',");
pipeSql.append(std::to_string(pipItem.dFlow));
pipeSql.append(",");
pipeSql.append(std::to_string(pipItem.dVelocity));
pipeSql.append(",");
pipeSql.append(std::to_string(pipItem.dHeadLoss));
pipeSql.append(",");
pipeSql.append(std::to_string(pipItem.dProjFlow));
pipeSql.append(",");
pipeSql.append(std::to_string(pipItem.dProjVelocity));
pipeSql.append(",");
pipeSql.append(std::to_string(pipItem.dPorjHeadLoss));
pipeSql.append(",'");
pipeSql.append(pipItem.dDateTime);
pipeSql.append("'),");
}
pipeSql = pipeSql.substr(0,pipeSql.length()-1);
std::string finalSql = mPrePipeSQL + pipeSql;
mConn->execSql(finalSql);
}
void CIvProjSimulResHelper::deleteByTimeAndPorjcode( const std::string& time,const std::string& projCode)
{
std::string nodeDelsql = "delete from \"方案模拟点表\" where \"时间点\"='" + time + "' and \"方案编码\" = '"+projCode+"'";
mConn->execSql(nodeDelsql);
std::string lineDelsql = "delete from \"方案模拟线表\" where \"时间点\"='" + time + "' and \"方案编码\" = '" + projCode + "'";
mConn->execSql(lineDelsql);
}
#pragma once
#include<string>
#include<vector>
#include "CivSimuResStruct.h"
#include "pandaDbManager.h"
#include "CivSimulResHelperAbs.h"
class CivConnection;
/**
*@brief 方案模拟结果操作类型
*/
class PANDADBMANAGER_API CIvProjSimulResHelper:public CivSimulResHelperAbs
{
public:
explicit CIvProjSimulResHelper(const std::string& uri);
~CIvProjSimulResHelper();
/**
*@brief 保存方案模拟的节点数据
*@param [ProjNodeResultItem] nodeItem 模拟的节点值
*/
virtual void saveNodeToDb(const std::vector<ProjNodeResultItem>& nodeItem);
/**
*@brief 保存方案模拟的管段数据
*@param [PorjPipeResultItem] nodeItem 模拟的节点值
*/
virtual void savePipeToDb(const std::vector<PorjPipeResultItem>& pipeItem);
// 根据时间点字段删除数据
void deleteByTimeAndPorjcode(const std::string& time, const std::string& projCode);
private:
std::string mPreNodeSQL;
std::string mPrePipeSQL;
};
......@@ -2,9 +2,9 @@
#define CIVASSEMBLY_H
#include "CivTypes.h"
#include <list>
#pragma warning(disable:4251)
#include "pandaDbManager.h"
#define DBEXPORT __declspec(dllexport)
#pragma warning(disable:4251)
#define Str std::string
......@@ -30,7 +30,7 @@ class CivAssembly
/**
节点类型
*/
class DBEXPORT CivNode: public CivAssembly
class PANDADBMANAGER_API CivNode: public CivAssembly
{
public:
typedef struct Table
......@@ -49,7 +49,7 @@ public:
/**
* 管线类型
*/
class DBEXPORT CivPipe: public CivAssembly
class PANDADBMANAGER_API CivPipe: public CivAssembly
{
public:
typedef struct Table
......@@ -74,7 +74,7 @@ public:
/*
水池类型
*/
class DBEXPORT CivTank:public CivAssembly
class PANDADBMANAGER_API CivTank:public CivAssembly
{
public:
typedef struct Table
......@@ -97,7 +97,7 @@ public:
/*
定义包含在管网中所有控制阀门。
*/
class DBEXPORT CivValve :public CivAssembly
class PANDADBMANAGER_API CivValve :public CivAssembly
{
public:
typedef struct Table
......@@ -119,7 +119,7 @@ public:
/**
水泵
*/
class DBEXPORT CivPumps :public CivAssembly
class PANDADBMANAGER_API CivPumps :public CivAssembly
{
public:
typedef struct Table
......@@ -138,7 +138,7 @@ public:
/*
定义管网中包含的所有水库节点
*/
class DBEXPORT CivReservoirs :public CivAssembly
class PANDADBMANAGER_API CivReservoirs :public CivAssembly
{
public:
typedef struct Table
......@@ -161,7 +161,7 @@ public:
/**
EMITTERS将模拟节点定义为扩散器(喷嘴或者孔口)。
*/
class DBEXPORT CivEmitters :public CivAssembly
class PANDADBMANAGER_API CivEmitters :public CivAssembly
{
public:
typedef struct Table
......@@ -181,7 +181,7 @@ public:
/**
坐标
*/
class DBEXPORT CivCoordinates :public CivAssembly
class PANDADBMANAGER_API CivCoordinates :public CivAssembly
{
public:
typedef struct Table
......@@ -201,7 +201,7 @@ public:
/**
参数控制选项
*/
class DBEXPORT CivMixing :public CivAssembly
class PANDADBMANAGER_API CivMixing :public CivAssembly
{
public:
typedef struct Table
......@@ -223,7 +223,7 @@ public:
/**
确定控制蓄水池混合的模型。
*/
class DBEXPORT CivParameter :public CivAssembly
class PANDADBMANAGER_API CivParameter :public CivAssembly
{
public:
typedef struct Table
......@@ -274,7 +274,7 @@ public:
/**
模式
*/
class DBEXPORT CivPatterns :public CivAssembly
class PANDADBMANAGER_API CivPatterns :public CivAssembly
{
public:
typedef struct Table
......@@ -290,7 +290,7 @@ public:
/*
定义数据曲线及其X、Y点。
*/
class DBEXPORT CivCurves :public CivAssembly
class PANDADBMANAGER_API CivCurves :public CivAssembly
{
public:
typedef struct Table
......@@ -307,7 +307,7 @@ public:
/**
定义连接节点的多模式需水,是对[JUNCTIONS]的补充。
*/
class DBEXPORT CivDemands :public CivAssembly
class PANDADBMANAGER_API CivDemands :public CivAssembly
{
public:
typedef struct Table
......@@ -329,7 +329,7 @@ public:
};
// 定义水质源头的位置。
class DBEXPORT CivSources :public CivAssembly
class PANDADBMANAGER_API CivSources :public CivAssembly
{
public:
typedef struct Table
......@@ -351,7 +351,7 @@ public:
};
// 定义模拟开始时被选管段的初始状态。
class DBEXPORT CivStatus :public CivAssembly
class PANDADBMANAGER_API CivStatus :public CivAssembly
{
public:
typedef struct Table
......@@ -369,7 +369,7 @@ public:
};
// 定义节点的初始水质。
class DBEXPORT CivQuality :public CivAssembly
class PANDADBMANAGER_API CivQuality :public CivAssembly
{
public:
typedef struct Table
......@@ -387,7 +387,7 @@ public:
};
// 给地图标签赋以坐标值。
class DBEXPORT CivLabels :public CivAssembly
class PANDADBMANAGER_API CivLabels :public CivAssembly
{
public:
typedef struct Table
......@@ -410,7 +410,7 @@ public:
};
// 将类型标签与特定节点和管段相连。
class DBEXPORT CivTags :public CivAssembly
class PANDADBMANAGER_API CivTags :public CivAssembly
{
public:
typedef struct Table
......
......@@ -21,17 +21,25 @@ CivHydrTableHelper::~CivHydrTableHelper()
bool CivHydrTableHelper::mainTain()
{
//unTopoMaintain();
// 节点
// 管网组件
updateAssem(TABLE_NODE, std::string("本点号"), "JD");
updateAssem(TABLE_PIPE, std::string("编号"), "GD");
updateAssem(TABLE_TANK, std::string("本点号"), "TK");
updateAssem(TABLE_VALVEE, std::string("本点号"), "VA");
updateAssem(TABLE_VALVE, std::string("本点号"), "VA");
updateAssem(TABLE_RESERVOIR, std::string("本点号"), "RE");
updateAssem(TABLE_PUMP, std::string("本点号"), "PU");
// 方案管网组件
updateAssem(PROJ_TABLE_NODE, std::string("本点号"), "PJD");
updateAssem(PROJ_TABLE_PIPE, std::string("编号"), "PGD");
updateAssem(PROJ_TABLE_TANK, std::string("本点号"), "PTK");
updateAssem(PROJ_TABLE_VALVE, std::string("本点号"), "PVA");
updateAssem(PROJ_TABLE_RESERVOIR, std::string("本点号"), "PRE");
updateAssem(PROJ_TABLE_PUMP, std::string("本点号"), "PPU");
if (!topoMaintain())
return false;
return true;
}
......@@ -65,8 +73,7 @@ void CivHydrTableHelper::updateAssem(const std::string& table, const std::string
sql = sql.substr(0, sql.length() - 1);
sql += ") as tmp(id, \""+ filed +"\") where "+ table +".id = tmp.id; ";
std::string utfsql = CivCommonUtils::string_To_UTF8(sql);
if (mConn && mConn->execSql(utfsql))
if (mConn && mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return;
......@@ -75,18 +82,47 @@ void CivHydrTableHelper::updateAssem(const std::string& table, const std::string
bool CivHydrTableHelper::topoMaintain()
{
// 管段与
topoMainTable(TABLE_PIPE, TABLE_NODE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
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"));
topoMainTable(TABLE_PIPE, TABLE_VALVE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, TABLE_VALVE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_NODE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_NODE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_RESERVOIR, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_TANK, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_VALVE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(TABLE_PIPE, PROJ_TABLE_VALVE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_NODE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_NODE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_RESERVOIR, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_TANK, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_VALVE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, TABLE_VALVE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_NODE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_NODE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_RESERVOIR, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_TANK, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_VALVE, std::string("起始节点"), std::string("本点号"), std::string("from_code"));
topoMainTable(PROJ_TABLE_PIPE, PROJ_TABLE_VALVE, std::string("终止节点"), std::string("本点号"), std::string("to_code"));
// 处理方案和阀门的拓扑关系
topoLikelyPipe(TABLE_PIPE, TABLE_VALVE, std::string("起始节点"), std::string("to_code"));
topoLikelyPipe(TABLE_PIPE, TABLE_VALVE, std::string("终止节点"), std::string("from_code"));
topoLikelyPipe(PROJ_TABLE_PIPE, TABLE_VALVE, std::string("起始节点"), std::string("to_code"));
topoLikelyPipe(PROJ_TABLE_PIPE, TABLE_VALVE, std::string("终止节点"), std::string("from_code"));
topoLikelyPipe(TABLE_PIPE, PROJ_TABLE_VALVE, std::string("起始节点"), std::string("to_code"));
topoLikelyPipe(TABLE_PIPE, PROJ_TABLE_VALVE, std::string("终止节点"), std::string("from_code"));
return true;
}
bool CivHydrTableHelper::unTopoMaintain()
......@@ -95,7 +131,7 @@ bool CivHydrTableHelper::unTopoMaintain()
unTopoTable(TABLE_PIPE, { std::string("编号"),std::string("起始节点"),std::string("终止节点") });
unTopoTable(TABLE_RESERVOIR, { std::string("本点号")});
unTopoTable(TABLE_TANK, { std::string("本点号") });
unTopoTable(TABLE_VALVEE, { std::string("本点号"),std::string("起始节点"),std::string("终止节点") });
unTopoTable(TABLE_VALVE, { std::string("本点号"),std::string("起始节点"),std::string("终止节点") });
return true;
}
......@@ -119,15 +155,30 @@ bool CivHydrTableHelper::topoMainTable(const std::string& sourceTable,
return true;
}
bool CivHydrTableHelper::topoLikelyPipe(const std::string& pipeTable, const std::string& nodeTable, const std::string& filed, const std::string& tocode)
{
std::string sql = "update \""+nodeTable+"\" as pu set \""+filed+"\" = \
(select pipe.\"编号\" from \""+pipeTable+"\" as pipe where pipe.\""+tocode+"\"=pu.\"code\") where exists (select 1 from \""+pipeTable+"\" as pipe1 where pipe1.\""+tocode+"\"=pu.\"code\")";
if (mConn && !mConn->execSql(sql))
{
mErrInfo = mConn->getLastError();
return false;
}
return true;
}
bool CivHydrTableHelper::topoValve(const std::string& sn,
const std::string& fromcode,
const std::string& tocode)
{
std::string sql = "update \"";
sql.append(TABLE_VALVEE);
sql.append(TABLE_VALVE);
sql.append("\" set \"" + sn + "\" = dd.\"本点号\"\
from(select node.\"本点号\" \"本点号\", node.\"code\" \"nodecode\", tt.\"code\" \"vacode\" from \
\""+TABLE_NODE+"\" node, (select t2.\""+tocode+"\" \""+tocode+"\", t1.\"code\" \"code\" from \""+TABLE_PIPE+"\" t2, \""+TABLE_VALVEE+"\" t1 where t2.\""+fromcode+"\" = t1.\"code\") tt\
\""+TABLE_NODE+"\" node, (select t2.\""+tocode+"\" \""+tocode+"\", t1.\"code\" \"code\" from \""+TABLE_PIPE+"\" t2, \""+TABLE_VALVE+"\" t1 where t2.\""+fromcode+"\" = t1.\"code\") tt\
where node.\"code\" = tt.\""+tocode+"\") dd\
where \"code\" = dd.\"vacode\"");
......
......@@ -2,12 +2,12 @@
#include<string>
#include<vector>
#include<map>
#include "pandaDbManager.h"
#include "CivConnection.h"
#define HYDRTABLEEXPORT __declspec(dllexport)
class HYDRTABLEEXPORT CivHydrTableHelper
class PANDADBMANAGER_API CivHydrTableHelper
{
public:
......@@ -39,6 +39,9 @@ private:
*@brief 拓扑维护阀门,需要特殊处理
*/
bool topoValve(const std::string& sn,const std::string& fromcode,const std::string& tocode );
bool topoLikelyPipe(const std::string& pipeTable, const std::string& nodeTable,
const std::string& filed, const std::string& tocode);
private:
std::vector<std::string> mNecessTables;
std::map<std::string, std::string> mNeedTableMap;
......
#include "CivInp.h"
#include<time.h>
bool CivInp::writeToFile(const char* fileName)
{
FILE* file;
std::string ss;
if (file = fopen(fileName, "wb"))
{
fprintf(file, mTextStream.str().c_str());
return true;
}
return false;
}
std::string CivInp::currentTime()
{
time_t timep;
struct tm* p;
time(&timep);
p = gmtime(&timep);
std::string currTime = std::to_string(1900 + p->tm_year) + "/" + std::to_string(1 + p->tm_mon) + \
"/" + std::to_string(p->tm_mday) + " " + std::to_string(p->tm_hour) + ":" + std::to_string(p->tm_min) + ":" + \
std::to_string(p->tm_sec);
return currTime;
}
void CivInp::writeTitles()
{
writeString("[TITLE]"); // дǩ
writeString("Scenario: Base");
writeString("Date:"+currentTime());
writeString("");
writeString("");
}
void CivInp::writeJunctions(Civitems items)
{
writeString("[JUNCTIONS]");
writeString(";ID Elev Demand Pattern ");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeItems(const Civitems& items)
{
size_t rows = items.size();
for (int i = 0; i < rows; i++)
{
CivItem item = items[i];
size_t itemSize = item.size();
int index = 0;
std::string itemStr = item[0] + " ";
while ((++index) < itemSize)
itemStr = item[index] + " ";
writeString(itemStr);
}
}
void CivInp::writePipes(Civitems items)
{
writeString("[PIPES]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeTanks(Civitems items)
{
writeString("[TANKS]");
writeString(";ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeReservoirs(Civitems items)
{
writeString("[RESERVOIRS]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writePumps(Civitems items)
{
writeString("[PUMPS]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeValves(Civitems items)
{
writeString("[VALVES]");
writeString(";ID Node1 Node2 Diameter Type Setting MinorLoss ");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeCoordinates(Civitems items)
{
writeString("[PIPES]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeLabels(Civitems items)
{
writeString("[PIPES]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeVertices(Civitems items)
{
writeString("[PIPES]");
writeString(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeDemand(Civitems items)
{
writeString("[DEMANDS]");
writeString(";Junction Demand Pattern Category");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeOptions(const Civitems& items)
{
writeString("[OPTIONS]");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writePatterns(Civitems items)
{
writeString("[PATTERNS]");
writeString(";ID Multipliers");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeBackdrop(Civitems items)
{
writeString("[BACKDROP]");
writeItems(items);
writeString("");
writeString("");
}
void CivInp::writeEnd()
{
writeString("[END]");
}
void CivInp::writeString(const std::string& s)
{
mTextStream << s << "\n";
}
\ No newline at end of file
#pragma once
#include <string>
#include <sstream>
#include <vector>
#define CivItem std::vector<std::string>
#define Civitems std::vector<CivItem>
/**
inp文件对象模型
*/
class CivInp
{
public:
/**
*@brief 保存inp文件
*@fileName: 文件名
*/
bool writeToFile(const char* fileName);
void writeTitles();
void writeJunctions(Civitems items);
void writePipes(Civitems items);
void writeTanks(Civitems items);
void writeReservoirs(Civitems items);
void writePumps(Civitems items);
void writeValves(Civitems items);
void writeCoordinates(Civitems items);
void writeLabels(Civitems items);
void writeVertices(Civitems items);
void writeBackdrop(Civitems items);
void writeEnd();
void writeString(const std::string& s);
void writeItems(const Civitems& items);
void writeOptions(const Civitems& items);
void writePatterns(Civitems items);
void writeDemand(Civitems items);
std::string currentTime();
private:
std::ostringstream mTextStream;
};
This diff is collapsed.
......@@ -2,16 +2,19 @@
#include "CivAssembly.h"
#include "CivInpHelperAbs.h"
#include <memory>
#include "pandaDbManager.h"
/**
从数据库获取inp文件相关的类
*/
class INPDLLEXPORT CivInpDbHelper:public CivInpHelperAbs
class PANDADBMANAGER_API CivInpDbHelper:public CivInpHelperAbs
{
public:
explicit CivInpDbHelper(const std::string& uri);
~CivInpDbHelper();
void handlePump() override;
void handleValve() override;
bool getNode(CivNode& node)override;
bool getPipe(CivPipe& pipe) override;
bool getTank(CivTank& tank) override;
......@@ -22,12 +25,4 @@ public:
bool getQuality(CivQuality& quality) override;
bool getStatus(CivStatus& status) override;
private:
// 处理阀门
void handleValves();
std::string mCondtion;
std::multimap<std::string,std::string> mValvePipeMap;
std::multimap<std::string, CivPipe::PipesTable> mPipesMap;
std::multimap<std::string, CivNode::NodeTable> mNodeMap; // 处理与阀门相连的管段
};
......@@ -2,6 +2,7 @@
#include "CivConnection.h"
#include "CivPgDbConnection.h"
#include "CivTableFields.h"
#include "StringUtils.h"
CivInpHelperAbs::CivInpHelperAbs(const std::string& uri)
{
......@@ -72,6 +73,14 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
bool CivInpHelperAbs::getPatterns(CivPatterns& patterns)
{
//延时不需要需水量模式
if (!isDelayTime)
{
convertPatterns();
return true;
}
PatternTable patternTable;
std::vector<std::string> fields = {
......@@ -137,7 +146,6 @@ bool CivInpHelperAbs::getSources(CivSources& sources)
return true;
}
bool CivInpHelperAbs::getLabels(CivLabels& labels)
{
return true;
......@@ -182,3 +190,86 @@ void CivInpHelperAbs::setQualityType(QualityType qualiType)
{
mQualityType = qualiType;
}
void CivInpHelperAbs::setPatternTime(std::string time)
{
std::vector<std::string> vec;
StringUtils::split(time, vec);
if (vec.size() < 2)
return;
std::string pattern = vec[1];
std::vector<std::string> timeVec;
StringUtils::split(pattern, timeVec, ":");
if (timeVec.size() < 3)
return;
std::string timetemp = timeVec[0];
mPatternTime = std::atoi(timetemp.c_str());
}
void CivInpHelperAbs::convertPatterns()
{
PatternTable patternTable;
std::vector<std::string> fields = {
patternTable.modelName,
patternTable.modelData,
};
std::vector<std::map<std::string, std::string>> resultVector;
mDbConn->query(PATTERNTABLE, fields, resultVector);
size_t totals = resultVector.size();
for (int i = 0; i < totals; i++)
{
std::map<std::string, std::string> map = resultVector[i];
CivPatterns::PatternTable pTable;
std::string name = map.find(patternTable.modelName)->second;
std::string val = map.find(patternTable.modelData)->second;
// 解析模式
std::vector<std::string> res;
StringUtils::split(val, res);
mPatterns.insert(std::pair<std::string, std::vector<std::string>>(name, res));
}
}
void CivInpHelperAbs::isDelayTimeSimul(bool isDelay)
{
isDelayTime = isDelay;
}
void CivInpHelperAbs::handleDelayPattern(const std::string& demand, const std::string& patternID, std::string& destDemand, std::string& pattern)
{
// 是否做延时模拟
if (isDelayTime)
{
destDemand = demand;
pattern = patternID;
}
else
{
auto iter = mPatterns.find(patternID);
if (iter != mPatterns.end())
{
std::vector<std::string> mulitiers = iter->second;
if (mPatternTime > mulitiers.size())
mPatternTime = mulitiers.size() - 1;
if (mPatternTime < 0)
mPatternTime = 0;
std::string mulitier = mulitiers[mPatternTime];
float intMul = std::atof(mulitier.c_str());
float dem = std::atof(demand.c_str());
destDemand = std::to_string(dem * intMul);
}
}
}
\ No newline at end of file
#pragma once
#include "CivAssembly.h"
#include "pandaDbManager.h"
class CivConnection;
#define INPDLLEXPORT __declspec(dllexport)
/**
转inp操作数据库类
*/
class INPDLLEXPORT CivInpHelperAbs
class PANDADBMANAGER_API CivInpHelperAbs
{
public:
// 水质模拟时间
......@@ -20,6 +20,8 @@ public:
explicit CivInpHelperAbs(const std::string& uri);
virtual ~CivInpHelperAbs();
virtual void handlePump() = 0;
virtual void handleValve() = 0;
// 组件需要重载
virtual bool getNode(CivNode& node)=0 ;
virtual bool getPipe(CivPipe& pipe)=0 ;
......@@ -35,6 +37,10 @@ public:
void getSnToCode(std::map<std::string, std::string>& coord);
// 不要重载函数
void setPatternTime(std::string time); // 解析模式时刻
void convertPatterns();
void isDelayTimeSimul(bool isDelay);
bool getPatterns(CivPatterns& patterns) ;
bool getCurves(CivCurves& curves) ;
bool getDemands(CivDemands& demands) ;
......@@ -48,4 +54,18 @@ public:
protected:
QualityType mQualityType;
CivConnection* mDbConn;
bool isDelayTime; // 是否做延时模拟
int mPatternTime; // 模式
std::map<std::string,std::vector<std::string>> mPatterns; // 需水量模式乘子
void handleDelayPattern(const std::string& sourceDemand, const std::string& patternID, std::string& demand, std::string& pattern);
std::string mCondtion;
std::vector<CivPipe::PipesTable> mPipesVec; //
std::vector<CivNode::NodeTable> mNodeVec; // 处理与阀门相连的管段
std::vector<CivValve::ValveTable> mValuvesVec; // 阀门
std::vector<CivStatus::StatusTable> mStatusVec; // 状态组件
std::vector<CivPumps::PumpTable> mPumpTables; // 水泵
std::vector<CivCoordinates::CoordTable> mCoords;
};
#include "CivMaintainModel.h"
CivMaintainModel::CivMaintainModel()
{
}
void CivMaintainModel::maintain()
{
}
void CivMaintainModel::addNecessaryTable(const std::string& table)
{
}
bool CivMaintainModel::checkTable(const std::string& table)
{
return true;
}
bool CivMaintainModel::checkTableFiled(const std::string& talbe, const std::string& filed, const std::string& filedType)
{
return true;
}
void CivMaintainModel::addTableFiled(const std::string& table, const std::string& filed, const std::string& filedType)
{
}
void CivMaintainModel::deleteTableFiled(const std::string& table, const std::string& filed)
{
}
\ No newline at end of file
#pragma once
#include "CivDbConn.h"
#include <vector>
/**
维护水力模型必要的表
*/
class DBEXPORT CivMaintainModel
{
public:
CivMaintainModel();
/**
*@brief 维护模型必要的表
*/
void maintain();
/**
*@brief 添加模型所必须的表
*@param table 表名
*/
void addNecessaryTable(const std::string& table);
private:
/**
*@brief 检查表是否存在
*/
bool checkTable(const std::string& table);
/**
*@brief 检查表字段
*@param table 表名
*@param filed 表字段
*@param filedType 表字段类型
*/
bool checkTableFiled(const std::string& table, const std::string& filed, const std::string& filedType);
/**
*@brief 添加表字段
*@param table 表名
*@param filed 表字段
*@param filedType 表字段类型
*/
void addTableFiled(const std::string& table, const std::string& filed, const std::string& filedType);
/**
*@brief 删除表字段
*@param table 表名
*@param filed 表字段
*/
void deleteTableFiled(const std::string& table, const std::string& filed);
private:
std::vector<std::string> mNecessTables;
};
......@@ -69,6 +69,7 @@ bool CivPgDbConnection::execSql(const std::string& sql)
if (!errorStr.empty())
{
mLastError = errorStr;
std::cout << sql << std::endl;
std::cout << mLastError << std::endl;
PQclear(mResult);
return false;
......
This diff is collapsed.
......@@ -5,12 +5,15 @@
/**
* 增加
*/
class INPDLLEXPORT CivProjInpDbHelper: public CivInpHelperAbs
class PANDADBMANAGER_API CivProjInpDbHelper: public CivInpHelperAbs
{
public:
explicit CivProjInpDbHelper(const std::string& uri);
~CivProjInpDbHelper();
void handlePump() override;
void handleValve() override;
bool getNode(CivNode& node)override;
bool getPipe(CivPipe& pipe) override;
bool getTank(CivTank& tank) override;
......@@ -24,6 +27,19 @@ public:
void setProjCode(const std::string& projCode);
private:
// 将方案详情表查出的数据按图层分类
void sortProjDeatil();
/**
*@brief 根据图层动态生成需要查询详情表条件
*/
std::string inline splicingConditions(const std::string& layer);
std::string inline genSql(const std::string& table);
std::string mPorjCode;
std::string mCondition;
// 根据方案编码做详情表的数据缓存
std::map<std::string,std::vector<std::map<std::string,std::string>>> mDetailMap;
};
......@@ -46,6 +46,37 @@ struct TankResultItem :public ResultItem
float dTankLevel;
};
// 方案结果
struct ProjResultItem
{
char szNo[64];
std::string code; // 编码,管段或者节点的数据标识
std::string projCode; // 方案编码,标识是哪一个方案
std::string dDateTime; // 存储数据的当前时间
std::string dTime; // 模拟的是哪一个时刻的值
};
// 方案点结果
struct ProjNodeResultItem : public ProjResultItem
{
float dHead; // 水头
float dPressure; // 压力
float dProjHead; // 方案水头
float dProjPressure;// 方案压力
};
// 方案线结果
struct PorjPipeResultItem : public ProjResultItem
{
float dFlow; // 流量
float dVelocity; //流速
float dHeadLoss;// 单位水头损失
float dPorjHeadLoss;// 方案单位水头损失
float dProjFlow; // 方案的流量
float dProjVelocity; // 方案的流速
};
#define NodeResultItems std::map<std::string,NodeResultItem>
#define LinkResultItems std::map<std::string,LinkResultItem>
#define TankResultItems std::map<std::string,TankResultItem>
......@@ -66,6 +97,9 @@ typedef struct PipeCoord
std::string endY;// 终止节点Y
}PipeCoord;
// 方案详情表信息结构
#define NodeCoords std::map<std::string,NodeCoord>
#define PipeCoords std::map<std::string,PipeCoord>
......@@ -93,7 +93,7 @@ bool CivSimulResDbHelper::insertLinksBulk(const std::map<int, LinkResultItems>&
sql.append("\'" + CurrentTime + "\'");
sql.append(",");
sql.append(std::to_string(linkItem.dChlorine));
sql.append("),");
sql.append("),");currentTime
condition = "\'" + linkItem.dTime + "\'";
}
......@@ -244,112 +244,3 @@ bool CivSimulResDbHelper::insertTanks(const TankResultItems& tankMap)
{
return true;
}
\ No newline at end of file
void CivSimulResDbHelper::getAllNodeCoords(NodeCoords& nodeCoords)
{
std::vector<std::string> fileds = {
"本点号","横坐标","纵坐标"
};
std::vector<std::map<std::string, std::string>> res;
if (!mConn->query(PIPENODE, fileds, res))
return;
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
NodeCoord nodeCoord;
std::string key = nodeInfo.find(fileds[0])->second;
nodeCoord.xCoord = nodeInfo.find(fileds[1])->second;
nodeCoord.yCoord = nodeInfo.find(fileds[2])->second;
nodeCoords[key] = nodeCoord;
}
}
void CivSimulResDbHelper::getAllPipeCoords(PipeCoords& pipeCoords)
{
std::vector<std::string> fileds = {
"ST_X(ST_StartPoint(ST_GeometryN(geom,1))) as startx",
"ST_Y(ST_StartPoint(ST_GeometryN(geom,1))) as starty",
"ST_X(ST_EndPoint(ST_GeometryN(geom,1))) as endX" ,
"ST_Y(ST_EndPoint(ST_GeometryN(geom,1))) as endY",
"编号"
};
std::vector<std::map<std::string, std::string>> res;
if (!mConn->query(PIPELINE, fileds, res))
return;
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string key = nodeInfo.find("编号")->second;
pipeCoord.startX = nodeInfo.find("startx")->second;
pipeCoord.startY = nodeInfo.find("starty")->second;
pipeCoord.endX = nodeInfo.find("endx")->second;
pipeCoord.endY = nodeInfo.find("endy")->second;
pipeCoords[key] = pipeCoord;
}
}
void CivSimulResDbHelper::getLinCodeSnMap(std::map<std::string, std::string>& map)
{
std::vector<std::string> fileds = {
"\"编号\"",
"\"code\""
};
std::vector<std::map<std::string, std::string>> res;
mConn->query(PIPELINE, fileds, res);
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string sn = nodeInfo.find("编号")->second;
std::string code = nodeInfo.find("code")->second;
map[sn] = code;
}
}
void CivSimulResDbHelper::getNodeCodeSnMap(std::map<std::string, std::string>& map)
{
std::vector<std::string> fileds = {
"\"本点号\"",
"\"code\""
};
std::vector<std::map<std::string, std::string>> res;
mConn->query(PIPENODE, fileds, res);
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string sn = nodeInfo.find("本点号")->second;
std::string code = nodeInfo.find("code")->second;
map[sn] = code;
}
}
bool CivSimulResDbHelper::beginTransaction()
{
return mConn->beginTransaction();
}
bool CivSimulResDbHelper::commitTransaction()
{
return mConn->commitTransaction();
}
\ No newline at end of file
......@@ -2,29 +2,20 @@
#include "CivSimulResHelperAbs.h"
#include<vector>
#include<string>
#include "pandaDbManager.h"
#define RESDBHELPER __declspec(dllexport)
class RESDBHELPER CivSimulResDbHelper :public CivSimulResHelperAbs
class PANDADBMANAGER_API CivSimulResDbHelper :public CivSimulResHelperAbs
{
public:
explicit CivSimulResDbHelper(const std::string& uri);
~CivSimulResDbHelper();
virtual bool beginTransaction();
virtual bool commitTransaction();
virtual bool insertNodes(const NodeResultItems& nodeitems);
virtual bool insertLinks(const LinkResultItems& linkMap);
virtual bool insertTanks(const TankResultItems& tankMap);
virtual bool insertLinksBulk(const std::map<int,LinkResultItems>& linksMap);
virtual bool insertNodeBulk(const std::map<int, NodeResultItems>& nodesMap);
virtual void getAllNodeCoords(NodeCoords& nodeCoords);
virtual void getAllPipeCoords(PipeCoords& pipeCoords);
virtual void getLinCodeSnMap(std::map<std::string, std::string>& map);
virtual void getNodeCodeSnMap(std::map<std::string, std::string>& map);
private:
std::vector<std::string> mNodeFields;
std::vector<std::string> mLinkFileds;
......
......@@ -11,19 +11,19 @@ CivSimulResHelperAbs::~CivSimulResHelperAbs()
{
}
bool CivSimulResHelperAbs::beginTransaction()
bool CivSimulResHelperAbs::insertNodes(const NodeResultItems& nodeMap)
{
return true;
}
bool CivSimulResHelperAbs::commitTransaction()
void CivSimulResHelperAbs::saveNodeToDb(const std::vector<ProjNodeResultItem>& nodeItems)
{
return true;
}
bool CivSimulResHelperAbs::insertNodes(const NodeResultItems& nodeMap)
void CivSimulResHelperAbs::savePipeToDb(const std::vector<PorjPipeResultItem>& pipeItems)
{
return true;
}
bool CivSimulResHelperAbs::insertLinks(const LinkResultItems& linkMap)
......@@ -48,22 +48,115 @@ bool CivSimulResHelperAbs::insertNodeBulk(const std::map<int, TankResultItems>&
void CivSimulResHelperAbs::getAllNodeCoords(NodeCoords& nodeCoords)
{
if (!mConn)
return;
std::vector<std::string> fileds = {
"本点号","横坐标","纵坐标"
};
std::vector<std::map<std::string, std::string>> res;
if (!mConn->query(PIPENODE, fileds, res))
return;
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
NodeCoord nodeCoord;
std::string key = nodeInfo.find(fileds[0])->second;
nodeCoord.xCoord = nodeInfo.find(fileds[1])->second;
nodeCoord.yCoord = nodeInfo.find(fileds[2])->second;
nodeCoords[key] = nodeCoord;
}
}
void CivSimulResHelperAbs::getAllPipeCoords(PipeCoords& pipeCoords)
{
if (!mConn)
return;
std::vector<std::string> fileds = {
"ST_X(ST_StartPoint(ST_GeometryN(geom,1))) as startx",
"ST_Y(ST_StartPoint(ST_GeometryN(geom,1))) as starty",
"ST_X(ST_EndPoint(ST_GeometryN(geom,1))) as endX" ,
"ST_Y(ST_EndPoint(ST_GeometryN(geom,1))) as endY",
"编号"
};
std::vector<std::map<std::string, std::string>> res;
if (!mConn->query(PIPELINE, fileds, res))
return;
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string key = nodeInfo.find("编号")->second;
pipeCoord.startX = nodeInfo.find("startx")->second;
pipeCoord.startY = nodeInfo.find("starty")->second;
pipeCoord.endX = nodeInfo.find("endx")->second;
pipeCoord.endY = nodeInfo.find("endy")->second;
pipeCoords[key] = pipeCoord;
}
}
void CivSimulResHelperAbs::getLinCodeSnMap(std::map<std::string, std::string>& map)
{
if (!mConn)
return;
std::vector<std::string> fileds = {
"\"编号\"",
"\"code\""
};
std::vector<std::map<std::string, std::string>> res;
mConn->query(PIPELINE, fileds, res);
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string sn = nodeInfo.find("编号")->second;
std::string code = nodeInfo.find("code")->second;
map[sn] = code;
}
}
void CivSimulResHelperAbs::getNodeCodeSnMap(std::map<std::string, std::string>& map)
{
if (!mConn)
return;
std::vector<std::string> fileds = {
"\"本点号\"",
"\"code\""
};
std::vector<std::map<std::string, std::string>> res;
mConn->query(PIPENODE, fileds, res);
size_t total = res.size();
for (int i = 0; i < total; i++)
{
std::map<std::string, std::string> nodeInfo = res[i];
PipeCoord pipeCoord;
std::string sn = nodeInfo.find("本点号")->second;
std::string code = nodeInfo.find("code")->second;
map[sn] = code;
}
}
#pragma once
#include <string>
#include <map>
#include <vector>
#include "CivSimuResStruct.h"
#include "pandaDbManager.h"
#define SIMULABSEXPORT __declspec(dllexport)
class CivConnection;
/**
ģ
*/
class SIMULABSEXPORT CivSimulResHelperAbs
class PANDADBMANAGER_API CivSimulResHelperAbs
{
public:
explicit CivSimulResHelperAbs();
virtual ~CivSimulResHelperAbs();
virtual bool beginTransaction();
virtual bool commitTransaction();
virtual bool insertNodes(const NodeResultItems& nodeitems);
virtual bool insertLinks(const LinkResultItems& linkMap);
virtual bool insertTanks(const TankResultItems& tankMap);
virtual bool insertLinksBulk(const std::map<int, LinkResultItems>& linksMap);
virtual bool insertNodeBulk(const std::map<int, TankResultItems>& nodesMap);
virtual void getAllNodeCoords(NodeCoords& nodeCoords);
virtual void getAllPipeCoords(PipeCoords& pipeCoords);
virtual void getLinCodeSnMap(std::map<std::string, std::string>& map);
virtual void getNodeCodeSnMap(std::map<std::string, std::string>& map);
virtual void saveNodeToDb(const std::vector<ProjNodeResultItem>& nodeItems);
virtual void savePipeToDb(const std::vector<PorjPipeResultItem>& pipeItems);
void getLinCodeSnMap(std::map<std::string, std::string>& map);
void getNodeCodeSnMap(std::map<std::string, std::string>& map);
void getAllNodeCoords(NodeCoords& nodeCoords);
void getAllPipeCoords(PipeCoords& pipeCoords);
protected:
CivConnection* mConn = nullptr;
......
......@@ -12,8 +12,18 @@
#define TABLE_NODE "节点"
#define TABLE_PIPE "管段"
#define TABLE_TANK "水池"
#define TABLE_VALVEE "阀门"
#define TABLE_VALVE "阀门"
#define TABLE_RESERVOIR "水库"
#define TABLE_PUMP "水泵"
#define PROJ_TABLE_NODE "方案节点"
#define PROJ_TABLE_PIPE "方案管段"
#define PROJ_TABLE_TANK "方案水池"
#define PROJ_TABLE_VALVE "方案阀门"
#define PROJ_TABLE_RESERVOIR "方案水库"
#define PROJ_TABLE_PUMP "方案水泵"
#define TABLE_PROJ "方案表"
#define TABLE_PIPESIMUL "管段模拟值"
#define TABLE_NODESIMUL "节点模拟值"
......
#pragma once
#if defined(PANDADBMANAGER_DLL)
#if defined(PANDADBMANAGER_EXPORTS)
#if defined(_MSC_VER)
#define PANDADBMANAGER_API __declspec(dllexport)
#else
#define PANDADBMANAGER_API
#endif
#else
#if defined(_MSC_VER)
#define PANDADBMANAGER_API __declspec(dllimport)
#else
#define PANDADBMANAGER_API
#endif
#endif
#else
#define PANDADBMANAGER_API
#endif
......@@ -134,7 +134,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WINDOWS</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WINDOWS;PANDADBMANAGER_DLL;PANDADBMANAGER_EXPORTS;PANDALOG_DLL;PANDALOG_EXPORTS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(OUTDIR)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>MaxSpeed</Optimization>
......@@ -158,6 +158,7 @@ copy CivSimuResStruct.h $(OutDir)..\include /y
copy CivSimulResHelperAbs.h $(OutDir)..\include /y
copy CivSimulResDbHelper.h $(OutDir)..\include /y
copy CivHydrTableHelper.h $(OutDir)..\include /y
copy CIvProjSimulResHelper.h $(OutDir)..\include /y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
......@@ -169,11 +170,13 @@ copy CivHydrTableHelper.h $(OutDir)..\include /y
<ClInclude Include="CivInpHelperAbs.h" />
<ClInclude Include="CivPgDbConnection.h" />
<ClInclude Include="CivProjInpDbHelper.h" />
<ClInclude Include="CIvProjSimulResHelper.h" />
<ClInclude Include="CivSimulResDbHelper.h" />
<ClInclude Include="CivSimulResHelperAbs.h" />
<ClInclude Include="CivSimuResStruct.h" />
<ClInclude Include="CivTableFields.h" />
<ClInclude Include="CivTypes.h" />
<ClInclude Include="pandaDbManager.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivAssembly.cpp" />
......@@ -183,6 +186,7 @@ copy CivHydrTableHelper.h $(OutDir)..\include /y
<ClCompile Include="CivInpHelperAbs.cpp" />
<ClCompile Include="CivPgDbConnection.cpp" />
<ClCompile Include="CivProjInpDbHelper.cpp" />
<ClCompile Include="CIvProjSimulResHelper.cpp" />
<ClCompile Include="CivSimulResDbHelper.cpp" />
<ClCompile Include="CivSimulResHelperAbs.cpp" />
</ItemGroup>
......
......@@ -51,6 +51,12 @@
<ClInclude Include="CivHydrTableHelper.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CIvProjSimulResHelper.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pandaDbManager.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivAssembly.cpp">
......@@ -80,5 +86,8 @@
<ClCompile Include="CivHydrTableHelper.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CIvProjSimulResHelper.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -2,9 +2,7 @@
#include<string>
#include<map>
#include<vector>
#define UTILSEXPORT __declspec(dllexport)
#include "pandaLog.h"
// 字符串转编码
#define TransUTFCoding(name) CivCommonUtils::string_To_UTF8(name)
......@@ -17,7 +15,7 @@
#define CurrentHour CivCommonUtils::currentHour()
class UTILSEXPORT CivCommonUtils
class PANDALOG_API CivCommonUtils
{
public:
......
......@@ -4,11 +4,11 @@
#include <sstream>
#include <string>
#include <vector>
#include "pandaLog.h"
#define CSVEXPORT __declspec(dllexport)
using namespace std;
class CSVEXPORT CivCsvReader
class PANDALOG_API CivCsvReader
{
public:
explicit CivCsvReader(const char*);
......
#pragma once
#include <string>
#include "pandaLog.h"
#define CDATEEXPORT __declspec(dllexport)
class CDATEEXPORT CivDate
class PANDALOG_API CivDate
{
private:
int year;
......
......@@ -4,13 +4,12 @@
#include <string>
#include<iostream>
#include<fstream>
#define SYSLOGEXPORT __declspec(dllexport)
#include "pandaLog.h"
/**
日志记录接口
*/
class SYSLOGEXPORT CivSysLog {
class PANDALOG_API CivSysLog {
private:
CivSysLog();
......
#include "StringUtils.h"
void StringUtils::split(std::string sourceStr, std::vector<std::string>& res, const std::string& delim)
{
char source[512];
strcpy(source,sourceStr.c_str());
char deli[32];
strcpy(deli, delim.c_str());
char* token;
char* ptr = source;
while ((token = strtok(ptr, deli)) != NULL)
{
std::string temp = token;
res.push_back(temp);
ptr = NULL;
}
}
\ No newline at end of file
#pragma once
#include <string>
#include <vector>
#include "pandaLog.h"
/**
字符串分割
*/
class PANDALOG_API StringUtils
{
public:
/**
*@brief 将字符串按照分隔符分割成字符串数组
*@param [std::string] 源字符串
*@param [std::vector] 分割后的字符串数组
*@param [std::string] delim 分割符,默认空格分割
*/
static void split(std::string sourceStr, std::vector<std::string>& res, const std::string& delim =" ");
};
#pragma once
#if defined(PANDALOG_DLL)
#if defined(PANDALOG_EXPORTS)
#if defined(_MSC_VER)
#define PANDALOG_API __declspec(dllexport)
#else
#define PANDALOG_API
#endif
#else
#if defined(_MSC_VER)
#define PANDALOG_API __declspec(dllimport)
#else
#define PANDALOG_API
#endif
#endif
#else
#define PANDALOG_API
#endif
......@@ -130,7 +130,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;PANDALOG_DLL;PANDALOG_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
......@@ -145,16 +145,20 @@
<Command>copy CivSysLog.h $(OutDir)..\include /y
copy CivCsvReader.h $(OutDir)..\include /y
copy CivCommonUtils.h $(OutDir)..\include /y
copy CivDate.h $(OutDir)..\include /y</Command>
copy CivDate.h $(OutDir)..\include /y
copy StringUtils.h $(OutDir)..\include /y
copy pandaLog.h $(OutDir)..\include /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CivCommonUtils.h" />
<ClInclude Include="CivCsvReader.h" />
<ClInclude Include="CivDate.h" />
<ClInclude Include="pandaLog.h" />
<ClInclude Include="CivSysLog.h" />
<ClInclude Include="cJSON.h" />
<ClInclude Include="JsonParseObject.h" />
<ClInclude Include="StringUtils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivCommonUtils.cpp" />
......@@ -163,6 +167,7 @@ copy CivDate.h $(OutDir)..\include /y</Command>
<ClCompile Include="CivSysLog.cpp" />
<ClCompile Include="cJSON.c" />
<ClCompile Include="JsonParseObject.cpp" />
<ClCompile Include="StringUtils.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -33,6 +33,12 @@
<ClInclude Include="JsonParseObject.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="StringUtils.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="pandaLog.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivSysLog.cpp">
......@@ -53,5 +59,8 @@
<ClCompile Include="JsonParseObject.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="StringUtils.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -78,7 +78,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(ProjectDir)..\tmp\$(PlatformName)\$(ProjectName)\$(Configuration)\</IntDir>
<OutDir>..\..\hModelProgram\lib\</OutDir>
<OutDir>$(ProjectDir)..\libs\x64\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......
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