Intermediate fleet summaries attempt
This commit is contained in:
		@@ -37,84 +37,11 @@ public class FleetManager : IEnableLogger, IDisposable
 | 
				
			|||||||
    public IObservableCache<FleetSummaryByDestination, string> FleetSummariesByDestination
 | 
					    public IObservableCache<FleetSummaryByDestination, string> FleetSummariesByDestination
 | 
				
			||||||
        => _fleetSummariesByDestination.AsObservableCache();
 | 
					        => _fleetSummariesByDestination.AsObservableCache();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>
 | 
					 | 
				
			||||||
    /// Public accessor to the continously updated fleet summaries.
 | 
					 | 
				
			||||||
    /// </summary>
 | 
					 | 
				
			||||||
    // public IObservableCache<FleetSummaryByDestination, string> FleetSummariesByDestination => _fleetSummaries.AsObservableCache();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// <summary>
 | 
					 | 
				
			||||||
    /// Disposal tracking
 | 
					 | 
				
			||||||
    /// </summary>
 | 
					 | 
				
			||||||
    // private IDisposable _fleetSummariesSubscription;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public FleetManager() 
 | 
					    public FleetManager() 
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // CreateFleetSummariesLink();
 | 
					        // CreateFleetSummariesLink();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // [MemberNotNull(nameof(_fleetSummariesSubscription))]
 | 
					 | 
				
			||||||
    // protected void CreateFleetSummariesLink()
 | 
					 | 
				
			||||||
    // {
 | 
					 | 
				
			||||||
    //     /*
 | 
					 | 
				
			||||||
    //     _fleetSummariesSubscription = _fleets.Connect()
 | 
					 | 
				
			||||||
    //         .Filter(fleet => fleet.TrueDestination != "-- ")
 | 
					 | 
				
			||||||
    //         .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher filter", fleet => $"{fleet}")            
 | 
					 | 
				
			||||||
    //         // .AutoRefreshOnObservable(fleet => fleet.WhenAnyValue(
 | 
					 | 
				
			||||||
    //         //     f => f.Ironium, f => f.Boranium, f => f.Germanium, f => f.Colonists))
 | 
					 | 
				
			||||||
    //         .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher refresh", fleet => $"{fleet}")
 | 
					 | 
				
			||||||
    //         .GroupOn(fleet => fleet.TrueDestination)
 | 
					 | 
				
			||||||
    //         .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher group", grp => $"{grp.TotalChanges} detected")
 | 
					 | 
				
			||||||
    //         .Transform(group => new FleetSummaryByDestination
 | 
					 | 
				
			||||||
    //             {   
 | 
					 | 
				
			||||||
    //                 Destination = group.GroupKey,
 | 
					 | 
				
			||||||
    //                 TotalIronium = group.List.Items.Sum(f => f.Ironium),
 | 
					 | 
				
			||||||
    //                 TotalBoranium = group.List.Items.Sum(f => f.Boranium),
 | 
					 | 
				
			||||||
    //                 TotalGermanium = group.List.Items.Sum(f => f.Germanium),
 | 
					 | 
				
			||||||
    //                 TotalColonists = group.List.Items.Sum(f => f.Colonists)
 | 
					 | 
				
			||||||
    //             })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //         .AddKey(fs => fs.Destination)
 | 
					 | 
				
			||||||
    //         .Log(this, "FleetManager _fleetSummaries update", changes => 
 | 
					 | 
				
			||||||
    //                 $"{changes.Adds} adds, {changes.Updates} updates, {changes.Removes} removes"
 | 
					 | 
				
			||||||
    //             )
 | 
					 | 
				
			||||||
    //         .PopulateInto(_fleetSummaries)
 | 
					 | 
				
			||||||
    //     ;
 | 
					 | 
				
			||||||
    //     */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //     /*
 | 
					 | 
				
			||||||
    //     // Demo only
 | 
					 | 
				
			||||||
    //     var sourceCache = new SourceCache<FleetSummaryByDestination, string>(fs => fs.Destination);
 | 
					 | 
				
			||||||
    //     var tmp = fleetSummaries
 | 
					 | 
				
			||||||
    //         .AddKey(fs => fs.Destination)
 | 
					 | 
				
			||||||
    //         .PopulateInto(sourceCache);
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    //     _fleetSummaries
 | 
					 | 
				
			||||||
    //         .ObserveOn(RxApp.MainThreadScheduler)
 | 
					 | 
				
			||||||
    //         .Bind(out summaries)
 | 
					 | 
				
			||||||
    //         .DisposeMany()
 | 
					 | 
				
			||||||
    //         .Subscribe();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //     d1 = summaries
 | 
					 | 
				
			||||||
    //         .Subscribe(Observer.Create<FleetSummaryByDestination>(f => 
 | 
					 | 
				
			||||||
    //             {
 | 
					 | 
				
			||||||
    //                 this.Log().Debug($"FleetSummaryByDestination observed: {f}");
 | 
					 | 
				
			||||||
    //             }
 | 
					 | 
				
			||||||
    //         ));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //     d2 = _fleetSummaries
 | 
					 | 
				
			||||||
    //         .ObserveOn(RxApp.MainThreadScheduler)
 | 
					 | 
				
			||||||
    //         .Subscribe(x => 
 | 
					 | 
				
			||||||
    //         {
 | 
					 | 
				
			||||||
    //             var lst = x.ToList();
 | 
					 | 
				
			||||||
    //             foreach (var f in lst)
 | 
					 | 
				
			||||||
    //             {
 | 
					 | 
				
			||||||
    //                 this.Log().Debug($"Reason {f.Reason}, Type {f.Type}: {f.Item.Current}");
 | 
					 | 
				
			||||||
    //             }
 | 
					 | 
				
			||||||
    //         }
 | 
					 | 
				
			||||||
    //         );
 | 
					 | 
				
			||||||
    //     */
 | 
					 | 
				
			||||||
    // }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Load the fleet records from the database and push them into our source cache.
 | 
					    /// Load the fleet records from the database and push them into our source cache.
 | 
				
			||||||
    /// If the data has been freshly imported, call PostProcessImportedData first.
 | 
					    /// If the data has been freshly imported, call PostProcessImportedData first.
 | 
				
			||||||
