Skip to content

Commit

Permalink
[Bot] Add Donation table to db
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Sep 23, 2024
1 parent 2e4c7c1 commit 7f6f74b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Bot/Clash/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ static async Task WaitRaidAsync()

private static async Task CheckDonationsAsync(ClanUtil clan)
{
long currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
Dictionary<string, Donation> donations = [];

List<Tuple<string, int>> donDelta = [], recDelta = [];
Dictionary<string, string> accToMainAcc = [];
AdjacencyGraph<string, TaggedEdge<string, int>> graph = new(false);
Expand All @@ -168,6 +171,12 @@ private static async Task CheckDonationsAsync(ClanUtil clan)
{
int donated = current.Donations - previous.Donations;

Donation donation = new(currentTime, tag)
{
Donated = donated
};
donations[tag] = donation;

donDelta.Add(new(current.Tag, donated));

graph.AddVertex(current.Tag);
Expand All @@ -186,6 +195,20 @@ private static async Task CheckDonationsAsync(ClanUtil clan)
{
string vertexName = $"#{current.Tag}"; // Double # for received node
int received = current.DonationsReceived - previous.DonationsReceived;
if (donations.TryGetValue(tag, out Donation? value))
{
value.Received = received;
}
else
{
Donation donation = new(currentTime, tag)
{
Received = received
};

donations[tag] = donation;
}

recDelta.Add(new(current.Tag, received));
graph.AddVertex(vertexName);
graph.AddEdge(new(vertexName, "t", received));
Expand All @@ -199,6 +222,8 @@ private static async Task CheckDonationsAsync(ClanUtil clan)
}
}

Db.InsertAll(donations.Values);

if (graph.VertexCount > 2)
{
ReversedEdgeAugmentorAlgorithm<string, TaggedEdge<string, int>> reverseAlgo = new(
Expand Down
21 changes: 21 additions & 0 deletions Bot/Sql/Donation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using SQLite;

namespace Hyperstellar.Sql;
public class Donation(long time, string cocId, int donated, int received) : DbObj<Donation>
{
[PrimaryKey, NotNull]
public long Time { get; set; } = time;

[PrimaryKey, NotNull]
public string CocID { get; set; } = cocId;

Check notice on line 10 in Bot/Sql/Donation.cs

View workflow job for this annotation

GitHub Actions / inspect

"[InconsistentNaming] Name 'CocID' does not match rule 'Properties'. Suggested name is 'CocId'." on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Sql/Donation.cs(10,19)

[NotNull]
public int Donated { get; set; } = donated;

Check warning on line 13 in Bot/Sql/Donation.cs

View workflow job for this annotation

GitHub Actions / inspect

"[UnusedAutoPropertyAccessor.Global] Auto-property accessor 'Donated.get' is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Sql/Donation.cs(13,26)

[NotNull]
public int Received { get; set; } = received;

public Donation() : this(0, "", 0, 0) { }

public Donation(long time, string cocId) : this(time, cocId, 0, 0) { }

Check notice on line 20 in Bot/Sql/Donation.cs

View workflow job for this annotation

GitHub Actions / inspect

"[IntroduceOptionalParameters.Global] Introduce optional parameter(s) for primary constructor 'Donation(long, string, int, int)'" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Sql/Donation.cs(20,66)
}

0 comments on commit 7f6f74b

Please sign in to comment.