Exemplo n.º 1
0
 private void NewStarListComputedAsync(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list)
 {
     if (this.IsHandleCreated)
     {
         this.BeginInvoke(new Action(() => NewStarListComputed(sys, list)));
     }
 }
Exemplo n.º 2
0
        public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                          int maxitems,
                                                          double mindist, double maxdist, bool spherical, SQLiteConnectionSystem cn = null)
        {
            bool owncn = cn == null;

            if (owncn)
            {
                cn = new SQLiteConnectionSystem(mode: SQLLiteExtensions.SQLExtConnection.AccessMode.Reader);
            }

            DB.SystemsDB.GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, cn, (s) => AddToCache(s));
            if (distlist.Count > 0)
            {
                foreach (var s in distlist)
                {
                    AddToCache(s.Value);
                }
            }

            if (owncn)
            {
                cn.Dispose();
            }
        }
Exemplo n.º 3
0
        public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                          int maxitems,
                                                          double mindist, double maxdist, bool spherical)
        {
            if (SystemsDatabase.Instance.RebuildRunning) // Return from cache if rebuild is running
            {
                lock (systemsByEdsmId)
                {
                    var sysdist = systemsByName.Values
                                  .SelectMany(s => s)
                                  .Select(s => new { distsq = s.DistanceSq(x, y, z), sys = s })
                                  .OrderBy(s => s.distsq)
                                  .ToList();
                    var minsq = mindist * mindist;
                    var maxsq = maxdist * maxdist;

                    foreach (var sd in sysdist)
                    {
                        if (sd.distsq <= minsq && sd.distsq >= maxsq)
                        {
                            distlist.Add(sd.distsq, sd.sys);
                        }

                        if (distlist.Count >= maxitems)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                SystemsDatabase.Instance.ExecuteWithDatabase(conn => GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, conn));
            }
        }
Exemplo n.º 4
0
        private void FillGrid(string name, BaseUtils.SortedListDoubleDuplicate <ISystem> csl)
        {
            dataGridViewNearest.Rows.Clear();

            if (csl != null && csl.Any())
            {
                SetControlText(string.Format("From {0}".Tx(this, "From"), name));
                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    double dist = Math.Sqrt(tvp.Key);   // distances are stored squared for speed, back to normal.

                    if (tvp.Value.Name != name && (checkBoxCube.Checked || (dist >= textMinRadius.Value && dist <= textMaxRadius.Value)))
                    {
                        int      visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);
                        object[] rowobj = { tvp.Value.Name, $"{dist:0.00}", $"{visits:n0}" };

                        int rowindex = dataGridViewNearest.Rows.Add(rowobj);
                        dataGridViewNearest.Rows[rowindex].Tag = tvp.Value;
                    }
                }
            }
            else
            {
                SetControlText(string.Empty);
            }
        }
Exemplo n.º 5
0
        private void buttonExtDBClick(object sender, EventArgs e)
        {
            ISystem sys = textBoxSystemName.Text.Length > 0 ? discoveryform.history.FindSystem(textBoxSystemName.Text, discoveryform.galacticMapping) : new SystemClass("Unknown", numberBoxDoubleX.Value, numberBoxDoubleY.Value, numberBoxDoubleZ.Value);     // find centre, i.e less 1 ly distance

            if (sys != null)
            {
                BaseUtils.SortedListDoubleDuplicate <ISystem> distlist = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                Cursor = Cursors.WaitCursor;

                SystemCache.GetSystemListBySqDistancesFrom(distlist, sys.X, sys.Y, sys.Z, 50000,
                                                           numberBoxMinRadius.Value, numberBoxMaxRadius.Value, !checkBoxCustomCube.Checked);

                Cursor = Cursors.Default;

                var res = (from x in distlist select new Tuple <ISystem, double>(x.Value, x.Value.Distance(sys))).ToList();

                if (extCheckBoxExcludeVisitedSystems.Checked)
                {
                    res = (from x in res where discoveryform.history.FindByName(x.Item1.Name) == null select x).ToList();
                }

                ReturnSystems(res);
            }
            else
            {
                ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Cannot find system ".T(EDTx.FindSystemsUserControl_Cannotfindsystem) + textBoxSystemName.Text, "Warning".T(EDTx.Warning), MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 6
0
        public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, // MUST use duplicate double list to protect against EDSM having two at the same point
                                                          double x, double y, double z,
                                                          int maxitems,
                                                          double mindist,       // 0 = no min dist, always spherical
                                                          double maxdist,
                                                          bool spherical,       // enforces sphere on maxdist, else its a cube for maxdist
                                                          SQLiteConnectionSystem cn,
                                                          Action <ISystem> LookedUp = null
                                                          )

        {
            // for comparision, using the grid screener is slower than the xy index. keep code for record
            // grid screener..  "s.sectorid IN (Select id FROM Sectors sx where sx.gridid IN (" + strinlist + ")) " +
            //var gridids = GridId.Ids(x - maxdist, x + maxdist, z - maxdist, z + maxdist);       // find applicable grid ids across this range..
            //var strinlist = string.Join(",", (from x1 in gridids select x1.ToStringInvariant()));     // here we convert using invariant for paranoia sake.

            int mindistint = mindist > 0 ? SystemClass.DoubleToInt(mindist) * SystemClass.DoubleToInt(mindist) : 0;

            // needs a xz index for speed

            using (DbCommand cmd = cn.CreateSelect("Systems s",
                                                   MakeSystemQueryEDDB,
                                                   where :
                                                   "s.x >= @xv - @maxdist " +
                                                   "AND s.x <= @xv + @maxdist " +
                                                   "AND s.z >= @zv - @maxdist " +
                                                   "AND s.z <= @zv + @maxdist " +
                                                   "AND s.y >= @yv - @maxdist " +
                                                   "AND s.y <= @yv + @maxdist " +
                                                   (mindist > 0 ? ("AND (s.x-@xv)*(s.x-@xv)+(s.y-@yv)*(s.y-@yv)+(s.z-@zv)*(s.z-@zv)>=" + (mindistint).ToStringInvariant()) : ""),
                                                   orderby: "(s.x-@xv)*(s.x-@xv)+(s.y-@yv)*(s.y-@yv)+(s.z-@zv)*(s.z-@zv)", // just use squares to order
                                                   joinlist: MakeSystemQueryEDDBJoinList,
                                                   limit: "@max"
                                                   ))
            {
                cmd.AddParameterWithValue("@xv", SystemClass.DoubleToInt(x));
                cmd.AddParameterWithValue("@yv", SystemClass.DoubleToInt(y));
                cmd.AddParameterWithValue("@zv", SystemClass.DoubleToInt(z));
                cmd.AddParameterWithValue("@max", maxitems + 1);     // 1 more, because if we are on a System, that will be returned
                cmd.AddParameterWithValue("@maxdist", SystemClass.DoubleToInt(maxdist));

//                System.Diagnostics.Debug.WriteLine(cn.ExplainQueryPlanString(cmd));

                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())// && distlist.Count < maxitems)           // already sorted, and already limited to max items
                    {
                        SystemClass s = MakeSystem(reader);
                        LookedUp?.Invoke(s);                            // callback to say looked up

                        double distsq = s.DistanceSq(x, y, z);
                        if ((!spherical || distsq <= maxdist * maxdist))
                        {
                            distlist.Add(distsq, s);                  // which Rob has seen crashing the program! Bad EDSM!
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void NewStarListComputed(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list) // In UI
        {
            System.Diagnostics.Debug.Assert(Application.MessageLoop);                                     // check!

            // Get nearby systems from our travel history. This will filter out duplicates from the systems DB.
            discoveryform.history.CalculateSqDistances(list, sys.X, sys.Y, sys.Z,
                                                       maxitems, textMinRadius.Value, textMaxRadius.Value, !checkBoxCube.Checked
                                                       );

            FillGrid(sys.Name, list);
        }
Exemplo n.º 8
0
        ///////////////////////////////////////// List of systems near xyz between mindist and maxdist

        public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                          int maxitems,
                                                          double mindist, double maxdist, bool spherical,
                                                          Action <ISystem> LookedUp = null
                                                          )
        {
            using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem(mode: SQLLiteExtensions.SQLExtConnection.AccessMode.Reader))
            {
                GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, cn, LookedUp);
            }
        }
        ///////////////////////////////////////// List of systems near xyz between mindist and maxdist

        public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                          int maxitems,
                                                          double mindist, double maxdist, bool spherical,
                                                          Action <ISystem> LookedUp = null
                                                          )
        {
            SystemsDatabase.Instance.ExecuteWithDatabase(db =>
            {
                GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, db.Connection, LookedUp);
            });
        }
        private void FillGrid(string name, BaseUtils.SortedListDoubleDuplicate <ISystem> csl)
        {
            DataGridViewColumn sortcolprev   = dataGridViewNearest.SortedColumn != null ? dataGridViewNearest.SortedColumn : dataGridViewNearest.Columns[1];
            SortOrder          sortorderprev = dataGridViewNearest.SortedColumn != null ? dataGridViewNearest.SortOrder : SortOrder.Ascending;

            dataGridViewNearest.Rows.Clear();

            if (csl != null && csl.Any())
            {
                SetControlText(string.Format("From {0}".T(EDTx.UserControlStarDistance_From), name));

                int maxdist = 0;
                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    double dist = Math.Sqrt(tvp.Key);   // distances are stored squared for speed, back to normal.

                    maxdist = Math.Max(maxdist, (int)dist);

                    if (tvp.Value.Name != name && (checkBoxCube.Checked || (dist >= textMinRadius.Value && dist <= textMaxRadius.Value)))
                    {
                        int      visits = discoveryform.history.GetVisitsCount(tvp.Value.Name);
                        object[] rowobj = { tvp.Value.Name, $"{dist:0.00}", $"{visits:n0}" };

                        int rowindex = dataGridViewNearest.Rows.Add(rowobj);
                        dataGridViewNearest.Rows[rowindex].Tag = tvp.Value;
                    }
                }

                if (csl.Count > maxitems / 2)           // if we filled up at least half the list, we limit to max distance plus
                {
                    lookup_limit = maxdist * 11 / 10;   // lookup limit is % more than max dist, to allow for growth
                }
                else if (csl.Count > maxitems / 10)
                {
                    lookup_limit = maxdist * 2;         // else we did not get close to filling the list, so double the limit and try again
                }
                else
                {
                    lookup_limit = 100;                 // got so few, lets reset
                }
                System.Diagnostics.Debug.WriteLine("Star distance Lookup " + name + " found " + csl.Count + " max was " + maxdist + " New limit " + lookup_limit);
            }
            else
            {
                SetControlText(string.Empty);
            }

            dataGridViewNearest.Sort(sortcolprev, (sortorderprev == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
            dataGridViewNearest.Columns[sortcolprev.Index].HeaderCell.SortGlyphDirection = sortorderprev;
        }
        private void NewStarListComputed(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list) // In UI
        {
            System.Diagnostics.Debug.Assert(Application.MessageLoop);                                     // check!

            //System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("SD1", true) + "SD main thread");

            double lookup_max = Math.Min(textMaxRadius.Value, lookup_limit);

            // Get nearby systems from our travel history. This will filter out duplicates from the systems DB.
            discoveryform.history.CalculateSqDistances(list, sys.X, sys.Y, sys.Z,
                                                       maxitems, textMinRadius.Value, lookup_max, !checkBoxCube.Checked, 5000); // only go back a sensible number of FSD entries

            FillGrid(sys.Name, list);

            //System.Diagnostics.Debug.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("SD1") + "SD  finish");
        }
Exemplo n.º 12
0
        // Add in any systems we have to the distlist

        public void CalculateSqDistances(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                         int maxitems, double mindistance, double maxdistance, bool spherical, int maxjumpsback = int.MaxValue)
        {
            HashSet <string> listnames = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (ISystem sys in distlist.Values.ToList())
            {
                listnames.Add(sys.Name);
            }

            mindistance *= mindistance;

            for (int i = historylist.Count - 1; i >= 0 && maxjumpsback > 0; i--)
            {
                HistoryEntry pos = historylist[i];

                if (pos.IsLocOrJump && pos.System.HasCoordinate && !listnames.Contains(pos.System.Name))
                {
                    double dx     = (pos.System.X - x);
                    double dy     = (pos.System.Y - y);
                    double dz     = (pos.System.Z - z);
                    double distsq = dx * dx + dy * dy + dz * dz;

                    listnames.Add(pos.System.Name); //stops repeats..

                    if (distsq >= mindistance &&
                        (spherical && distsq <= maxdistance * maxdistance ||
                         !spherical && Math.Abs(dx) <= maxdistance && Math.Abs(dy) <= maxdistance && Math.Abs(dz) <= maxdistance))
                    {
                        if (distlist.Count < maxitems)          // if less than max, add..
                        {
                            distlist.Add(distsq, pos.System);
                        }
                        else if (distsq < distlist.Keys[distlist.Count - 1]) // if last entry (which must be the biggest) is greater than dist..
                        {
                            distlist.Add(distsq, pos.System);                // add in
                            distlist.RemoveAt(maxitems);                     // remove last..
                        }
                    }

                    maxjumpsback--;
                }
            }
        }
Exemplo n.º 13
0
        private void BackgroundStardistWorkerThread()
        {
            while (!PendingClose)
            {
                int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, stardistRequested });

                if (PendingClose)
                {
                    break;
                }

                StardistRequest stardistreq = null;

                switch (wh)
                {
                case 0:      // Close Requested
                    break;

                case 1:      // Star Distances Requested
                    while (!PendingClose && closestsystem_queue.TryDequeue(out stardistreq))
                    {
                        if (!stardistreq.IgnoreOnDuplicate || closestsystem_queue.Count == 0)
                        {
                            StardistRequest req = stardistreq;
                            ISystem         sys = req.System;
                            BaseUtils.SortedListDoubleDuplicate <ISystem> closestsystemlist = new BaseUtils.SortedListDoubleDuplicate <ISystem>();   //lovely list allowing duplicate keys - can only iterate in it.

                            //System.Diagnostics.Debug.WriteLine("DB Computer Max distance " + sys.X + " " + sys.Y + " " + sys.Z + " " + req.MaxItems + " " + req.MinDistance + " -> " + req.MaxDistance + " "  + req.Spherical);

                            DB.SystemCache.GetSystemListBySqDistancesFrom(closestsystemlist, sys.X, sys.Y, sys.Z, req.MaxItems,
                                                                          req.MinDistance, req.MaxDistance, req.Spherical);

                            if (!PendingClose)
                            {
                                req.Callback(sys, closestsystemlist);
                            }
                        }
                    }

                    break;
                }
            }
        }
