Skip to content

Commit

Permalink
moved to new API, added version view to benchmark
Browse files Browse the repository at this point in the history
- Moved website and API to a single website (website still W.I.P)
- Added a checkbox in benchmark window to only show results for current version
  • Loading branch information
Prevter committed Aug 13, 2022
1 parent 34ff3fd commit a0debfd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FloatTool/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static string FirstCharToUpper(this string input) =>

public static class Utils
{
public const string API_URL = "https://prevterapi.000webhostapp.com";
public const string API_URL = "https://git.prevter.ml/api/floattool";
private static readonly HttpClient Client = new();

public static async Task<decimal> GetWearFromInspectURL(string inspect_url)
Expand Down
3 changes: 2 additions & 1 deletion FloatTool/Languages/Lang.uk.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<v:String x:Key="m_Threads">Потоків</v:String>
<v:String x:Key="m_Thread">Поток</v:String>
<v:String x:Key="m_PublishResult">Опублікувати результат</v:String>

<v:String x:Key="m_OnlyVersion">Показувати тільки поточну версію</v:String>

<!-- Combination -->
<v:String x:Key="m_Copy">Скопіювати</v:String>
<v:String x:Key="m_PossibleFloat">Можливий флоат:</v:String>
Expand Down
1 change: 1 addition & 0 deletions FloatTool/Languages/Lang.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<v:String x:Key="m_Threads">Threads</v:String>
<v:String x:Key="m_Thread">Thread</v:String>
<v:String x:Key="m_PublishResult">Publish result</v:String>
<v:String x:Key="m_OnlyVersion">Show only current version</v:String>

<!-- Combination -->
<v:String x:Key="m_Copy">Copy</v:String>
Expand Down
48 changes: 34 additions & 14 deletions FloatTool/ViewModels/BenchmarkViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ public class BenchmarkResult
private int progressPercentage;
private bool buttonsEnabled = true;
private bool canPublish = false;
private bool showOnlyCurrent = false;
private int multithreadedSpeed = 0;
private int threadCount = Environment.ProcessorCount;
private int singlethreadedSpeed = 0;
private bool isUpdatingEnabled;

private static readonly LinearGradientBrush AMDBrush = Application.Current.Resources["AmdBenchmarkFill"] as LinearGradientBrush;
private static readonly LinearGradientBrush IntelBrush = Application.Current.Resources["IntelBenchmarkFill"] as LinearGradientBrush;
private static readonly LinearGradientBrush CurrentBrush = Application.Current.Resources["CurrentBenchmarkFill"] as LinearGradientBrush;

public int ProgressPercentage
{
get { return progressPercentage; }
Expand Down Expand Up @@ -77,8 +86,7 @@ public bool CanPublish
OnPropertyChanged();
}
}

private int threadCount = Environment.ProcessorCount;

public int ThreadCount
{
get
Expand All @@ -91,8 +99,20 @@ public int ThreadCount
OnPropertyChanged();
}
}
public bool ShowOnlyCurrent
{
get
{
return showOnlyCurrent;
}
set
{
showOnlyCurrent = value;
PollBenchmarkResults();
OnPropertyChanged();
}
}

private int multithreadedSpeed = 0;
public int MultithreadedSpeed
{
get { return multithreadedSpeed; }
Expand All @@ -104,7 +124,6 @@ public int MultithreadedSpeed
}
public string MultithreadedSpeedText { get { return $"{multithreadedSpeed:n0}"; } }

