Example #1
0
 public void AddPoints(IEnumerable <XY> points)
 {
     foreach (var point in points.Where(point => Points.All(p => p.N != point.N)))
     {
         Points.Add(point);
     }
 }
Example #2
0
        public bool ReadChar(ref int x, int y)
        {
            int _x = x;

            for (int i = 0; i < Loops; i++)
            {
                if (Points.All(pt => pt.CheckFrom(_x + i, y)))
                {
                    x += Width + i;
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
            public Rectangle?CalculateRegion()
            {
                if (Region != null)
                {
                    return((Rectangle)Region);
                }
                else if (Points.All(p => p != null) && Points[0] != Points[1])
                {
                    Rectangle rec         = new Rectangle();
                    var       firstPoint  = Points[0].Value;
                    var       secondPoint = Points[1].Value;

                    if (firstPoint.X < secondPoint.X &&
                        firstPoint.Y < secondPoint.Y)
                    {
                        rec.X      = firstPoint.X;
                        rec.Y      = firstPoint.Y;
                        rec.Width  = secondPoint.X - firstPoint.X;
                        rec.Height = secondPoint.Y - firstPoint.Y;
                    }
                    else if (firstPoint.X > secondPoint.X &&
                             firstPoint.Y < secondPoint.Y)
                    {
                        rec.X      = secondPoint.X;
                        rec.Y      = firstPoint.Y;
                        rec.Width  = firstPoint.X - secondPoint.X;
                        rec.Height = secondPoint.Y - firstPoint.Y;
                    }
                    else if (firstPoint.X < secondPoint.X &&
                             firstPoint.Y > secondPoint.Y)
                    {
                        rec.X      = firstPoint.X;
                        rec.Y      = secondPoint.Y;
                        rec.Width  = secondPoint.X - firstPoint.X;
                        rec.Height = firstPoint.Y - secondPoint.Y;
                    }
                    else if (firstPoint.X > secondPoint.X &&
                             firstPoint.Y > secondPoint.Y)
                    {
                        rec.X      = secondPoint.X;
                        rec.Y      = secondPoint.Y;
                        rec.Width  = firstPoint.X - secondPoint.X;
                        rec.Height = firstPoint.Y - secondPoint.Y;
                    }
                    return(rec);
                }

                return(null);
            }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TheoremObjectWithPoints"/> class
        /// defined by <see cref="NumberOfDefiningPoints"/> points.
        /// </summary>
        /// <param name="points">The points defining this object.</param>
        protected TheoremObjectWithPoints(params ConfigurationObject[] points)
        {
            // Set the points
            Points = points?.ToReadOnlyHashSet() ?? throw new ArgumentNullException(nameof(points));

            // Set the points list
            PointsList = points;

            // Make sure there count fits
            if (Points.Count != NumberOfDefiningPoints)
            {
                throw new GeoGenException($"The {GetType()} must have {NumberOfDefiningPoints} points, but has {Points.Count}.");
            }

            // Make sure they're points
            if (!Points.All(point => point.ObjectType == ConfigurationObjectType.Point))
            {
                throw new GeoGenException("The passed object must be points");
            }
        }
        public void AppendPoints()
        {
            Log.Info(Context.ExecutingFileVersion);

            (Points, Notes) = GetPoints();

            AdjustNotes();

            if (Points.All(p => p.Type != PointType.Gap))
            {
                Points = Points
                         .OrderBy(p => p.Time)
                         .ToList();
            }

            ThrowIfInvalidGapInterval();

            AdjustGradesAndQualifiers(Points);

            if (!string.IsNullOrEmpty(Context.SaveCsvPath))
            {
                new CsvWriter(Context)
                .WritePoints(Points, Notes);

                if (Context.StopAfterSavingCsv)
                {
                    return;
                }
            }

            Log.Info($"Connecting to {Context.Server} ...");

            using (var client = CreateConnectedClient())
            {
                Log.Info($"Connected to {Context.Server} ({client.ServerVersion})");

                ThrowIfGapsNotSupported(client);

                if (Context.CreateMode != CreateMode.Never)
                {
                    new TimeSeriesCreator
                    {
                        Context = Context,
                        Client  = client
                    }.CreateMissingTimeSeries(Context.TimeSeries);
                }

                var timeSeries = client.GetTimeSeriesInfo(Context.TimeSeries);

                var isReflected  = Context.Command == CommandType.Reflected || timeSeries.TimeSeriesType == TimeSeriesType.Reflected;
                var hasTimeRange = isReflected || DeleteCommands.Contains(Context.Command) || Context.Command == CommandType.OverwriteAppend;

                if (hasTimeRange)
                {
                    var timeRange = GetTimeRange();

                    if (Notes.Any(note => note.TimeRange != null && (!timeRange.Contains(note.TimeRange.Value.Start) ||
                                                                     !timeRange.Contains(note.TimeRange.Value.End))))
                    {
                        throw new ExpectedException($"All notes to append must be completely within the {timeRange} interval.");
                    }
                }

                Log.Info(Context.Command == CommandType.DeleteAllPoints
                    ? $"Deleting all existing points from {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                    : hasTimeRange
                        ? $"Appending {PointSummarizer.Summarize(Points)} and {"note".ToQuantity(Notes.Count)} within TimeRange={GetTimeRange()} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ..."
                        : $"Appending {PointSummarizer.Summarize(Points)} and {"note".ToQuantity(Notes.Count)} to {timeSeries.Identifier} ({timeSeries.TimeSeriesType}) ...");

                var numberOfPointsAppended = 0;
                var numberOfPointsDeleted  = 0;
                var numberOfNotesAppended  = 0;
                var numberOfNotesDeleted   = 0;
                var stopwatch = Stopwatch.StartNew();

                var pointBatches = GetPointBatches(Points).ToList();
                var isBatched    = pointBatches.Count > 1;
                var batchIndex   = 1;

                foreach (var batch in pointBatches)
                {
                    if (isBatched)
                    {
                        var batchSummary =
                            $"Appending batch #{batchIndex}: {PointSummarizer.Summarize(batch.Points)}";

                        Log.Info(hasTimeRange
                            ? $"{batchSummary} within TimeRange={batch.TimeRange} ..."
                            : $"{batchSummary} ...");
                    }

                    var result = AppendPointBatch(client, timeSeries, batch.Points, batch.TimeRange, isReflected, hasTimeRange);
                    numberOfPointsAppended += result.NumberOfPointsAppended;
                    numberOfPointsDeleted  += result.NumberOfPointsDeleted;
                    ++batchIndex;

                    if (!ValidStatusCodesByWaitMode[Context.Wait].Contains(result.AppendStatus))
                    {
                        throw new ExpectedException($"Unexpected append status={result.AppendStatus}");
                    }
                }

                if (DeleteCommands.Contains(Context.Command))
                {
                    numberOfNotesDeleted += DeleteNotesWithinTimeRange(client, timeSeries, GetTimeRange());
                }
                else
                {
                    numberOfNotesAppended += AppendNotes(client, timeSeries);
                }

                var batchText = isBatched ? $" using {"append".ToQuantity(pointBatches.Count)}" : "";
                var waitText  = Context.Wait ? string.Empty : " (without waiting for appends to complete)";

                Log.Info($"Appended {"point".ToQuantity(numberOfPointsAppended)} and {"note".ToQuantity(numberOfNotesAppended)} (deleting {"point".ToQuantity(numberOfPointsDeleted)} and {"note".ToQuantity(numberOfNotesDeleted)}) in {stopwatch.ElapsedMilliseconds / 1000.0:F1} seconds{batchText}{waitText}.");
            }
        }
Example #6
0
 protected bool Equals(Fighter other)
 {
     return(Points.All(other.Points.Contains) && Points.Count == other.Points.Count && string.Equals(Id, other.Id));
 }