Exemplo n.º 14
0
        private void buttonExtDBClick(object sender, EventArgs e)
        {
            ISystem sys = textBoxSystemName.Text.Length > 0 ? discoveryform.history.FindSystem(textBoxSystemName.Text, discoveryform.galacticMapping) : new SystemClass("Unknown", numberBoxDoubleX.Value, numberBoxDoubleY.Value, numberBoxDoubleZ.Value);     // find centre, i.e less 1 ly distance

            if (sys != null)
            {
                BaseUtils.SortedListDoubleDuplicate <ISystem> distlist = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                Cursor = Cursors.WaitCursor;

                EliteDangerousCore.DB.SystemClassDB.GetSystemListBySqDistancesFrom(distlist, sys.X, sys.Y, sys.Z, 50000,
                                                                                   numberBoxMinRadius.Value, numberBoxMaxRadius.Value, !checkBoxCustomCube.Checked);

                Cursor = Cursors.Default;

                ReturnSystems((from x in distlist select new Tuple <ISystem, double>(x.Value, x.Value.Distance(sys))).ToList());
            }
            else
            {
                ExtendedControls.MessageBoxTheme.Show(this.FindForm(), "Cannot find system ".Tx(this) + textBoxSystemName.Text, "Warning".Tx(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        ///////////////////////////////////////// List of systems near xyz between mindist and maxdist

        internal static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, // MUST use duplicate double list to protect against EDSM having two at the same point
                                                            double x, double y, double z,
                                                            int maxitems,
                                                            double mindist,     // 0 = no min dist, always spherical
                                                            double maxdist,
                                                            bool spherical,     // enforces sphere on maxdist, else its a cube for maxdist
                                                            SQLiteConnectionSystem cn,
                                                            Action <ISystem> LookedUp = null
                                                            )

        {
            // for comparision, using the grid screener is slower than the xy index. keep code for record
            // grid screener..  "s.sectorid IN (Select id FROM Sectors sx where sx.gridid IN (" + strinlist + ")) " +
            //var gridids = GridId.Ids(x - maxdist, x + maxdist, z - maxdist, z + maxdist);       // find applicable grid ids across this range..
            //var strinlist = string.Join(",", (from x1 in gridids select x1.ToStringInvariant()));     // here we convert using invariant for paranoia sake.

            // System.Diagnostics.Debug.WriteLine("Time1 " + BaseUtils.AppTicks.TickCountLap("SDC"));

            int mindistint = mindist > 0 ? SystemClass.DoubleToInt(mindist) * SystemClass.DoubleToInt(mindist) : 0;

            // needs a xz index for speed

            using (DbCommand cmd = cn.CreateSelect("Systems s",
                                                   MakeSystemQueryNamed,
                                                   where :
                                                   "s.x >= @xv - @maxdist " +
                                                   "AND s.x <= @xv + @maxdist " +
                                                   "AND s.z >= @zv - @maxdist " +
                                                   "AND s.z <= @zv + @maxdist " +
                                                   "AND s.y >= @yv - @maxdist " +
                                                   "AND s.y <= @yv + @maxdist " +
                                                   (mindist > 0 ? ("AND (s.x-@xv)*(s.x-@xv)+(s.y-@yv)*(s.y-@yv)+(s.z-@zv)*(s.z-@zv)>=" + (mindistint).ToStringInvariant()) : ""),
                                                   orderby: "(s.x-@xv)*(s.x-@xv)+(s.y-@yv)*(s.y-@yv)+(s.z-@zv)*(s.z-@zv)", // just use squares to order
                                                   joinlist: MakeSystemQueryNamedJoinList,
                                                   limit: "@max"
                                                   ))
            {
                cmd.AddParameterWithValue("@xv", SystemClass.DoubleToInt(x));
                cmd.AddParameterWithValue("@yv", SystemClass.DoubleToInt(y));
                cmd.AddParameterWithValue("@zv", SystemClass.DoubleToInt(z));
                cmd.AddParameterWithValue("@max", maxitems + 1);     // 1 more, because if we are on a System, that will be returned
                cmd.AddParameterWithValue("@maxdist", SystemClass.DoubleToInt(maxdist));

                // System.Diagnostics.Debug.WriteLine(cn.ExplainQueryPlanString(cmd));

                int  xi         = SystemClass.DoubleToInt(x);
                int  yi         = SystemClass.DoubleToInt(y);
                int  zi         = SystemClass.DoubleToInt(z);
                long maxdistsqi = (long)SystemClass.DoubleToInt(maxdist) * (long)SystemClass.DoubleToInt(maxdist);

                long count = 0;
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    //  System.Diagnostics.Debug.WriteLine("Time1.5 " + BaseUtils.AppTicks.TickCountLap("SDC"));

                    while (reader.Read())      // already sorted, and already limited to max items
                    {
                        int sxi = reader.GetInt32(0);
                        int syi = reader.GetInt32(1);
                        int szi = reader.GetInt32(2);

                        long distsqi = (long)(xi - sxi) * (long)(xi - sxi) + (long)(yi - syi) * (long)(yi - syi) + (long)(zi - szi) * (long)(zi - szi);

                        if (!spherical || distsqi <= maxdistsqi)
                        {
                            SystemClass s        = MakeSystem(reader);
                            double      distnorm = ((double)distsqi) / SystemClass.XYZScalar / SystemClass.XYZScalar;
                            //System.Diagnostics.Debug.WriteLine("System " + s.Name + " " + Math.Sqrt(distnorm).ToString("0.0"));
                            LookedUp?.Invoke(s);                        // callback to say looked up
                            distlist.Add(distnorm, s);                  // which Rob has seen crashing the program! Bad EDSM!
                        }

                        count++;
                    }

                    //  System.Diagnostics.Debug.WriteLine("Time2 " + BaseUtils.AppTicks.TickCountLap("SDC") + "  count " + count);
                }
            }
        }
Exemplo n.º 16
0
        private void FillPlot(BaseUtils.SortedListDoubleDuplicate <ISystem> csl, ISystem currentSystem)
        {
            SetControlText("2D Plot of systems in range from " + currentSystem.Name);

            var pointSize = 4;

            // initializing the plot
            var modelTop   = new PlotModel {
            };
            var modelFront = new PlotModel {
            };
            var modelSide  = new PlotModel {
            };

            this.plotViewTop.Model   = modelTop;
            this.plotViewFront.Model = modelFront;
            this.plotViewSide.Model  = modelSide;

            modelTop.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelTop.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet
            });
            modelFront.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelFront.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet
            });
            modelSide.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelSide.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet
            });

            // Define defaults properties of the series for the Top view
            var currentSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Define defaults properties of the series for the Front view
            var currentSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Define defaults properties of the series for the Side view
            var currentSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Add the series
            modelTop.Series.Add(currentSeriesTop);
            modelTop.Series.Add(lastoneSeriesTop);
            modelTop.Series.Add(visitedSeriesTop);
            modelTop.Series.Add(inrangeSeriesTop);

            // Add the series
            modelFront.Series.Add(currentSeriesFront);
            modelFront.Series.Add(lastoneSeriesFront);
            modelFront.Series.Add(visitedSeriesFront);
            modelFront.Series.Add(inrangeSeriesFront);

            // Add the series
            modelSide.Series.Add(currentSeriesSide);
            modelSide.Series.Add(lastoneSeriesSide);
            modelSide.Series.Add(visitedSeriesSide);
            modelSide.Series.Add(inrangeSeriesSide);

            // titles
            modelTop.Title   = "Plot around " + currentSystemName + ", viewed from the top";
            modelFront.Title = "Plot around " + currentSystemName + ", viewed from the front";
            modelSide.Title  = "Plot around " + currentSystemName + ", viewed from the side";

            // Title of the report
            reportView.Text += ("\nSystems around " + currentSystemName + ", from " + textMinRadius.Value.ToString() + " to " + textMaxRadius.Value.ToString() + "Ly: " + csl.Count.ToString() + "\n");

            // Fill with some information for the report
            //reportView.AppendText("\nText " + currentSystem.some_value_interesting_to_report);
            reportView.Text += ("\nVisits: " + discoveryform.history.GetVisitsCount(currentSystem.Name, currentSystem.EDSMID));
            reportView.Text += ("\nNotes: " + currentSystem.SystemNote + "\n");

            // If the are any system inside the defined range...
            if (csl.Count() > 0)
            {
                // ...then iterate through each system in the list:
                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    // calculate the average distance;
                    var distFromCurrentSys = Math.Round(Math.Sqrt(tvp.Key), 2, MidpointRounding.AwayFromZero);

                    // count the total visits for each system;
                    int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);

                    // Then, populate the Grid with the systems in range
                    if (distFromCurrentSys >= textMinRadius.Value && distFromCurrentSys <= textMaxRadius.Value && tvp.Value.Name != currentSystemName)
                    {
                        // get the coordinates of each system in range;
                        var sysX = tvp.Value.X;
                        var sysY = tvp.Value.Y;
                        var sysZ = tvp.Value.Z;

                        // print information on each member of the list;
                        reportView.Text += ("\n" + tvp.Value.Name.ToString() + ", distant " + distFromCurrentSys + "Ly ");
                        reportView.Text += ("\n" + "Visits: " + visits.ToString());
                        reportView.Text += ("\nCoordinates: " + "X:" + sysX + ", Y:" + sysY + ", Z:" + sysZ);

                        // Create the list, with each system's name, distances by x, y and z coordinates and number of visits
                        object[] plotobj  = { tvp.Value.Name, $"{sysX:0.00}", $"{sysY:0.00}", $"{sysZ:0.00}", $"{visits:n0}" };
                        int      rowindex = dataGridList.Rows.Add(plotobj);
                        dataGridList.Rows[rowindex].Tag = tvp.Value;

                        var seriesTop   = inrangeSeriesTop;
                        var seriesFront = inrangeSeriesFront;
                        var seriesSide  = inrangeSeriesSide;

                        // Assign each system to the correct color and series, depending of its state:
                        // visited; lastone; inrange (not visited).
                        if (visits > 0)
                        {
                            // is visited
                            if (tvp.Value.Name != previousSystemName)
                            {
                                seriesTop   = visitedSeriesTop;
                                seriesFront = visitedSeriesFront;
                                seriesSide  = visitedSeriesSide;
                            }
                            // is visited, and is the last visited system
                            else if (tvp.Value.Name == previousSystemName)
                            {
                                seriesTop   = lastoneSeriesTop;
                                seriesFront = lastoneSeriesFront;
                                seriesSide  = lastoneSeriesSide;
                            }
                        }
                        else
                        // is not visited yet
                        {
                            seriesTop   = inrangeSeriesTop;
                            seriesFront = inrangeSeriesFront;
                            seriesSide  = inrangeSeriesSide;
                        }
                        //

                        // Draw each point in the Plot
                        seriesTop.Points.Add(new ScatterPoint(Convert.ToDouble(plotobj[1]), Convert.ToDouble(plotobj[2]), pointSize, Convert.ToDouble(plotobj[3]), plotobj[0]));
                        seriesFront.Points.Add(new ScatterPoint(Convert.ToDouble(plotobj[1]), Convert.ToDouble(plotobj[3]), pointSize, Convert.ToDouble(plotobj[2]), plotobj[0]));
                        seriesSide.Points.Add(new ScatterPoint(Convert.ToDouble(plotobj[2]), Convert.ToDouble(plotobj[3]), pointSize, Convert.ToDouble(plotobj[1]), plotobj[0]));

                        // Create a tracker which shows the name of the system and its coordinates

                        string TrackerTop   = "{Tag}\n" + "X: {2:0.###}; Y: {4:0.###}; Z: {6:0.###}";
                        string TrackerFront = "{Tag}\n" + "X: {2:0.###}; Z: {4:0.###}; Y: {6:0.###}";
                        string TrackerSide  = "{Tag}\n" + "Y: {2:0.###}; Z: {4:0.###}; X: {6:0.###}";

                        seriesTop.TrackerFormatString   = TrackerTop;
                        seriesFront.TrackerFormatString = TrackerFront;
                        seriesSide.TrackerFormatString  = TrackerSide;
                    }

                    currentSeriesTop.Points.Add(new ScatterPoint(currentSystem.X, currentSystem.Y, pointSize, currentSystem.Z, currentSystemName));
                    currentSeriesFront.Points.Add(new ScatterPoint(currentSystem.X, currentSystem.Z, pointSize, currentSystem.Y, currentSystemName));
                    currentSeriesSide.Points.Add(new ScatterPoint(currentSystem.Y, currentSystem.Z, pointSize, currentSystem.X, currentSystemName));

                    string currentTracker = "{Tag}";

                    currentSeriesTop.TrackerFormatString   = currentTracker;
                    currentSeriesFront.TrackerFormatString = currentTracker;
                    currentSeriesSide.TrackerFormatString  = currentTracker;

                    // End of the systems list
                    reportView.Text += ("\n");
                }

                // End of the Report
                reportView.Text += ("\n\nReport created on " + DateTime.Now.ToString());
            }
        }
 private void NewStarListComputedAsync(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list)
 {
     //System.Diagnostics.Debug.WriteLine("Computer returned " + list.Count);
     this.ParentForm.BeginInvoke(new Action(() => NewStarListComputed(sys, list)));
 }
