Ejemplo n.º 1
0
        /// <summary>
        /// Check that all route's breaks can be visited.
        /// For invalid breaks add error messages.
        /// </summary>
        /// <param name="tripTimeRange">Trip start time window.</param>
        /// <rereturns>'True' if all breaks can be visited, 'false' otherwise.</rereturns>
        private bool _CheckBreaksCanBeVisited(TimeRange tripTimeRange)
        {
            var result = true;

            // Prepare breaks for validation.
            Breaks sortedBreaks = _GetSortedBreaks();

            // Collection with breaks, which cannot be completed at time.
            Breaks invalidBreaks = new Breaks();

            // Check that all breaks can be completed in time.
            for (int i = 0; i < sortedBreaks.Count; i++)
            {
                TimeWindowBreak breakToCheck = sortedBreaks[i] as TimeWindowBreak;

                // Try to calculate break start.
                var breakStart = tripTimeRange.Intersection(breakToCheck.EffectiveFrom,
                                                            breakToCheck.EffectiveTo);

                // If break cannot be started - it is invalid. Check next break.
                if (breakStart == null)
                {
                    invalidBreaks.Add(breakToCheck);
                }
                // Check that break can be finished.
                else
                {
                    // Try calculate break finish.
                    var breakFinish = breakStart.Shift(TimeSpan.FromMinutes(breakToCheck.Duration));
                    breakFinish = breakFinish.Intersection(tripTimeRange);

                    // If break cannot be finished - it is invalid.
                    if (breakFinish == null)
                    {
                        invalidBreaks.Add(breakToCheck);
                    }
                }
            }

            // If there was invalid breaks - show error messages.
            if (invalidBreaks.Count != 0)
            {
                _AddErrorMessages(invalidBreaks);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 2
0
 public TaxTable()
 {
     Breaks.Add(150);
     Breaks.Add(350);
     Percents.Add(.1);
     Percents.Add(.2);
     Percents.Add(.3);
 }
Ejemplo n.º 3
0
        private async Task AddBreakExecuteAsync()
        {
            var newBreak = new Break
            {
                StartBreakTime = DateTime.Now.TimeOfDay.TotalMinutes,
                EndBreakTime   = DateTime.Now.TimeOfDay.TotalMinutes,
                TimeAccount    = _currentAccounting
            };

            if (!_currentAccounting.IsClosed)
            {
                _timeAccountingContext.Breaks.Add(newBreak);
                await _timeAccountingContext.SaveChangesAsync()
                .ConfigureAwait(false);
            }
            else
            {
                Breaks.Add(newBreak);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the raster breaks.
        /// </summary>
        public void UpdateRasterBreaks()
        {
            if (_rasterLayer == null)
            {
                return;
            }
            IColorCategory selectedBrk = null;

            if (_selectedSlider != null)
            {
                selectedBrk = _selectedSlider.Category as IColorCategory;
            }
            Breaks.Clear();
            Statistics stats = _rasterSymbolizer.Scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IColorCategory category in _rasterSymbolizer.Scheme.Categories)
            {
                ColorRange cr = new ColorRange(category.LowColor, category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr)
                {
                    Color       = _breakColor,
                    SelectColor = _selectedBreakColor
                };
                if (selectedBrk != null && category == selectedBrk)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }

                bs.Value = category.Maximum != null?double.Parse(category.Maximum.ToString()) : stats.Maximum;

                bs.Category = category;
                Breaks.Add(bs);
            }

            Breaks.Sort();

            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < Breaks.Count - 1; i++)
            {
                Breaks[i].NextCategory = Breaks[i + 1].Category;

                // We use the maximums to set up breaks. Minimums should simply
                // be set to work with the maximums of the previous category.
                // _breaks[i + 1].Category.Minimum = _breaks[i].Value; REMOVED BY jany_ (2015-07-07) Don't set minimum, because that changes the minimum of the rasters category which causes the colors to change when saving in RasterColorControl without making changes or for example only applying opacity without wanting to use statistics.
            }

            if (Breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = Breaks[breakIndex];
            int         count      = 0;

            if (_graph?.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }

                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= Breaks.Count)
                    {
                        break;
                    }

                    nextSlider = Breaks[breakIndex];
                }

                count = 0;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Given a scheme, this will build the break list to match approximately. This does not
        /// force the interval method to build a new scheme.
        /// </summary>
        public void UpdateBreaks()
        {
            if (_isRaster)
            {
                UpdateRasterBreaks();
                return;
            }

            if (_scheme == null)
            {
                return;
            }
            IFeatureCategory selectedCat = null;

            if (_selectedSlider != null)
            {
                selectedCat = _selectedSlider.Category as IFeatureCategory;
            }
            Breaks.Clear();
            Statistics stats = _scheme.Statistics;
            Rectangle  gb    = _graph.GetGraphBounds();

            _graph.ColorRanges.Clear();
            foreach (IFeatureCategory category in _scheme.GetCategories())
            {
                ColorRange cr = new ColorRange(category.GetColor(), category.Range);
                _graph.ColorRanges.Add(cr);
                BreakSlider bs = new BreakSlider(gb, _graph.Minimum, _graph.Maximum, cr)
                {
                    Color       = _breakColor,
                    SelectColor = _selectedBreakColor
                };
                if (selectedCat != null && category == selectedCat)
                {
                    bs.Selected          = true;
                    _selectedSlider      = bs;
                    _graph.SelectedRange = cr;
                }

                bs.Value = category.Maximum != null?double.Parse(category.Maximum.ToString()) : stats.Maximum;

                bs.Category = category;
                Breaks.Add(bs);
            }

            Breaks.Sort();

            // Moving a break generally affects both a maximum and a minimum.
            // Point to the next category to actuate that.
            for (int i = 0; i < Breaks.Count - 1; i++)
            {
                Breaks[i].NextCategory = Breaks[i + 1].Category;

                // We use the maximums to set up breaks. Minimums should simply
                // be set to work with the maximums of the previous category.
                Breaks[i + 1].Category.Minimum = Breaks[i].Value;
            }

            if (Breaks.Count == 0)
            {
                return;
            }
            int         breakIndex = 0;
            BreakSlider nextSlider = Breaks[breakIndex];
            int         count      = 0;

            if (_graph?.Bins == null)
            {
                return;
            }
            foreach (double value in _values)
            {
                if (value < nextSlider.Value)
                {
                    count++;
                    continue;
                }

                nextSlider.Count = count;
                while (value > nextSlider.Value)
                {
                    breakIndex++;
                    if (breakIndex >= Breaks.Count)
                    {
                        break;
                    }

                    nextSlider = Breaks[breakIndex];
                }

                count = 0;
            }
        }
Ejemplo n.º 6
0
        public override void Match(string line)
        {
            if (line.StartsWith("//"))
            {
                var section = line.Trim();
                switch (section)
                {
                case SectionBgVideo:
                    _currentSection = SectionBgVideo;
                    break;

                case SectionBreak:
                    _currentSection = SectionBreak;
                    break;

                case SectionSbSamples:
                    if (!_options.StoryboardIgnored)
                    {
                        ElementGroup = ElementGroup.ParseFromText(_sbInfo.ToString().Trim('\r', '\n'));
                    }
                    _currentSection = SectionSbSamples;
                    break;

                default:
                    if (section.StartsWith(SectionStoryboard))
                    {
                        _currentSection = SectionStoryboard;
                        _sbInfo.AppendLine(line);
                    }
                    else
                    {
                        _currentSection = section;
                        _unknownSection.Add(section, new StringBuilder());
                    }
                    break;
                }
            }
            else
            {
                switch (_currentSection)
                {
                case SectionBgVideo:
                    // https://osu.ppy.sh/help/wiki/osu!_File_Formats/Osu_(file_format)#videos
                    if (line.StartsWith("Video,") || line.StartsWith("1,"))
                    {
                        var infos = line.Split(',');
                        VideoInfo = new VideoData {
                            Offset = double.Parse(infos[1]), Filename = infos[2].Trim('"')
                        };
                    }
                    else
                    {
                        var    infos = line.Split(',');
                        double x = 0, y = 0;
                        if (infos.Length > 3)
                        {
                            x = double.Parse(infos[3]);
                            y = double.Parse(infos[4]);
                        }

                        BackgroundInfo = new BackgroundData
                        {
                            Unknown1 = infos[0],
                            Unknown2 = infos[1],
                            Filename = infos[2].Trim('"'),
                            X        = x,
                            Y        = y
                        };
                    }
                    break;

                case SectionBreak:
                {
                    var infos = line.Split(',');
                    Breaks.Add(new RangeValue <int>(int.Parse(infos[1]), int.Parse(infos[2])));
                }
                break;

                case SectionSbSamples:
                    if (!_options.SampleIgnored)
                    {
                        if (line.StartsWith("Sample,") || line.StartsWith("5,"))
                        {
                            var infos = line.Split(',');
                            SampleInfo.Add(new StoryboardSampleData
                            {
                                Offset     = int.Parse(infos[1]),
                                MagicalInt = int.Parse(infos[2]),
                                Filename   = infos[3].Trim('"'),
                                Volume     = infos.Length > 4 ? int.Parse(infos[4]) : 0,
                            });
                        }
                    }
                    break;

                case SectionStoryboard:
                    if (!_options.StoryboardIgnored)
                    {
                        _sbInfo.AppendLine(line);
                    }
                    break;

                default:
                    _unknownSection[_currentSection].AppendLine(line);
                    break;
                }
            }
        }
Ejemplo n.º 7
0
 public void AddBreak(TvBreak @break)
 {
     Breaks.Add(@break);
 }
 public override void VisitBreakStatement(BreakStatement node)
 {
     Breaks.Add(node);
     return;
 }