researchman 7 years ago
parent
commit
a8d38a57dd
1 changed files with 269 additions and 269 deletions
  1. 269 269
      classdef.cpp

+ 269 - 269
classdef.cpp

@@ -3833,275 +3833,275 @@ int Card::PersonLocation(int cnt)
 //	return ret;
 //}
 
-////拟合度实现方案
-//int Card::DiscreteLocate(int cnt)
-//{
-//	int ret = 0;
-//	std::shared_ptr<Cell> cell = nullptr;
-//	std::shared_ptr<Cell> tmp_cell = std::make_shared<Cell>();
-//	is_fit_pos = false;
-//	std::shared_ptr<POS> pos = nullptr;
-//
-//	//1.数据有效性判断
-//	ret = CheckDistData(cnt);
-//	if(ret){
-//		return 1;
-//	}else{
-//		//2.组装数据
-//		std::shared_ptr<ReceiveDataMap> pRdm = std::make_shared<ReceiveDataMap>();
-//		pRdm->clear();
-//		ret = AssembleDistData(pRdm);
-//		if(ret){
-//			return 1;
-//		}else{
-//			if (pRdm->size() <= 0)
-//			{
-//				return 1;
-//			}
-//
-//			pos = std::make_shared<POS>();
-//			//3.算法定位	
-//			std::vector<std::shared_ptr<POS>> udm_pos;
-//			udm_pos.resize(0);
-//			ret = LocateAlgorithm::CalcTdoaPosition(pRdm,pTdoaReaderPathMap,udm_pos);
-//			//4.从多解中筛选出一个解,存在两种可能:
-//			//a.可能无解返回非0,
-//			//b.可能有解,但解不正确,比如解的位置在4727,-100,但选出的解是4727,-200
-//			ret = ChooseOneSolution(pRdm, udm_pos, pos);
-//			SaveOriginDataBeforeFilter(pos);
-//			if (ret)
-//			{
-//				return 1;
-//			}
-//
-//			bool bRet = false;
-//			bRet = LocateAlgorithm::IsOnMap(pos,pTdoaReaderPathMap);
-//			if (!bRet)
-//			{
-//				return 1;
-//			}
-//			if (card_id == "0020000001023" && time_stamp_cal == 12885)
-//			{
-//				int aa = 1;
-//				aa = his_cell.size();
-//			}
-//			if (ret)
-//			{
-//				if (his_cell.size() < 5)
-//				{
-//					return 1;
-//				}
-//				//如果从多解中未选出解,则按上一次格子的步进匀速运动
-//				int nStep = 1;
-//				if (last_cell->nStep > 1)
-//				{
-//					nStep = last_cell->nStep;
-//				}
-//				std::shared_ptr<Cell> cell = GetNextCell(last_cell,nIncrease,nStep,nullptr);
-//				if (cell)
-//				{
-//					cell->originId = cell->id;
-//				}
-//			}else{
-//				std::shared_ptr<POS> tmp_pos = std::make_shared<POS>();
-//				//获取分站信息
-//				bool bRet = false;
-//				*tmp_pos = *pos;
-//
-//				if (ret == 0)
-//				{	
-//					//将坐标转为格子信息
-//					cell = Position2Cell(tmp_pos);
-//					if (cell)
-//					{
-//						originCellId = cell->id;
-//						originCellReaderName = cell->strSubjectReader;
-//						cell->card_stamp_time = time_stamp_cal;
-//						cell->originId = cell->id;
-//						cell->strOriginReaderName = cell->strSubjectReader;
-//						nStartLocateCounts++;
-//
-//						if (lvCells.size() >= MAX_FIT_DATA_COUNTS)
-//						{
-//							lvCells.pop_front();
-//						}
-//						lvCells.push_back(cell);
-//
-//						if (!is_algo_first_location)
-//						{
-//							double degree = 0;
-//							degree = GetFittingDegree(lvCells);
-//
-//							bool bOverThre = false;
-//							bool isDirectOutput = false;	//是否直接输出数据
-//
-//							if (degree - 0.9 > ZERO_PRECISION)
-//							{
-//								bOverThre = false;
-//								isDirectOutput = true;
-//								pos->update = true;
-//							} else if ((degree - 0.7) > ZERO_PRECISION && (0.9 - degree) > ZERO_PRECISION)
-//							{
-//								//向前大跳
-//								bOverThre = true;
-//								lvCells.pop_back();
-//							}else if ((degree - 0.5) > ZERO_PRECISION &&(0.7 - degree) > ZERO_PRECISION)
-//							{
-//								bOverThre = false;
-//							}
-//							else if(0.5 - degree > ZERO_PRECISION)
-//							{
-//								//向后大跳
-//								bOverThre = true;
-//								lvCells.pop_back();
-//							}
-//
-//							if (!isDirectOutput)
-//							{
-//								if (bOverThre)
-//								{
-//									//根据之前的拟合方程k,b进行补格子
-//									int tmpOriginId = 0;
-//									std::string tmpOriginReaderName = "";
-//									tmpOriginId = cell->originId;
-//									tmpOriginReaderName = cell->strOriginReaderName;
-//
-//									//根据上一次数据计算格子数,并根据上一次方向进行偏移
-//									double y = 0;
-//									std::list<std::shared_ptr<Cell>>::iterator it = lvCells.begin();
-//
-//									y = fit_k*(this->time_stamp_cal - (*it)->card_stamp_time + 1) + fit_b;
-//
-//									int nCellId  = 0 ;
-//									std::string strReaderName = "";
-//									//判断两次格子的id是否在相同分站内,不在走跨分站逻辑
-//									if ((*it)->strOriginReaderName != cell->strOriginReaderName)
-//									{
-//										int nRealId = 0;
-//										nCellId = LocateAlgorithm::round(y);
-//										//换基站了
-//										int first_min = (*it)->minReaderId;		//first_cell_temp对应的最小分站
-//										int first_max = (*it)->maxReaderId;		//first_cell_temp对应的最大分站
-//										int cell_min = cell->minReaderId;		//cell对应的最小分站
-//										int cell_max = cell->maxReaderId;		//cell对应的最大分站
-//
-//										if(first_min == cell_min){	
-//											if (nCellId == 0)
-//											{
-//												nRealId = 1;
-//												strReaderName = cell->strSubjectReader;
-//											}else if(nCellId > 0){
-//												nRealId = nCellId;
-//												strReaderName = (*it)->strSubjectReader;
-//											}else if(nCellId < 0){
-//												nRealId = abs(nCellId);
-//												strReaderName = cell->strSubjectReader;
-//											}
-//										}
-//										if(first_min == cell_max){	
-//											if (nCellId == 0)
-//											{
-//												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size();
-//												strReaderName = cell->strSubjectReader;
-//											}else if(nCellId > 0){
-//												nRealId = nCellId;
-//												strReaderName = (*it)->strSubjectReader;
-//											}else if(nCellId < 0){
-//												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size() - abs(nCellId);
-//												strReaderName = cell->strSubjectReader;
-//											}
-//										}
-//										if(first_max == cell_min){	
-//											//只存在nCellId>0的情况,但还要区分它是否大于所在分站的总格子数
-//											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
-//											{
-//												nRealId = nCellId - mpCellPath->find(cell->strSubjectReader)->second.size();
-//												if (nRealId == 0)
-//												{
-//													nRealId = 1;
-//												}
-//												strReaderName = cell->strSubjectReader;
-//											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
-//												nRealId = nCellId;
-//												strReaderName = (*it)->strSubjectReader;
-//											}
-//										}
-//										if(first_max == cell_max){
-//											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
-//											{
-//												nRealId = mpCellPath->find(cell->strOriginReaderName)->second.size() - (nCellId - mpCellPath->find((*it)->strSubjectReader)->second.size());
-//												strReaderName = cell->strOriginReaderName;
-//											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
-//												nRealId = nCellId;
-//												strReaderName = (*it)->strSubjectReader;
-//											}
-//										}
-//										nCellId = nRealId;
-//									}else{
-//										nCellId = LocateAlgorithm::round(y);
-//										strReaderName = cell->strOriginReaderName;
-//									}
-//									//将新格子的信息除了格子id信息
-//									cell = FindCell(strReaderName,nCellId);
-//									if (cell)
-//									{
-//										cell->originId = tmpOriginId;
-//										cell->strOriginReaderName = tmpOriginReaderName;
-//									}
-//								} 
-//								else
-//								{
-//									colourfulCloudsChasingTheMoon(cell,his_cell);
-//								}
-//							}else{
-//								//直接输出数据需要放入拟合队列中
-//								colourfulCloudsChasingTheMoon(cell,his_cell);
-//							}
-//						}else{
-//							//如果是第一次定位结果,调用以下函数将cell放入到his_cell队列中
-//							if (his_cell.size() > 0)
-//							{
-//								his_cell.erase(his_cell.begin(),his_cell.end());
-//								fit_k = fit_b = 0;
-//							}
-//							colourfulCloudsChasingTheMoon(cell,his_cell);
-//						}
-//					}else{
-//						originCellId = 0;
-//						originCellReaderName = "";
-//					}
-//				}
-//			}
-//		}
-//	}
-//
-//	if (cell)
-//	{
-//		//做加速度处理
-//		double dAcce = 0;
-//		bool bRet = false;
-//		if (abs(fit_k - last_k) < ZERO_PRECISION)
-//		{
-//			bRet = true;
-//		}else{
-//			dAcce = abs((fit_k - last_k)/(delta_ct))*1.2;
-//			if (dAcce > 10)
-//			{
-//				bRet = false;
-//			}else{
-//				bRet = true;
-//			}
-//		}
-//
-//		if (bRet)
-//		{
-//			SaveCardAlgoData(cell);
-//		}
-//		//SaveCardAlgoData(cell);
-//	}	
-//
-//	return ret;
-//}
+//拟合度实现方案
+int Card::DiscreteLocate(int cnt)
+{
+	int ret = 0;
+	std::shared_ptr<Cell> cell = nullptr;
+	std::shared_ptr<Cell> tmp_cell = std::make_shared<Cell>();
+	is_fit_pos = false;
+	std::shared_ptr<POS> pos = nullptr;
+
+	//1.数据有效性判断
+	ret = CheckDistData(cnt);
+	if(ret){
+		return 1;
+	}else{
+		//2.组装数据
+		std::shared_ptr<ReceiveDataMap> pRdm = std::make_shared<ReceiveDataMap>();
+		pRdm->clear();
+		ret = AssembleDistData(pRdm);
+		if(ret){
+			return 1;
+		}else{
+			if (pRdm->size() <= 0)
+			{
+				return 1;
+			}
+
+			pos = std::make_shared<POS>();
+			//3.算法定位	
+			std::vector<std::shared_ptr<POS>> udm_pos;
+			udm_pos.resize(0);
+			ret = LocateAlgorithm::CalcTdoaPosition(pRdm,pTdoaReaderPathMap,udm_pos);
+			//4.从多解中筛选出一个解,存在两种可能:
+			//a.可能无解返回非0,
+			//b.可能有解,但解不正确,比如解的位置在4727,-100,但选出的解是4727,-200
+			ret = ChooseOneSolution(pRdm, udm_pos, pos);
+			SaveOriginDataBeforeFilter(pos);
+			if (ret)
+			{
+				return 1;
+			}
+
+			bool bRet = false;
+			bRet = LocateAlgorithm::IsOnMap(pos,pTdoaReaderPathMap);
+			if (!bRet)
+			{
+				return 1;
+			}
+			if (card_id == "0020000001023" && time_stamp_cal == 12885)
+			{
+				int aa = 1;
+				aa = his_cell.size();
+			}
+			if (ret)
+			{
+				if (his_cell.size() < 5)
+				{
+					return 1;
+				}
+				//如果从多解中未选出解,则按上一次格子的步进匀速运动
+				int nStep = 1;
+				if (last_cell->nStep > 1)
+				{
+					nStep = last_cell->nStep;
+				}
+				std::shared_ptr<Cell> cell = GetNextCell(last_cell,nIncrease,nStep,nullptr);
+				if (cell)
+				{
+					cell->originId = cell->id;
+				}
+			}else{
+				std::shared_ptr<POS> tmp_pos = std::make_shared<POS>();
+				//获取分站信息
+				bool bRet = false;
+				*tmp_pos = *pos;
+
+				if (ret == 0)
+				{	
+					//将坐标转为格子信息
+					cell = Position2Cell(tmp_pos);
+					if (cell)
+					{
+						originCellId = cell->id;
+						originCellReaderName = cell->strSubjectReader;
+						cell->card_stamp_time = time_stamp_cal;
+						cell->originId = cell->id;
+						cell->strOriginReaderName = cell->strSubjectReader;
+						nStartLocateCounts++;
+
+						if (lvCells.size() >= MAX_FIT_DATA_COUNTS)
+						{
+							lvCells.pop_front();
+						}
+						lvCells.push_back(cell);
+
+						if (!is_algo_first_location)
+						{
+							double degree = 0;
+							degree = GetFittingDegree(lvCells);
+
+							bool bOverThre = false;
+							bool isDirectOutput = false;	//是否直接输出数据
+
+							if (degree - 0.9 > ZERO_PRECISION)
+							{
+								bOverThre = false;
+								isDirectOutput = true;
+								pos->update = true;
+							} else if ((degree - 0.7) > ZERO_PRECISION && (0.9 - degree) > ZERO_PRECISION)
+							{
+								//向前大跳
+								bOverThre = true;
+								lvCells.pop_back();
+							}else if ((degree - 0.5) > ZERO_PRECISION &&(0.7 - degree) > ZERO_PRECISION)
+							{
+								bOverThre = false;
+							}
+							else if(0.5 - degree > ZERO_PRECISION)
+							{
+								//向后大跳
+								bOverThre = true;
+								lvCells.pop_back();
+							}
+
+							if (!isDirectOutput)
+							{
+								if (bOverThre)
+								{
+									//根据之前的拟合方程k,b进行补格子
+									int tmpOriginId = 0;
+									std::string tmpOriginReaderName = "";
+									tmpOriginId = cell->originId;
+									tmpOriginReaderName = cell->strOriginReaderName;
+
+									//根据上一次数据计算格子数,并根据上一次方向进行偏移
+									double y = 0;
+									std::list<std::shared_ptr<Cell>>::iterator it = lvCells.begin();
+
+									y = fit_k*(this->time_stamp_cal - (*it)->card_stamp_time + 1) + fit_b;
+
+									int nCellId  = 0 ;
+									std::string strReaderName = "";
+									//判断两次格子的id是否在相同分站内,不在走跨分站逻辑
+									if ((*it)->strOriginReaderName != cell->strOriginReaderName)
+									{
+										int nRealId = 0;
+										nCellId = LocateAlgorithm::round(y);
+										//换基站了
+										int first_min = (*it)->minReaderId;		//first_cell_temp对应的最小分站
+										int first_max = (*it)->maxReaderId;		//first_cell_temp对应的最大分站
+										int cell_min = cell->minReaderId;		//cell对应的最小分站
+										int cell_max = cell->maxReaderId;		//cell对应的最大分站
+
+										if(first_min == cell_min){	
+											if (nCellId == 0)
+											{
+												nRealId = 1;
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId > 0){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}else if(nCellId < 0){
+												nRealId = abs(nCellId);
+												strReaderName = cell->strSubjectReader;
+											}
+										}
+										if(first_min == cell_max){	
+											if (nCellId == 0)
+											{
+												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size();
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId > 0){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}else if(nCellId < 0){
+												nRealId = mpCellPath->find(cell->strSubjectReader)->second.size() - abs(nCellId);
+												strReaderName = cell->strSubjectReader;
+											}
+										}
+										if(first_max == cell_min){	
+											//只存在nCellId>0的情况,但还要区分它是否大于所在分站的总格子数
+											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
+											{
+												nRealId = nCellId - mpCellPath->find(cell->strSubjectReader)->second.size();
+												if (nRealId == 0)
+												{
+													nRealId = 1;
+												}
+												strReaderName = cell->strSubjectReader;
+											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}
+										}
+										if(first_max == cell_max){
+											if (nCellId >= mpCellPath->find((*it)->strSubjectReader)->second.size())
+											{
+												nRealId = mpCellPath->find(cell->strOriginReaderName)->second.size() - (nCellId - mpCellPath->find((*it)->strSubjectReader)->second.size());
+												strReaderName = cell->strOriginReaderName;
+											}else if(nCellId < mpCellPath->find((*it)->strSubjectReader)->second.size()){
+												nRealId = nCellId;
+												strReaderName = (*it)->strSubjectReader;
+											}
+										}
+										nCellId = nRealId;
+									}else{
+										nCellId = LocateAlgorithm::round(y);
+										strReaderName = cell->strOriginReaderName;
+									}
+									//将新格子的信息除了格子id信息
+									cell = FindCell(strReaderName,nCellId);
+									if (cell)
+									{
+										cell->originId = tmpOriginId;
+										cell->strOriginReaderName = tmpOriginReaderName;
+									}
+								} 
+								else
+								{
+									colourfulCloudsChasingTheMoon(cell,his_cell);
+								}
+							}else{
+								//直接输出数据需要放入拟合队列中
+								colourfulCloudsChasingTheMoon(cell,his_cell);
+							}
+						}else{
+							//如果是第一次定位结果,调用以下函数将cell放入到his_cell队列中
+							if (his_cell.size() > 0)
+							{
+								his_cell.erase(his_cell.begin(),his_cell.end());
+								fit_k = fit_b = 0;
+							}
+							colourfulCloudsChasingTheMoon(cell,his_cell);
+						}
+					}else{
+						originCellId = 0;
+						originCellReaderName = "";
+					}
+				}
+			}
+		}
+	}
+
+	if (cell)
+	{
+		//做加速度处理
+		double dAcce = 0;
+		bool bRet = false;
+		if (abs(fit_k - last_k) < ZERO_PRECISION)
+		{
+			bRet = true;
+		}else{
+			dAcce = abs((fit_k - last_k)/(delta_ct))*1.2;
+			if (dAcce > 10)
+			{
+				bRet = false;
+			}else{
+				bRet = true;
+			}
+		}
+
+		if (bRet)
+		{
+			SaveCardAlgoData(cell);
+		}
+		//SaveCardAlgoData(cell);
+	}	
+
+	return ret;
+}
 
 //只有通过加速度判断丢失数据部分
 int Card::DiscreteLocate(int cnt)