Exemplo n.º 18
0
 public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                   int maxitems,
                                                   double mindist, double maxdist, bool spherical, SystemsDatabaseConnection cn)
 {
     DB.SystemsDB.GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, cn.Connection, (s) => AddToCache(s));
 }
 internal static ISystem GetSystemByPosition(double x, double y, double z, SQLiteConnectionSystem cn, double maxdist = 0.125)
 {
     BaseUtils.SortedListDoubleDuplicate <ISystem> distlist = new BaseUtils.SortedListDoubleDuplicate <ISystem>();
     GetSystemListBySqDistancesFrom(distlist, x, y, z, 1, 0, maxdist, true, cn); // return 1 item, min dist 0, maxdist
     return((distlist.Count > 0) ? distlist.First().Value : null);
 }
Exemplo n.º 20
0
 public static void GetSystemListBySqDistancesFrom(BaseUtils.SortedListDoubleDuplicate <ISystem> distlist, double x, double y, double z,
                                                   int maxitems,
                                                   double mindist, double maxdist, bool spherical)
 {
     SystemsDatabase.Instance.ExecuteWithDatabase(conn => GetSystemListBySqDistancesFrom(distlist, x, y, z, maxitems, mindist, maxdist, spherical, conn));
 }
Exemplo n.º 21
0
        public Form1()
        {
            InitializeComponent();

            bool deletedb = false;

            string edsminfile = @"c:\code\edsm\edsmsystems.10e6.json";
            bool   reloadjson = false;

            string eddbinfile = @"c:\code\edsm\eddbsystems.json";
            bool   reloadeddb = false;

            bool printstars     = false;
            bool printstarseddb = false;
            bool testdelete     = false;
            bool loadaliases    = false;

            if (deletedb)
            {
                BaseUtils.FileHelpers.DeleteFileNoError(EliteDangerousCore.EliteConfigInstance.InstanceOptions.SystemDatabasePath);
            }

            SQLiteConnectionSystem.Initialize();
            SQLiteConnectionSystem.UpgradeSystemTableFrom102TypeDB(() => { return(false); }, (s) => System.Diagnostics.Debug.WriteLine(s), false);

            if (reloadjson)
            {
                SQLiteConnectionSystem.UpgradeSystemTableFromFile(edsminfile, null, () => false, (s) => System.Diagnostics.Debug.WriteLine(s));
            }

            if (reloadeddb)
            {
                BaseUtils.AppTicks.TickCountLap();
                long updated = SystemsDB.ParseEDDBJSONFile(eddbinfile, () => false);
                System.Diagnostics.Debug.WriteLine("EDDB Load : " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
                updated = SystemsDB.ParseEDDBJSONFile(eddbinfile, () => false);
                System.Diagnostics.Debug.WriteLine("EDDB Load : " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
            }

            if (printstars)
            {
                using (StreamWriter wr = new StreamWriter(@"c:\code\edsm\starlistout.lst"))
                {
                    SystemsDB.ListStars(orderby: "s.sectorid,s.edsmid", eddbinfo: false, starreport: (s) =>
                    {
                        wr.WriteLine(s.Name + " " + s.Xi + "," + s.Yi + "," + s.Zi + ", EDSM:" + s.EDSMID + " Grid:" + s.GridID);
                    });
                }
            }

            if (testdelete)
            {
                SystemsDB.RemoveGridSystems(new int[] { 810, 911 });

                using (StreamWriter wr = new StreamWriter(@"c:\code\edsm\starlistout2.lst"))
                {
                    SystemsDB.ListStars(orderby: "s.sectorid,s.edsmid", eddbinfo: false, starreport: (s) =>
                    {
                        wr.WriteLine(s.Name + " " + s.Xi + "," + s.Yi + "," + s.Zi + ", EDSM:" + s.EDSMID + " Grid:" + s.GridID);
                    });
                }
            }

            if (loadaliases)
            {
                string infile = @"c:\code\edsm\hiddensystems.jsonl";
                BaseUtils.AppTicks.TickCountLap();
                long updated = SystemsDB.ParseAliasFile(infile);
                System.Diagnostics.Debug.WriteLine("Alias Load: " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
                BaseUtils.AppTicks.TickCountLap();
                string infile2 = @"c:\code\edsm\hiddensystems2.jsonl";
                updated = SystemsDB.ParseAliasFile(infile2);
                System.Diagnostics.Debug.WriteLine("Alias Load: " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
            }

            if (printstarseddb)
            {
                List <ISystem> stars = SystemsDB.ListStars(orderby: "s.sectorid,s.edsmid", eddbinfo: true);
                using (StreamWriter wr = new StreamWriter(@"c:\code\edsm\starlisteddb.lst"))
                {
                    foreach (var s in stars)
                    {
                        wr.Write(s.Name + " " + s.Xi + "," + s.Yi + "," + s.Zi + ", EDSM:" + s.EDSMID + " Grid:" + s.GridID);
                        if (s.EDDBID != 0)
                        {
                            wr.Write(" EDDBID:" + s.EDDBID + " " + s.Population + " " + s.Faction + " " + s.Government + " " + s.Allegiance + " " + s.State + " " + s.Security + " " + s.PrimaryEconomy
                                     + " " + s.Power + " " + s.PowerState + " " + s.NeedsPermit + " " + s.EDDBUpdatedAt);
                        }
                        wr.WriteLine("");
                    }
                }
            }


            ///////////////////////////////////////////// main tests

            {
                //BaseUtils.AppTicks.TickCountLap();  // Repeated run 1420/2.. removed too slow
                //ISystem s;

                //for (int I = 0; I < 2; I++)
                //{
                //    long total = SystemsDB.GetTotalSystems();
                //    System.Diagnostics.Debug.Assert(total > 9999);
                //}

                //System.Diagnostics.Debug.WriteLine("total systems for X: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                long aliasn;
                aliasn = SystemsDB.FindAlias(-1, "CM Draco");
                System.Diagnostics.Debug.Assert(aliasn == 19700);
                aliasn = SystemsDB.FindAlias(1, null);
                System.Diagnostics.Debug.Assert(aliasn == 19700);
                aliasn = SystemsDB.FindAlias(-1, "CM qwkqkq");
                System.Diagnostics.Debug.Assert(aliasn == -1);
                List <ISystem> aliaslist = SystemsDB.FindAliasWildcard("Horsehead");
                System.Diagnostics.Debug.Assert(aliaslist.Count > 10);
            }

            {
                BaseUtils.AppTicks.TickCountLap();
                ISystem s;

                for (int I = 0; I < 50; I++)              // 6/4/18 50 @ 38       (76 no index on systems)
                {
                    s = SystemsDB.FindStar("HIP 112535"); // this one is at the front of the DB
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 112535"));
                }

                System.Diagnostics.Debug.WriteLine("FindStar HIP x for X: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                ISystem s;

                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 50; I++)
                {
                    s = SystemsDB.FindStar("HIP 14490");        // This one is at the back of the DB
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 14490"));
                    //   System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Standard for X: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                ISystem s;

                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 50; I++)        // 6/4/18 50 @ 26ms (No need for system index)
                {
                    s = SystemsDB.FindStar("kanur");
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412 && s.EDDBID == 10442);
                }

                System.Diagnostics.Debug.WriteLine("Find Kanur for X: " + BaseUtils.AppTicks.TickCountLap());
            }

            { // 16/4/18 100 @ 52ms  (48 no system tables)
                ISystem s;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 100; I++)
                {
                    s = SystemsDB.FindStar(2836547);
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Tucanae Sector SP-N b7-6") && s.Xi == 10844 && s.Yi == -18100 && s.Zi == 28036 && s.EDSMID == 2836547 && s.EDDBID == 0);
                }

                System.Diagnostics.Debug.WriteLine("Find EDSMID for 100: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                ISystem s;
                s = SystemsDB.FindStar("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507") && s.EDDBID == 8856);
                s = SystemsDB.FindStar("Byua Eurk GL-Y d107");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Byua Eurk GL-Y d107") && s.X == -3555.5625 && s.Y == 119.25 && s.Z == 5478.59375);
                s = SystemsDB.FindStar("BD+18 711");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("BD+18 711") && s.Xi == 1700 && s.Yi == -68224 && s.Zi == -225284);
                s = SystemsDB.FindStar("Chamaeleon Sector FG-W b2-3");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Chamaeleon Sector FG-W b2-3") && s.Xi == 71440 && s.Yi == -12288 && s.Zi == 35092);
            }



            { // No system indexes = 4179  xz=10 @21, xz=100 @ 176,  x= 100 @ 1375, xz 100 @ 92 xz vacummed 76.
                System.Diagnostics.Debug.WriteLine("Begin Find Pos for 100");
                ISystem s;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 100; I++)
                {
                    s = SystemsDB.GetSystemByPosition(-100.7, 166.4, -36.8);
                    System.Diagnostics.Debug.Assert(s != null && s.Name == "Col 285 Sector IZ-B b15-2");
                    //  System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Pos for 100: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                ISystem s;
                s = SystemCache.FindSystem("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507") && s.EDDBID == 8856);
                s = SystemCache.FindSystem("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507") && s.EDDBID == 8856);
                s = SystemCache.FindSystem("Byua Eurk GL-Y d107");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Byua Eurk GL-Y d107") && s.X == -3555.5625 && s.Y == 119.25 && s.Z == 5478.59375);
                s = SystemCache.FindSystem("BD+18 711");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("BD+18 711") && s.Xi == 1700 && s.Yi == -68224 && s.Zi == -225284);
                s = SystemCache.FindSystem("Chamaeleon Sector FG-W b2-3");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Chamaeleon Sector FG-W b2-3") && s.Xi == 71440 && s.Yi == -12288 && s.Zi == 35092);
                s = SystemCache.FindSystem("kanur");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412 && s.EDDBID == 10442);
                s = SystemCache.FindSystem(s.EDSMID);
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412 && s.EDDBID == 10442);
                s = SystemCache.FindSystem("CM DRACO");     // this is an alias system
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("CM Draconis") && s.EDSMID == 19700);
            }

            {
                List <ISystem> slist;

                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("Tucanae Sector CQ-Y");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 20);
                    //System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard Standard trunced: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                BaseUtils.AppTicks.TickCountLap();
                List <ISystem> slist;
                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("HIP 6");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 48);
                    foreach (var e in slist)
                    {
                        System.Diagnostics.Debug.Assert(e.Name.StartsWith("HIP 6"));
                    }
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard HIP 6: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                BaseUtils.AppTicks.TickCountLap();
                List <ISystem> slist;
                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("USNO-A2.0 127");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 185);
                    foreach (var e in slist)
                    {
                        System.Diagnostics.Debug.Assert(e.Name.StartsWith("USNO-A2.0"));
                    }
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard USNo: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                List <ISystem> slist;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 1; I++)
                {
                    slist = SystemsDB.FindStarWildcard("HIP");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 48);
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard HIP: " + BaseUtils.AppTicks.TickCountLap());
            }
            {
                List <ISystem> slist;

                slist = SystemsDB.FindStarWildcard("Synuefai MC-H");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c12");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count == 0);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c12-");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);

                slist = SystemsDB.FindStarWildcard("HIP 6");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count > 5);

                slist = SystemsDB.FindStarWildcard("Coalsack Sector");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 4);

                slist = SystemsDB.FindStarWildcard("Coalsack");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 4);

                slist = SystemsDB.FindStarWildcard("4 S");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 1);

                slist = SystemsDB.FindStarWildcard("Beagle Point");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count == 1);
                ISystem bp = slist[0];
                slist = SystemsDB.FindAliasWildcard("Ceeckia ZQ-L C24-0");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count == 1 && bp.Name == slist[0].Name);
            }

            {   // xz index = 70ms
                BaseUtils.SortedListDoubleDuplicate <ISystem> list = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                BaseUtils.AppTicks.TickCountLap();
                double x = 0, y = 0, z = 0;

                SystemsDB.GetSystemListBySqDistancesFrom(list, x, y, z, 20000, 0.5, 20, true);
                System.Diagnostics.Debug.WriteLine("Stars Near Sol: " + BaseUtils.AppTicks.TickCountLap());
                System.Diagnostics.Debug.Assert(list != null && list.Count >= 20);

                //foreach (var k in list)   System.Diagnostics.Debug.WriteLine(Math.Sqrt(k.Key).ToString("N1") + " Star " + k.Value.ToStringVerbose());
            }

            { // xz index = 185ms
                BaseUtils.SortedListDoubleDuplicate <ISystem> list = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                BaseUtils.AppTicks.TickCountLap();
                double x = 490, y = 0, z = 0;

                SystemsDB.GetSystemListBySqDistancesFrom(list, x, y, z, 20000, 0.5, 50, true); //should span 2 grids 810/811
                System.Diagnostics.Debug.WriteLine("Stars Near x490: " + BaseUtils.AppTicks.TickCountLap());
                System.Diagnostics.Debug.Assert(list != null && list.Count >= 20);

                //foreach (var k in list) System.Diagnostics.Debug.WriteLine(Math.Sqrt(k.Key).ToString("N1") + " Star " + k.Value.ToStringVerbose());
            }

            { // 142ms with xz and no sector lookup
                BaseUtils.AppTicks.TickCountLap();
                ISystem s;
                s = SystemsDB.GetSystemNearestTo(new Point3D(100, 0, 0), new Point3D(1, 0, 0), 110, 20, SystemsDB.metric_waypointdev2);
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Sol"));
                System.Diagnostics.Debug.WriteLine("Find Nearest Star: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                SystemCache.AddToAutoCompleteList(new List <string>()
                {
                    "galone", "galtwo", "sol2"
                });
                List <string> sys;
                sys = SystemCache.ReturnSystemAutoCompleteList("Sol", null);
                System.Diagnostics.Debug.Assert(sys != null && sys.Contains("Sol") && sys.Count >= 5);
            }


            {
                uint[]    colours   = null;
                Vector3[] vertices  = null;
                uint[]    colours2  = null;
                Vector3[] vertices2 = null;

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(5, ref vertices, ref colours, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(vertices.Length > 10000);
                System.Diagnostics.Debug.WriteLine("5 load : " + BaseUtils.AppTicks.TickCountLap());

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices, ref colours, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.WriteLine("810 load 100 : " + BaseUtils.AppTicks.TickCountLap());


                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices2, ref colours2, 50, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(vertices.Length >= vertices2.Length * 2);
                System.Diagnostics.Debug.WriteLine("810 load 50 : " + BaseUtils.AppTicks.TickCountLap());

                int lengthall = vertices.Length;

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices, ref colours, ref vertices2, ref colours2, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(vertices.Length >= 20000);
                System.Diagnostics.Debug.Assert(vertices2.Length >= 300000);
                System.Diagnostics.Debug.Assert(vertices.Length + vertices2.Length == lengthall);
                System.Diagnostics.Debug.WriteLine("810 load dual : " + BaseUtils.AppTicks.TickCountLap());

                int pop   = vertices.Length;
                int unpop = vertices2.Length;

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices, ref colours, ref vertices2, ref colours2, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); }, SystemsDB.SystemAskType.PopulatedStars);
                System.Diagnostics.Debug.Assert(vertices.Length == pop);
                System.Diagnostics.Debug.Assert(vertices2 == null);
                System.Diagnostics.Debug.WriteLine("810 load pop : " + BaseUtils.AppTicks.TickCountLap());

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices, ref colours, ref vertices2, ref colours2, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); }, SystemsDB.SystemAskType.UnpopulatedStars);
                System.Diagnostics.Debug.Assert(vertices.Length == unpop);
                System.Diagnostics.Debug.Assert(vertices2 == null);
                System.Diagnostics.Debug.WriteLine("810 load unpop : " + BaseUtils.AppTicks.TickCountLap());
            }



            {
                var v = SystemsDB.GetStarPositions(5, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                //       var v2 = SystemClassDB.GetStarPositions(100, (x, y, z) => { return new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f); });
            }
        }
