From d2bfcf76039f1153d0789482b82d76caa4f097f3 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 6 Sep 2019 18:49:24 -0500 Subject: [PATCH] remove avg price delta columns from new pnl --- .../Modules/Trading/PNL/PNLWindowFactory.cs | 99 +++++++++++++++++++ .../Trading/PNL/Settings/PNLSettings.cs | 24 ++--- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs b/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs index 5112918e5..8abe6220b 100644 --- a/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs +++ b/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs @@ -20,6 +20,7 @@ using System.Collections.Specialized; using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; @@ -277,5 +278,103 @@ namespace bts.shell { return false; } } + + class RemoveAvgPriceDeltaColumns { + static IEnumerable _price_delta_cols => + EnumHelper.get_values() + .Where(c => Regex.IsMatch(c.ToString(), ".*pricedelta.*", RegexOptions.IgnoreCase)); + + [Export] + public IPNLSettingsMigrationRule remove_columns => new RemoveColumnsMigrationRule(_price_delta_cols); + + [Export] + public IPNLSettingsMigrationRule remove_triggers => new RemoveColumnAnimationsMigrationRule(_price_delta_cols); + + class RemoveColumnsMigrationRule : IPNLSettingsMigrationRule { + readonly HashSet _cols_to_remove; + + public RemoveColumnsMigrationRule(IEnumerable cols_to_remove) => + _cols_to_remove = new HashSet(cols_to_remove); + + public bool apply(PNLSettings settings, out PNLSettings new_settings) { + if (settings != null) { + if (_apply(ref settings, settings.grid.columns, (s, cols) => s.with(grid: s.grid.with(cols))) | + _apply(ref settings, settings.group_columns, (s, cols) => s.with(group_columns: cols)) | + _apply(ref settings, settings.header_columns, (s, cols) => s.with(header_columns: cols))) { + new_settings = settings; + return true; + } + } + new_settings = null; + return false; + } + + bool _apply(ref PNLSettings settings, IEnumerable columns, Func, PNLSettings> set_columns) { + if (_apply(columns, out var new_cols)) { + settings = set_columns(settings, new_cols); + return true; + } + return false; + } + + bool _apply(IEnumerable columns, out IEnumerable result) { + var col_list = columns.ToList(); + int orig_count = col_list.Count; + col_list.RemoveWhere(c => _cols_to_remove.Contains(EnumHelper.parse(c.id))); + if (col_list.Count < orig_count) { + result = col_list; + return true; + } + result = null; + return false; + } + } + + class RemoveColumnAnimationsMigrationRule : IPNLSettingsMigrationRule { + readonly HashSet _cols_to_remove; + + public RemoveColumnAnimationsMigrationRule(IEnumerable cols_to_remove) => + _cols_to_remove = new HashSet(cols_to_remove); + + public bool apply(PNLSettings settings, out PNLSettings new_settings) { + if (settings != null) { + if (_apply(ref settings, settings.animations, (s, t) => s.with(animations: t)) | + _apply(ref settings, settings.group_header_animations, (s, t) => s.with(group_header_animations: t)) | + _apply(ref settings, settings.header_row_animations, (s, t) => s.with(header_row_animations: t))) { + new_settings = settings; + return true; + } + } + new_settings = null; + return false; + } + + bool _apply(ref PNLSettings settings, IEnumerable triggers, Func, PNLSettings> set_triggers) { + if (_apply(triggers, out var new_triggers)) { + settings = set_triggers(settings, new_triggers); + return true; + } + return false; + } + + bool _apply(IEnumerable triggers, out IEnumerable result) { + var trigger_map = triggers.ToImmutableDictionary(t => t.expression); + var snapshot = trigger_map; + foreach (var t in trigger_map.Values) { + var anims = t.animations.ToList(); + int orig_count = anims.Count; + anims.RemoveWhere(a => _cols_to_remove.Contains(a.column)); + if (anims.Count < orig_count) + trigger_map = trigger_map.SetItem(t.expression, t.with(animations: anims.ToArray())); + } + if (trigger_map != snapshot) { + result = trigger_map.Values; + return true; + } + result = null; + return false; + } + } + } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs index 264b5fba2..4765e7123 100644 --- a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs +++ b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs @@ -382,37 +382,37 @@ namespace bts.shell.pnl { yield return day_pnl; /// total yield return total_net_pos; - yield return total_net_avg_price_delta; // hidden + //yield return total_net_avg_price_delta; // hidden // total long yield return total_long_pos; // hidden yield return total_long_avg_price; // hidden - yield return total_long_avg_price_delta; // hidden + //yield return total_long_avg_price_delta; // hidden // total short yield return total_short_pos; // hidden yield return total_short_avg_price; // hidden - yield return total_short_avg_price_delta; // hidden + //yield return total_short_avg_price_delta; // hidden /// sod yield return sod_net_pos; - yield return sod_net_avg_price_delta; // hidden + //yield return sod_net_avg_price_delta; // hidden // sod long yield return sod_long_pos; // hidden yield return sod_long_avg_price; // hidden - yield return sod_long_avg_price_delta; // hidden + //yield return sod_long_avg_price_delta; // hidden // sod short yield return sod_short_pos; // hidden yield return sod_short_avg_price; // hidden - yield return sod_short_avg_price_delta; // hidden + //yield return sod_short_avg_price_delta; // hidden /// day yield return day_net_pos; - yield return day_net_avg_price_delta; // hidden + //yield return day_net_avg_price_delta; // hidden // day long yield return day_long_pos; // hidden yield return day_long_avg_price; // hidden - yield return day_long_avg_price_delta; // hidden + //yield return day_long_avg_price_delta; // hidden // day short yield return day_short_pos; // hidden yield return day_short_avg_price; // hidden - yield return day_short_avg_price_delta; // hidden + //yield return day_short_avg_price_delta; // hidden /// raw day yield return raw_day_long_pos; // hidden yield return raw_day_short_pos; // hidden @@ -422,15 +422,15 @@ namespace bts.shell.pnl { /// working // working net yield return working_net_pos; - yield return working_net_avg_price_delta; + //yield return working_net_avg_price_delta; // working long yield return working_long_pos; yield return working_long_avg_price; - yield return working_long_avg_price_delta; + //yield return working_long_avg_price_delta; // working short yield return working_short_pos; yield return working_short_avg_price; - yield return working_short_avg_price_delta; + //yield return working_short_avg_price_delta; /// market yield return bid_price; yield return ask_price;