コード例 #1
0
        public void InsertRouteGap(VerticalCurve previousCurve, VerticalCurve currentCurve)
        {
            var toInsert = new VerticalCurve()
            {
                ROUTE      = currentCurve.ROUTE,
                FROMMEAS   = previousCurve.TOMEAS,
                TOMEAS     = currentCurve.FROMMEAS,
                DISTANCE   = (currentCurve.FROMMEAS - previousCurve.TOMEAS).ToString(),
                PERCENTGRA = 0,
                VAFT       = ""
            };

            InsertVerticalCurve(toInsert);
        }
コード例 #2
0
        public void DeleteVerticalCurve(VerticalCurve curve)
        {
            var sql  = "DELETE FROM VerticalCurves WHERE ROUTE = @0 AND FROMMEAS = @1 AND TOMEAS = @2";
            var args = new List <object>();

            args.Add(curve.ROUTE);
            args.Add(curve.FROMMEAS);
            args.Add(curve.TOMEAS);
            var table = new VerticalCurves();

            table.Execute(sql, args: args.ToArray());
            var str = string.Format("DELETED ROUTE: {0}, FROMMEAS: {1}, TOMEAS: {2}", curve.ROUTE, curve.FROMMEAS, curve.TOMEAS);

            Console.WriteLine(str);
        }
コード例 #3
0
        public void InsertVerticalCurve(VerticalCurve curve)
        {
            var query = "INSERT INTO VerticalCurves (ROUTE, FROMMEAS, TOMEAS, DISTANCE, PERCENTGRA, VAFT) VALUES (@0, @1, @2, @3, @4, @5)";
            var args  = new List <object>();

            args.Add(curve.ROUTE);
            args.Add(curve.FROMMEAS);
            args.Add(curve.TOMEAS);
            args.Add(curve.DISTANCE);
            args.Add(curve.PERCENTGRA);
            args.Add(curve.VAFT);
            new VerticalCurves().Execute(query, args: args.ToArray());
            var str = string.Format("RowCount: {0},INSERTED ROUTE: {1}, FROMMEAS: {2}, TOMEAS: {3}", rowCount = rowCount + 1, curve.ROUTE, curve.FROMMEAS, curve.TOMEAS);

            Console.WriteLine(str);
        }
コード例 #4
0
        public void InsertRouteStart(VerticalCurve curve)
        {
            /* if the distance of the route start is greater than 528 insert two records
             * 1st, FROMEAS is 0, TOMEAS is the next's FROMMEAS
             * 2nd, FROMMEAS is current curve record's TOMEAS - 528 and TOMEAS is its FROMEAS
             * the InsertRouteStart contains this logic
             */
            if (curve.FROMMEAS > 528)
            {
                var toInsertB = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = curve.FROMMEAS - 528,
                    TOMEAS     = curve.FROMMEAS,
                    DISTANCE   = "528",
                    PERCENTGRA = 0,
                    VAFT       = ""
                };

                var toIsertA = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = 0,
                    TOMEAS     = toInsertB.FROMMEAS,
                    DISTANCE   = toInsertB.FROMMEAS.ToString(),
                    PERCENTGRA = 0,
                    VAFT       = ""
                };

                InsertVerticalCurve(toIsertA);
                InsertVerticalCurve(toInsertB);
            }
            else
            {
                var toInsert = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = 0,
                    TOMEAS     = curve.FROMMEAS,
                    DISTANCE   = curve.FROMMEAS.ToString(),
                    PERCENTGRA = 0,
                    VAFT       = ""
                };
                InsertVerticalCurve(toInsert);
            }
        }
コード例 #5
0
        public void InsertRouteEnd(VerticalCurve curve, RouteLength route)
        {
            /*
             * if distance is greater than 528 ft, insert two records
             * 1st, the FROMMEAS is the previous TOMEAS, and TOMEAS is FROMMEAS + 528
             * 2nd, FROMMEAS is 1st record's TOMEAS and TOMEAS is ROUTE LENGTH
             */
            if (route.LENGTH - curve.TOMEAS > 528)
            {
                var toInsertA = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = curve.TOMEAS,
                    TOMEAS     = curve.TOMEAS + 528,
                    DISTANCE   = "528",
                    PERCENTGRA = 0,
                    VAFT       = ""
                };

                var toInsertB = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = toInsertA.TOMEAS,
                    TOMEAS     = route.LENGTH,
                    DISTANCE   = (route.LENGTH - toInsertA.TOMEAS).ToString(),
                    PERCENTGRA = 0,
                    VAFT       = ""
                };
                InsertVerticalCurve(toInsertA);
                InsertVerticalCurve(toInsertB);
            }
            else
            {
                var toInsert = new VerticalCurve()
                {
                    ROUTE      = curve.ROUTE,
                    FROMMEAS   = curve.TOMEAS,
                    TOMEAS     = route.LENGTH,
                    DISTANCE   = (route.LENGTH - curve.TOMEAS).ToString(),
                    PERCENTGRA = 0,
                    VAFT       = ""
                };
                InsertVerticalCurve(toInsert);
            }
        }
