firozzer / PaceConverterBot

A Reddit bot to convert running & cycling paces.
1 stars 1 forks source link

checkNike1stVariation in variousRegexChecks not detecting the unit correctly #1

Open kotaroyama opened 1 year ago

kotaroyama commented 1 year ago

On C25K subreddit, I noticed the bot was detecting the unit (mile or km) incorrectly.

https://www.reddit.com/r/C25K/comments/126kqlw/restarting_c25k_but_outside_this_time_w7d3_done/

This user has multiple posts containing pictures of her workout summaries, and the bot seems to be incorrectly detecting the unit in every single one of them.

https://www.reddit.com/user/yuyithemermaid/

It appears that this user is located in the United Kingdom, and the calories burned during a workout is listed using "Kilocalories" instead of "Calories" in the US.

In variousRegexChecks, I noticed that the function checkNike1stVariation is possibly causing the problem in line 173. Specifically, when determining the unit used in the post, it looks whether the string "kilo" is included anywhere in the text. When it's assessing the word "kilocalories", "kilo" is included in it. Therefore, the function incorrctly determines that km is used in the post, when it it uses mile because the user is located in United Kingdom.

A possible solution is to add a space after the word: use "kilo " instead to exclude words like "kilocalories".

firozzer commented 1 year ago

Hi, thank you for the issue & solution, I'll accept your PR and hopefully it doesn't cause the bot to skip too many posts.

Over the past couple months I've noticed my regex logic working incorrectly many times, so started collecting the incorrect images recently in the hopes of making a batch fix in the future after I have a good enough collection.

Edit - deployed your fix to server, let's see how it performs.