From 8a96b00f64f96950e0aeb77a87ec5caaf037585d Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 18 Sep 2019 13:56:37 -0500 Subject: [PATCH] add 'User' column to Synthetic Management window --- .../Spreader/SyntheticManagementView.xaml.cs | 9 ++++++- .../SyntheticManagementWindowFactory.cs | 24 ++++++++++++------- .../VM/SyntheticManagementDialogVM.cs | 13 +++++++++- .../UserSettings/ISettingsMigrationRule.cs | 1 + .../UserSettings/UserSettingsHub.cs | 18 +++++++++++--- .../Filters/VM/DiscreteValuesFilterVM.cs | 14 ++++++----- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementView.xaml.cs b/src/client/spark/Modules/Spreader/SyntheticManagementView.xaml.cs index c3b7e6bea..e74b52c18 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementView.xaml.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementView.xaml.cs @@ -7,8 +7,15 @@ namespace mbts.ui.spark { /// Interaction logic for SyntheticManagementView.xaml /// partial class SyntheticManagementView : UserControl { + public enum Columns { + Name, + Description, + n_legs, + n_working_orders, + SecurityKey, + User + } - public enum Columns { Name, Description, n_legs, n_working_orders, SecurityKey} public SyntheticManagementView() => InitializeComponent(); } diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementWindowFactory.cs b/src/client/spark/Modules/Spreader/SyntheticManagementWindowFactory.cs index e676dd306..29125b873 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementWindowFactory.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementWindowFactory.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.settings; using mbts.persist; using mbts.spark; using mbts.spark.filters; @@ -7,6 +8,7 @@ using mbts.ui.settings; using ProtoBuf; using System; using System.Collections.Generic; +using System.ComponentModel.Composition; using System.Reactive.Linq; using System.Threading.Tasks; using static mbts.ui.controls.DIYGrid; @@ -33,13 +35,8 @@ namespace bts.shell { public async void show(SparkTags.Nothing nothing) => _bus.post(SparkTags.ShowWindow, await load(new StartupData())); - IShellWindow _create(StartupData state) { - var settings_manager = new WindowSettingsManager(_settings_hub, - state.grid, - get: us => us.synthetic_management_grid, - set: (us, gs) => us.with(provided_synthetic_management_gridsettings: gs)); - return new SyntheticManagementWindow(this, _bus, _orders_model, state, settings_manager); - } + IShellWindow _create(StartupData state) => + new SyntheticManagementWindow(this, _bus, _orders_model, state, _settings_hub.create_synth_settings_manager(state.grid)); [ProtoContract] public class StartupData { @@ -67,6 +64,7 @@ namespace bts.shell { public static GridColumnSettings n_legs => new GridColumnSettings(col_id(Columns.n_legs), DefaultColumnHeaders.N_Legs, width: DefaultColumnWidths.N_Legs); public static GridColumnSettings n_working_orders => new GridColumnSettings(col_id(Columns.n_working_orders), DefaultColumnHeaders.N_Working_Orders, width: DefaultColumnWidths.N_Working_Orders); public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey); + public static GridColumnSettings user => new GridColumnSettings(col_id(Columns.User), DefaultColumnHeaders.User, is_visible: false, width: DefaultColumnWidths.User); public static IEnumerable default_sorting_criterion { get { @@ -81,6 +79,7 @@ namespace bts.shell { yield return n_legs; yield return n_working_orders; yield return security_key; + yield return user; } } @@ -101,6 +100,15 @@ namespace bts.shell { public UIntMinMaxState n_working_orders; [ProtoMember(6)] public string security_key; + [ProtoMember(7)] + public uint[] user; + } + + // migration rules + [Export(typeof(ISyntheticManagementMigrationRule))] + class AddMissingColumnsMigrationRule : ISyntheticManagementMigrationRule { + public bool apply(GridSettings settings, out GridSettings new_settings) => + settings.add_missing_columns(StartupData.DefaultGridSettings.columns, out new_settings); } } -} +} \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs index 1e62b973c..1f63cb046 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs @@ -2,6 +2,7 @@ using bts.api; using bts.collections; using bts.spark; +using bts.utils; using mbts.persist; using mbts.spark.filters; using mbts.ui; @@ -30,6 +31,9 @@ namespace mbts.spark { _bus = bus; _orders_model = orders_model; _settings_manager = settings_manager; + // init filters + user_filter = DiscreteValuesFilterVM.CreateTableUpdate(r => r.user_tuple, UserTuple.key_fn, out var user_filter_items_observer, out var user_filter_items_view, nameof(Row.user_tuple)); + user_filter_items_view.CustomSort = Comparer.Default.wrap(ut => ut.name).to_non_generic(); if (filters != null) { create_time_filter.load_state(filters.create_time); name_filter.load_state(filters.name); @@ -37,6 +41,7 @@ namespace mbts.spark { n_legs_filter.load_state(filters.n_legs); n_working_orders_filter.load_state(filters.n_working_orders); security_key_filter.load_state(filters.security_key); + user_filter.load_state(filters.user); } // columns add_col(Columns.Name, DefaultColumnHeaders.Name, r => r.name, nameof(Row.name), name_filter, DataGridFilterKnownTemplates.Regex, DefaultColumnWidths.Security); @@ -53,6 +58,7 @@ namespace mbts.spark { Width = DefaultColumnWidths.N_Working_Orders }); add_col(Columns.SecurityKey, DefaultColumnHeaders.SecurityKey, r => r.security_key.ToString(), nameof(Row.security_key), security_key_filter, DataGridFilterKnownTemplates.Regex, DefaultColumnWidths.SecurityKey); + add_col(Columns.User, DefaultColumnHeaders.User, r => r.user_name, nameof(Row.user_name), user_filter, DataGridFilterKnownTemplates.DiscreteValues, DefaultColumnWidths.User); // void add_col(Columns col_key, string header, Func get_text, string prop, IDataGridColumnFilter filter, string filter_template, double width) => columns.Add(new RenderTextColumn(col_key, get_text, filter, filter_template) { @@ -67,6 +73,7 @@ namespace mbts.spark { grid_settings_manager.load_from(settings_manager.current_settings()); _resources.AddRange( + orders_model.admin_model.all_user_tuples.OnDispatcher().Subscribe(user_filter_items_observer), DataGridFilterHelper.hook_all(this, rows_view), settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager) ); @@ -81,6 +88,7 @@ namespace mbts.spark { public IDataGridColumnPersistentFilter n_legs_filter { get; } = new IntMinMax(r => r.n_legs, nameof(Row.n_legs)); public IDataGridColumnPersistentFilter n_working_orders_filter { get; } = new UIntMinMax(r => r.n_working_orders, nameof(Row.n_legs)); public IDataGridColumnPersistentFilter security_key_filter { get; } = new RegexFilterVM(r => r.security_key.ToString(), nameof(Row.security_key)); + public IDataGridColumnPersistentFilter user_filter { get; } public GridSettings get_grid_save_state() => _settings_manager.instance_settings == null ? null : grid_settings_manager.create(); @@ -101,7 +109,8 @@ namespace mbts.spark { name = name_filter.get_state(), n_legs = n_legs_filter.get_state(), n_working_orders = n_working_orders_filter.get_state(), - security_key = security_key_filter.get_state() + security_key = security_key_filter.get_state(), + user = user_filter.get_state() }; public class Row : SecurityRow, IEquatable, IRowVM, IActionableRowVM { @@ -130,6 +139,8 @@ namespace mbts.spark { public DateTime create_time => DateTime.MinValue; //TODO public string name { get; } + public string user_name => synthetic_tuple.user_name; + public UserTuple user_tuple => new UserTuple(synthetic_tuple.security.Synthetic.UserId, user_name); public int n_legs { get; } public string description { get; } public ExecutionStrategyImmutable? strategy => synthetic_tuple.strategy; diff --git a/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs b/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs index 9e4b314c5..ce301199a 100644 --- a/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs +++ b/src/client/spark/core/ShellInterface/UserSettings/ISettingsMigrationRule.cs @@ -17,6 +17,7 @@ namespace bts.settings { interface IMarketViewGridSettingsMigrationRule : ISettingsMigrationRule { } interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule { } interface IPNLSettingsMigrationRule : ISettingsMigrationRule { } + interface ISyntheticManagementMigrationRule : ISettingsMigrationRule { } static class SettingsMigrationHelper { public static bool apply(T settings, IEnumerable> migration_rules, out T new_settings) { diff --git a/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs b/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs index a2b70175d..50dd84359 100644 --- a/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs +++ b/src/client/spark/core/ShellInterface/UserSettings/UserSettingsHub.cs @@ -25,7 +25,8 @@ namespace mbts.persist { static readonly IImmutableProperty _fills_propi = ImmutableProperty.create(us => us.fills_grid, (us, gs) => us.with(provided_fills_gridsettings: gs)), _mview_propi = ImmutableProperty.create(us => us.market_view_grid, (us, gs) => us.with(provided_market_view_gridsettings: gs)), - _pandl_propi = ImmutableProperty.create(us => us.pnl_grid, (us, gs) => us.with(provided_pnl_gridsettings: gs)); + _pandl_propi = ImmutableProperty.create(us => us.pnl_grid, (us, gs) => us.with(provided_pnl_gridsettings: gs)), + _synth_propi = ImmutableProperty.create(us => us.synthetic_management_grid, (us, gs) => us.with(provided_synthetic_management_gridsettings: gs)); static readonly IImmutableProperty _pnl_propi = ImmutableProperty.create(us => us.pnl, (us, pnl) => us.with(pnl: pnl)); @@ -36,6 +37,7 @@ namespace mbts.persist { readonly IEnumerable _mview_migration_rules; readonly IEnumerable _pandl_migration_rules; readonly IEnumerable _pnl_migration_rules; + readonly IEnumerable _synth_migration_rules; readonly IUserPersist _persist; UserSettings _default_settings; @@ -46,13 +48,15 @@ namespace mbts.persist { [ImportMany]IEnumerable fills_migration_rules, [ImportMany]IEnumerable mview_migration_rules, [ImportMany]IEnumerable pandl_migration_rules, - [ImportMany]IEnumerable pnl_migration_rules) { + [ImportMany]IEnumerable pnl_migration_rules, + [ImportMany]IEnumerable synth_migration_rules) { // _persist = persist; _fills_migration_rules = fills_migration_rules ?? Enumerable.Empty(); _mview_migration_rules = mview_migration_rules ?? Enumerable.Empty(); _pandl_migration_rules = pandl_migration_rules ?? Enumerable.Empty(); _pnl_migration_rules = pnl_migration_rules ?? Enumerable.Empty(); + _synth_migration_rules = synth_migration_rules ?? Enumerable.Empty(); init(); async void init() { UserSettings s; @@ -62,7 +66,9 @@ namespace mbts.persist { var wrapped_rules = new[] { _fills_migration_rules.merge().wrap(_fills_propi), _mview_migration_rules.merge().wrap(_mview_propi), - _pandl_migration_rules.merge().wrap(_pandl_propi) + _pandl_migration_rules.merge().wrap(_pandl_propi), + _pnl_migration_rules.merge().wrap(_pnl_propi), + _synth_migration_rules.merge().wrap(_synth_propi) }; SettingsMigrationHelper.apply_quiet(ref s, wrapped_rules); // TODO: move ladder sanitization logic into ISettingsMigrationRule @@ -136,6 +142,12 @@ namespace mbts.persist { _pnl_migration_rules, _pnl_propi); + public IWindowSettingsManager create_synth_settings_manager(GridSettings instance_settings) => + _create_settings_manager( + instance_settings, + _synth_migration_rules, + _synth_propi); + public async Task save_default(UserSettings value) { // notify observers before persisting so the changes are reflected immediately in the ui lock (_default_settings_lock) { diff --git a/src/client/spark/view/Controls/DataGridEx/Filters/VM/DiscreteValuesFilterVM.cs b/src/client/spark/view/Controls/DataGridEx/Filters/VM/DiscreteValuesFilterVM.cs index ce8927104..e42550ee5 100644 --- a/src/client/spark/view/Controls/DataGridEx/Filters/VM/DiscreteValuesFilterVM.cs +++ b/src/client/spark/view/Controls/DataGridEx/Filters/VM/DiscreteValuesFilterVM.cs @@ -68,10 +68,11 @@ namespace mbts.spark.filters { Func factory, Func key, out IObserver> items_observer, - out ListCollectionView items_view) + out ListCollectionView items_view, + string prop_name = null) where TKey : struct, IEquatable => // - CreateTableUpdate(factory, key, keys => keys, keys => keys.ToArray(), out items_observer, out items_view); + CreateTableUpdate(factory, key, keys => keys, keys => keys.ToArray(), out items_observer, out items_view, prop_name); public static IDataGridColumnPersistentFilter CreateTableUpdate( Func factory, @@ -79,10 +80,11 @@ namespace mbts.spark.filters { Func> load_state, Func, TState> get_state, out IObserver> items_observer, - out ListCollectionView items_view) + out ListCollectionView items_view, + string prop_name = null) where TKey : struct, IEquatable { // - var filter = new TableUpdateItemsFilter(factory, key, load_state, get_state); + var filter = new TableUpdateItemsFilter(factory, key, load_state, get_state, prop_name); items_observer = filter; items_view = filter.items_view; return filter; @@ -291,8 +293,8 @@ namespace mbts.spark.filters { readonly HashSet _selected_keys = new HashSet(), _desired_keys = new HashSet(); ListCollectionView _items_view; - public TableUpdateItemsFilter(Func factory, Func key, Func> load_state, Func, TState> get_state) - : base(factory, null) { + public TableUpdateItemsFilter(Func factory, Func key, Func> load_state, Func, TState> get_state, string prop_name) + : base(factory, prop_name) { _factory = factory; _key = key; _load_state = load_state;