Compare commits

...

5 Commits
v2 ... master

2 changed files with 86 additions and 7 deletions

View File

@ -1,4 +1,11 @@
# edsmAround # edsmAround
Shitty code to see what's around in Elite Dangerous. Uses EDSM data. Shitty code to see what's around in Elite Dangerous. Uses EDSM data.
To use, open the file and modify the Sector Name. Then run with python3
Usage :
```python3 edsmAround.py [OPTIONS]```
Description :
-i : enable interactive mode, user enter values via the CLI instead of writing them in the script."

View File

@ -3,21 +3,22 @@ import re
import json import json
from datetime import datetime as dt from datetime import datetime as dt
from math import floor from math import floor
import sys
#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 = "Phleedgaa" sectorName = "Stuemeae"
### "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 = ["a","b","c","d","e"] #weightsToQuery = ["f","g","h"]
weightsToQuery = ["d"]
### 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"] postFixList =["FG-Y"]
@ -32,7 +33,7 @@ def fetchEdsmSystems(sectorName, postFix, weight):
hasMultipleHyphens = False 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+" "+weight).content):
if pattern.match(system['name']): if pattern.match(system['name']):
systemList.append(system['name']) systemList.append(system['name'])
hasMultipleHyphens = system['name'].count("-") > 1 # if at least one of those has multiple hyphens, we consider all of them do hasMultipleHyphens = system['name'].count("-") > 1 # if at least one of those has multiple hyphens, we consider all of them do
@ -57,12 +58,73 @@ def maxSystemValue(systemList):
return currentMax return currentMax
###interactive part
if (len(sys.argv) > 1):
for arg in sys.argv:
if arg == "-i":
print("Starting interactive mode.")
print("Please input a sector name with only the first letter capitalized (ex : Byoomiae) ")
sectorNamePattern = re.compile("^[A-Z][a-z]+ *[A-Z]*[a-z]*$")
possibleSectorName = input()
while not sectorNamePattern.match(possibleSectorName):
print("The sector name you have entered is incorrect. Please try again")
possibleSectorName = input()
sectorName = possibleSectorName
print(f"Entered Sector name is {sectorName}")
print("Please enter the postFix you want to use. PostFix are the letters after the sector name (AA-A, RD-A). Write one per line, in all caps, with the hyphen. Send an empty line to finish")
possiblePostFix = input()
postFixList = []
while possiblePostFix != "":
postFixPattern = re.compile("^[A-Z][A-Z]-[A-Z]$")
if postFixPattern.match(possiblePostFix):
if possiblePostFix not in postFixList:
postFixList.append(possiblePostFix)
print(f"added {possiblePostFix} to the list of patterns. Current list is {postFixList}")
else:
print(f"PostFix already in list! Current list is {postFixList}")
possiblePostFix = input()
else:
print("This postFix doesn't look right. Try again")
possiblePostFix = input()
if postFixList == []:
print("postFix list empty. Exiting!")
exit()
print("Please enter the weights you want to use. One letter per line, in lowercase, send an empty line to finish.")
possibleWeights = input()
weightsToQuery = []
while possibleWeights != "":
weightPattern = re.compile("^[a-h]$")
if weightPattern.match(possibleWeights):
if possibleWeights not in weightsToQuery:
weightsToQuery.append(possibleWeights)
print(f"added {possibleWeights} to the list of weights. Current list is {weightsToQuery}")
else:
print(f"Weight already in list! Current list is {weightsToQuery}")
possibleWeights = input()
else:
print("This weight doesn't look right. Try again")
possibleWeights = input()
if weightsToQuery == []:
print("weight list empty. Exiting!")
exit()
print("Starting search!")
#dict of dict of systems keyed by postfix, keyed by weight ( dict["AA-A"]["g"] gives back all the AA-A GXXX systems) #dict of dict of systems keyed by postfix, keyed by weight ( dict["AA-A"]["g"] gives back all the AA-A GXXX systems)
sysWeightDict = {} 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 = {}
#This is used to register how much systems are in EDSM to compute an "explored" percentage further
sysDiscovered = {}
postFixWithMultipleHyphens = {} # deals with system names like "Sector AA-A e5-8" 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
@ -73,11 +135,13 @@ base = ""
reference = "" 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] = {}
sysDiscovered[weight] = {}
postFixWithMultipleHyphens[weight] = {} postFixWithMultipleHyphens[weight] = {}
#then we populate our dicts with the provided postfix #then we populate our dicts with the provided postfix
@ -85,6 +149,7 @@ for weight in weightsToQuery:
for postfix in postFixList: for postfix in postFixList:
sysWeightDict[weight][postfix], postFixWithMultipleHyphens[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])
sysDiscovered[weight][postfix] = 0
#now we generate the inverse of the known system list #now we generate the inverse of the known system list
@ -96,7 +161,7 @@ for weight in weightsToQuery:
if postFixWithMultipleHyphens[weight][postfix]: #if we have multiple hyphens we take the first system to see what's in front of the hyphen 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] reference = sysWeightDict[weight][postfix][0]
base = reference[:reference.rfind("-")+1] base = reference[:reference.rfind("-")+1]
print(f"Warning, sector {sectorName} {postfix} has multiple hyphens, predictions may be wrong!") print(f"Warning, sector {sectorName} {postfix} with size {weight} has multiple hyphens, predictions may be wrong!")
else: else:
base =f"{sectorName} {postfix} {weight}" base =f"{sectorName} {postfix} {weight}"
@ -104,6 +169,10 @@ for weight in weightsToQuery:
candidate = f"{base}{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)
else:
sysDiscovered[weight][postfix] += 1
#this computes the percentage of systems that are already discovered on EDSM
sysDiscovered[weight][postfix] = round(sysDiscovered[weight][postfix] / sysMaxDict[weight][postfix] * 100,2)
@ -111,6 +180,9 @@ for weight in weightsToQuery:
print("These are the systems known to EDSM") print("These are the systems known to EDSM")
print(sysMaxDict) print(sysMaxDict)
print("These are the exploration stats in percent of systems known to EDSM versus all the possible systems")
print(sysDiscovered)
#Finally writes the results to a JSON file. #Finally writes the results to a JSON file.
with open(f"{floor(dt.now().timestamp())}-{sectorName}-RESULTS-v2.json",'w') as f: with open(f"{floor(dt.now().timestamp())}-{sectorName}-RESULTS-v2.json",'w') as f: