Esempio n. 1
0
//缺失值填充
bool TCManager::FillMissing(TCPacket &inP, AnaWord &aw, string szVO, TCPacket &outP)
{
	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));

	string szTableName = "";
	int nCount = aw.GetWordCount();
	for (int i=0;i<nCount;i++)
	{
		if (aw.GetAt(i) == "/DATA" &&  i< nCount-2 )
		{
			szTableName = aw.GetAt(i+2);
			break;
		}
	}
	if (szTableName.size()==0)
		return SetResultState(false,outP,GetLanguage(FormatIsError));
	//接口指针
	CDataInterface *pDI = g_system.GetCurData(nUserID,szTableName);
	if (pDI ==NULL)
	{
		if (g_system.OpenTable(nUserID,szTableName,szTableName)==false)
			return SetResultState(false,outP,GetLanguage(OperationFail)); 
		
		pDI = g_system.GetCurData(nUserID,szTableName);
		if (pDI ==NULL)
			return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
	}
#ifdef WINPLAT
	CTString szPath = "tlBase.dll";
	TCSystem::GetModulePath(szPath);
	szPath += "/DataDeal.dll";	
	HINSTANCE hmod = LoadLibrary(szPath.GetData());
	if (hmod==NULL)
	{//没有找到对应的DLL
		SetResultState(false,outP,GetLanguage(DLLFileNotFind));//"没有找到对应的DLL"
		return false;
	}
	
	typedef int (*pFillMissing)(CDataInterface *pData, LPCTSTR lpszVO);
	pFillMissing proc;
	proc = (pFillMissing)GetProcAddress(hmod,"FillMissing");
	if (proc==NULL)
	{//"没有找到对应的过程名"
		SetResultState(false,outP,GetLanguage(ProcNameNotFind));
		return false;
	}
	
	int rst = (*proc)(pDI,szVO.c_str());
	if (rst == 0)
		return SetResultState(false,outP,"");
	else
		return SetResultState(true,outP);
	
#else
	
#endif
	return SetResultState(true,outP);
}
Esempio n. 2
0
/*
数据过滤
Filter /DATA =表名 /EXPR \"条件表达式\"
 */
bool TCManager::Filter(TCPacket &inP,AnaWord &aw, TCPacket &outP)
{
	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));

	int nTableIndex = -1;
	int nConditionIndex = -1;
	for (int i=2;i<aw.GetWordCount();i++)
	{
		if (aw.GetAt(i-2)=="/DATA" && aw.GetAt(i-1)=="=")
		{
			nTableIndex = i;
		}
		if (aw.GetAt(i-1)=="/EXPR")
		{
			nConditionIndex = i;
		}
	}

	if (nTableIndex == -1 || nConditionIndex == -1)
		return SetResultState(false,outP,GetLanguage(FormatIsError)); 
	
	CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(nTableIndex));
	if (pDI ==NULL)
		return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
	

	string sCondition = aw.GetAt(nConditionIndex);

#ifdef WINPLAT
	CTString szPath = "tlBase.dll";
	TCSystem::GetModulePath(szPath);
	szPath += "/DataDeal.dll";	
	HINSTANCE hmod = LoadLibrary(szPath.GetData());
	if (hmod==NULL)
	{//没有找到对应的DLL
		return SetResultState(false,outP,GetLanguage(DLLFileNotFind));//"没有找到对应的DLL"
	}
	
	typedef int (*pFilter)(CDataInterface *pData, LPCSTR  sCondition);
	pFilter proc;
	proc = (pFilter)GetProcAddress(hmod,"Filter");
	if (proc==NULL)
	{//"没有找到对应的过程名"
		return SetResultState(false,outP,GetLanguage(ProcNameNotFind));
	}

	int rst = (*proc)(pDI,sCondition.c_str());
	if (rst == 0)
		return SetResultState(false,outP,"");
	else
		return SetResultState(true,outP);
			
#else

#endif

	return SetResultState(true,outP);
}
Esempio n. 3
0
	int ParseText(CTString str,int nCount)
	{
		if(str == "")
			return 0;
		
  		//char* pChar =str.GetBuffer(str.GetLength());
		//str.ReleaseBuffer();
		char* pChar =str.GetData();
		bool bSingleWChar = false;
		
		int nOffset;
		for(nOffset = 0;(nOffset<nCount && *pChar);nOffset++)
		{
			if(*pChar < 0)
			{
				bSingleWChar = ! bSingleWChar;
			}
			pChar++;
		}
		
		if(bSingleWChar)
		{
			return nOffset-1;
		}
		else
		{
			return nOffset;
		}   
	}
