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