Skip to content

Commit

Permalink
Add emptychronicle option (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus authored Mar 15, 2024
1 parent 46fbb43 commit 1082bf6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion NineChroniclesUtilBackend.Store/Scrapper/ArenaScrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async Task FlushBufferAsync()

if (arenaData != null && avatarData != null)
{
buffer.Add((arenaData, avatarData));
buffer.Add((avatarAddress, arenaData, avatarData));
}

if (buffer.Count >= maxBufferSize)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace NineChroniclesUtilBackend.Options;

public class DataProviderOption
public class EmptyChronicleOption
{
public Uri Endpoint { get; set; }
}
1 change: 0 additions & 1 deletion NineChroniclesUtilBackend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
builder.Configuration.AddEnvironmentVariables();

builder.Services.Configure<HeadlessStateServiceOption>(builder.Configuration.GetRequiredSection("StateService"));
builder.Services.Configure<DataProviderOption>(builder.Configuration.GetRequiredSection("DataProvider"));
builder.Services.Configure<DatabaseOption>(builder.Configuration.GetRequiredSection("Database"));
builder.Services.ConfigureHttpJsonOptions(options =>
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using MongoDB.Driver;
using Nekoyume.Model.State;
using NineChroniclesUtilBackend.Models.Agent;
using NineChroniclesUtilBackend.Models.Arena;
using NineChroniclesUtilBackend.Options;
using NineChroniclesUtilBackend.Services;

namespace NineChroniclesUtilBackend.Repositories;

public class ArenaRankingRepository(MongoDBCollectionService mongoDBCollectionService)
public class ArenaRankingRepository(MongoDBCollectionService mongoDBCollectionService, IOptions<EmptyChronicleOption> options)
{
private CpRepository cpRepository = new CpRepository(options.Value.Endpoint);

private readonly IMongoCollection<dynamic> ArenaCollection =
mongoDBCollectionService.GetCollection<dynamic>("arena");

Expand Down Expand Up @@ -85,7 +89,7 @@ private async Task<ArenaRanking> BuildArenaRankingFromDocument(BsonDocument docu
(rune["RuneId"].AsInt32, rune["Level"].AsInt32)
);

var cp = await CpRepository.CalculateCp(avatar, characterId, equipmentids, costumeids, runeSlots);
var cp = await cpRepository.CalculateCp(avatar, characterId, equipmentids, costumeids, runeSlots);
arenaRanking.CP = cp;
Console.WriteLine($"CP Calculate {arenaRanking.ArenaAddress}");

Expand Down
29 changes: 18 additions & 11 deletions NineChroniclesUtilBackend/Repositories/CpRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@

namespace NineChroniclesUtilBackend.Repositories;

public static class CpRepository
public class CpRepository
{
public static async Task<int?> CalculateCp(
private Uri emptyChronicleEndpoint { get; set; }

public CpRepository(Uri _emptyChronicleEndpoint)
{
emptyChronicleEndpoint = _emptyChronicleEndpoint;
}

public async Task<int?> CalculateCp(
Avatar avatar,
int characterId,
IEnumerable<string> equipmentIds,
Expand Down Expand Up @@ -53,7 +60,7 @@ public static class CpRepository
}
}

private static async Task<Dictionary<string, Dictionary>> GetInventory(string address)
private async Task<Dictionary<string, Dictionary>> GetInventory(string address)
{
var inventoryState = await GetInventoryState(address);

Expand All @@ -72,7 +79,7 @@ private static async Task<Dictionary<string, Dictionary>> GetInventory(string ad
});
}

private static async Task<RuneOptionSheet.Row.RuneOptionInfo> GetRuneOptionInfo(
private async Task<RuneOptionSheet.Row.RuneOptionInfo> GetRuneOptionInfo(
int id,
int level
)
Expand All @@ -92,7 +99,7 @@ int level
return option;
}

private static async Task<CharacterSheet.Row> GetCharacterRow(int characterId)
private async Task<CharacterSheet.Row> GetCharacterRow(int characterId)
{
var sheets = await GetSheet(new CharacterSheet());

Expand All @@ -104,7 +111,7 @@ int level
return row;
}

private static async Task<T> GetSheet<T>(T sheets)
private async Task<T> GetSheet<T>(T sheets)
where T : ISheet
{
var sheetsAddress = Addresses.GetSheetAddress<T>();
Expand All @@ -114,18 +121,18 @@ private static async Task<T> GetSheet<T>(T sheets)
return sheets;
}

private static async Task<T> GetState<T>(Address address, string? account = null)
private async Task<T> GetState<T>(Address address, string? account = null)
where T : IValue => await GetState<T>(address.ToString(), account);

// TODO: Cache
private static async Task<T?> GetState<T>(string address, string? account = null)
private async Task<T?> GetState<T>(string address, string? account = null)
where T : IValue
{
var codec = new Codec();
var url =
account == null
? $"http://localhost:5009/api/states/{address}/raw"
: $"http://localhost:5009/api/states/{address}/raw?account={account}";
? $"${emptyChronicleEndpoint}/api/states/{address}/raw"
: $"${emptyChronicleEndpoint}/api/states/{address}/raw?account={account}";
var client = new HttpClient();
var response = await client.GetAsync(url);
var json = JsonNode.Parse(await response.Content.ReadAsStringAsync());
Expand All @@ -139,6 +146,6 @@ private static async Task<T> GetState<T>(Address address, string? account = null
return (T)value;
}

private static async Task<List> GetInventoryState(string address) =>
private async Task<List> GetInventoryState(string address) =>
await GetState<List?>(address, Addresses.Inventory.ToString()) ?? [];
}

0 comments on commit 1082bf6

Please sign in to comment.