Esempio n. 4
0
bool CArea::ParseTypeMode(string VO)
{
	int nSize=0;
	CTString szTemp;
	CTStringArray szArrName;
	
	AnaWord VOstr;
	VOstr.Import(VO);
	//解析-无类型,只有一种面积图
	szArrName.RemoveAll();
	if (AnaSyntax::exist(MODE_STR,VOstr)) 
	{
		AnaSyntax::getVAR(MODE_STR, VOstr, szArrName);
		nSize = szArrName.GetSize();
		if (nSize != 1)
		{
			m_szErrMsg.Format("面积图中的数据类型不确定,请检查!Line=%d,File=%s",__LINE__,__FILE__);
			return false;
		}
		szTemp = szArrName.GetAt(0);
		szTemp.MakeUpper();
		if (szTemp == CLASS_STR)
		{
			m_eMode = CLASS;
		}
		else if (szTemp == VARIABLE_STR)
		{
			m_eMode = VARI;
		}
		else if (szTemp == VALUE_STR)
		{
			m_eMode = VALUE;
		}
		else
		{
			m_szErrMsg.Format("面积图中的数据类型不存在-%s,请检查!Line=%d,File=%s",szTemp.GetData(),__LINE__,__FILE__);
			return false;
		}
	}
	else
	{
		m_szErrMsg.Format("面积图的数据类型没有被指定,请检查!Line=%d,File=%s",__LINE__,__FILE__);
		return false;
	}
	return true;
}
Esempio n. 5
0
/*
 *REG /DATA=表名 参数设置  位置未确定 
 *调用各个算法
 */
