Ejemplo n.º 1
0
        void Command_Select_Invert()
        {
            var start = new[] { 0 }.Concat(Selections.Select(sel => sel.End));
            var end = Selections.Select(sel => sel.Start).Concat(new[] { Data.NumChars });

            SetSelections(Enumerable.Zip(start, end, (startPos, endPos) => new Range(endPos, startPos)).Where(range => (range.HasSelection) || ((range.Start != 0) && (range.Start != Data.NumChars))).ToList());
        }
        void Command_Position_Copy(GotoType gotoType, bool withLine)
        {
            var starts = new Dictionary <GotoType, List <int> >();
            var ends   = new Dictionary <GotoType, List <int> >();

            var count = Selections.Count;

            starts[GotoType.Position] = Selections.Select(range => range.Start).ToList();
            ends[GotoType.Position]   = Selections.Select(range => range.End).ToList();

            if ((gotoType == GotoType.Line) || (gotoType == GotoType.Column) || (gotoType == GotoType.Index))
            {
                starts[GotoType.Line] = starts[GotoType.Position].Select(pos => Data.GetOffsetLine(pos)).ToList();
                ends[GotoType.Line]   = ends[GotoType.Position].Select(pos => Data.GetOffsetLine(pos)).ToList();
            }

            if ((gotoType == GotoType.Column) || (gotoType == GotoType.Index))
            {
                starts[GotoType.Index] = Enumerable.Range(0, count).Select(x => Data.GetOffsetIndex(starts[GotoType.Position][x], starts[GotoType.Line][x])).ToList();
                ends[GotoType.Index]   = Enumerable.Range(0, count).Select(x => Data.GetOffsetIndex(ends[GotoType.Position][x], ends[GotoType.Line][x])).ToList();

                if (gotoType == GotoType.Column)
                {
                    starts[GotoType.Column] = Enumerable.Range(0, count).Select(x => Data.GetColumnFromIndex(starts[GotoType.Line][x], starts[GotoType.Index][x])).ToList();
                    ends[GotoType.Column]   = Enumerable.Range(0, count).Select(x => Data.GetColumnFromIndex(ends[GotoType.Line][x], ends[GotoType.Index][x])).ToList();
                }
            }

            var delta = gotoType == GotoType.Position ? 0 : 1;

            SetClipboardStrings(Enumerable.Range(0, count).Select(index => $"{(withLine ? $"{starts[GotoType.Line][index] + 1}:" : "")}{starts[gotoType][index] + delta}{(starts[GotoType.Position][index] != ends[GotoType.Position][index] ? $"-{((withLine) && (starts[GotoType.Line][index] != ends[GotoType.Line][index]) ? $"{ends[GotoType.Line][index] + 1}:" : "")}{ends[gotoType][index] + delta}" : "")}"));
        }
Ejemplo n.º 3
0
 protected override void ShowMenu(Point coords)
 {
     if (ShowMenuEvent != null)
     {
         List <LMTimelineEvent> plays = Selections.Select(p => (p.Drawable as TimelineEventLocationView).ViewModel.Model).ToList();
         ShowMenuEvent(plays);
     }
 }
        void Command_Numeric_Series_LinearGeometric(NumericSeriesDialog.Result result, bool linear)
        {
            var variables = GetVariables();
            var start     = new NEExpression(result.StartExpression).Evaluate <double>(variables);
            var increment = new NEExpression(result.IncrementExpression).Evaluate <double>(variables);

            ReplaceSelections(Selections.Select((range, index) => (linear ? start + increment * index : start *Math.Pow(increment, index)).ToString()).ToList());
        }
Ejemplo n.º 5
0
 protected override void ShowMenu(Point coords)
 {
     if (ShowMenuEvent != null)
     {
         List <TimelineEvent> plays = Selections.Select(p => (p.Drawable as PositionObject).Play).ToList();
         ShowMenuEvent(plays);
     }
 }
Ejemplo n.º 6
0
        void ShowPeriodsMenu(Point coords)
        {
            TimerVM t = Selections.Select(p => (p.Drawable as TimerTimeNodeView).Timer).FirstOrDefault();

            if (ShowPeriodsMenuEvent != null)
            {
                ShowPeriodsMenuEvent(t?.Model, Utils.PosToTime(coords, SecondsPerPixel));
            }
        }
