From bb125e7c7ddfdf2fcf81565e175153ab7f300afe Mon Sep 17 00:00:00 2001
From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com>
Date: Tue, 4 Jul 2023 21:20:33 +0200
Subject: [PATCH] Speech, auto avoid, bug fixes, iu improments
---
LearningChineseFixed/Classes/CCharStats.cs | 28 ++++
LearningChineseFixed/Client/Program.cs | 2 +
.../LearningChineseFixed.csproj | 1 +
LearningChineseFixed/Pages/Index.razor | 27 +++-
LearningChineseFixed/Pages/Learn.razor | 121 +++++++++++++++---
.../Properties/launchSettings.json | 2 +-
LearningChineseFixed/_Imports.razor | 3 +-
LearningChineseFixed/wwwroot/index.html | 2 +-
8 files changed, 164 insertions(+), 22 deletions(-)
create mode 100644 LearningChineseFixed/Classes/CCharStats.cs
diff --git a/LearningChineseFixed/Classes/CCharStats.cs b/LearningChineseFixed/Classes/CCharStats.cs
new file mode 100644
index 0000000..37fa208
--- /dev/null
+++ b/LearningChineseFixed/Classes/CCharStats.cs
@@ -0,0 +1,28 @@
+namespace LearningChineseFixed
+{
+ public class CCharStats
+ {
+ public CChar cchar { get; set; }
+ public int NumOfCorrects { get; set; } = 0;
+ public int NumOfWrongs { get; set; } = 0;
+ public int TotalAnswers { get => NumOfCorrects + NumOfWrongs; }
+ public float Accuracy
+ {
+ get
+ {
+ return (float)NumOfCorrects / (float)TotalAnswers;
+ }
+ }
+
+ public CCharStats(CChar cchar)
+ {
+ this.cchar = cchar;
+ }
+ }
+
+ public enum StatType
+ {
+ NumOfCorrects,
+ NumOfWrongs
+ }
+}
\ No newline at end of file
diff --git a/LearningChineseFixed/Client/Program.cs b/LearningChineseFixed/Client/Program.cs
index 88e280b..fe0fd9d 100644
--- a/LearningChineseFixed/Client/Program.cs
+++ b/LearningChineseFixed/Client/Program.cs
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor;
using Blazored.LocalStorage;
using MudBlazor.Services;
+using Toolbelt.Blazor.Extensions.DependencyInjection;
namespace LearningChineseFixed
{
@@ -27,6 +28,7 @@ namespace LearningChineseFixed
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomCenter;
});
builder.Services.AddBlazoredLocalStorage();
+ builder.Services.AddSpeechSynthesis();
await builder.Build().RunAsync();
}
diff --git a/LearningChineseFixed/LearningChineseFixed.csproj b/LearningChineseFixed/LearningChineseFixed.csproj
index 740303a..51b2277 100644
--- a/LearningChineseFixed/LearningChineseFixed.csproj
+++ b/LearningChineseFixed/LearningChineseFixed.csproj
@@ -15,6 +15,7 @@
+
diff --git a/LearningChineseFixed/Pages/Index.razor b/LearningChineseFixed/Pages/Index.razor
index 652b218..32f06fc 100644
--- a/LearningChineseFixed/Pages/Index.razor
+++ b/LearningChineseFixed/Pages/Index.razor
@@ -2,6 +2,7 @@
@inject NavigationManager navigator
@inject HttpClient httpClient
@inject Blazored.LocalStorage.ILocalStorageService localStorage
+@inject SpeechSynthesis SpeechSynthesis
Index
@@ -105,17 +106,35 @@
Parallel.For(0, numOfChunks, async (i)=>
{
await Task.Delay(10*i);
- jsonChunks[i] = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
+ try
+ {
+ jsonChunks[i] = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
+ }
+ catch (Exception)
+ {
+ await Task.Delay(100);
+ jsonChunks[i] = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
+ }
- if (string.IsNullOrEmpty(jsonChunks[i])) return;
+ if (string.IsNullOrEmpty(jsonChunks[i])) throw new Exception("Couldn't load chunk: " + i);
- await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunks[i]);
- savedChunks = i + 1;
+ try
+ {
+ await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunks[i]);
+ }
+ catch (Exception)
+ {
+ await Task.Delay(100);
+ await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunks[i]);
+ }
+
+ if (!await localStorage.ContainKeyAsync($"Normalized_chunk_{i.ToString("000")}.json")) throw new Exception("Couldn't save chunk: " + i);
});
while (jsonChunks.Any(x => x == null))
{
await Task.Delay(1);
+ savedChunks = jsonChunks.Count(x=>x != null);
StateHasChanged();
}
diff --git a/LearningChineseFixed/Pages/Learn.razor b/LearningChineseFixed/Pages/Learn.razor
index 65c2232..f61b59a 100644
--- a/LearningChineseFixed/Pages/Learn.razor
+++ b/LearningChineseFixed/Pages/Learn.razor
@@ -6,7 +6,7 @@
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@inject HttpClient httpClient
@inject ISnackbar Snackbar
-
+@inject SpeechSynthesis SpeechSynthesis