Exemplo n.º 22
0
 private void NewStarListComputed(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list) // In UI
 {
     System.Diagnostics.Debug.Assert(Application.MessageLoop);                                     // check!
     discoveryform.history.CalculateSqDistances(list, sys.X, sys.Y, sys.Z, maxitems, textMinRadius.Value, textMaxRadius.Value, true);
     FillPlot(list, sys);
 }
Exemplo n.º 23
0
        public TestSQLForm()
        {
            InitializeComponent();


            string edsminfile = @"c:\code\edsm\edsmsystems.10e6.json";
            bool   deletedb   = false;
            bool   reloadjson = false;

            bool printstars  = false;
            bool testdelete  = false;
            bool loadaliases = false;

            if (deletedb)
            {
                BaseUtils.FileHelpers.DeleteFileNoError(EliteDangerousCore.EliteConfigInstance.InstanceOptions.SystemDatabasePath);
            }

            SystemsDatabase.Instance.MaxThreads    = 8;
            SystemsDatabase.Instance.MinThreads    = 2;
            SystemsDatabase.Instance.MultiThreaded = true;
            SystemsDatabase.Instance.Initialize();
//            SQLiteConnectionSystem.UpgradeSystemTableFrom102TypeDB(() => { return false; }, (s) => System.Diagnostics.Debug.WriteLine(s),false);

            if (reloadjson)
            {
                SystemsDatabase.Instance.UpgradeSystemTableFromFile(edsminfile, null, () => false, (s) => System.Diagnostics.Debug.WriteLine(s));
            }


            if (printstars)
            {
                using (StreamWriter wr = new StreamWriter(@"c:\code\edsm\starlistout.lst"))
                {
                    SystemsDB.ListStars(orderby: "s.sectorid,s.edsmid", starreport: (s) =>
                    {
                        wr.WriteLine(s.Name + " " + s.Xi + "," + s.Yi + "," + s.Zi + ", EDSM:" + s.EDSMID + " Grid:" + s.GridID);
                    });
                }
            }

            if (testdelete)
            {
                SystemsDB.RemoveGridSystems(new int[] { 810, 911 });

                using (StreamWriter wr = new StreamWriter(@"c:\code\edsm\starlistout2.lst"))
                {
                    SystemsDB.ListStars(orderby: "s.sectorid,s.edsmid", starreport: (s) =>
                    {
                        wr.WriteLine(s.Name + " " + s.Xi + "," + s.Yi + "," + s.Zi + ", EDSM:" + s.EDSMID + " Grid:" + s.GridID);
                    });
                }
            }

            if (loadaliases)
            {
                string infile = @"c:\code\edsm\hiddensystems.jsonl";
                BaseUtils.AppTicks.TickCountLap();
                long updated = SystemsDB.ParseAliasFile(infile);
                System.Diagnostics.Debug.WriteLine("Alias Load: " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
                BaseUtils.AppTicks.TickCountLap();
                string infile2 = @"c:\code\edsm\hiddensystems2.jsonl";
                updated = SystemsDB.ParseAliasFile(infile2);
                System.Diagnostics.Debug.WriteLine("Alias Load: " + BaseUtils.AppTicks.TickCountLap() + " updated " + updated);
            }

            // ********************************************
            // TESTS BASED on the 10e6 json file
            // ********************************************

            {
                long aliasn;
                aliasn = SystemsDB.FindAlias(-1, "CM Draco");
                System.Diagnostics.Debug.Assert(aliasn == 19700);
                aliasn = SystemsDB.FindAlias(1, null);
                System.Diagnostics.Debug.Assert(aliasn == 19700);
                aliasn = SystemsDB.FindAlias(-1, "CM qwkqkq");
                System.Diagnostics.Debug.Assert(aliasn == -1);
                List <ISystem> aliaslist = SystemsDB.FindAliasWildcard("Horsehead");
                System.Diagnostics.Debug.Assert(aliaslist.Count > 10);
            }

            {
                BaseUtils.AppTicks.TickCountLap();
                ISystem s;

                for (int I = 0; I < 50; I++)              // 6/4/18 50 @ 38       (76 no index on systems)
                {
                    s = SystemsDB.FindStar("HIP 112535"); // this one is at the front of the DB
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 112535"));
                }

                System.Diagnostics.Debug.WriteLine("FindStar HIP x for X: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                ISystem s;

                BaseUtils.AppTicks.TickCountLap();
                string star = "HIP 101456";
                for (int I = 0; I < 50; I++)
                {
                    s = SystemsDB.FindStar(star);       // This one is at the back of the DB
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals(star));
                    //   System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Standard for X: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                ISystem s;

                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 50; I++)        // 6/4/18 50 @ 26ms (No need for system index)
                {
                    s = SystemsDB.FindStar("kanur");
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412);
                }

                System.Diagnostics.Debug.WriteLine("Find Kanur for X: " + BaseUtils.AppTicks.TickCountLap());
            }

            { // 16/4/18 100 @ 52ms  (48 no system tables)
                ISystem s;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 100; I++)
                {
                    s = SystemsDB.FindStar(2836547);
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Tucanae Sector SP-N b7-6") && s.Xi == 10844 && s.Yi == -18100 && s.Zi == 28036 && s.EDSMID == 2836547);
                }

                System.Diagnostics.Debug.WriteLine("Find EDSMID for 100: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                ISystem s;
                s = SystemsDB.FindStar("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507"));
                s = SystemsDB.FindStar("Byua Eurk GL-Y d107");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Byua Eurk GL-Y d107") && s.X == -3555.5625 && s.Y == 119.25 && s.Z == 5478.59375);
                s = SystemsDB.FindStar("BD+18 711");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("BD+18 711") && s.Xi == 1700 && s.Yi == -68224 && s.Zi == -225284);
                s = SystemsDB.FindStar("Chamaeleon Sector FG-W b2-3");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Chamaeleon Sector FG-W b2-3") && s.Xi == 71440 && s.Yi == -12288 && s.Zi == 35092);
            }



            { // No system indexes = 4179  xz=10 @21, xz=100 @ 176,  x= 100 @ 1375, xz 100 @ 92 xz vacummed 76.
                System.Diagnostics.Debug.WriteLine("Begin Find Pos for 100");
                ISystem s;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 100; I++)
                {
                    SystemsDatabase.Instance.DBRead(db =>
                    {
                        s = SystemsDB.GetSystemByPosition(-100.7, 166.4, -36.8, db);
                        System.Diagnostics.Debug.Assert(s != null && s.Name == "Col 285 Sector IZ-B b15-2");
                    });

                    //  System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Pos for 100: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                ISystem s;
                s = SystemCache.FindSystem("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507"));
                s = SystemCache.FindSystem("hip 91507");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("HIP 91507"));
                s = SystemCache.FindSystem("Byua Eurk GL-Y d107");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Byua Eurk GL-Y d107") && s.X == -3555.5625 && s.Y == 119.25 && s.Z == 5478.59375);
                s = SystemCache.FindSystem("BD+18 711");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("BD+18 711") && s.Xi == 1700 && s.Yi == -68224 && s.Zi == -225284);
                s = SystemCache.FindSystem("Chamaeleon Sector FG-W b2-3");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Chamaeleon Sector FG-W b2-3") && s.Xi == 71440 && s.Yi == -12288 && s.Zi == 35092);
                s = SystemCache.FindSystem("kanur");
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412);
                //s = SystemCache.FindSystem(s.EDSMID);
                //System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Kanur") && s.Xi == -2832 && s.Yi == -3188 && s.Zi == 12412);
                s = SystemCache.FindSystem("CM DRACO");     // this is an alias system
                System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("CM Draconis") && s.EDSMID == 19700);
            }

            {
                List <ISystem> slist;

                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("Tucanae Sector CQ-Y");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 20);
                    //System.Diagnostics.Debug.WriteLine("Lap : " + BaseUtils.AppTicks.TickCountLap());
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard Standard trunced: " + BaseUtils.AppTicks.TickCountLap());
            }


            {
                BaseUtils.AppTicks.TickCountLap();
                List <ISystem> slist;
                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("HIP 6");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 48);
                    foreach (var e in slist)
                    {
                        System.Diagnostics.Debug.Assert(e.Name.StartsWith("HIP 6"));
                    }
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard HIP 6: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                BaseUtils.AppTicks.TickCountLap();
                List <ISystem> slist;
                for (int I = 0; I < 10; I++)
                {
                    slist = SystemsDB.FindStarWildcard("USNO-A2.0 127");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 185);
                    foreach (var e in slist)
                    {
                        System.Diagnostics.Debug.Assert(e.Name.StartsWith("USNO-A2.0"));
                    }
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard USNo: " + BaseUtils.AppTicks.TickCountLap());
            }

            {
                List <ISystem> slist;
                BaseUtils.AppTicks.TickCountLap();

                for (int I = 0; I < 1; I++)
                {
                    slist = SystemsDB.FindStarWildcard("HIP");
                    System.Diagnostics.Debug.Assert(slist != null && slist.Count > 48);
                }

                System.Diagnostics.Debug.WriteLine("Find Wildcard HIP: " + BaseUtils.AppTicks.TickCountLap());
            }
            {
                List <ISystem> slist;

                slist = SystemsDB.FindStarWildcard("Synuefai MC-H");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c12");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count == 0);
                slist = SystemsDB.FindStarWildcard("Synuefai MC-H c12-");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 3);

                slist = SystemsDB.FindStarWildcard("HIP 6");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count > 5);

                slist = SystemsDB.FindStarWildcard("Coalsack Sector");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 4);

                slist = SystemsDB.FindStarWildcard("Coalsack");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 4);

                slist = SystemsDB.FindStarWildcard("4 S");
                System.Diagnostics.Debug.Assert(slist != null && slist.Count >= 1);
            }

            {   // xz index = 70ms
                BaseUtils.SortedListDoubleDuplicate <ISystem> list = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                BaseUtils.AppTicks.TickCountLap();
                double x = 0, y = 0, z = 0;

                SystemsDatabase.Instance.DBRead(db =>
                {
                    SystemsDB.GetSystemListBySqDistancesFrom(list, x, y, z, 20000, 0.5, 20, true, db);
                    System.Diagnostics.Debug.WriteLine("Stars Near Sol: " + BaseUtils.AppTicks.TickCountLap());
                    System.Diagnostics.Debug.Assert(list != null && list.Count >= 20);
                });

                //foreach (var k in list)   System.Diagnostics.Debug.WriteLine(Math.Sqrt(k.Key).ToString("N1") + " Star " + k.Value.ToStringVerbose());
            }

            { // xz index = 185ms
                BaseUtils.SortedListDoubleDuplicate <ISystem> list = new BaseUtils.SortedListDoubleDuplicate <ISystem>();

                BaseUtils.AppTicks.TickCountLap();
                double x = 490, y = 0, z = 0;

                SystemsDatabase.Instance.DBRead(db =>
                {
                    SystemsDB.GetSystemListBySqDistancesFrom(list, x, y, z, 20000, 0.5, 50, true, db); //should span 2 grids 810/811
                    System.Diagnostics.Debug.WriteLine("Stars Near x490: " + BaseUtils.AppTicks.TickCountLap());
                    System.Diagnostics.Debug.Assert(list != null && list.Count >= 20);
                });

                //foreach (var k in list) System.Diagnostics.Debug.WriteLine(Math.Sqrt(k.Key).ToString("N1") + " Star " + k.Value.ToStringVerbose());
            }

            { // 142ms with xz and no sector lookup
                SystemsDatabase.Instance.DBRead(db =>
                {
                    BaseUtils.AppTicks.TickCountLap();
                    ISystem s;
                    s = SystemsDB.GetSystemNearestTo(new Point3D(100, 0, 0), new Point3D(1, 0, 0), 110, 20, SystemsDB.SystemsNearestMetric.IterativeWaypointDevHalf, db);
                    System.Diagnostics.Debug.Assert(s != null && s.Name.Equals("Alpha Centauri"));
                    System.Diagnostics.Debug.WriteLine("Find Nearest Star: " + BaseUtils.AppTicks.TickCountLap());
                });
            }

            {
                SystemCache.AddToAutoCompleteList(new List <string>()
                {
                    "galone", "galtwo", "sol2"
                });
                List <string> sys;
                sys = SystemCache.ReturnSystemAutoCompleteList("Sol", null);
                System.Diagnostics.Debug.Assert(sys != null && sys.Contains("Solati") && sys.Count >= 4);
            }


            {
                uint[]    colours   = null;
                Vector3[] vertices  = null;
                uint[]    colours2  = null;
                Vector3[] vertices2 = null;

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(5, ref vertices, ref colours, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(vertices.Length > 1000);
                System.Diagnostics.Debug.WriteLine("5 load : " + BaseUtils.AppTicks.TickCountLap());

                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices, ref colours, 100, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.WriteLine("810 load 100 : " + BaseUtils.AppTicks.TickCountLap());


                BaseUtils.AppTicks.TickCountLap();
                SystemsDB.GetSystemVector(810, ref vertices2, ref colours2, 50, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(vertices.Length >= vertices2.Length * 2);
                System.Diagnostics.Debug.WriteLine("810 load 50 : " + BaseUtils.AppTicks.TickCountLap());
            }



            {
                var v = SystemsDB.GetStarPositions(5, (x, y, z) => { return(new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f)); });
                System.Diagnostics.Debug.Assert(v.Count > 450000);
                //       var v2 = SystemClassDB.GetStarPositions(100, (x, y, z) => { return new Vector3((float)x / 128.0f, (float)y / 128.0f, (float)z / 128.0f); });
            }
        }
