-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7df2385
commit 4a75f10
Showing
31 changed files
with
246 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="clr-namespace:GalaxyBudsClient.Interface.Controls" | ||
xmlns:pages="clr-namespace:GalaxyBudsClient.Interface.ViewModels.Pages" | ||
xmlns:ext="clr-namespace:GalaxyBudsClient.Interface.MarkupExtensions" | ||
xmlns:i18N="clr-namespace:GalaxyBudsClient.Generated.I18N" | ||
xmlns:config="clr-namespace:GalaxyBudsClient.Model.Config" | ||
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" | ||
xmlns:plot="clr-namespace:ScottPlot.Avalonia;assembly=ScottPlot.Avalonia" | ||
xmlns:control="clr-namespace:ScottPlot.Control;assembly=ScottPlot" | ||
mc:Ignorable="d" d:DesignWidth="800" | ||
x:Class="GalaxyBudsClient.Interface.Pages.BatteryHistoryPage" | ||
x:DataType="pages:BatteryHistoryPageViewModel" | ||
x:CompileBindings="True"> | ||
|
||
<Design.DataContext> | ||
<pages:BatteryHistoryPageViewModel /> | ||
</Design.DataContext> | ||
|
||
<Grid RowDefinitions="Auto,*" | ||
Margin="{StaticResource AppPageMargin}"> | ||
|
||
<controls:CustomInfoBar Title="{ext:Translate {x:Static i18N:Keys.Hint}}" | ||
Message="{ext:Translate {x:Static i18N:Keys.BattHistHint}}" | ||
IsClosable="True" | ||
IsOpen="{Binding !IsBatteryHistoryHintHidden, Source={x:Static config:Settings.Data}}" | ||
Severity="Informational" | ||
Closed="OnHintClosed" | ||
Margin="0,0,0,8"/> | ||
|
||
<!-- AvaPlot does not support bindings :( --> | ||
<plot:AvaPlot Name="PlotControl" | ||
Grid.Row="1" /> | ||
</Grid> | ||
</UserControl> |
24 changes: 24 additions & 0 deletions
24
GalaxyBudsClient/Interface/Pages/BatteryHistoryPage.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using FluentAvalonia.UI.Controls; | ||
using GalaxyBudsClient.Interface.ViewModels.Pages; | ||
using GalaxyBudsClient.Model.Config; | ||
|
||
namespace GalaxyBudsClient.Interface.Pages; | ||
|
||
public partial class BatteryHistoryPage : BasePage<BatteryHistoryPageViewModel> | ||
{ | ||
public BatteryHistoryPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
ViewModel!.Plot = PlotControl.Plot; | ||
base.OnInitialized(); | ||
} | ||
|
||
private void OnHintClosed(InfoBar sender, InfoBarClosedEventArgs args) | ||
{ | ||
Settings.Data.IsBatteryHistoryHintHidden = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
GalaxyBudsClient/Interface/ViewModels/Pages/BatteryHistoryPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Avalonia.Controls; | ||
using GalaxyBudsClient.Generated.I18N; | ||
using GalaxyBudsClient.Interface.Pages; | ||
using GalaxyBudsClient.Utils; | ||
using GalaxyBudsClient.Utils.Interface; | ||
using Microsoft.EntityFrameworkCore; | ||
using ReactiveUI.Fody.Helpers; | ||
using ScottPlot; | ||
using ScottPlot.AxisRules; | ||
using ScottPlot.Control; | ||
using ScottPlot.TickGenerators; | ||
|
||
namespace GalaxyBudsClient.Interface.ViewModels.Pages; | ||
|
||
public class BatteryHistoryPageViewModel : SubPageViewModelBase | ||
{ | ||
public override Control CreateView() => new BatteryHistoryPage { DataContext = this }; | ||
public override string TitleKey => Keys.SystemBatteryStatistics; | ||
public Plot? Plot { set; get; } | ||
|
||
public BatteryHistoryPageViewModel() | ||
{ | ||
} | ||
|
||
public override async void OnNavigatedTo() | ||
{ | ||
if(Plot == null) | ||
return; | ||
|
||
Plot.Clear(); | ||
Plot.Add.Palette = new ScottPlot.Palettes.Nord(); | ||
|
||
await using var disposableQuery = await BatteryHistoryManager.BeginDisposableQueryAsync(); | ||
var cutOffDate = DateTime.Now - TimeSpan.FromDays(1); | ||
|
||
var query = disposableQuery.Queryable | ||
.Where(record => record.Timestamp > cutOffDate); | ||
|
||
var batteryL = new List<float>(); | ||
var batteryR = new List<float>(); | ||
var timestampL = new List<DateTime>(); | ||
var timestampR = new List<DateTime>(); | ||
|
||
await foreach (var record in query.AsAsyncEnumerable()) | ||
{ | ||
batteryL.Add(record.BatteryL > 0 ? record.BatteryL ?? float.NaN : float.NaN); | ||
timestampL.Add(record.Timestamp); | ||
batteryR.Add(record.BatteryR > 0 ? record.BatteryR ?? float.NaN : float.NaN); | ||
timestampR.Add(record.Timestamp); | ||
} | ||
|
||
var plotBatteryL = Plot.Add.Scatter(timestampL, batteryL); | ||
plotBatteryL.MarkerShape = MarkerShape.None; | ||
plotBatteryL.LegendText = Strings.Left; | ||
|
||
var plotBatteryR = Plot.Add.Scatter(timestampR, batteryR); | ||
plotBatteryR.MarkerShape = MarkerShape.None; | ||
plotBatteryR.LegendText = Strings.Right; | ||
|
||
|
||
/*Plot.Axes.Rules.Add(new MaximumBoundary(Plot.Axes.Bottom, Plot.Axes.Left, new AxisLimits(new CoordinateRect | ||
{ | ||
Right = DateTimeOffset.Now.ToUnixTimeMilliseconds(), | ||
Left = (DateTimeOffset.Now - TimeSpan.FromDays(7)).ToUnixTimeMilliseconds(), | ||
Top = 105, | ||
Bottom = 0 | ||
})));*/ | ||
Plot.Axes.Left.TickGenerator = new NumericAutomatic() | ||
{ | ||
LabelFormatter = value => value is < 0 or > 100 ? string.Empty : NumericAutomatic.DefaultLabelFormatter(value), | ||
}; | ||
|
||
Plot.YLabel("Charge (%)"); | ||
Plot.ShowLegend(); | ||
|
||
Plot?.Axes.DateTimeTicksBottom(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.