private void writeResToDb() { //Console.WriteLine(string.Format("merge outcome..., init num : {0}", this.GridStrengths.Count)); //Console.ReadKey(); DateTime d1, d2; d1 = DateTime.Now; CalcGridStrength calc = new CalcGridStrength(this.cellInfo, null); this.GridStrengths = calc.MergeMultipleTaskStrength(this.MultiTasksGridStrengths); d2 = DateTime.Now; Console.WriteLine(string.Format("merge done. now num : {0}, using time: {1}ms", this.GridStrengths.Count, (d2 - d1).TotalMilliseconds)); // 2017.6.14 Console.WriteLine(); Console.WriteLine("射线所能达到的最远地面距离: {0} m,该点功率:{1} dbm", calc.maxDistGround, calc.dbm); Console.WriteLine("小区平面坐标:({0}, {1})", calc.cellInfo.SourcePoint.X, calc.cellInfo.SourcePoint.Y); Console.WriteLine("射线所能达到的最远地面坐标:({0}, {1})", calc.gx, calc.gy); Console.WriteLine("覆盖栅格总数: {0}", this.GridStrengths.Count); Console.WriteLine(); //Console.WriteLine("connection = " + DB.DataUtil.ConnectionString); Console.WriteLine("writing to database ..."); GridCover gc = GridCover.getInstance(); gc.convertToDt(this.GridStrengths); this.GridStrengths.Clear(); Hashtable ht = new Hashtable(); ht["eNodeB"] = this.cellInfo.eNodeB; ht["CI"] = this.cellInfo.CI; //gc.deleteGroundCover(ht); gc.wirteGroundCover(ht); gc.clearGround(); //if (this.computeIndoor) { //gc.deleteBuildingCover(ht); gc.writeBuildingCover(ht); gc.clearBuilding(); } Console.WriteLine("地面栅格总数: {0}", gc.ng); Console.WriteLine("立体栅格总数: {0}", gc.nb); end = DateTime.Now; string info = string.Format("总运行时间:{0}毫秒\n", (end - start).TotalMilliseconds); Console.WriteLine(info); Console.WriteLine("write done"); RedisMq.Pub("cover2db_finish", this.cellInfo.eNodeB); //this.GridStrengths.Clear(); //Console.ReadKey(); // 2019.04.12 this.cs.free(); this.Close(); // 2019.04.12 //this.procDoneNum = 0; }
// getTb:读数据库的sql // flag:false--操作tbGridPathloss, true--操作tbBuildingGridPathloss // 只有半径比较大的时候才会用到,因为一次算不完 private void mergePwr1(double EIRP, string getTb, bool flag, int eNodeB, int CI) { Hashtable ht = new Hashtable(); ht["CI"] = CI; ht["eNodeB"] = eNodeB; DataTable tb = IbatisHelper.ExecuteQueryForDataTable(getTb, ht); GridCover gc = GridCover.getInstance(); if (flag) { gc.deleteBuildingCover(ht); } else { gc.deleteGroundCover(ht); } Dictionary <string, GridStrength> gridStrengths = new Dictionary <string, GridStrength>(); foreach (DataRow dataRow in tb.Rows) { #region 读入数据,按栅格分组,合并 int GXID = int.Parse(dataRow["GXID"].ToString()); int GYID = int.Parse(dataRow["GYID"].ToString()); int GZID = 0; if (flag) { GZID = int.Parse(dataRow["Level"].ToString()); } string key = String.Format("{0},{1},{2}", GXID, GYID, GZID); if (!gridStrengths.ContainsKey(key)) { GridStrength gs = new GridStrength(); gs.GXID = GXID; gs.GYID = GYID; gs.Level = GZID; gs.eNodeB = int.Parse(dataRow["eNodeB"].ToString()); gs.CI = int.Parse(dataRow["CI"].ToString()); if (dataRow["FieldIntensity"].ToString() != "") { gs.FieldIntensity = double.Parse(dataRow["FieldIntensity"].ToString()); } gs.DirectNum = int.Parse(dataRow["DirectPwrNum"].ToString()); gs.DirectPwrW = double.Parse(dataRow["DirectPwrW"].ToString()); gs.MaxDirectPwrW = double.Parse(dataRow["MaxDirectPwrW"].ToString()); gs.RefNum = int.Parse(dataRow["RefPwrNum"].ToString()); gs.RefPwrW = double.Parse(dataRow["RefPwrW"].ToString()); gs.MaxRefPwrW = double.Parse(dataRow["MaxRefPwrW"].ToString()); gs.RefBuildingID = dataRow["RefBuildingID"].ToString(); gs.DiffNum = int.Parse(dataRow["DiffNum"].ToString()); gs.DiffPwrW = double.Parse(dataRow["DiffPwrW"].ToString()); gs.MaxDiffPwrW = double.Parse(dataRow["MaxDiffPwrW"].ToString()); gs.DiffBuildingID = dataRow["DiffBuildingID"].ToString(); gs.BTSGridDistance = double.Parse(dataRow["BTSGridDistance"].ToString()); //gs.ReceivedPowerW = double.Parse(dataRow["ReceivedPowerW"].ToString()); //gs.ReceivedPowerdbm = double.Parse(dataRow["ReceivedPowerdbm"].ToString()); //gs.PathLoss = double.Parse(dataRow["PathLoss"].ToString()); if (flag) { gs.TransNum = int.Parse(dataRow["TransNum"].ToString()); gs.TransPwrW = double.Parse(dataRow["TransPwrW"].ToString()); gs.MaxTransPwrW = double.Parse(dataRow["MaxTransPwrW"].ToString()); gs.TransmitBuildingID = dataRow["TransmitBuildingID"].ToString(); } else { gs.TransNum = 0; gs.TransPwrW = 0; gs.MaxTransPwrW = 0; gs.TransmitBuildingID = ""; } gridStrengths.Add(key, gs); } else { GridStrength ogs = gridStrengths[key]; ogs.DirectNum += int.Parse(dataRow["DirectPwrNum"].ToString()); double pwr = double.Parse(dataRow["DirectPwrW"].ToString()); ogs.DirectPwrW += double.Parse(dataRow["DirectPwrW"].ToString()); if (ogs.MaxDirectPwrW < double.Parse(dataRow["MaxDirectPwrW"].ToString())) { ogs.MaxDirectPwrW = double.Parse(dataRow["MaxDirectPwrW"].ToString()); } ogs.RefBuildingID += dataRow["RefBuildingID"].ToString(); ogs.RefNum += int.Parse(dataRow["RefPwrNum"].ToString()); ogs.RefPwrW += double.Parse(dataRow["RefPwrW"].ToString()); if (ogs.MaxRefPwrW < double.Parse(dataRow["MaxRefPwrW"].ToString())) { ogs.MaxRefPwrW = double.Parse(dataRow["MaxRefPwrW"].ToString()); } ogs.DiffNum += int.Parse(dataRow["DiffNum"].ToString()); ogs.DiffPwrW += double.Parse(dataRow["DiffPwrW"].ToString()); ogs.DiffBuildingID += dataRow["DiffBuildingID"].ToString(); if (ogs.MaxDiffPwrW < double.Parse(dataRow["MaxDiffPwrW"].ToString())) { ogs.MaxDiffPwrW = double.Parse(dataRow["MaxDiffPwrW"].ToString()); } if (flag) { ogs.TransNum += int.Parse(dataRow["TransNum"].ToString()); ogs.TransPwrW += double.Parse(dataRow["TransPwrW"].ToString()); ogs.TransmitBuildingID += dataRow["TransmitBuildingID"].ToString(); if (ogs.MaxTransPwrW < double.Parse(dataRow["MaxTransPwrW"].ToString())) { ogs.MaxTransPwrW = double.Parse(dataRow["MaxTransPwrW"].ToString()); } } //dictionary不能自动更新 gridStrengths[key] = ogs; } #endregion if (gridStrengths.Count > 30000) { # region 计算栅格最终功率 foreach (var k in gridStrengths.Keys.ToArray()) { GridStrength ogs = gridStrengths[k]; double p = ogs.DirectPwrW + ogs.DiffPwrW + ogs.RefPwrW + ogs.TransPwrW; if (p > 0) { ogs.ReceivedPowerW = p; } ogs.ReceivedPowerdbm = convertw2dbm(ogs.ReceivedPowerW); ogs.PathLoss = EIRP - ogs.ReceivedPowerdbm; //反射、绕射建筑物id去重 ogs.RefBuildingID = DistinctStringArray(ogs.RefBuildingID.Split(';')); ogs.DiffBuildingID = DistinctStringArray(ogs.DiffBuildingID.Split(';')); ogs.TransmitBuildingID = DistinctStringArray(ogs.TransmitBuildingID.Split(';')); //dictionary 不能自动更新 gridStrengths[k] = ogs; } #endregion #region 写入数据库 gc.convertToDt(gridStrengths); if (flag) { gc.writeBuildingCover(ht); gc.clearBuilding(); } else { gc.wirteGroundCover(ht); gc.clearGround(); } #endregion gridStrengths.Clear(); } }