Exemplo n.º 24
0
        private void FillPlot(BaseUtils.SortedListDoubleDuplicate <ISystem> csl, ISystem currentSystem)
        {
            SetControlText("");

            if (csl.Count() > 0)
            {
                SetControlText("2D Plot of systems in range from " + currentSystem.Name);

                // position the current system in the center of the references coordinates
                chartBubble.Series[0].Points.AddXY(0, 0, 4);
                chartBubble.Series[0].ToolTip = currentSystem.Name;
                chartBubble.Series[3].Points.AddXY(0, 0, 4);
                chartBubble.Series[3].ToolTip = currentSystem.Name;
                chartBubble.Series[6].Points.AddXY(0, 0, 4);
                chartBubble.Series[6].ToolTip = currentSystem.Name;

                // create a point for each system in range
                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    var inRangeSystem = tvp.Value;

                    if (tvp.Value.Name != currentSystem.Name && tvp.Value.Name != previousSystemName)
                    {
                        // get the coordinates of each system in range
                        var sysX = inRangeSystem.X;
                        var sysY = inRangeSystem.Y;
                        var sysZ = inRangeSystem.Z;

                        // get the coordinates of the current system, to properly calculate the distance
                        var curX = currentSystem.X;
                        var curY = currentSystem.Y;
                        var curZ = currentSystem.Z;

                        // calculate the distance
                        var distFromCurrentSys = Math.Round(Math.Sqrt(tvp.Key), 2, MidpointRounding.AwayFromZero);

                        // reset charts axis
                        chartBubble.ChartAreas[0].AxisY.IsStartedFromZero = false;
                        chartBubble.ChartAreas[1].AxisY.IsStartedFromZero = false;
                        chartBubble.ChartAreas[2].AxisY.IsStartedFromZero = false;
                        chartBubble.ChartAreas[0].AxisX.IsStartedFromZero = false;
                        chartBubble.ChartAreas[1].AxisX.IsStartedFromZero = false;
                        chartBubble.ChartAreas[2].AxisX.IsStartedFromZero = false;

                        // for a spherical distribution, do not count distances bigger than the selected radius
                        if (distFromCurrentSys > textMinRadius.Value)
                        {
                            // count the total visits for each system
                            int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);

                            // create the label for the tooltip
                            StringBuilder label = new StringBuilder();
                            label.Append(inRangeSystem.Name + " / " + visits + " visits" + "\n" + distFromCurrentSys);

                            // calculate the reference for each coordinate
                            double dx = curX - sysX;
                            double dy = curY - sysY;
                            double dz = curZ - sysZ;

                            // prepare the value to be displayed by the plot and fix the orientation
                            int px = Convert.ToInt32(dx) * -1;
                            int py = Convert.ToInt32(dy) * -1;
                            int pz = Convert.ToInt32(dz) * -1;

                            // visited systems go to series #1, #4 and #7; unvisited to series #2, #5 and #8.
                            // series #0, #3 and #6 is for the current system...

                            if (visits > 0)
                            {
                                // Top view
                                chartBubble.Series[1].Points.AddXY(px, py, pz);
                                chartBubble.Series[1].ToolTip = label.ToString();

                                // Front view
                                chartBubble.Series[4].Points.AddXY(px, pz, py);
                                chartBubble.Series[4].ToolTip = label.ToString();

                                // Side view
                                chartBubble.Series[7].Points.AddXY(py, pz, px);
                                chartBubble.Series[7].ToolTip = label.ToString();
                            }
                            else
                            {
                                // Top view
                                chartBubble.Series[2].Points.AddXY(px, py, pz);
                                chartBubble.Series[2].ToolTip = label.ToString();

                                // Front view
                                chartBubble.Series[5].Points.AddXY(px, pz, py);
                                chartBubble.Series[5].ToolTip = label.ToString();

                                // Side view
                                chartBubble.Series[8].Points.AddXY(py, pz, px);
                                chartBubble.Series[8].ToolTip = label.ToString();
                            }
                        }
                    }

                    if (tvp.Value.Name != currentSystem.Name && tvp.Value.Name == previousSystemName)
                    {
                        // Previous system coordinates, distances and label
                        int prevx = Convert.ToInt32(currentSystem.X - prevX) * -1;
                        int prevy = Convert.ToInt32(currentSystem.Y - prevY) * -1;
                        int prevz = Convert.ToInt32(currentSystem.Z - prevZ) * -1;

                        int visits             = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);
                        var distFromCurrentSys = Math.Round(Math.Sqrt(tvp.Key), 2, MidpointRounding.AwayFromZero);

                        StringBuilder label = new StringBuilder();
                        label.Append(previousSystemName + " / " + visits + " visits" + "\n" + distFromCurrentSys);

                        // Top view
                        chartBubble.Series[9].Points.AddXY(prevx, prevy, prevz);
                        chartBubble.Series[9].ToolTip = label.ToString();

                        // Front view
                        chartBubble.Series[10].Points.AddXY(prevx, prevz, prevy);
                        chartBubble.Series[10].ToolTip = label.ToString();

                        // Side view
                        chartBubble.Series[11].Points.AddXY(prevy, prevz, prevx);
                        chartBubble.Series[11].ToolTip = label.ToString();
                    }
                }
            }
        }
