Skip to content

Commit a365f51

Browse files
authored
Merge pull request #760 from Path-of-Modifiers/759-fix-text-roll-updating-regex
#759 Fix text roll updating regex
2 parents 0d5ff76 + e156f7f commit a365f51

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

src/backend_data_retrieval/data_retrieval_app/data_deposit/modifier/modifier_data/CaneOfKulemak.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ minRoll,maxRoll,textRolls,position,effect,static,unique,veiled
1010
5,8,,0,"+#% to Quality of Socketed Support Gems",,True,True
1111
20,30,,0,"Enemies you Kill have a #% chance to Explode, dealing a quarter of their maximum Life as Chaos Damage",,True,True
1212
1,1,,0,"Socketed Gems are Supported by Level # #",,True,True
13-
,,"Cast While Channelling|Cast On Critical Strike",1,"Socketed Gems are Supported by Level # #",,True,True
13+
,,"Cast while Channelling|Cast On Critical Strike",1,"Socketed Gems are Supported by Level # #",,True,True
1414
12,14,,0,"#% chance to deal Double Damage",,True,True
1515
34,38,,0,"Minions have #% increased # Speed",,True,True
1616
,,"Attack|Cast",1,"Minions have #% increased Ca#st Speed",,True,True

src/backend_data_retrieval/data_retrieval_app/data_deposit/modifier/modifier_data_depositor.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
check_for_new_related_unique,
1111
check_for_updated_numerical_rolls,
1212
check_for_updated_text_rolls,
13+
do_update_regex,
1314
)
1415
from data_retrieval_app.logs.logger import data_deposit_logger as logger
1516
from data_retrieval_app.utils import df_to_JSON
@@ -78,6 +79,7 @@ def _update_duplicates(
7879
update_url = self.data_url + "?modifierId={}"
7980

8081
rolls = None
82+
update_regex = False
8183
for (_, row_cur), (_, row_new) in zip(
8284
current_duplicate_modifiers_df.iterrows(),
8385
duplicate_df.iterrows(),
@@ -88,6 +90,7 @@ def _update_duplicates(
8890
position = int(data["position"])
8991
# if position is higher than 1, we want to store the types of rolls it has
9092
if position >= 1 and rolls is None:
93+
update_regex = False
9194
effect = data["effect"]
9295
same_modifier_df = duplicate_df.loc[
9396
duplicate_df["effect"] == effect
@@ -102,27 +105,30 @@ def _update_duplicates(
102105
elif not pd.isna(same_modifier_row["textRolls"]):
103106
rolls.append(same_modifier_row["textRolls"])
104107
else:
105-
# We only need to check if the roll is of type float,
106-
# which we only need 'minRoll' for and not both 'minRoll' and 'maxRoll'
107-
rolls.append(same_modifier_row["minRoll"])
108+
rolls.append(None)
108109

109110
if "updatedAt" in data:
110111
data.pop("updatedAt")
111112

112113
if not pd.isna(row_new["static"]):
113114
pass
114115
elif not pd.isna(row_new["textRolls"]):
115-
data, put_update = check_for_updated_text_rolls(
116+
data, put_update, rolls = check_for_updated_text_rolls(
116117
data=data,
117118
row_new=row_new,
118119
rolls=rolls,
119120
regex_creator=self.regex_creator,
120121
)
122+
update_regex = put_update
121123
else:
122124
data, put_update = check_for_updated_numerical_rolls(
123125
data=data, row_new=row_new
124126
)
125127

128+
if update_regex:
129+
data = do_update_regex(data, rolls, regex_creator=self.regex_creator)
130+
put_update = True
131+
126132
data, put_update = check_for_additional_modifier_types(
127133
data=data,
128134
put_update=put_update,
@@ -160,6 +166,7 @@ def _update_duplicates(
160166
# We reset the rolls if the position is 0, because then the next row will be a new modifier
161167
if position == 0 and rolls is not None:
162168
rolls = None
169+
update_regex = False
163170

164171
def _remove_duplicates(self, new_modifiers_df: pd.DataFrame) -> pd.DataFrame:
165172
current_modifiers_df = self._get_current_modifiers()
@@ -171,7 +178,11 @@ def _remove_duplicates(self, new_modifiers_df: pd.DataFrame) -> pd.DataFrame:
171178
return new_modifiers_df
172179

173180
logger.info("Removing duplicate modifiers")
174-
duplicate_mask = new_modifiers_df["effect"].isin(current_modifiers_df["effect"])
181+
duplicate_mask = (
182+
new_modifiers_df["effect"]
183+
.str.lower()
184+
.isin(current_modifiers_df["effect"].str.lower())
185+
)
175186

176187
duplicate_df = new_modifiers_df.loc[duplicate_mask].copy()
177188
self._update_duplicates(duplicate_df, current_modifiers_df)

src/backend_data_retrieval/data_retrieval_app/data_deposit/modifier/modifier_processing_modules.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _post_process(
181181

182182
def remove_quantifier(ser: pd.Series) -> pd.Series:
183183
contains_q_mask = ser.str.contains("?", regex=False)
184-
ser_contains_q = ser.loc[contains_q_mask]
184+
ser_contains_q = ser.loc[contains_q_mask].copy()
185185

186186
if ser_contains_q.empty:
187187
return ser
@@ -231,27 +231,58 @@ def add_regex(self, modifier_df: pd.DataFrame) -> pd.DataFrame:
231231
def check_for_updated_text_rolls(
232232
data: dict[str, Any],
233233
row_new: pd.DataFrame,
234-
rolls: list[int | str],
234+
rolls: list[None | str],
235235
regex_creator: ModifierRegexCreator,
236-
) -> tuple[dict[str, Any], bool]:
236+
) -> tuple[dict[str, Any], bool, list[None | str]]:
237237
if data["textRolls"] != row_new["textRolls"]:
238238
logger.info(
239239
f"Found a modifier with new 'textRolls'. Modifier: {data['effect']}"
240240
)
241-
data["textRolls"] = row_new["textRolls"]
241+
new_rolls: list[str] = row_new["textRolls"].split("|")
242+
old_rolls: list[str] = data["textRolls"].split("|")
243+
combined_rolls = old_rolls + [
244+
roll
245+
for roll in new_rolls
246+
if roll.lower() not in [old_roll.lower() for old_roll in old_rolls]
247+
]
242248
if rolls is not None:
243-
data["rolls"] = rolls
244-
data["effect"] = data["effect"].replace("+", r"\+")
245-
data["regex"] = regex_creator.create_regex_from_row(data)
249+
rolls[int(data["position"])] = "|".join(combined_rolls)
250+
data["textRolls"] = rolls
251+
else:
252+
data["textRolls"] = [data["textRolls"]]
253+
254+
data["effect"] = data["effect"].replace("+", r"\+")
255+
data["regex"] = regex_creator.create_regex_from_row(data)
256+
data["effect"] = data["effect"].replace(r"\+", "+")
246257

247-
data["effect"] = data["effect"].replace(r"\+", "+")
248-
data.pop("rolls")
258+
data["textRolls"] = "|".join(combined_rolls)
249259

250260
put_update = True
251261
else:
252262
put_update = False
253263

254-
return data, put_update
264+
return data, put_update, rolls
265+
266+
267+
def do_update_regex(
268+
data: dict[str, Any], rolls: list[None, str], regex_creator: ModifierRegexCreator
269+
) -> dict[str, Any]:
270+
if "textRolls" in data:
271+
text_rolls = data["textRolls"]
272+
else:
273+
text_rolls = None
274+
275+
data["textRolls"] = rolls
276+
data["effect"] = data["effect"].replace("+", r"\+")
277+
data["regex"] = regex_creator.create_regex_from_row(data)
278+
data["effect"] = data["effect"].replace(r"\+", "+")
279+
280+
if text_rolls is not None:
281+
data["textRolls"] = text_rolls
282+
else:
283+
data.pop("textRolls")
284+
285+
return data
255286

256287

257288
def check_for_updated_numerical_rolls(

src/backend_data_retrieval/data_retrieval_app/external_data_retrieval/transforming_data/roll_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def extract_rolls(matchobj: re.Match) -> str:
9595
index=False
9696
):
9797
matched_modifiers = dynamic_df["modifier"].str.replace(
98-
regex, extract_rolls, regex=True
98+
regex, extract_rolls, regex=True, case=False
9999
)
100100
matched_modifiers_mask = matched_modifiers.str.contains("matched", na=False)
101101

@@ -171,8 +171,8 @@ def _process_dynamic(
171171
def convert_text_roll_to_index(row: pd.DataFrame) -> int:
172172
text_rolls: str = row["textRolls"]
173173
if text_rolls != "None":
174-
text_rolls = text_rolls.split("|")
175-
roll = text_rolls.index(row["roll"])
174+
text_rolls = text_rolls.lower().split("|")
175+
roll = text_rolls.index(row["roll"].lower())
176176
else:
177177
roll = row["roll"]
178178

0 commit comments

Comments
 (0)