Example #1
0
        private void ByGridFasion(StreamWriter wr1, StreamWriter wr2, StreamWriter wr3, IRepository<DataAccess.DFOdata> dfoDataRepository)
        {
            Console.Write("Processing ..\n");
            var rectArea = GetRectArea(dfoDataRepository);
            var selectedPointsStr = "";
            var cellCenterStr = "";
            var nanCellStr = "";
            var insertStatement = "Insert into dbo.Cells(X,Y,U,V) ";
            var totalCell = 0;
            var startTime = DateTime.Now;
            double distanceBetween2AdjacentCellCenterPoint = 2 * HalfOfEachCellArea;

            for (double y = rectArea.MaxY, i = 0.0; y >= rectArea.MinY; y = y - distanceBetween2AdjacentCellCenterPoint, i ++)
            {
                for (double x = rectArea.MinX, j = 0.0; x <= rectArea.MaxX; x = x + distanceBetween2AdjacentCellCenterPoint, j ++)
                {
                    var adjacentCell = new GridCell(x,y);
                    var sqlQuery = string.Format("Select * from DFOdata where X >= {0} and X <= {1} and Y >= {2} and Y <= {3}",
                                                 adjacentCell.X - HalfOfEachCellArea,
                                                 adjacentCell.X + HalfOfEachCellArea,
                                                 adjacentCell.Y - HalfOfEachCellArea,
                                                 adjacentCell.Y + HalfOfEachCellArea);
                    var dfoDataPoints = dfoDataRepository.ExecuteCommand<DataAccess.DFOdata>(sqlQuery);
                    var uCompSum = 0.0;
                    var vCompSum = 0.0;

                    foreach (var dfoDataPoint in dfoDataPoints)
                    {
                        selectedPointsStr += string.Format("{0},{1},{2},{3}\n", dfoDataPoint.X, dfoDataPoint.Y, dfoDataPoint.U, dfoDataPoint.V);
                        wr1.WriteLine("{0},{1},{2},{3}", dfoDataPoint.X, dfoDataPoint.Y, dfoDataPoint.U, dfoDataPoint.V);
                        uCompSum += dfoDataPoint.U;
                        vCompSum += dfoDataPoint.V;
                    }
                    var totalDataPoint = dfoDataPoints.Count;
                    double uComp = uCompSum / totalDataPoint;
                    double vComp = vCompSum / totalDataPoint;
                    if (!Double.IsNaN(uComp) && !Double.IsNaN(vComp))
                    {
                        cellCenterStr += string.Format("{0},{1},{2},{3}\n", adjacentCell.X, adjacentCell.Y, uComp, vComp);
                        var cellX = Convert.ToInt32(i);
                        var cellY = Convert.ToInt32(j);

                        if (totalCell == 0)
                            insertStatement += string.Format("SELECT {0}, {1}, {2}, {3}", cellY , cellX, uComp, vComp);
                        else
                            insertStatement += string.Format("UNION ALL SELECT {0}, {1}, {2}, {3}", cellY, cellX, uComp, vComp);
                        totalCell++;
                        Console.Write(string.Format("{0} {1}\n", i, j));
                    }
                    else
                    {
                        nanCellStr += string.Format("{0},{1},{2},{3}\n", adjacentCell.X, adjacentCell.Y, uComp, vComp);
                    }
                    //Console.Write("Total {0} poins for cell {1},{2}.\n", totalDataPoint, adjacentCell.X, adjacentCell.Y);

                }
                //if(Convert.ToInt32(i) == 1)
                //{
                //    break;
                //}

            }

            //dfoDataRepository.ExecuteCommandDirectly(insertStatement);

            wr1.Write(selectedPointsStr);
            wr2.Write(cellCenterStr);
            wr3.Write(nanCellStr);

            var currentTime = DateTime.Now;
            var diff = currentTime.Subtract(startTime).TotalSeconds;
            Console.Write("Done..\n Timing: {0}",diff);
        }
Example #2
0
 private void BySpiralFasion(StreamWriter wr1, StreamWriter wr2, IRepository<DataAccess.DFOdata> dfoDataRepository)
 {
     var fixedCenterCell = new GridCell(0.0, 0.0);
     for (int nLayer = 1; nLayer <= 55; nLayer++)
     {
         var adjacentCells = GetNthSurroundingCellsFromCenterCell(fixedCenterCell, nLayer);
         foreach (var adjacentCell in adjacentCells)
         {
             Console.WriteLine(string.Format("{0},{1}", adjacentCell.X, adjacentCell.Y));
         }
         Console.Write(string.Format("Toal adjacent: {0}\n", adjacentCells.Count));
         foreach (var adjacentCell in adjacentCells)
         {
             var sqlQuery = string.Format("Select * from DFOdata where X >= {0} and X <= {1} and Y >= {2} and Y <= {3}",
                                          adjacentCell.X - HalfOfEachCellArea,
                                          adjacentCell.X + HalfOfEachCellArea,
                                          adjacentCell.Y - HalfOfEachCellArea,
                                          adjacentCell.Y + HalfOfEachCellArea);
             var dfoDataPoints = dfoDataRepository.ExecuteCommand<DataAccess.DFOdata>(sqlQuery);
             var uCompSum = 0.0;
             var vCompSum = 0.0;
             foreach (var dfoDataPoint in dfoDataPoints)
             {
                 wr1.WriteLine("{0},{1},{2},{3}", dfoDataPoint.X, dfoDataPoint.Y, dfoDataPoint.U, dfoDataPoint.V);
                 uCompSum += dfoDataPoint.U;
                 vCompSum += dfoDataPoint.V;
             }
             var totalDataPoint = dfoDataPoints.Count;
             double uComp = uCompSum / totalDataPoint;
             double vComp = vCompSum / totalDataPoint;
             //if (!Double.IsNaN(uComp) && !Double.IsNaN(vComp))
             //{
             wr2.WriteLine("{0},{1},{2},{3}", adjacentCell.X, adjacentCell.Y, uComp, vComp);
             //}
             //Console.Write("Total {0} poins for cell {1},{2}.\n", totalDataPoint, adjacentCell.X, adjacentCell.Y);
         }
         Console.WriteLine("--------------------\n");
     }
 }
Example #3
0
 public RectArea GetRectArea(IRepository<DataAccess.DFOdata> dfoDataRepository)
 {
     const string sqlQuery = "select max(X) as MaxX, min(X) as MinX, max(Y) as MaxY, min(Y) as MinY from dbo.DFOdata";
     var rectArea = dfoDataRepository.ExecuteCommand<RectArea>(sqlQuery);
     if (rectArea == null)
         throw new Exception("Can't get the rect area !!");
     return rectArea.ElementAt(0);
 }