-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating_functions.py
129 lines (101 loc) · 5 KB
/
rating_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from utils import findWords, FindOptions
from typing import List
import re
'''
def _getStandardRating(name):
points = 0
name = name.lower()
isJap=False
if findWords([["europe", FindOptions.WORD], ["eur", FindOptions.WORD], ["\(E\)", FindOptions.REGEX]], name): points += 50
if findWords([["japan", FindOptions.WORD], ["jap", FindOptions.WORD], ["\(J\)", FindOptions.REGEX]], name): points += 10; isJap=True
if findWords([["usa", FindOptions.WORD], ["\(U\)", FindOptions.REGEX], ["australia", FindOptions.WORD]], name): points += 30
if findWords([["world", FindOptions.WORD]], name): points += 20
if findWords([["beta", FindOptions.WORD]], name): points -=30
if findWords([["\(proto.*?\)", FindOptions.REGEX]], name): points -= 50
if findWords([["spain", FindOptions.WORD]], name): points += 100
if findWords([["\[!\]", FindOptions.REGEX]], name): points += 40
if findWords([["\[b\d{0,2}\]", FindOptions.REGEX]], name): points -= 40
if findWords([["\[h\d{0,2}\]", FindOptions.REGEX]], name): points -= 100
if findWords([["\(UE\)", FindOptions.REGEX], ["\(EU\)", FindOptions.REGEX]], name): points+=50
if findWords([["\(UJ\)", FindOptions.REGEX], ["(JU)", FindOptions.REGEX]], name): points += 30
if findWords([["\[a\d{0,2}(?![-\w])\]", FindOptions.REGEX]], name): points-=10
if findWords([["\[o\d{0,2}(?![-\w])\]", FindOptions.REGEX]], name): points -= 10 #Overdump
if findWords([["\[t\-eng.*?\]", FindOptions.REGEX]], name):
points += 50
elif findWords([["\[t\-spa.*?\]", FindOptions.REGEX]], name): points += 60
elif findWords([["\[t\-.*?\]", FindOptions.REGEX]], name):
if isJap:
points += 40
else:
points -=40
if findWords([["partial", FindOptions.REGEX]], name):
points-=10
if findWords([["\[t\d{0,2}(?![-\w])\]", FindOptions.REGEX]], name): points -= 20 #No trainers please
return points
'''
def buildAllSearchTermsCases(searchTerm:str) -> str:
return f"\(\s*{searchTerm}\s*\)|\(\s*{searchTerm}\s*|,\s*{searchTerm}\s*|\s*{searchTerm}\s*\)"
def searchAnyGameMetadataToken(searchTerms: List[str], text:str):
finalRegExStr:str = ""
i=0
for searchTerm in searchTerms:
if i!=0:
finalRegExStr+="|"
#If a [x] is passed we will add it directly because it is a rom flag
if(searchTerm.startswith("\[")):
finalRegExStr+=searchTerm
else:
finalRegExStr+=buildAllSearchTermsCases(searchTerm)
return re.search(rf'{finalRegExStr}',text, re.IGNORECASE)
def searchAllGameMetadataToken(searchTerms: List[str], text:str):
for searchTerm in searchTerms:
finalRegExStr: str = ""
# If a [x] is passed we will add it directly because it is a rom flag
if (searchTerm.startswith("\[")):
finalRegExStr = searchTerm
else:
finalRegExStr = buildAllSearchTermsCases(searchTerm)
result = re.search(rf'{finalRegExStr}',text, re.IGNORECASE)
if result is None:
return False
return True
def DSFilesRating(name:str) -> int:
points = 0
name = name.lower()
isJap=False
# Check if we can get a spanish one if not european english if not english...
if searchAnyGameMetadataToken(["es", "spain"], name):
points += 1000
else:
if searchAllGameMetadataToken(["europe","en"],name):
points+= 900 # If europe and en exist for this game
elif searchAnyGameMetadataToken(["usa","U","australia"],name):
points +=800
elif searchAnyGameMetadataToken(["en"], name):
points += 700
elif searchAnyGameMetadataToken(["europe"],name):
# we have an european rom but that has no es or en. Get the shortest
# rom name (we hope to get just the ones with europe and no languages
points+=600-len(name)
elif searchAnyGameMetadataToken(["japan","jap","J"],name):
points +=500
# b stands for bad dump. and it can be [b] or [b1], [b2].. [bn]
if searchAnyGameMetadataToken(["beta","proto", "demo", "kiosk","\[b\d*\]"], name): points -=1000
if searchAnyGameMetadataToken(["rev"],name): points +=100
return points
def DSValidateGame(name:str ):
name = name.lower()
avoidables = ["/my ","barbie", "ds download station", "dreamer series", "drawn to life", "dora ","/disney ",
"/diva girls", "/club penguin","/clever kids","/charm girls","/bratz","ds spirits","/[BIOS]","ZhuZhu",
"winx club","(France)", "(Germany)", "(German)", "(Korea)", "Tokuten Ryoku","TOEIC","spongebob","smart girl","smart boy","petz","/paws",
"monster high","/mon coach","/maru goukaku","/maji de manabu","/littlest pet shop","/let's",
"/lernen","/layton"]
for avoidable in avoidables:
avoidable = avoidable.lower()
if avoidable.startswith("/"):
if name.startswith(avoidable[1:]) == True:
return False
else:
if avoidable in name:
return False
return True