private int singlethreadedSpeed = 0;
public int SinglethreadedSpeed
{
get { return singlethreadedSpeed; }
Expand All @@ -120,11 +139,6 @@ public int SinglethreadedSpeed
public string CurrentCpuName { get; set; }
public static string CurrentCpuThreads { get { return $"{Environment.ProcessorCount}"; } }

private static readonly LinearGradientBrush AMDBrush = Application.Current.Resources["AmdBenchmarkFill"] as LinearGradientBrush;
private static readonly LinearGradientBrush IntelBrush = Application.Current.Resources["IntelBenchmarkFill"] as LinearGradientBrush;
private static readonly LinearGradientBrush CurrentBrush = Application.Current.Resources["CurrentBenchmarkFill"] as LinearGradientBrush;

private bool isUpdatingEnabled;
public bool IsUpdatingEnabled
{
get { return isUpdatingEnabled; }
Expand All @@ -133,13 +147,16 @@ public bool IsUpdatingEnabled

public async void PollBenchmarkResults()
{
Logger.Log.Info("Getting benchmark results");
var url = Utils.API_URL + "/load";
if (ShowOnlyCurrent) url += $"?version={AppHelpers.VersionCode}";
Logger.Log.Info($"Getting benchmark results from {url}");
IsUpdatingEnabled = false;
try
{
BenchmarkResults.Clear();
using var client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(Utils.API_URL + "/LoadBenchmarks.php");

HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(responseBody);
Expand Down Expand Up @@ -181,13 +198,16 @@ public async void PollBenchmarkResults()
}
}

Logger.Log.Info("Benchmark results loaded");
Logger.Log.Info($"Benchmark results loaded: {BenchmarkResults.Count} items");

if (BenchmarkResults.Count == 0)
throw new Exception("0 results");
}
catch (Exception ex)
{
BenchmarkResults.Add(new BenchmarkResult
{
CpuName = "Error loading benchmark table.",
CpuName = "Error loading benchmark table: " + ex.Message,
FillSize = new GridLength(0, GridUnitType.Star),
EmptySize = new GridLength(1, GridUnitType.Star),
});
Expand All @@ -205,7 +225,7 @@ public async void PushBenchmarkResults()
using var client = new HttpClient();
var version = Assembly.GetExecutingAssembly().GetName().Version;
client.DefaultRequestHeaders.Add("User-Agent", $"FloatTool/{AppHelpers.VersionCode}");
string paramedURL = $"/AddBenchmark.php?cpu={CurrentCpuName}&threads={ThreadCount}&multicore={MultithreadedSpeed}&singlecore={SinglethreadedSpeed}";
string paramedURL = $"/submit?cpu={CurrentCpuName}&threads={ThreadCount}&multicore={MultithreadedSpeed}&singlecore={SinglethreadedSpeed}";
HttpResponseMessage response = await client.GetAsync(Utils.API_URL + paramedURL);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Expand Down
6 changes: 6 additions & 0 deletions FloatTool/Views/BenchmarkWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@

</StackPanel>
<StackPanel VerticalAlignment="Bottom" Margin="10">
<CheckBox Style="{DynamicResource CheckBoxStyle}"
Content="{DynamicResource m_OnlyVersion}"
FontSize="14"
Foreground="{DynamicResource BenchmarkWindowMainForeground}"
Margin="0,0,0,8"
IsChecked="{Binding ShowOnlyCurrent}"/>
<Border Height="52" CornerRadius="8" Margin="0,0,0,2">
<Grid>
<Grid.ColumnDefinitions>
Expand Down
4 changes: 2 additions & 2 deletions FloatTool/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ private void Window_KeyUp(object sender, KeyEventArgs e)
switch (e.Key)
{
case Key.F1:
Process.Start(new ProcessStartInfo { FileName = "https://prevter.github.io/FloatTool/table.html", UseShellExecute = true });
Process.Start(new ProcessStartInfo { FileName = "https://git.prevter.ml/floattool/table", UseShellExecute = true });
break;
case Key.F2:
Process.Start(new ProcessStartInfo { FileName = "https://prevter.github.io/FloatTool/utils.html", UseShellExecute = true });
Process.Start(new ProcessStartInfo { FileName = "https://git.prevter.ml/floattool/tools", UseShellExecute = true });
break;
case Key.F3:
string skin = $"{ViewModel.WeaponName} | {ViewModel.SkinName}";
Expand Down

0 comments on commit a0debfd

Please sign in to comment.