Exemplo n.º 25
0
        private void FillPlot(BaseUtils.SortedListDoubleDuplicate <ISystem> csl, ISystem currentSystem)
        {
            SetControlText(string.Format("2D Plot of systems in range from {0} ".Tx(this, "2d"), currentSystem.Name));

            const int pointSize = 4;

            // initializing the plot
            var modelTop   = new PlotModel {
            };
            var modelFront = new PlotModel {
            };
            var modelSide  = new PlotModel {
            };

            this.plotViewTop.Model   = modelTop;
            this.plotViewFront.Model = modelFront;
            this.plotViewSide.Model  = modelSide;

            modelTop.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelTop.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet, StartPosition = 1, EndPosition = -1
            });
            modelFront.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelFront.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet
            });
            modelSide.Axes.Add(new LinearAxis {
                Position = AxisPosition.Bottom, TicklineColor = OxyColors.BlueViolet
            });
            modelSide.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, TicklineColor = OxyColors.BlueViolet
            });

            // Define defaults properties of the series for the Top view
            var currentSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesTop = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Define defaults properties of the series for the Front view
            var currentSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesFront = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Define defaults properties of the series for the Side view
            var currentSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Red
            };
            var lastoneSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Purple
            };
            var inrangeSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Yellow
            };
            var visitedSeriesSide = new ScatterSeries {
                MarkerType = MarkerType.Circle, MarkerSize = pointSize, MarkerFill = OxyColors.Cyan
            };

            // Add the series
            modelTop.Series.Add(currentSeriesTop);
            modelTop.Series.Add(lastoneSeriesTop);
            modelTop.Series.Add(visitedSeriesTop);
            modelTop.Series.Add(inrangeSeriesTop);

            // Add the series
            modelFront.Series.Add(currentSeriesFront);
            modelFront.Series.Add(lastoneSeriesFront);
            modelFront.Series.Add(visitedSeriesFront);
            modelFront.Series.Add(inrangeSeriesFront);

            // Add the series
            modelSide.Series.Add(currentSeriesSide);
            modelSide.Series.Add(lastoneSeriesSide);
            modelSide.Series.Add(visitedSeriesSide);
            modelSide.Series.Add(inrangeSeriesSide);

            // titles
            modelTop.Title   = string.Format("Plot around {0}, viewed from the top".Tx(this, "PTOP"), currentSystemName);
            modelFront.Title = string.Format("Plot around {0}, viewed from the front".Tx(this, "PFRONT"), currentSystemName);
            modelSide.Title  = string.Format("Plot around {0}, viewed from the side".Tx(this, "PSIDE"), currentSystemName);

            // Title of the report
            reportView.Text += string.Format(("Systems around {0}, from {1} to {2}, Ly: {3}").Tx(this, "SysAROUND"), currentSystemName,
                                             textMinRadius.Value.ToString(), textMaxRadius.Value.ToString(), csl.Count.ToString());

            // Fill with some information for the report
            //reportView.AppendText("\nText " + currentSystem.some_value_interesting_to_report);
            reportView.Text += string.Format((Environment.NewLine + "    Visits: {0}").Tx(this, "Vs"), discoveryform.history.GetVisitsCount(currentSystem.Name, currentSystem.EDSMID));
            reportView.Text += string.Format((Environment.NewLine + "    Notes: {0}" + Environment.NewLine).Tx(this, "Nt"), currentSystem.SystemNote);

            // If the are any system inside the defined range...
            if (csl.Count() > 0)
            {
                // ...then iterate through each system in the list:
                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    // calculate the average distance;
                    var distFromCurrentSys = Math.Round(Math.Sqrt(tvp.Key), 2, MidpointRounding.AwayFromZero);

                    // count the total visits for each system;
                    int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);

                    // Then, populate the Grid with the systems in range
                    if (distFromCurrentSys >= textMinRadius.Value && distFromCurrentSys <= textMaxRadius.Value && tvp.Value.Name != currentSystemName)
                    {
                        // get the coordinates of each system in range;
                        var sysX = tvp.Value.X;
                        var sysY = tvp.Value.Y;
                        var sysZ = tvp.Value.Z;

                        // print information on each member of the list;
                        reportView.Text += string.Format((Environment.NewLine + "{0} distance {1:N2} Ly").Tx(this, "D1"), tvp.Value.Name.ToString(), distFromCurrentSys);
                        reportView.Text += string.Format((Environment.NewLine + "    Visits: {0}").Tx(this, "D2"), visits.ToString());
                        reportView.Text += string.Format((Environment.NewLine + "    Coordinates: X:{0:N2}, Y:{1:N2}, Z:{2:N2}" + Environment.NewLine).Tx(this, "D3"), sysX, sysY, sysZ);

                        // Create the list, with each system's name, distances by x, y and z coordinates and number of visits
                        object[] value = { tvp.Value.Name, $"{sysX:0.00}", $"{sysY:0.00}", $"{sysZ:0.00}", $"{visits:n0}" };
                        var      i     = dataGridList.Rows.Add(value);
                        dataGridList.Rows[i].Tag = tvp.Value;

                        var seriesTop   = inrangeSeriesTop;
                        var seriesFront = inrangeSeriesFront;
                        var seriesSide  = inrangeSeriesSide;

                        // Assign each system to the correct color and series, depending of its state:
                        // visited; lastone; inrange (not visited).
                        if (visits > 0)
                        {
                            // is visited
                            if (tvp.Value.Name != previousSystemName)
                            {
                                seriesTop   = visitedSeriesTop;
                                seriesFront = visitedSeriesFront;
                                seriesSide  = visitedSeriesSide;
                            }
                            // is visited, and is the last visited system
                            else if (tvp.Value.Name == previousSystemName)
                            {
                                seriesTop   = lastoneSeriesTop;
                                seriesFront = lastoneSeriesFront;
                                seriesSide  = lastoneSeriesSide;
                            }
                        }
                        else
                        // is not visited yet
                        {
                            seriesTop   = inrangeSeriesTop;
                            seriesFront = inrangeSeriesFront;
                            seriesSide  = inrangeSeriesSide;
                        }
                        //

                        // Draw each point in the Plot
                        seriesTop.Points.Add(new ScatterPoint(Convert.ToDouble(value[1]), Convert.ToDouble(value[2]), pointSize, Convert.ToDouble(value[3]), value[0]));
                        seriesFront.Points.Add(new ScatterPoint(Convert.ToDouble(value[1]), Convert.ToDouble(value[3]), pointSize, Convert.ToDouble(value[2]), value[0]));
                        seriesSide.Points.Add(new ScatterPoint(Convert.ToDouble(value[2]), Convert.ToDouble(value[3]), pointSize, Convert.ToDouble(value[1]), value[0]));

                        // Create a tracker which shows the name of the system and its coordinates
                        const string trackerTop   = "{Tag}\n" + "X: {2:0.###}; Y: {4:0.###}; Z: {6:0.###}";
                        const string trackerFront = "{Tag}\n" + "X: {2:0.###}; Z: {4:0.###}; Y: {6:0.###}";
                        const string trackerSide  = "{Tag}\n" + "Y: {2:0.###}; Z: {4:0.###}; X: {6:0.###}";

                        seriesTop.TrackerFormatString   = trackerTop;
                        seriesFront.TrackerFormatString = trackerFront;
                        seriesSide.TrackerFormatString  = trackerSide;
                    }

                    currentSeriesTop.Points.Add(new ScatterPoint(currentSystem.X, currentSystem.Y, pointSize, currentSystem.Z, currentSystemName));
                    currentSeriesFront.Points.Add(new ScatterPoint(currentSystem.X, currentSystem.Z, pointSize, currentSystem.Y, currentSystemName));
                    currentSeriesSide.Points.Add(new ScatterPoint(currentSystem.Y, currentSystem.Z, pointSize, currentSystem.X, currentSystemName));

                    const string currentTrackerTop   = "{Tag}\n" + "X: {2:0.###}; Y: {4:0.###}; Z: {6:0.###}";
                    const string currentTrackerFront = "{Tag}\n" + "X: {2:0.###}; Z: {4:0.###}; Y: {6:0.###}";
                    const string currentTrackerSide  = "{Tag}\n" + "Y: {2:0.###}; Z: {4:0.###}; X: {6:0.###}";

                    currentSeriesTop.TrackerFormatString   = currentTrackerTop;
                    currentSeriesFront.TrackerFormatString = currentTrackerFront;
                    currentSeriesSide.TrackerFormatString  = currentTrackerSide;
                }

                // End of the Report
                reportView.Text += Environment.NewLine + Environment.NewLine + " @ " + DateTime.Now.ToString();
            }
        }
