Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit de6df61

Browse files
committed
Improved the gem sum utility.
1 parent ebf9871 commit de6df61

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Text;
2+
using LiberPrimusAnalysisTool.Utility.Character;
3+
using MediatR;
4+
5+
namespace LiberPrimusAnalysisTool.Application.Commands.TextUtilies;
6+
7+
public class CalculateDetailGematriaSum
8+
{
9+
public class Command : IRequest<Tuple<long, long[], long[]>>
10+
{
11+
public Command(string text)
12+
{
13+
Text = text;
14+
}
15+
16+
public string Text { get; set; }
17+
}
18+
19+
public class Handler : IRequestHandler<Command, Tuple<long, long[], long[]>>
20+
{
21+
private readonly ICharacterRepo _characterRepo;
22+
public Handler(ICharacterRepo characterRepo)
23+
{
24+
_characterRepo = characterRepo;
25+
}
26+
27+
public Task<Tuple<long, long[], long[]>> Handle(Command request, CancellationToken cancellationToken)
28+
{
29+
long sum = 0;
30+
List<long> numbers = new List<long>();
31+
List<long> wordSums = new List<long>();
32+
33+
long currentWordSum = 0;
34+
foreach (var rune in request.Text)
35+
{
36+
if (_characterRepo.IsRune(rune.ToString(), false) || rune == '\'' || rune == '"')
37+
{
38+
var characterValue = _characterRepo.GetValueFromRune(rune.ToString());
39+
if (characterValue != null)
40+
{
41+
numbers.Add(characterValue);
42+
currentWordSum += characterValue;
43+
sum += characterValue;
44+
}
45+
}
46+
else
47+
{
48+
if (currentWordSum > 0)
49+
{
50+
wordSums.Add(currentWordSum);
51+
}
52+
currentWordSum = 0;
53+
}
54+
}
55+
56+
if (currentWordSum > 0)
57+
{
58+
wordSums.Add(currentWordSum);
59+
}
60+
61+
return Task.FromResult(new Tuple<long, long[], long[]>(sum, numbers.ToArray(), wordSums.ToArray()));
62+
}
63+
}
64+
}

LiberPrimusUi/ViewModels/MainWindowViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ partial void OnSelectedListItemChanged(ListItemTemplate? value)
9999
_windows.Add(new Tuple<string, object>(value.Label, new HomePageViewModel()));
100100
CurrentPage = _windows.FirstOrDefault(w => w.Item1 == value.Label)?.Item2 as HomePageViewModel;
101101
break;
102+
102103
case Type t when t == typeof(PrimeCheckerViewModel):
103104
if (!_windows.Any(w => w.Item1 == value.Label))
104105
_windows.Add(new Tuple<string, object>(value.Label, new PrimeCheckerViewModel(_mediator)));
105106
CurrentPage = _windows.FirstOrDefault(w => w.Item1 == value.Label)?.Item2 as PrimeCheckerViewModel;
106107
break;
108+
107109
case Type t when t == typeof(GenerateSequenceViewModel):
108110
if (!_windows.Any(w => w.Item1 == value.Label))
109111
_windows.Add(new Tuple<string, object>(value.Label, new GenerateSequenceViewModel(_mediator)));

LiberPrimusUi/ViewModels/SumGemSentencesViewModel.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@ public async void SumText()
2929
var sentences = _textToTranspose.Split(Environment.NewLine);
3030
foreach (var sentence in sentences)
3131
{
32-
var result = await _mediator.Send(new CalculateGematriaSum.Command(sentence.Trim()));
33-
if (result != "0")
32+
if (sentence.Trim().Length == 0)
3433
{
35-
var value = Convert.ToUInt64(result);
36-
var isPrime = await _mediator.Send(new GetIsPrime.Query(value));
37-
38-
counter++;
39-
sb.Append($"Line: {counter} - Is Prime: {isPrime} - Sum: {result}");
40-
sb.AppendLine("");
34+
continue;
4135
}
36+
37+
var result = await _mediator.Send(new CalculateDetailGematriaSum.Command(sentence.Trim()));
38+
var value = Convert.ToUInt64(result.Item1);
39+
var isPrime = await _mediator.Send(new GetIsPrime.Query(value));
40+
41+
counter++;
42+
sb.AppendLine($"Line: {counter} - {sentence.Trim()}");
43+
sb.AppendLine($"Line: {counter} - Is Prime: {isPrime} - Sum: {result.Item1}");
44+
sb.AppendLine($"Line: {counter} - Letter Values: {string.Join(",", result.Item2)}");
45+
sb.AppendLine($"Line: {counter} - Word Sums: {string.Join(",", result.Item3)}");
46+
sb.AppendLine("");
4247
}
43-
48+
4449
Response = sb.ToString();
4550
}
4651

0 commit comments

Comments
 (0)