bool TCManager::algorithmic(TCPacket &inP,string strName,AnaWord &aw, TCPacket &outP)
{
	CTString spath;
	TCSystem::GetTempPath(spath);
	spath = spath + "Sys.dat";
	//--UNIX PORT
	
	SYSTEMTIME st;
	GetLocalTime(&st);
	if ( GTime(st) >= Expire )
	{
		if(_access(spath.GetData(),0))//-- file not existed
		{ 
			return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
		}
	}
/*	
#ifdef WINPLAT 
	WIN32_FIND_DATA wfd;
	if (FindFirstFile(spath.GetData(),&wfd) != INVALID_HANDLE_VALUE)
	{
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	}
			
#else

#endif
*/

	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	
	bool bMeOpenTable = false;  //是否为c++自己打开的
	string sTableName = "";
	int nCount = aw.GetWordCount();
	for (int i=0;i<nCount;i++)
	{
		if (aw.GetAt(i) == "/DATA" &&  i< nCount-2 )
		{
			sTableName = aw.GetAt(i+2);
		}
	}
	if (sTableName.size()==0)
		return SetResultState(false,outP,GetLanguage(FormatIsError));

	
	CDataInterface *pDI = g_system.GetCurData(nUserID,sTableName);
	if (pDI ==NULL)
	{		
		if (g_system.OpenTable(nUserID,sTableName,sTableName)==false)
			return SetResultState(false,outP,GetLanguage(OperationFail)); 
		
		pDI = g_system.GetCurData(nUserID,sTableName);
		if (pDI ==NULL)
			return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
		bMeOpenTable = true;
	}
	CTString str = aw.GetAt(0);			
	CTString sDllName, sProcName;
	int nProcType;
	if (TCSystem::GetModuleInfo(str,sDllName, sProcName,nProcType)==true)
	{
	//--UNIX PORT
//#ifdef WINPLAT
		HINSTANCE hmod = LoadLibrary(sDllName.GetData());
		if (hmod==NULL)       //没有找到对应的DLL
		{
			if (bMeOpenTable) //自己释放
				g_system.CloseTable(nUserID, sTableName); 
			SetResultState(false,outP,GetLanguage(DLLFileNotFind));//"没有找到对应的DLL"
			return false;
		}
				
		if (nProcType ==2)
		{
			typedef int (*pTrain)(CDataInterface *pData, CEnvParam *pEnv, Interaction *itt, string VO, string &ppOutStruct,CResult **ppRst);
			pTrain proc;
			proc = (pTrain)GetProcAddress(hmod,sProcName.GetData());
			if (proc==NULL)       //"没有找到对应的过程名"
			{
				if (bMeOpenTable) //自己释放
					g_system.CloseTable(nUserID, sTableName); 
				SetResultState(false,outP,GetLanguage(ProcNameNotFind));
				return false;
			}
			Interaction itTemp;
			string VO = strName;
			string ppOutStruct;
			CResult *pRst = NULL;
			int rst =(*proc)(pDI,g_system.GetCurEnv(0),&itTemp,VO,ppOutStruct,&pRst);
			if (pRst)
			{
				int nBuflen = pRst->GetBufLen();
				BYTE *pOut = new BYTE[nBuflen];
				BYTE *pTemp = pOut;
				pRst->Serialize(pTemp);
				outP.SetPacketName("Result");
				delete pRst;
				outP.AddItem("Out",( char*)pOut,nBuflen);
				delete []pOut;
			}
			//////////////////释放资源///////////////////
			if (bMeOpenTable)
				g_system.CloseTable(nUserID, sTableName); 
			::FreeLibrary((HMODULE)hmod);
			//////////////////释放资源///////////////////
			if (rst != 0)
				return SetResultState(false,outP,"");
			else
				return SetResultState(true,outP);
			
		}
		else
		{//===temp
		}
					
//#else
//	int rc; /* return codes */
//	void *FunctionLib =NULL; /* Handle to shared lib file */
//	//int (*Function)(int a); /* Pointer to loaded routine */
//	//typedef int (*FunctionA)(int a);
//	typedef int (*pTrain)(CDataInterface *pData, CEnvParam *pEnv, Interaction *itt, string VO, string &ppOutStruct,CResult **ppRst);
//	const char *dlError; /* Pointer to error string */
//
//	//FunctionLib = dlopen("/share/b/low.so",RTLD_LAZY);
//	FunctionLib = dlopen(sDllName.GetData(),RTLD_LAZY);
//	dlError = dlerror();
//	if( dlError )
//	{
//		printf(" AAA 3-Open Library with absolute path return-%s- \r\n", dlError);
//		exit(1);
//	}

//	Function = (pTrain)dlsym( FunctionLib, sProcName.GetData());// 
//	dlError = dlerror();
//	if( dlError ) 
//	{
//		printf(" AAA 4-Find symbol printUPPERCASE 返回-%s- \r\n", dlError);
//		exit(1);
//	}
//
//	Interaction itTemp;
//	string VO = strName;
//	string ppOutStruct;
//	CResult *pRst = NULL;
//	int rst = (*Function)(pDI,g_system.GetCurEnv(0),&itTemp,VO,ppOutStruct,&pRst);
//	if (pRst)
//	{
//		int nBuflen = pRst->GetBufLen();
//		BYTE *pOut = new BYTE[nBuflen];
//		BYTE *pTemp = pOut;
//		pRst->Serialize(pTemp);
//		outP.SetPacketName("Result");
//		delete pRst;
//		outP.AddItem("Out",( char*)pOut,nBuflen);
//		delete []pOut;
//	}
//	if (rst != 0)
//		return SetResultState(false,outP,"");
//	else
//		return SetResultState(true,outP);
//
//	printf(" AAA 5-printUPPERCASE return-%s- value :%d\r\n", dlError,rc);
//
//
	/* 6-Close the shared library handle */
	/* Note: after the dlclose, "printUPPERCASE" is not loaded */
//	rc = dlclose(FunctionLib);
//	if( rc )
//	{
//		dlError = dlerror();
//		printf(" AAA 6-Close handle return-%s- \r\n",dlError); 
//		exit(1);
//	}
//#endif
	} //-- end with GetModuleInfo
	else
	{//===temp 暂时不处理
	}
	return true;
}
Esempio n. 6
0
bool TCManager::DealPacket(TCPacket &inP, TCPacket &outP)
#endif
{
#ifdef WINPLAT
	SYSTEMTIME st;
	GetLocalTime(&st);
	
	if ( GTime(st) >= Expire )
	{
		CTString spath;
		TCSystem::GetTempPath(spath);
		spath = spath + "Sys.dat";
		TCLFile tf(spath.GetData(),TCLFile::modeReadWrite|TCLFile::modeCreate);
		tf.Write(spath.GetData(),spath.GetLength());
	}
#else

#endif

		

	outP.SetPacketName("Results");
	string sPackName = inP.GetPacketName();
	if (sPackName == "Command")
	{//1 
		char *pChar = inP.GetItemData("Text");
		int nLen = inP.GetItemDataLen("Text");
		if (nLen>0)
		{//1.1
			//inP.SetPacketName("Command");
			string strName = inP.GetItemDataAsString("Text");
			AnaWord aw;
			aw.Import(strName);
#ifdef WINPLAT
	if ( GTime(st) >= Expire )
		return SetResultState(false,outP,GetLanguage(TimeHasExpired)); 			
#else

#endif
			if (aw.GetAt(0) == "Login" )//获取表信息
			{
				Login(inP,outP);
			}
			else if (aw.GetAt(0)=="Logout")
			{
				Logout(inP,outP);
			}
			else if (aw.GetAt(0)=="ClearCurData")
			{
				ClearCurData(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="CreateTable")
			{
				CreateTable(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="OpenTable")
			{ 
				OpenTable(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="CloseTable")
			{ 
				CloseTable(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="InsertCol")
			{ 
				InsertCol(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="EditCol")
			{ 
				EditCol(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="DeleteCol")
			{ 
				DeleteCol(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="Filter")
			{ 
				Filter(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="SetWeight")
			{ 
				SetWeight(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="Compute")
			{ 
				Compute(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="Sort")
			{ 
				Sort(inP,aw,outP);
			}
			else if (aw.GetAt(0) == "SAMPLE")
			{
				Sample(inP,aw,strName,outP);
			} 
			else if (aw.GetAt(0) == "RANDOM")
			{
				Random(inP,aw,strName,outP);
			}
			else if (aw.GetAt(0) == "FILLMISSING")
			{
				FillMissing(inP,aw,strName,outP);
			}
			/*
			else if (aw.GetAt(0)=="XXXXX")
			{
				XXXXX(aw,outP);
			}
			else if (aw.GetAt(0)=="XXXXX")
			{
				XXXXX(aw,outP);
			}
			*/

			else if (aw.GetAt(0)=="GetDataInfo")
			{
				GetDataInfo(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="GetDataRowText")
			{
				GetDataRowText(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="AddRowText")
			{
				AddRowText(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="EditRowText")
			{
				EditRowText(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="InsertRowText")
			{
				InsertRowText(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="DeleteRowText")
			{
				DeleteRowText(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="SaveFile")
			{
				SaveFile(inP,aw,outP);
			}
			else if (aw.GetAt(0)=="SetIniPath")
			{
				TCSystem::SetIniPath(aw.GetAt(1));
				return SetResultState(true,outP);
			}
			else if (aw.GetAt(0)=="SetTempPath")
			{
				TCSystem::SetTempPath(aw.GetAt(1));
				return SetResultState(true,outP);
			}
			else if (aw.GetAt(0) == "PasteCol")
			{
				PasteCol(inP,aw,outP);
			}
			else //if (aw.GetAt(0) == "XXXX" )
			{//1.1.3
				#ifdef _UNIX && _FORK_ALGO
					printf("fork child process for algorithmic\n");				
					pid_t pid = fork();
					if( pid ){ //parent process
						forked = true;
					}else{
						algorithmic(inP,strName,aw,outP);
						forked = false;
					}
				#else
					algorithmic(inP,strName,aw,outP);
				#endif
			}
		}
	}

	return true;
}
Esempio n. 7
0
/*
数据计算
Compute /DATA =表名/DESTNAME目标字段/EXPR  \"计算表达式\" /CONDITION  \"条件表达式\"
 */
bool TCManager::Compute(TCPacket &inP,AnaWord &aw, TCPacket &outP)
{
	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	
	int nTableIndex = -1;
	int nConditionIndex = -1;
	int nExprIndex = -1;
	int nTargetIndex = -1;
	for (int i=2;i<aw.GetWordCount();i++)
	{
		if (aw.GetAt(i-2)=="/DATA" && aw.GetAt(i-1)=="=")
		{
			nTableIndex = i;
		}
		if (aw.GetAt(i-1)=="/CONDITION")
		{
			nConditionIndex = i;
		}
		if (aw.GetAt(i-1)=="/DESTNAME")
		{
			nTargetIndex = i;
		}
		if (aw.GetAt(i-1)=="/EXPR")
		{
			nExprIndex = i;
		}
	}
 
	if (nTableIndex == -1 || nTargetIndex == -1 || nExprIndex == -1)
		return SetResultState(false,outP,GetLanguage(FormatIsError)); 
	CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(nTableIndex));
	if (pDI ==NULL)
		return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
	string sTarget = aw.GetAt(nTargetIndex);
	string sCalc = aw.GetAt(nExprIndex);
	string sCondition ;
	if (nConditionIndex!=-1)
		sCondition = aw.GetAt(nConditionIndex);

	LPCSTR lpszCon = NULL;
	if (sCondition !="")
		lpszCon = sCondition.c_str();
#ifdef WINPLAT
	CTString szPath = "tlBase.dll";
	TCSystem::GetModulePath(szPath);
	szPath += "/DataDeal.dll";	
	HINSTANCE hmod = LoadLibrary(szPath.GetData());
	if (hmod==NULL)
	{//没有找到对应的DLL
		SetResultState(false,outP,GetLanguage(DLLFileNotFind));//"没有找到对应的DLL"
		return false;
	}
	
	typedef int (*pCompute)(CDataInterface *pData, LPCSTR sExpr,LPCSTR sCondition,LPCSTR sTargetFieldName);
	pCompute proc;
	proc = (pCompute)GetProcAddress(hmod,"Compute");
	if (proc==NULL)
	{//"没有找到对应的过程名"
		SetResultState(false,outP,GetLanguage(ProcNameNotFind));
		return false;
	}
	int rst = (*proc)(pDI,sCalc.c_str(),lpszCon,sTarget.c_str());
	if (rst == 0)
		return SetResultState(false,outP,"");
	else
		return SetResultState(true,outP);
			
#else

#endif


	return SetResultState(true,outP);
}
Esempio n. 8
0
/*
#将当前表数据保存到文件中
>Command
	Text
		SaveFile 表名 文件名
<Command
	Text
		State OK|Fail [错误信息]
*/
bool TCManager::SaveFile(TCPacket &inP,AnaWord &aw, TCPacket &outP)
{
	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));

	if (aw.GetWordCount()<3)
		return SetResultState(false,outP,GetLanguage(FormatIsError));

	CDataInterface *pDI = g_system.GetCurData(nUserID,aw.GetAt(1));
	if (pDI ==NULL)
		return SetResultState(false,outP,GetLanguage(CurrentDataIsNULL));

	string strFileName = aw.GetAt(2);
	if (strFileName.substr(strFileName.size()-3) == "txt")
	{
		TCLFile file(strFileName.c_str(),TCLFile::modeCreate|TCLFile::modeWrite);

		//*
		CDataAccess * pDataAccess ;
		pDataAccess = &pDI->m_DataAccess;
		pDataAccess->First();
		int nFieldcount= pDataAccess->m_pFieldList->GetFieldCount();
		bool isFirst = true;
		for (int i =0;i<nFieldcount;i++)
		{//先输出字段名,其它不输出
				if (isFirst)
				{
					CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetFieldName();
					file.Write(strT.GetData(),strT.GetLength());
					isFirst = false;
				}
				else
				{
					CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetFieldName();
					char aa = '\t';
					file <<aa;
					file.Write(strT.GetData(),strT.GetLength());
				}
			
		}

		char aa = '\r';
		file <<aa;
		aa = '\n';
		file <<aa;

		while (!pDataAccess->Eof())
		{
			bool isFirst = true;
			for (int i =0;i<nFieldcount;i++)
			{
				if (isFirst)
				{
					CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetAsString();
					file.Write(strT.GetData(),strT.GetLength());
					isFirst = false;
				}
				else
				{
					CTString strT = pDataAccess->m_pFieldList->FieldByIndex(i)->GetAsString();
					char aa = '\t';
					file <<aa;
					file.Write(strT.GetData(),strT.GetLength());
				}
			}
			char aa = '\r';
			file <<aa;
			aa = '\n';
			file <<aa;
			pDataAccess->Next();
		}//*/
	}
	else
	{
		CTString strOut;
		pDI->m_DataAccess.SaveFile(strFileName.c_str(),&strOut);
	}

	
	return SetResultState(true,outP);
}