Exemplo n.º 26
0
        private void FillRadar(BaseUtils.SortedListDoubleDuplicate <ISystem> csl, ISystem centerSystem)
        {
            SetControlText("");

            if (csl.Count() > 0)
            {
                SetControlText("2D Plot of systems in range from " + centerSystem.Name);

                chartBubble.Series[0].Points.AddXY(0, 0, 4);
                chartBubble.Series[0].ToolTip = centerSystem.Name;
                chartBubble.Series[3].Points.AddXY(0, 0, 4);
                chartBubble.Series[3].ToolTip = centerSystem.Name;
                chartBubble.Series[6].Points.AddXY(0, 0, 4);
                chartBubble.Series[6].ToolTip = centerSystem.Name;

                foreach (KeyValuePair <double, ISystem> tvp in csl)
                {
                    if (tvp.Value.Name != centerSystem.Name)
                    {
                        var theISystemInQuestion = tvp.Value;
                        var sysX = theISystemInQuestion.X;
                        var sysY = theISystemInQuestion.Y;
                        var sysZ = theISystemInQuestion.Z;
                        var distFromCurrentSys = Math.Round(Math.Sqrt(tvp.Key), 2, MidpointRounding.AwayFromZero);
                        var curX = centerSystem.X;
                        var curY = centerSystem.Y;
                        var curZ = centerSystem.Z;

                        // reset charts axis
                        chartBubble.ChartAreas[0].AxisY.IsStartedFromZero = false;
                        chartBubble.ChartAreas[1].AxisY.IsStartedFromZero = false;
                        chartBubble.ChartAreas[2].AxisY.IsStartedFromZero = false;

                        chartBubble.ChartAreas[0].AxisX.IsStartedFromZero = false;
                        chartBubble.ChartAreas[1].AxisX.IsStartedFromZero = false;
                        chartBubble.ChartAreas[2].AxisX.IsStartedFromZero = false;


                        if (distFromCurrentSys > textMinRadius.Value)
                        {
                            int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID);

                            StringBuilder label = new StringBuilder();
                            label.Append(theISystemInQuestion.Name + " / " + visits + " visits" + "\n" + distFromCurrentSys);

                            double dx = curX - sysX;
                            double dy = curY - sysY;
                            double dz = curZ - sysZ;

                            int px = Convert.ToInt32(dx) * -1;
                            int py = Convert.ToInt32(dy);
                            int pz = Convert.ToInt32(dz);

                            // visited systems go to series #1, #4 and #7; unvisited to series #2, #5 and #8.
                            // Serie #0, #3 and #6 is for the current system...

                            if (visits > 0)
                            {
                                chartBubble.Series[1].Points.AddXY(px, py, pz);
                                chartBubble.Series[1].ToolTip = label.ToString();

                                chartBubble.Series[4].Points.AddXY(px, pz, py);
                                chartBubble.Series[4].ToolTip = label.ToString();

                                chartBubble.Series[7].Points.AddXY(py, pz, px);
                                chartBubble.Series[7].ToolTip = label.ToString();
                            }
                            else
                            {
                                chartBubble.Series[2].Points.AddXY(px, py, pz);
                                chartBubble.Series[2].ToolTip = label.ToString();

                                chartBubble.Series[5].Points.AddXY(px, pz, py);
                                chartBubble.Series[5].ToolTip = label.ToString();

                                chartBubble.Series[8].Points.AddXY(py, pz, px);
                                chartBubble.Series[8].ToolTip = label.ToString();
                            }
                        }
                    }
                }
            }
        }