コード例 #6
0
        public void UpdateVerticalCurve(VerticalCurve source, VerticalCurve toUpdate)
        {
            var query = "UPDATE VerticalCurves SET FROMMEAS = @0, TOMEAS = @1, DISTANCE = @2, PERCENTGRA = @3, VAFT = @4 WHERE ROUTE = @5 AND FROMMEAS = @6 AND TOMEAS = @7";
            var args  = new List <object>();

            args.Add(toUpdate.FROMMEAS);   // 0
            args.Add(toUpdate.TOMEAS);     // 1
            args.Add(toUpdate.DISTANCE);   // 2
            args.Add(toUpdate.PERCENTGRA); // 3
            args.Add(toUpdate.VAFT);       // 4
            args.Add(source.ROUTE);        // 5
            args.Add(source.FROMMEAS);     // 6
            args.Add(source.TOMEAS);       // 7
            var table = new VerticalCurves();

            table.Execute(query, args: args.ToArray());
            var str = string.Format("RowCount: {0}, UPDATED ROUTE: {1}, FROMMEAS: {2}, TOMEAS: {3}, VAFT: {4}", rowCount = rowCount + 1, toUpdate.ROUTE, toUpdate.FROMMEAS, toUpdate.TOMEAS, toUpdate.VAFT);

            Console.WriteLine(str);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: srailsback/VerticalCurves
        static void Main(string[] args)
        {
            ICurvesRepository _repo = new CurvesRepository();


            // truncate VerticalCurves destination table
            _repo.TruncateVerticalCurves();

            /* rip through VerticalCurves source and update the destination
             *  insert gaps for start - routes that don't start at 0 FROMMEAS
             *  insert records for gaps in the route, the previous TOMEAS does not equal the next FROMMEAS, use the previous TOMEAS for the new FROMMEAS and next FROMMEAS for new TOMEAS
             *  insert records for gaps at end of route, the last TOMEAS does not equal the RouteLength, use the last TOMEAS for new FROMMEAS and RunLength for new TOMEAS
             */

            // get all run lengths
            var routes = _repo.GetAllRouteLengths();

            #region insert vertical curves

            foreach (var route in routes)
            {
                var curves = _repo.GetVerticalCurvesByRoute(route.ROUTE, true);

                var lastIndex = curves.Count() - 1;

                foreach (var curve in curves)
                {
                    // start at the beginning, if route does not start with 0 FROMMEAS insert it.
                    var index = curves.IndexOf(curve);
                    if (index == 0)
                    {
                        /* if the distance of the route start is greater than 528 insert two records
                         * 1st, FROMEAS is 0, TOMEAS is the next's FROMMEAS
                         * 2nd, FROMMEAS is current curve record's TOMEAS - 528 and TOMEAS is its FROMEAS
                         * the InsertRouteStart contains this logic
                         */
                        if (curve.FROMMEAS > 0)
                        {
                            _repo.InsertRouteStart(curve);
                            _repo.InsertVerticalCurve(curve);
                        }
                        else
                        {
                            _repo.InsertVerticalCurve(curve);
                        }
                    }

                    if (index > 0)
                    {
                        // now figure out gaps in route
                        var previous = curves.Skip(curves.IndexOf(curve) - 1).Take(1).FirstOrDefault();
                        var next     = curves.Skip(curves.IndexOf(curve) + 1).Take(1).FirstOrDefault();

                        if (curve.FROMMEAS != previous.TOMEAS)
                        {
                            _repo.InsertRouteGap(previous, curve);
                            _repo.InsertVerticalCurve(curve);
                        }
                        else
                        {
                            _repo.InsertVerticalCurve(curve);
                        }
                    }


                    // check end of route, the TOMEAS should equal the RouteLength.LENGTH
                    if (index == lastIndex)
                    {
                        /*
                         * if distance is greater than 528 ft, insert two records
                         * 1st, the FROMMEAS is the previous TOMEAS, and TOMEAS is FROMMEAS + 528
                         * 2nd, FROMMEAS is 1st record's TOMEAS and TOMEAS is ROUTE LENGTH
                         * our InsertRouteEnd wraps this logic
                         */
                        if (curve.TOMEAS != route.LENGTH)
                        {
                            _repo.InsertRouteEnd(curve, route);
                        }
                    }
                }
            }
            #endregion


            #region update vertical curves
            _repo.ResetRowCount();
            foreach (var route in routes)
            {
                var curves = _repo.GetVerticalCurvesByRoute(route.ROUTE, false);
                foreach (var current in curves)
                {
                    var index     = curves.IndexOf(current);
                    var lastIndex = curves.IndexOf(curves.Last());

                    // previous and next curve records
                    VerticalCurve previous = null;
                    VerticalCurve next     = null;
                    if (index == 0)
                    {
                        next = curves.Skip(curves.IndexOf(current) + 1).First();
                    }
                    else if (index == lastIndex)
                    {
                        previous = curves.Skip(curves.IndexOf(current) - 1).First();
                    }
                    else
                    {
                        previous = curves.Skip(curves.IndexOf(current) - 1).First();
                        next     = curves.Skip(curves.IndexOf(current) + 1).First();
                    }

                    // if this it start or end of the route skip it
                    if (index > 0 && index < lastIndex)
                    {
                        // update the VAFT

                        /*
                         + 0 + CVC
                         + - 0 - SVC
                         + - 0 + SVC
                         + 0 - CVC
                         + 0 0 - CVC
                         + 0 0 + SVC
                         + - 0 0 SCV
                         + 0 0 CVC
                         + if current PERCENTGRA == 0 figure out the VAFT
                         + if current PERCENTGRA != 0, it's VG
                         */
                        if (current.PERCENTGRA != 0)
                        {
                            current.VAFT = VAFT.VG.ToString();
                            _repo.UpdateVerticalCurve(current, current);
                        }
                        else
                        {
                            if (previous.PERCENTGRA > 0 && next.PERCENTGRA > 0)
                            {
                                current.VAFT = VAFT.CVC.ToString();
                            }
                            else if (previous.PERCENTGRA < 0 && next.PERCENTGRA < 0)
                            {
                                current.VAFT = VAFT.SVC.ToString();
                            }
                            else if (previous.PERCENTGRA < 0 && next.PERCENTGRA > 0)
                            {
                                current.VAFT = VAFT.SVC.ToString();
                            }
                            else if (previous.PERCENTGRA > 0 && next.PERCENTGRA < 0)
                            {
                                current.VAFT = VAFT.CVC.ToString();
                            }
                            else if (previous.PERCENTGRA == 0 && next.PERCENTGRA < 0)
                            {
                                current.VAFT = VAFT.CVC.ToString();
                            }
                            else if (previous.PERCENTGRA == 0 && next.PERCENTGRA > 0)
                            {
                                current.VAFT = VAFT.SVC.ToString();
                            }
                            else if (previous.PERCENTGRA < 0 && next.PERCENTGRA == 0)
                            {
                                current.VAFT = VAFT.SVC.ToString();
                            }
                            else if (previous.PERCENTGRA > 0 && next.PERCENTGRA == 0)
                            {
                                current.VAFT = VAFT.CVC.ToString();
                            }
                            else if (previous.PERCENTGRA == 0 && next.PERCENTGRA == 0 && current.PERCENTGRA != 0)
                            {
                                current.VAFT = VAFT.VG.ToString();
                            }

                            if (current.VAFT != "")
                            {
                                _repo.UpdateVerticalCurve(current, current);
                            }
                        }
                    }


                    // case for the last record
                    if (index == lastIndex && float.Parse(current.DISTANCE) <= 528)
                    {
                        if (current.PERCENTGRA != 0)
                        {
                            current.VAFT = VAFT.VG.ToString();
                            _repo.UpdateVerticalCurve(current, current);
                        }
                        else
                        {
                            if (previous.PERCENTGRA != 0)
                            {
                                current.VAFT = previous.PERCENTGRA < 0 ? VAFT.SVC.ToString() : VAFT.CVC.ToString();
                                _repo.UpdateVerticalCurve(current, current);
                            }
                        }
                    }
                }
            }

            #endregion

            #region last records

            /*
             * unique case, if there are 3 consecutive 0 PERCENTGRA at end of route,
             * combine them then apply the 528 rule
             */
            foreach (var route in routes)
            {
                var curves = _repo.GetVerticalCurvesByRoute(route.ROUTE, false);
                // get the last three
                if (curves.Count > 3)
                {
                    var lastRows = curves.Skip(curves.Count - 3).Take(3);
                    if (lastRows.Where(x => x.PERCENTGRA == 0).Count() == 3)
                    {
                        var first  = lastRows.First();
                        var second = lastRows.Skip(1).First();
                        var third  = lastRows.Last();


                        _repo.UpdateVerticalCurve(first, new VerticalCurve()
                        {
                            ROUTE      = first.ROUTE,
                            FROMMEAS   = first.FROMMEAS,
                            TOMEAS     = first.FROMMEAS + 528,
                            DISTANCE   = "528",
                            PERCENTGRA = first.PERCENTGRA,
                            VAFT       = first.VAFT
                        });

                        _repo.UpdateVerticalCurve(second, new VerticalCurve()
                        {
                            ROUTE      = second.ROUTE,
                            FROMMEAS   = first.FROMMEAS + 528,
                            TOMEAS     = third.TOMEAS,
                            DISTANCE   = (third.TOMEAS - (first.FROMMEAS + 528)).ToString(),
                            PERCENTGRA = second.PERCENTGRA,
                            VAFT       = second.VAFT
                        });

                        _repo.DeleteVerticalCurve(third);
                    }
                }
            }

            #endregion
            Console.WriteLine("Done");
            //Console.ReadKey();
        }