@@ -201,7 +128,6 @@ public class FleetManager : IEnableLogger, IDisposable
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if (disposing)
 | 
					        if (disposing)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // _fleetSummariesSubscription.Dispose();
 | 
					 | 
				
			||||||
            _fleetSummariesByDestination.Dispose();
 | 
					            _fleetSummariesByDestination.Dispose();
 | 
				
			||||||
            _fleets.Dispose();
 | 
					            _fleets.Dispose();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,7 +50,10 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
            .ToProperty(this, vm => vm.RemainingFactories);
 | 
					            .ToProperty(this, vm => vm.RemainingFactories);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _factoryGermaniumDeltaHelper = this
 | 
					        _factoryGermaniumDeltaHelper = this
 | 
				
			||||||
            .WhenAnyValue(vm => vm.RemainingFactories)
 | 
					            .WhenAnyValue(vm => vm.RemainingFactories,
 | 
				
			||||||
 | 
					                vm => vm.EnRouteGermanium,
 | 
				
			||||||
 | 
					                vm => vm.SurfaceGermanium,
 | 
				
			||||||
 | 
					                (remFact, gerEnRoute, surGer) => remFact)
 | 
				
			||||||
            .Select(gerCost => ComputeFactoryGermaniumDelta())
 | 
					            .Select(gerCost => ComputeFactoryGermaniumDelta())
 | 
				
			||||||
            .ToProperty(this, vm => vm.FactoryGermaniumDelta);
 | 
					            .ToProperty(this, vm => vm.FactoryGermaniumDelta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,15 +70,36 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
            .Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}")
 | 
					            .Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}")
 | 
				
			||||||
        ;
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _populationEnRouteHelper = _fleetSummaryChanges
 | 
					        _enRoutePopulationHelper = _fleetSummaryChanges
 | 
				
			||||||
            .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalColonists : 0)
 | 
					            .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalColonists : 0)
 | 
				
			||||||
            .Log(this, "PopulationEnRoute", pop => $"{Name}: {pop}")
 | 
					            .Log(this, "EnRoutePopulation", pop => $"{Name}: {pop}")
 | 
				
			||||||
            .ToProperty(this, vm => vm.PopulationEnRoute)
 | 
					            .ToProperty(this, vm => vm.EnRoutePopulation)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _enRouteIroniumHelper = _fleetSummaryChanges
 | 
				
			||||||
 | 
					            .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalIronium : 0)
 | 
				
			||||||
 | 
					            .Log(this, "EnRouteIronium", ironium => $"{Name}: {ironium}")
 | 
				
			||||||
 | 
					            .ToProperty(this, vm => vm.EnRouteIronium)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _enRouteBoraniumHelper = _fleetSummaryChanges
 | 
				
			||||||
 | 
					            .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalBoranium : 0)
 | 
				
			||||||
 | 
					            .Log(this, "EnRouteBoranium", boranium => $"{Name}: {boranium}")
 | 
				
			||||||
 | 
					            .ToProperty(this, vm => vm.EnRouteBoranium)
 | 
				
			||||||
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _enRouteGermaniumHelper = _fleetSummaryChanges
 | 
				
			||||||
 | 
					            .Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalGermanium : 0)
 | 
				
			||||||
 | 
					            .Log(this, "EnRouteGermanium", germanium => $"{Name}: {germanium}")
 | 
				
			||||||
 | 
					            .ToProperty(this, vm => vm.EnRouteGermanium)
 | 
				
			||||||
        ;
 | 
					        ;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        this.WhenActivated((CompositeDisposable disposables) => 
 | 
					        this.WhenActivated((CompositeDisposable disposables) => 
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            disposables.Add(_populationEnRouteHelper);
 | 
					            disposables.Add(_enRoutePopulationHelper);
 | 
				
			||||||
 | 
					            disposables.Add(_enRouteIroniumHelper);
 | 
				
			||||||
 | 
					            disposables.Add(_enRouteBoraniumHelper);
 | 
				
			||||||
 | 
					            disposables.Add(_enRouteGermaniumHelper);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // /* handle activation */
 | 
					            // /* handle activation */
 | 
				
			||||||
            // Disposable
 | 
					            // Disposable
 | 
				
			||||||
@@ -167,7 +191,7 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
 | 
					    public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int PopulationT1 => Population + PopulationGrowth /* TODO + Pop En Route */;
 | 
					    public int PopulationT1 => Population + PopulationGrowth + EnRoutePopulation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
 | 
					    public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -187,26 +211,25 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public int AvailableGermanium => MRGermanium + SurfaceGermanium;
 | 
					    public int AvailableGermanium => MRGermanium + SurfaceGermanium;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _populationTarget;
 | 
				
			||||||
    private int _populationTarget;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _populationToShip;
 | 
				
			||||||
    private int _populationToShip;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _targetFactories;
 | 
				
			||||||
    private int _targetFactories;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _remainingFactories;
 | 
				
			||||||
    private int _remainingFactories;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _factoryGermaniumDelta;
 | 
				
			||||||
    private int _factoryGermaniumDelta;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _remainingMines;
 | 
				
			||||||
    private int _remainingMines;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [ObservableAsProperty]
 | 
					    [ObservableAsProperty] private int _enRoutePopulation;
 | 
				
			||||||
    private int _populationEnRoute;
 | 
					
 | 
				
			||||||
 | 
					    [ObservableAsProperty] private int _enRouteIronium;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [ObservableAsProperty] private int _enRouteBoranium;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [ObservableAsProperty] private int _enRouteGermanium;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -230,24 +253,19 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
        if (gerReq < AvailableGermanium)
 | 
					        if (gerReq < AvailableGermanium)
 | 
				
			||||||
            return Math.Max(0, SurfaceGermanium - gerReq);
 | 
					            return Math.Max(0, SurfaceGermanium - gerReq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return AvailableGermanium + MRGermanium - gerReq;
 | 
					        // When extrapolating to T1, we take the available Germanium
 | 
				
			||||||
        // TODO: Extrapolate to T1, so that excess Germanium is visible.
 | 
					        // this turn (surface + MR), add MR a second time (the mines
 | 
				
			||||||
        // TODO: Take shipping into account.
 | 
					        // will yield it next turn as well) and add the inbound shipping
 | 
				
			||||||
 | 
					        // as this will be available next turn as well. That#s the basis
 | 
				
			||||||
 | 
					        // for the Germanium requirement in the next turn. We will top
 | 
				
			||||||
 | 
					        // it out at 0, as we don't have any Germanium available this
 | 
				
			||||||
 | 
					        // turn, and we don't want to show a projected surplus here
 | 
				
			||||||
 | 
					        // (we can't pull it off the planet in this turn anyway).
 | 
				
			||||||
 | 
					        return Math.Min(
 | 
				
			||||||
 | 
					            AvailableGermanium + EnRouteGermanium + MRGermanium - gerReq
 | 
				
			||||||
 | 
					            , 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    private int ComputePopulationEnRoute()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        using var db = Locator.Current.GetService<Model.StarsDatabase>()!;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        var enRoute = from flt in db.Fleet
 | 
					 | 
				
			||||||
            where flt.OwnerFileId == Game.Player.PlayerFileId && flt.TrueDestination == Planet.Name
 | 
					 | 
				
			||||||
            select new {  Colonists = flt.Sum(f => f.Colonists) };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return enRoute.Colonists ?? 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -21,7 +21,7 @@
 | 
				
			|||||||
        <DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
 | 
					        <DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
 | 
					        <DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
					        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Pop T1" Binding="{Binding PopulationEnRoute}" />
 | 
					        <DataGridTextColumn Header="Pop T1" Binding="{Binding EnRoutePopulation}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
 | 
					        <DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
 | 
				
			||||||
        <DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" />
 | 
					        <DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" />
 | 
				
			||||||
        <!-- Terra Delta assumed -->
 | 
					        <!-- Terra Delta assumed -->
 | 
				
			||||||
@@ -31,13 +31,19 @@
 | 
				
			|||||||
        <!-- Cargo Cap T1 -->
 | 
					        <!-- Cargo Cap T1 -->
 | 
				
			||||||
        <!-- Cargo Cap T0 -->
 | 
					        <!-- Cargo Cap T0 -->
 | 
				
			||||||
        <!-- Iro MRE including Shipping -->
 | 
					        <!-- Iro MRE including Shipping -->
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Iro Sur" Binding="{Binding SurfaceIronium}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Iro Avl" Binding="{Binding AvailableIronium}" />
 | 
					        <DataGridTextColumn Header="Iro Avl" Binding="{Binding AvailableIronium}" />
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Iro Trn" Binding="{Binding EnRouteIronium}" />
 | 
				
			||||||
        <!-- Iro Shipping including MRE -->
 | 
					        <!-- Iro Shipping including MRE -->
 | 
				
			||||||
        <!-- Bor MRE including Shipping -->
 | 
					        <!-- Bor MRE including Shipping -->
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Bor Sur" Binding="{Binding SurfaceBoranium}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Bor Avl" Binding="{Binding AvailableBoranium}" />
 | 
					        <DataGridTextColumn Header="Bor Avl" Binding="{Binding AvailableBoranium}" />
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Bor Trn" Binding="{Binding EnRouteBoranium}" />
 | 
				
			||||||
        <!-- Bor Shipping including MRE -->
 | 
					        <!-- Bor Shipping including MRE -->
 | 
				
			||||||
        <!-- Ger MRE including Shipping -->
 | 
					        <!-- Ger MRE including Shipping -->
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Ger Sur" Binding="{Binding SurfaceGermanium}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Ger Avl" Binding="{Binding AvailableGermanium}" />
 | 
					        <DataGridTextColumn Header="Ger Avl" Binding="{Binding AvailableGermanium}" />
 | 
				
			||||||
 | 
					        <DataGridTextColumn Header="Ger Trn" Binding="{Binding EnRouteGermanium}" />
 | 
				
			||||||
        <!-- Bor Shipping including MRE -->
 | 
					        <!-- Bor Shipping including MRE -->
 | 
				
			||||||
        <!-- Shipbuilding Columns -->
 | 
					        <!-- Shipbuilding Columns -->
 | 
				
			||||||
        <DataGridTextColumn Header="Fact Rem" Binding="{Binding RemainingFactories}" />
 | 
					        <DataGridTextColumn Header="Fact Rem" Binding="{Binding RemainingFactories}" />
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user