xp tracker: don't add duplicate entries if nothing changes
This commit is contained in:
@@ -26,8 +26,10 @@ package net.runelite.http.api.xp;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(exclude = "time")
|
||||||
public class XpData
|
public class XpData
|
||||||
{
|
{
|
||||||
private Instant time;
|
private Instant time;
|
||||||
@@ -56,6 +58,7 @@ public class XpData
|
|||||||
private int hunter_xp;
|
private int hunter_xp;
|
||||||
private int construction_xp;
|
private int construction_xp;
|
||||||
|
|
||||||
|
private int overall_rank;
|
||||||
private int attack_rank;
|
private int attack_rank;
|
||||||
private int defence_rank;
|
private int defence_rank;
|
||||||
private int strength_rank;
|
private int strength_rank;
|
||||||
|
|||||||
@@ -24,9 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.xp;
|
package net.runelite.http.service.xp;
|
||||||
|
|
||||||
|
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||||
import net.runelite.http.api.xp.XpData;
|
import net.runelite.http.api.xp.XpData;
|
||||||
import net.runelite.http.service.xp.beans.XpEntity;
|
import net.runelite.http.service.xp.beans.XpEntity;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
@@ -35,4 +37,54 @@ public interface XpMapper
|
|||||||
XpMapper INSTANCE = Mappers.getMapper(XpMapper.class);
|
XpMapper INSTANCE = Mappers.getMapper(XpMapper.class);
|
||||||
|
|
||||||
XpData xpEntityToXpData(XpEntity xpEntity);
|
XpData xpEntityToXpData(XpEntity xpEntity);
|
||||||
|
|
||||||
|
@Mapping(source = "attack.experience", target = "attack_xp")
|
||||||
|
@Mapping(source = "defence.experience", target = "defence_xp")
|
||||||
|
@Mapping(source = "strength.experience", target = "strength_xp")
|
||||||
|
@Mapping(source = "hitpoints.experience", target = "hitpoints_xp")
|
||||||
|
@Mapping(source = "ranged.experience", target = "ranged_xp")
|
||||||
|
@Mapping(source = "prayer.experience", target = "prayer_xp")
|
||||||
|
@Mapping(source = "magic.experience", target = "magic_xp")
|
||||||
|
@Mapping(source = "cooking.experience", target = "cooking_xp")
|
||||||
|
@Mapping(source = "woodcutting.experience", target = "woodcutting_xp")
|
||||||
|
@Mapping(source = "fletching.experience", target = "fletching_xp")
|
||||||
|
@Mapping(source = "fishing.experience", target = "fishing_xp")
|
||||||
|
@Mapping(source = "firemaking.experience", target = "firemaking_xp")
|
||||||
|
@Mapping(source = "crafting.experience", target = "crafting_xp")
|
||||||
|
@Mapping(source = "smithing.experience", target = "smithing_xp")
|
||||||
|
@Mapping(source = "mining.experience", target = "mining_xp")
|
||||||
|
@Mapping(source = "herblore.experience", target = "herblore_xp")
|
||||||
|
@Mapping(source = "agility.experience", target = "agility_xp")
|
||||||
|
@Mapping(source = "thieving.experience", target = "thieving_xp")
|
||||||
|
@Mapping(source = "slayer.experience", target = "slayer_xp")
|
||||||
|
@Mapping(source = "farming.experience", target = "farming_xp")
|
||||||
|
@Mapping(source = "runecraft.experience", target = "runecraft_xp")
|
||||||
|
@Mapping(source = "hunter.experience", target = "hunter_xp")
|
||||||
|
@Mapping(source = "construction.experience", target = "construction_xp")
|
||||||
|
|
||||||
|
@Mapping(source = "overall.rank", target = "overall_rank")
|
||||||
|
@Mapping(source = "attack.rank", target = "attack_rank")
|
||||||
|
@Mapping(source = "defence.rank", target = "defence_rank")
|
||||||
|
@Mapping(source = "strength.rank", target = "strength_rank")
|
||||||
|
@Mapping(source = "hitpoints.rank", target = "hitpoints_rank")
|
||||||
|
@Mapping(source = "ranged.rank", target = "ranged_rank")
|
||||||
|
@Mapping(source = "prayer.rank", target = "prayer_rank")
|
||||||
|
@Mapping(source = "magic.rank", target = "magic_rank")
|
||||||
|
@Mapping(source = "cooking.rank", target = "cooking_rank")
|
||||||
|
@Mapping(source = "woodcutting.rank", target = "woodcutting_rank")
|
||||||
|
@Mapping(source = "fletching.rank", target = "fletching_rank")
|
||||||
|
@Mapping(source = "fishing.rank", target = "fishing_rank")
|
||||||
|
@Mapping(source = "firemaking.rank", target = "firemaking_rank")
|
||||||
|
@Mapping(source = "crafting.rank", target = "crafting_rank")
|
||||||
|
@Mapping(source = "smithing.rank", target = "smithing_rank")
|
||||||
|
@Mapping(source = "mining.rank", target = "mining_rank")
|
||||||
|
@Mapping(source = "herblore.rank", target = "herblore_rank")
|
||||||
|
@Mapping(source = "agility.rank", target = "agility_rank")
|
||||||
|
@Mapping(source = "thieving.rank", target = "thieving_rank")
|
||||||
|
@Mapping(source = "slayer.rank", target = "slayer_rank")
|
||||||
|
@Mapping(source = "farming.rank", target = "farming_rank")
|
||||||
|
@Mapping(source = "runecraft.rank", target = "runecraft_rank")
|
||||||
|
@Mapping(source = "hunter.rank", target = "hunter_rank")
|
||||||
|
@Mapping(source = "construction.rank", target = "construction_rank")
|
||||||
|
XpData hiscoreResultToXpData(HiscoreResult hiscoreResult);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ package net.runelite.http.service.xp;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||||
|
import net.runelite.http.api.xp.XpData;
|
||||||
import net.runelite.http.service.hiscore.HiscoreResultBuilder;
|
import net.runelite.http.service.hiscore.HiscoreResultBuilder;
|
||||||
import net.runelite.http.service.hiscore.HiscoreService;
|
import net.runelite.http.service.hiscore.HiscoreService;
|
||||||
import net.runelite.http.service.xp.beans.PlayerEntity;
|
import net.runelite.http.service.xp.beans.PlayerEntity;
|
||||||
@@ -39,6 +41,7 @@ import org.sql2o.Connection;
|
|||||||
import org.sql2o.Sql2o;
|
import org.sql2o.Sql2o;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class XpTrackerService
|
public class XpTrackerService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -61,6 +64,19 @@ public class XpTrackerService
|
|||||||
{
|
{
|
||||||
PlayerEntity playerEntity = findOrCreatePlayer(username);
|
PlayerEntity playerEntity = findOrCreatePlayer(username);
|
||||||
|
|
||||||
|
XpEntity currentXp = findXpAtTime(username, Instant.now());
|
||||||
|
if (currentXp != null)
|
||||||
|
{
|
||||||
|
XpData hiscoreData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
|
||||||
|
XpData existingData = XpMapper.INSTANCE.xpEntityToXpData(currentXp);
|
||||||
|
|
||||||
|
if (hiscoreData.equals(existingData))
|
||||||
|
{
|
||||||
|
log.debug("Hiscore for {} already up to date", username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp,"
|
con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp,"
|
||||||
+ "fletching_xp,fishing_xp,firemaking_xp,crafting_xp,smithing_xp,mining_xp,herblore_xp,agility_xp,thieving_xp,slayer_xp,farming_xp,"
|
+ "fletching_xp,fishing_xp,firemaking_xp,crafting_xp,smithing_xp,mining_xp,herblore_xp,agility_xp,thieving_xp,slayer_xp,farming_xp,"
|
||||||
+ "runecraft_xp,hunter_xp,construction_xp,attack_rank,defence_rank,strength_rank,hitpoints_rank,ranged_rank,prayer_rank,magic_rank,"
|
+ "runecraft_xp,hunter_xp,construction_xp,attack_rank,defence_rank,strength_rank,hitpoints_rank,ranged_rank,prayer_rank,magic_rank,"
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.service.xp;
|
||||||
|
|
||||||
|
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||||
|
import net.runelite.http.api.hiscore.Skill;
|
||||||
|
import net.runelite.http.api.xp.XpData;
|
||||||
|
import net.runelite.http.service.xp.beans.XpEntity;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class XpMapperTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testXpEntityToXpData()
|
||||||
|
{
|
||||||
|
XpEntity xpEntity = new XpEntity();
|
||||||
|
xpEntity.setAgility_rank(42);
|
||||||
|
xpEntity.setAgility_xp(9001);
|
||||||
|
|
||||||
|
XpData xpData = XpMapper.INSTANCE.xpEntityToXpData(xpEntity);
|
||||||
|
assertEquals(42, xpData.getAgility_rank());
|
||||||
|
assertEquals(9001, xpData.getAgility_xp());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHiscoreResultToXpData()
|
||||||
|
{
|
||||||
|
HiscoreResult hiscoreResult = new HiscoreResult();
|
||||||
|
hiscoreResult.setAgility(new Skill(42, 9, 9001));
|
||||||
|
|
||||||
|
XpData xpData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
|
||||||
|
assertEquals(42, xpData.getAgility_rank());
|
||||||
|
assertEquals(9001, xpData.getAgility_xp());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user