added workaround for systems with double hyphens in the name (Thanks Light)
This commit is contained in:
parent
400cfeb61f
commit
1717d25ddb
|
|
@ -7,15 +7,16 @@ from math import floor
|
||||||
#IMPORTANT BITS
|
#IMPORTANT BITS
|
||||||
|
|
||||||
###This is the name of the sector you want to search into (Do not use caps!)
|
###This is the name of the sector you want to search into (Do not use caps!)
|
||||||
sectorName = "Cleeque"
|
sectorName = "Phleedgaa"
|
||||||
|
|
||||||
|
|
||||||
### "weights" to query, beware of big results when searching for lighter systems in more dense area
|
### "weights" to query, beware of big results when searching for lighter systems in more dense area
|
||||||
weightsToQuery = ["h","g","f"]
|
weightsToQuery = ["a","b","c","d","e"]
|
||||||
|
|
||||||
|
|
||||||
### postFix List, modify as needed
|
### postFix List, modify as needed
|
||||||
postFixList =["AA-A","BA-A","CL-Y","DL-Y","EG-Y","FG-Y","YE-A","ZE-A"]
|
#postFixList =["AA-A","BA-A","CL-Y","DL-Y","EG-Y","FG-Y","YE-A","ZE-A"]
|
||||||
|
postFixList =["UJ-Q"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,20 +29,28 @@ def apiCall(systemName):
|
||||||
|
|
||||||
# takes a sector name, a postfix and a weight, returns list of known systems in EDSM matching that
|
# takes a sector name, a postfix and a weight, returns list of known systems in EDSM matching that
|
||||||
def fetchEdsmSystems(sectorName, postFix, weight):
|
def fetchEdsmSystems(sectorName, postFix, weight):
|
||||||
|
hasMultipleHyphens = False
|
||||||
systemList = []
|
systemList = []
|
||||||
pattern = re.compile(f".*{postFix} {weight}.*")
|
pattern = re.compile(f".*{postFix} {weight}.*")
|
||||||
for system in json.loads(apiCall(sectorName +" "+postFix).content):
|
for system in json.loads(apiCall(sectorName +" "+postFix).content):
|
||||||
if pattern.match(system['name']):
|
if pattern.match(system['name']):
|
||||||
systemList.append(system['name'])
|
systemList.append(system['name'])
|
||||||
return systemList
|
hasMultipleHyphens = system['name'].count("-") > 1 # if at least one of those has multiple hyphens, we consider all of them do
|
||||||
|
return systemList, hasMultipleHyphens
|
||||||
|
|
||||||
#given a list of systems (assumed to be all the same weight and postfix) returns the maximum value of the integer value in the system name for that list
|
#given a list of systems (assumed to be all the same weight and postfix) returns the maximum value of the integer value in the system name for that list
|
||||||
def maxSystemValue(systemList):
|
def maxSystemValue(systemList):
|
||||||
currentMax = 0
|
currentMax = 0
|
||||||
pattern = re.compile(f".*[A-Z][A-Z]-[A-Z] [A-Za-z]([0-9]+)")
|
patternWithoutHyphen = re.compile(f".*[A-Z][A-Z]-[A-Z] [A-Za-z]([0-9]+)")
|
||||||
|
patternWithHyphen = re.compile(f".*[A-Z][A-Z]-[A-Z] [A-Za-z][0-9]*-([0-9]+)")
|
||||||
for system in systemList:
|
for system in systemList:
|
||||||
val = 0
|
val = 0
|
||||||
match = pattern.match(system)
|
|
||||||
|
if system.count("-") > 1:
|
||||||
|
match = patternWithHyphen.match(system)
|
||||||
|
else:
|
||||||
|
match = patternWithoutHyphen.match(system)
|
||||||
|
|
||||||
val = int(match.group(1))
|
val = int(match.group(1))
|
||||||
if val > currentMax:
|
if val > currentMax:
|
||||||
currentMax = val
|
currentMax = val
|
||||||
|
|
@ -54,19 +63,27 @@ sysWeightDict = {}
|
||||||
#dict of dict of systems maximum value by postfix, keyed by weight ( dict["AA-A"]["g"] gives back the maximum recorded value for X where X is the integer in a system name : AA-A GX)
|
#dict of dict of systems maximum value by postfix, keyed by weight ( dict["AA-A"]["g"] gives back the maximum recorded value for X where X is the integer in a system name : AA-A GX)
|
||||||
sysMaxDict = {}
|
sysMaxDict = {}
|
||||||
|
|
||||||
|
postFixWithMultipleHyphens = {} # deals with system names like "Sector AA-A e5-8"
|
||||||
|
|
||||||
#dict of dict of all the systems in a sector keyed by postfix, keyed by weight, used later for substracting EDSM values from ALL systems
|
#dict of dict of all the systems in a sector keyed by postfix, keyed by weight, used later for substracting EDSM values from ALL systems
|
||||||
sysCandidates = {}
|
sysCandidates = {}
|
||||||
|
|
||||||
|
|
||||||
|
base = ""
|
||||||
|
reference = ""
|
||||||
|
|
||||||
|
|
||||||
#for each weight class, we initialize our dicts with our postfix list
|
#for each weight class, we initialize our dicts with our postfix list
|
||||||
for weight in weightsToQuery:
|
for weight in weightsToQuery:
|
||||||
sysWeightDict[weight] = {}
|
sysWeightDict[weight] = {}
|
||||||
sysMaxDict[weight] = {}
|
sysMaxDict[weight] = {}
|
||||||
sysCandidates[weight] = {}
|
sysCandidates[weight] = {}
|
||||||
|
postFixWithMultipleHyphens[weight] = {}
|
||||||
|
|
||||||
#then we populate our dicts with the provided postfix
|
#then we populate our dicts with the provided postfix
|
||||||
|
|
||||||
for postfix in postFixList:
|
for postfix in postFixList:
|
||||||
sysWeightDict[weight][postfix] = fetchEdsmSystems(sectorName, postfix, weight) # this is reversed from IG "AA-A G"
|
sysWeightDict[weight][postfix], postFixWithMultipleHyphens[weight][postfix] = fetchEdsmSystems(sectorName, postfix, weight) # this is reversed from IG "AA-A G"
|
||||||
sysMaxDict[weight][postfix] = maxSystemValue(sysWeightDict[weight][postfix])
|
sysMaxDict[weight][postfix] = maxSystemValue(sysWeightDict[weight][postfix])
|
||||||
|
|
||||||
#now we generate the inverse of the known system list
|
#now we generate the inverse of the known system list
|
||||||
|
|
@ -74,8 +91,17 @@ for weight in weightsToQuery:
|
||||||
# for all systems indexes to the max known index
|
# for all systems indexes to the max known index
|
||||||
sysCandidates[weight][postfix] = []
|
sysCandidates[weight][postfix] = []
|
||||||
|
|
||||||
|
if len(sysWeightDict[weight][postfix]) > 0:
|
||||||
|
|
||||||
|
if postFixWithMultipleHyphens[weight][postfix]: #if we have multiple hyphens we take the first system to see what's in front of the hyphen
|
||||||
|
reference = sysWeightDict[weight][postfix][0]
|
||||||
|
base = reference[:reference.rfind("-")+1]
|
||||||
|
print(f"Warning, sector {sectorName} {postfix} has multiple hyphens, predictions may be wrong!")
|
||||||
|
else:
|
||||||
|
base =f"{sectorName} {postfix} {weight}"
|
||||||
|
|
||||||
for i in range(sysMaxDict[weight][postfix]):
|
for i in range(sysMaxDict[weight][postfix]):
|
||||||
candidate = f"{sectorName} {postfix} {weight}{i}"
|
candidate = f"{base}{i}"
|
||||||
if candidate not in sysWeightDict[weight][postfix]:
|
if candidate not in sysWeightDict[weight][postfix]:
|
||||||
sysCandidates[weight][postfix].append(candidate)
|
sysCandidates[weight][postfix].append(candidate)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user