Core: Update ratio display

This commit is contained in:
Genteure 2021-04-21 19:48:28 +08:00
parent aefc078868
commit 7c9a3582a0
5 changed files with 25 additions and 12 deletions

View File

@ -27,23 +27,22 @@ namespace BililiveRecorder.Core.Recording
protected override void StartRecordingLoop(Stream stream)
{
var paths = this.CreateFileName();
var (fullPath, relativePath) = this.CreateFileName();
try
{ Directory.CreateDirectory(Path.GetDirectoryName(paths.fullPath)); }
{ Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); }
catch (Exception) { }
this.fileOpeningEventArgs = new RecordFileOpeningEventArgs(this.room)
{
SessionId = this.SessionId,
FullPath = paths.fullPath,
RelativePath = paths.relativePath,
FullPath = fullPath,
RelativePath = relativePath,
FileOpenTime = DateTimeOffset.Now,
};
this.OnRecordFileOpening(this.fileOpeningEventArgs);
var file = new FileStream(paths.fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
var file = new FileStream(fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
_ = Task.Run(async () => await this.WriteStreamToFileAsync(stream, file).ConfigureAwait(false));
}

View File

@ -44,7 +44,7 @@ namespace BililiveRecorder.Core.Recording
this.ct = this.cts.Token;
this.timer.Elapsed += this.Timer_Elapsed_TriggerStats;
this.timer.Elapsed += this.Timer_Elapsed_TriggerNetworkStats;
}
public Guid SessionId { get; } = Guid.NewGuid();
@ -90,7 +90,7 @@ namespace BililiveRecorder.Core.Recording
protected abstract void StartRecordingLoop(Stream stream);
private void Timer_Elapsed_TriggerStats(object sender, ElapsedEventArgs e)
private void Timer_Elapsed_TriggerNetworkStats(object sender, ElapsedEventArgs e)
{
int bytes;
TimeSpan diff;
@ -129,12 +129,12 @@ namespace BililiveRecorder.Core.Recording
protected (string fullPath, string relativePath) CreateFileName()
{
var formatString = room.RoomConfig.RecordFilenameFormat!;
var formatString = this.room.RoomConfig.RecordFilenameFormat!;
var now = DateTime.Now;
var date = now.ToString("yyyyMMdd");
var time = now.ToString("HHmmss");
var randomStr = random.Next(100, 999).ToString();
var randomStr = this.random.Next(100, 999).ToString();
var relativePath = formatString
.Replace(@"{date}", date)

View File

@ -16,6 +16,11 @@ namespace BililiveRecorder.Core
private long totalOutputBytes;
private double duraionRatio;
public RecordingStats()
{
this.Reset();
}
public TimeSpan SessionDuration { get => this.sessionDuration; set => this.SetField(ref this.sessionDuration, value); }
public TimeSpan SessionMaxTimestamp { get => this.sessionMaxTimestamp; set => this.SetField(ref this.sessionMaxTimestamp, value); }
public TimeSpan FileMaxTimestamp { get => this.fileMaxTimestamp; set => this.SetField(ref this.fileMaxTimestamp, value); }
@ -32,7 +37,7 @@ namespace BililiveRecorder.Core
this.SessionDuration = TimeSpan.Zero;
this.SessionMaxTimestamp = TimeSpan.Zero;
this.FileMaxTimestamp = TimeSpan.Zero;
this.DuraionRatio = 0;
this.DuraionRatio = double.NaN;
this.TotalInputBytes = 0;
this.TotalOutputBytes = 0;
this.NetworkMbps = 0;

View File

@ -223,6 +223,7 @@ namespace BililiveRecorder.Core
task.RecordSessionEnded += this.RecordTask_RecordSessionEnded;
this.recordTask = task;
this.recordTaskStartTime = DateTimeOffset.UtcNow;
this.Stats.Reset();
this.OnPropertyChanged(nameof(this.Recording));
_ = Task.Run(async () =>
@ -368,6 +369,8 @@ namespace BililiveRecorder.Core
this.basicDanmakuWriter.Disable();
this.OnPropertyChanged(nameof(this.Recording));
this.Stats.Reset();
RecordSessionEnded?.Invoke(this, new RecordSessionEndedEventArgs(this)
{
SessionId = id

View File

@ -8,6 +8,7 @@ namespace BililiveRecorder.WPF.Converters
{
internal class RatioToColorBrushConverter : IValueConverter
{
private static readonly SolidColorBrush Disabled = new SolidColorBrush(Colors.AliceBlue);
private static readonly SolidColorBrush[] ColorMap;
static RatioToColorBrushConverter()
@ -29,7 +30,12 @@ namespace BililiveRecorder.WPF.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var i = (int)Math.Ceiling((1.1d - Math.Abs((1d - (double)value) * 4d)) * 20d);
var input = (double)value;
if (double.IsNaN(input))
return Disabled;
var i = (int)Math.Ceiling((1.1d - Math.Abs((1d - input) * 4d)) * 20d);
return i switch
{
< 0 => ColorMap[0],