Ejemplo n.º 7
0
        protected void ShowTimersMenu(Point coords)
        {
            List <TimeNodeVM> nodes = Selections.Select(p => (p.Drawable as TimeNodeView).TimeNode).ToList();

            if (nodes.Count > 0 && ShowTimersMenuEvent != null)
            {
                ShowTimersMenuEvent(nodes.Select(n => n.Model).ToList());
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Deletes the current selection from the frame drawing.
 /// </summary>
 public void DeleteSelection()
 {
     foreach (ICanvasDrawableObject o in Selections.Select(s => s.Drawable))
     {
         RemoveObject(o);
         drawing.Drawables.Remove((Drawable)o.IDrawableObject);
     }
     ClearSelection();
     UpdateCounters();
     widget.ReDraw();
 }
Ejemplo n.º 9
0
        void Command_Text_Select_MinMax_Length(bool max)
        {
            if (!Selections.Any())
            {
                throw new Exception("No selections");
            }

            var lengths = Selections.Select(range => range.Length).ToList();
            var find    = max ? lengths.OrderByDescending().First() : lengths.OrderBy().First();

            SetSelections(lengths.Indexes(length => length == find).Select(index => Selections[index]).ToList());
        }
Ejemplo n.º 10
0
        protected void ShowPlaysMenu(Point coords, EventTypeTimelineView catTimeline)
        {
            EventType ev = null;
            List <TimelineEventVM> plays;

            plays = Selections.Select(p => (p.Drawable as TimelineEventView).TimelineEvent).ToList();

            ev = catTimeline.ViewModel.EventTypeVM.Model;
            if (ev != null && ShowMenuEvent != null)
            {
                ShowMenuEvent(plays, ev, Utils.PosToTime(coords, SecondsPerPixel));
            }
        }
Ejemplo n.º 11
0
        void ShowPlaysMenu(Point coords, CategoryTimeline catTimeline)
        {
            EventType            ev = null;
            List <TimelineEvent> plays;

            plays = Selections.Select(p => (p.Drawable as TimelineEventObject).Event).ToList();

            ev = eventsTimelines.GetKeyByValue(catTimeline);
            if (ev != null && ShowMenuEvent != null)
            {
                ShowMenuEvent(plays, ev, Utils.PosToTime(coords, SecondsPerPixel));
            }
        }
Ejemplo n.º 12
0
        public AccessibilityResource DisableUnsupportedBraille(IEnumerable <string> supportedCodes)
        {
            if (ResourceCode != "BrailleType")
            {
                return(this);
            }

            var newSelections = Selections
                                .Select(s => s.WithDisabled(!supportedCodes
                                                            .Any(c => (c == s.SelectionCode && !s.Disabled) || s.SelectionCode == "TDS_BT0"))
                                        ).ToImmutableArray();

            return(WithSelections(newSelections));
        }
Ejemplo n.º 13
0
        void Command_Select_Repeats_ByCount(SelectByCountDialog.Result result)
        {
            var strs   = Selections.Select((range, index) => Tuple.Create(GetString(range), index)).ToList();
            var counts = new Dictionary <string, int>(result.CaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);

            foreach (var tuple in strs)
            {
                if (!counts.ContainsKey(tuple.Item1))
                {
                    counts[tuple.Item1] = 0;
                }
                ++counts[tuple.Item1];
            }
            strs = strs.Where(tuple => ((!result.MinCount.HasValue) || (counts[tuple.Item1] >= result.MinCount)) && ((!result.MaxCount.HasValue) || (counts[tuple.Item1] <= result.MaxCount))).ToList();
            SetSelections(strs.Select(tuple => Selections[tuple.Item2]).ToList());
        }
Ejemplo n.º 14
0
        public AccessibilityResource ToDisabled()
        {
            var newSelections = Selections
                                .Select(sel => sel.WithDisabled(true))
                                .ToImmutableArray();

            var newResource = new AccessibilityResource(
                resourceCode: ResourceCode,
                currentSelectionCode: CurrentSelectionCode,
                order: Order,
                defaultSelection: DefaultSelection,
                selections: newSelections,
                label: Label,
                description: Description,
                disabled: true,
                resourceType: ResourceTypeId);

            return(newResource);
        }
Ejemplo n.º 15
0
 void ShowTimersMenu(Point coords)
 {
     if (coords.Y >= PeriodsTimeline.OffsetY &&
         coords.Y < PeriodsTimeline.OffsetY + PeriodsTimeline.Height)
     {
         Timer t = Selections.Select(p => (p.Drawable as TimerTimeNodeObject).Timer).FirstOrDefault();
         if (ShowTimerMenuEvent != null)
         {
             ShowTimerMenuEvent(t, Utils.PosToTime(coords, SecondsPerPixel));
         }
     }
     else
     {
         List <TimeNode> nodes = Selections.Select(p => (p.Drawable as TimeNodeObject).TimeNode).ToList();
         if (nodes.Count > 0 && ShowTimersMenuEvent != null)
         {
             ShowTimersMenuEvent(nodes);
         }
     }
 }
Ejemplo n.º 16
0
        void Command_Edit_Navigate_AllRight(bool selecting)
        {
            if (!Selections.Any())
            {
                return;
            }

            var offsets = Selections.Select(range => range.Cursor).ToList();
            var lines   = offsets.AsParallel().AsOrdered().Select(offset => Data.GetOffsetLine(offset)).ToList();

            var index    = offsets.Zip(lines, (offset, line) => Data.GetOffsetIndex(offset, line)).Min();
            var endIndex = lines.Select(line => Data.GetLineLength(line)).Min();

            var currentIsSpace = default(bool?);

            while (true)
            {
                if (index > endIndex)
                {
                    offsets = lines.Select(line => Data.GetOffset(line, Data.GetLineLength(line))).ToList();
                    break;
                }

                var isSpace = lines.All(line => GetWordSkipType(line, index) == WordSkipType.Space);

                if (!currentIsSpace.HasValue)
                {
                    currentIsSpace = isSpace;
                }
                else if (isSpace != currentIsSpace)
                {
                    offsets = lines.Select(line => Data.GetOffset(line, index)).ToList();
                    break;
                }

                ++index;
            }

            SetSelections(Selections.Zip(offsets, (range, offset) => MoveCursor(range, offset, selecting)).ToList());
        }
Ejemplo n.º 17
0
        void Command_Numeric_Add_AddSubtractClipboard(bool add)
        {
            if (Selections.Count == 0)
            {
                return;
            }

            var clipboardStrings = Clipboard;

            if ((clipboardStrings.Count == 1) && (Selections.Count != 1))
            {
                clipboardStrings = Selections.Select(str => clipboardStrings[0]).ToList();
            }

            if (Selections.Count != clipboardStrings.Count())
            {
                throw new Exception("Must have either one or equal number of clipboards.");
            }

            var mult = add ? 1 : -1;

            ReplaceSelections(Selections.Zip(clipboardStrings, (sel, clip) => new { sel, clip }).AsParallel().AsOrdered().Select(obj => (double.Parse(GetString(obj.sel)) + double.Parse(obj.clip) * mult).ToString()).ToList());
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Runs backtest for all Selections and numeric Parameters
        /// </summary>
        /// <param name="pushResultsToSignal">Update signal's backtest results during execution</param>
        /// <returns>Collection of backtest results per each selection and parameters combination</returns>
        public List <BacktestResults> Backtest(bool pushResultsToSignal = true)
        {
            if (_backtestNestingLevel > 2)
            {
                Alert("Won't run backtest: possible infinite recursion loop");
                return(null);
            }

            var resetBusyFlag = !_isBusy;

            _isBusy = true;

            var results = new List <BacktestResults>();

            if (pushResultsToSignal)
            {
                BacktestProgress = 0F;
                BacktestResults.Clear();
            }

            lock (_locker)
            {
                try
                {
                    _backtestNestingLevel++;

                    //run backtest for each instrument using each possible parameters combinations
                    var paramSpaces       = GetParamCombinations(_origParameters);
                    var paramNames        = GetParamNames(_origParameters);
                    var paramCombinations = CartesianProduct(paramSpaces);
                    var total             = paramCombinations.Count()
                                            * Selections.Select(i => i.MarketDataSlot).Distinct().Count();
                    results.Capacity = total;
                    var current = 0;
                    foreach (var slot in Selections.GroupBy(i => i.MarketDataSlot))
                    {
                        foreach (var paramsCombo in paramCombinations)
                        {
                            while (State == SignalState.BacktestingPaused)
                            {
                                System.Threading.Thread.Sleep(50);
                            }

                            if (State == SignalState.Stopped)
                            {
                                return(results);
                            }

                            try
                            {
                                var allTrades = BacktestSlotItem(slot, paramsCombo);
                                var progress  = (++current / (float)total) * 100F;
                                var result    = new BacktestResults
                                {
                                    SignalName    = this.Name,
                                    Slot          = slot.Key,
                                    Index         = current,
                                    StartDate     = BacktestSettings.StartDate,
                                    EndDate       = BacktestSettings.EndDate,
                                    TotalProgress = progress
                                };

                                for (var i = 0; i < paramNames.Length; i++)
                                {
                                    result.Parameters.Add(paramNames[i] + "|" + paramsCombo.ElementAt(i).ToString());
                                }

                                if (allTrades != null && allTrades.Count > 0 && State != SignalState.Stopped)
                                {
                                    foreach (var symTrades in allTrades.GroupBy(i => new
                                    {
                                        i.Instrument.Symbol,
                                        i.Instrument.Timeframe,
                                        i.Instrument.TimeFactor
                                    }))
                                    {
                                        var key     = symTrades.First().Instrument;
                                        var summary = GetBacktestSummary(key, symTrades);
                                        summary.TradesCompressed = CompressTrades(symTrades);
                                        result.Summaries.Add(summary);
                                    }
                                }

                                results.Add(result);
                                if (pushResultsToSignal)
                                {
                                    BacktestResults.Add(result);
                                    BacktestProgress = progress;
                                }
                            }
                            catch (Exception e)
                            {
                                Alert($"Failed to run backtest for {Name} on slot #{slot.Key}: {e.Message}");
                            }
                        } //^ parameters loop
                    }     //^ slots loop
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.TraceError($"Failed to run backtest for {Name}: {e.Message}");
                }
                finally
                {
                    if (pushResultsToSignal)
                    {
                        BacktestProgress = 100F;
                    }
                    if (resetBusyFlag)
                    {
                        _isBusy = false;
                    }
                    _backtestNestingLevel--;
                }
            } //^ lock

            return(results);
        }
Ejemplo n.º 19
0
        void Command_Text_FirstDistinct(TextFirstDistinctDialog.Result result)
        {
            var opResult = ProgressDialog.Run(WindowParent, "Finding characters...", (cancelled, progress) =>
            {
                var valid = new HashSet <char>(result.Chars.Select(ch => result.MatchCase ? ch : char.ToLowerInvariant(ch)));
                var data  = GetSelectionStrings().Select(str => result.MatchCase ? str : str.ToLowerInvariant()).Select((str, strIndex) => Tuple.Create(str, strIndex, str.Indexes(ch => valid.Contains(ch)).Distinct(index => str[index]).ToList())).OrderBy(tuple => tuple.Item3.Count).ToList();
                var chars = data.Select(tuple => tuple.Item3.Select(index => tuple.Item1[index]).ToList()).ToList();

                var onChar       = new int[chars.Count];
                var current      = 0;
                onChar[0]        = -1;
                var best         = default(int[]);
                var bestScore    = int.MaxValue;
                var used         = new HashSet <char>();
                var currentScore = 0;
                var score        = new int[chars.Count + 1];
                var moveBack     = false;

                while (true)
                {
                    if (cancelled())
                    {
                        break;
                    }

                    if (moveBack)
                    {
                        currentScore  -= score[current];
                        score[current] = 0;
                        --current;
                        if (current < 0)
                        {
                            break;
                        }
                        used.Remove(chars[current][onChar[current]]);
                        moveBack = false;
                    }

                    ++onChar[current];
                    if ((onChar[current] >= chars[current].Count) || (currentScore >= bestScore))
                    {
                        moveBack = true;
                        continue;
                    }

                    var ch = chars[current][onChar[current]];
                    ++score[current];
                    ++currentScore;

                    if (used.Contains(ch))
                    {
                        continue;
                    }

                    used.Add(ch);

                    ++current;
                    if (current == chars.Count)
                    {
                        // Found combination!
                        if (currentScore < bestScore)
                        {
                            bestScore = currentScore;
                            best      = onChar.ToArray();
                        }
                        moveBack = true;
                        continue;
                    }

                    onChar[current] = -1;
                }

                if (best == null)
                {
                    throw new ArgumentException("No distinct combinations available");
                }

                var map = new int[data.Count];
                for (var ctr = 0; ctr < data.Count; ++ctr)
                {
                    map[data[ctr].Item2] = ctr;
                }

                return(Selections.Select((range, index) => Range.FromIndex(range.Start + data[map[index]].Item3[best[map[index]]], 1)).ToList());
            }) as List <Range>;

            if (opResult != null)
            {
                SetSelections(opResult);
            }
        }
Ejemplo n.º 20
0
        void Command_Select_Selection_ToggleAnchor(object preResult)
        {
            var anchorStart = (bool)preResult;

            SetSelections(Selections.Select(range => new Range(anchorStart ? range.End : range.Start, anchorStart ? range.Start : range.End)).ToList());
        }
Ejemplo n.º 21
0
 void Command_Content_Uncomment() => ReplaceSelections(Selections.Select(range => Parser.Uncomment(ContentType, Data, range)).ToList());
Ejemplo n.º 22
0
 ImageGrabColorDialog.Result Command_Image_GrabColor_Dialog() => ImageGrabColorDialog.Run(WindowParent, Selections.Select(range => GetString(range)).FirstOrDefault());
Ejemplo n.º 23
0
 void Command_Numeric_Series_OneBased() => ReplaceSelections(Selections.Select((range, index) => (index + 1).ToString()).ToList());
Ejemplo n.º 24
0
 List <Range> GetSortLines() => Selections.Select(range => Data.GetOffsetLine(range.Start)).Select(line => Range.FromIndex(Data.GetOffset(line, 0), Data.GetLineLength(line))).ToList();