Skip to content

Commit

Permalink
import attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jul 13, 2023
1 parent 9208119 commit afc1d21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
28 changes: 15 additions & 13 deletions src/main/java/link/locutus/discord/db/NationDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void load() throws SQLException {
int treaties = loadTreaties();
LOGGER.info("Loaded " + treaties + " treaties");

importLegacyNationLoot();
importLegacyNationLoot(true);

markDirtyIncorrectNations(true, true);

Expand Down Expand Up @@ -2933,9 +2933,9 @@ public void acceptThrows(LootEntry entry, PreparedStatement stmt) throws Excepti
}
}

private void importLegacyNationLoot() throws SQLException {
private void importLegacyNationLoot(boolean fromAttacks) throws SQLException {
List<LootEntry> lootInfoList = new ArrayList<>();
if (tableExists("NATION_LOOT")) {
List<LootEntry> lootInfoList = new ArrayList<>();

try (PreparedStatement stmt = prepareQuery("select * FROM NATION_LOOT WHERE id IN (SELECT nation_id FROM NATIONS2)")) {
try (ResultSet rs = stmt.executeQuery()) {
Expand All @@ -2955,18 +2955,20 @@ private void importLegacyNationLoot() throws SQLException {
}
}

Map<Integer, Map.Entry<Long, double[]>> nationLoot = Locutus.imp().getWarDb().getNationLootFromAttacksLegacy();
for (Map.Entry<Integer, Map.Entry<Long, double[]>> entry : nationLoot.entrySet()) {
int nationId = entry.getKey();
long date = entry.getValue().getKey();
double[] loot = entry.getValue().getValue();
NationLootType type = NationLootType.WAR_LOSS;
lootInfoList.add(new LootEntry(nationId, loot, date, type));
}
getDb().drop("NATION_LOOT");
}

Map<Integer, Map.Entry<Long, double[]>> nationLoot = Locutus.imp().getWarDb().getNationLootFromAttacksLegacy();
for (Map.Entry<Integer, Map.Entry<Long, double[]>> entry : nationLoot.entrySet()) {
int nationId = entry.getKey();
long date = entry.getValue().getKey();
double[] loot = entry.getValue().getValue();
NationLootType type = NationLootType.WAR_LOSS;
lootInfoList.add(new LootEntry(nationId, loot, date, type));
}

if (!lootInfoList.isEmpty()) {
saveNationLoot(lootInfoList);

getDb().drop("NATION_LOOT");
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/link/locutus/discord/db/WarDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,6 @@ public void saveAttacks(Collection<DBAttack> values) {
Map<ResourceType, Double> loot = attack.getLoot();
Double pct;
if (loot == null) {
loot = Collections.emptyMap();
pct = 1d;
} else {
pct = attack.getLootPercent();
Expand Down Expand Up @@ -1833,6 +1832,7 @@ public boolean test(WarAttack v3Attack) {
}

List<DBAttack> dbAttacks = new ArrayList<>();
List<DBAttack> newAttacks;
Set<DBWar> warsToSave = new LinkedHashSet<>();
List<DBAttack> dirtyCities = new ArrayList<>();

Expand All @@ -1849,7 +1849,6 @@ public boolean test(WarAttack v3Attack) {
}
}

List<DBAttack> newAttacks;
if (v2) {
try {
List<WarAttacksContainer> attacksv2 = Locutus.imp().getPnwApiV2().getWarAttacksByMinWarAttackId(maxId).getWarAttacksContainers();
Expand Down Expand Up @@ -2034,7 +2033,7 @@ public boolean test(WarAttack v3Attack) {
}

{ // add to db
saveAttacks(dbAttacks);
saveAttacks(newAttacks);
}

if (runAlerts && eventConsumer != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/link/locutus/discord/gpt/GptHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public GptHandler() throws SQLException, ClassNotFoundException {
this.embeddingDatabase = new AdaEmbedding(registry, service);
// TODO change ^ that to mini

File gpt4freePath = new File("../gpt4free/mymain.py");
File gpt4freePath = new File("../gpt4free/gpt3_5_turbo.py");
File venvExe = new File("../gpt4free/venv/Scripts/python.exe");
// ensure files exist
if (!gpt4freePath.exists()) {
Expand Down

0 comments on commit afc1d21

Please sign in to comment.