Add statistics to list of rom sets.

This commit is contained in:
2020-08-24 01:57:15 +01:00
parent 86b63e5e31
commit 3d87c2e778
7 changed files with 108 additions and 44 deletions

View File

@@ -36,5 +36,11 @@ namespace RomRepoMgr.Core.Models
public string Version { get; set; } public string Version { get; set; }
public string Filename { get; set; } public string Filename { get; set; }
public string Sha384 { get; set; } public string Sha384 { get; set; }
public long TotalMachines { get; set; }
public long CompleteMachines { get; set; }
public long IncompleteMachines { get; set; }
public long TotalRoms { get; set; }
public long HaveRoms { get; set; }
public long MissRoms { get; set; }
} }
} }

View File

@@ -114,22 +114,6 @@ namespace RomRepoMgr.Core.Workers
Context.Singleton.RomSets.Add(romSet); Context.Singleton.RomSets.Add(romSet);
Context.Singleton.SaveChanges(); Context.Singleton.SaveChanges();
RomSetAdded?.Invoke(this, new RomSetEventArgs
{
RomSet = new RomSetModel
{
Author = romSet.Author,
Comment = romSet.Comment,
Date = romSet.Date,
Description = romSet.Description,
Filename = romSet.Filename,
Homepage = romSet.Homepage,
Name = romSet.Name,
Sha384 = romSet.Sha384,
Version = romSet.Version
}
});
SetMessage?.Invoke(this, new MessageEventArgs SetMessage?.Invoke(this, new MessageEventArgs
{ {
Message = "Compressing DAT file..." Message = "Compressing DAT file..."
@@ -473,6 +457,30 @@ namespace RomRepoMgr.Core.Workers
}); });
WorkFinished?.Invoke(this, System.EventArgs.Empty); WorkFinished?.Invoke(this, System.EventArgs.Empty);
romSet = Context.Singleton.RomSets.Find(romSet.Id);
RomSetAdded?.Invoke(this, new RomSetEventArgs
{
RomSet = new RomSetModel
{
Author = romSet.Author,
Comment = romSet.Comment,
Date = romSet.Date,
Description = romSet.Description,
Filename = romSet.Filename,
Homepage = romSet.Homepage,
Name = romSet.Name,
Sha384 = romSet.Sha384,
Version = romSet.Version,
TotalMachines = romSet.Machines.Count,
CompleteMachines = romSet.Machines.Count(m => m.Files.All(f => f.File.IsInRepo)),
IncompleteMachines = romSet.Machines.Count(m => m.Files.Any(f => !f.File.IsInRepo)),
TotalRoms = romSet.Machines.Sum(m => m.Files.Count),
HaveRoms = romSet.Machines.Sum(m => m.Files.Count(f => f.File.IsInRepo)),
MissRoms = romSet.Machines.Sum(m => m.Files.Count(f => !f.File.IsInRepo))
}
});
} }
catch(Exception e) catch(Exception e)
{ {

View File

@@ -25,6 +25,7 @@
using System; using System;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using RomRepoMgr.Database.Models; using RomRepoMgr.Database.Models;
namespace RomRepoMgr.Database namespace RomRepoMgr.Database
@@ -62,7 +63,12 @@ namespace RomRepoMgr.Database
public static Context Create(string dbPath) public static Context Create(string dbPath)
{ {
var optionsBuilder = new DbContextOptionsBuilder(); var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseLazyLoadingProxies().UseSqlite($"Data Source={dbPath}");
optionsBuilder.UseLazyLoadingProxies()
#if DEBUG
.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()))
#endif
.UseSqlite($"Data Source={dbPath}");
return new Context(optionsBuilder.Options); return new Context(optionsBuilder.Options);
} }

View File

@@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -61,7 +61,12 @@ namespace RomRepoMgr.ViewModels
public string RomSetDateLabel => "Date"; public string RomSetDateLabel => "Date";
public string RomSetDescriptionLabel => "Description"; public string RomSetDescriptionLabel => "Description";
public string RomSetCommentLabel => "Comment"; public string RomSetCommentLabel => "Comment";
public string RomSetHomepageLabel => "Homepage"; public string RomSetTotalMachinesLabel => "Games";
public string RomSetCompleteMachinesLabel => "Complete";
public string RomSetIncompleteMachinesLabel => "Incomplete";
public string RomSetTotalRomsLabel => "ROMs";
public string RomSetHaveRomsLabel => "Have";
public string RomSetMissRomsLabel => "Miss";
public string Greeting => "Hello World!"; public string Greeting => "Hello World!";
public bool NativeMenuSupported => public bool NativeMenuSupported =>

View File

@@ -378,7 +378,15 @@ namespace RomRepoMgr.ViewModels
Homepage = r.Homepage, Homepage = r.Homepage,
Name = r.Name, Name = r.Name,
Sha384 = r.Sha384, Sha384 = r.Sha384,
Version = r.Version Version = r.Version,
TotalMachines = r.Machines.Count,
CompleteMachines =
r.Machines.Count(m => m.Files.All(f => f.File.IsInRepo)),
IncompleteMachines =
r.Machines.Count(m => m.Files.Any(f => !f.File.IsInRepo)),
TotalRoms = r.Machines.Sum(m => m.Files.Count),
HaveRoms = r.Machines.Sum(m => m.Files.Count(f => f.File.IsInRepo)),
MissRoms = r.Machines.Sum(m => m.Files.Count(f => !f.File.IsInRepo))
}).ToList() }).ToList()
}); });

View File

@@ -66,6 +66,36 @@
<TextBlock Text="{Binding RomSetHomepageLabel}" /> <TextBlock Text="{Binding RomSetHomepageLabel}" />
</DataGridTextColumn.Header> </DataGridTextColumn.Header>
</DataGridTextColumn> </DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalMachines}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetTotalMachinesLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding CompleteMachines}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetCompleteMachinesLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding IncompleteMachines}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetIncompleteMachinesLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalRoms}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetTotalRomsLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding HaveRoms}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetHaveRomsLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding MissRoms}" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.Header>
<TextBlock Text="{Binding RomSetMissRomsLabel}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
</TabItem> </TabItem>