Skip to content

Instantly share code, notes, and snippets.

@Mijago
Last active February 10, 2022 17:22
Show Gist options
  • Save Mijago/871b4df9141baa47ef8df305ec4f3c44 to your computer and use it in GitHub Desktop.
Save Mijago/871b4df9141baa47ef8df305ec4f3c44 to your computer and use it in GitHub Desktop.
Get armor pieces from your vault that are as close as possible to a certain roll

Download your destinyArmor.csv from DIM, place it in the same directory as the script, and go! You may need to install: pandas, scipy

The result for [2, 16, 16, 2, 16, 16] looks like this for my vault:

Result
                       ItemID      Score  mob  res  rec  dis  int  str
0    id:"6917529566280381859"   3.605551    2   13   16    2   14   16
1    id:"6917529413158318975"   5.656854    2   12   20    2   16   16
2    id:"6917529404154264966"   7.071068    3   16   15    6   12   12
3    id:"6917529423920377150"   8.124038    2   19   12    2   11   20
4    id:"6917529546389056812"   8.306624    2   16   12    6   10   15
..                        ...        ...  ...  ...  ...  ...  ...  ...
171  id:"6917529285136492719"  35.411862   15   10    7   26    2    2
172  id:"6917529474388856014"  36.455452    6    2   23   28    2    2
173  id:"6917529200703343963"  37.175261   19   11    2   26    6    2
174  id:"6917529211255146453"  38.794329   18   10    2   27    2    2
175  id:"6917529518932654388"  39.255573   15    2   16   30    2    2

Armor with a lower score is closer and thus better for your result.

import pandas as pd
# Your target values
# mob res rec dis int str
target = [2, 16, 16, 2, 16, 16]
clazz = "Titan" # "Titan" or "Warlock" or "Hunter"
# %% Load the dataset
pd_armor = pd.read_csv("./destinyArmor.csv")
pd_armor = pd_armor[pd_armor["Equippable"] == clazz]
pd_armor = pd_armor[["Id", "Mobility (Base)", "Resilience (Base)", "Recovery (Base)", "Discipline (Base)", "Intellect (Base)", "Strength (Base)"]]
pd_armor = pd_armor.rename(columns={
"Mobility (Base)": "mob",
"Resilience (Base)": "res",
"Recovery (Base)": "rec",
"Discipline (Base)": "dis",
"Intellect (Base)": "int",
"Strength (Base)": "str",
}).set_index("Id")
# %% Calculate distances
from scipy.spatial.distance import pdist, squareform
results = []
for k, armor in pd_armor.iterrows():
dist = pdist([
target,
armor.values
], metric="euclidean")
results.append(("id:%s" % k, dist[0], *armor.values))
results.sort(key=lambda tup: tup[1])
print("Done calculating")
#%% Output
df = pd.DataFrame(results, columns=["ItemID", "Score", "mob", "res", "rec", "dis", "int", "str"])
df.to_html("result.html")
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
print("Result")
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment