Skip to content

Commit

Permalink
Implement global xp modifier setting
Browse files Browse the repository at this point in the history
Resolves #39

Refactoring without change of functionality:
- Simplify the adjustedivl calculation
- Change some config queries to use get(), making them more robust
  • Loading branch information
zjosua committed Nov 12, 2023
1 parent 4945beb commit 14dc8ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 3 additions & 4 deletions designer/pokemanki_options.ui
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dsb_xp_modifier_global">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>not implemented yet</string>
<string>Adjusts how many XP are gained per review
min 0.001
max 1'000</string>
</property>
<property name="decimals">
<number>3</number>
Expand Down
2 changes: 1 addition & 1 deletion src/pokemanki/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
Version information
"""

__version__ = "1.4.8"
__version__ = "1.5.0"
22 changes: 14 additions & 8 deletions src/pokemanki/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def FirstPokemon() -> None:
# stats = mw.col.db.all("""select id, ivl from cards where did in (%s)""" % deck)

# cardIds = mw.col.db.all("""select id from cards where did in (%s)""" % deck)
global_startdate = get_synced_conf().get("global_startdate", 1160006400000)
conf = get_synced_conf()
global_startdate = conf.get("global_startdate", 1160006400000)
global_xp_modifier = conf.get("xp_modifier_global", 1)
cardIds = cardIdsFromDeckIds(mw.col.db, [deck])
stats = []
for cid in cardIds:
Expand All @@ -255,7 +257,7 @@ def FirstPokemon() -> None:

sumivl = 0
for id, ivl in stats:
adjustedivl = 100 * (ivl / 100) ** 0.5
adjustedivl = global_xp_modifier * 10 * ivl**0.5
sumivl += adjustedivl
if len(stats) != 0:
Level = int(sumivl / len(stats) + 0.5)
Expand Down Expand Up @@ -358,15 +360,17 @@ def MultiPokemon(
# If no results, return
if len(results) == 0:
return
prestigelist = get_synced_conf()["prestigelist"]
everstonelist = get_synced_conf()["everstonelist"]
everstonepokemonlist = get_synced_conf()["everstonepokemonlist"]
conf = get_synced_conf()
prestigelist = conf.get("prestigelist", [])
everstonelist = conf.get("everstonelist", [])
everstonepokemonlist = conf.get("everstonepokemonlist", [])
global_xp_modifier = conf.get("xp_modifier_global", 1)
# Determine level of Pokemon (if zero, do not assign Pokemon)
for item in results:
result = item[1]
sumivl = 0
for id, ivl in result:
adjustedivl = 100 * (ivl / 100) ** (0.5)
adjustedivl = global_xp_modifier * 10 * ivl**0.5
sumivl += adjustedivl
if len(result) == 0:
continue
Expand Down Expand Up @@ -586,12 +590,14 @@ def TagPokemon() -> (
results = TagStats()
if len(results) == 0:
return
prestigelist = get_synced_conf()["prestigelist"]
conf = get_synced_conf()
prestigelist = conf.get("prestigelist", [])
global_xp_modifier = conf.get("xp_modifier_global", 1)
for item in results:
result = item[1]
sumivl = 0
for id, ivl in result:
adjustedivl = 100 * (ivl / 100) ** (0.5)
adjustedivl = global_xp_modifier * 10 * ivl**0.5
sumivl += adjustedivl
if len(result) == 0:
continue
Expand Down

0 comments on commit 14dc8ab

Please sign in to comment.