Last active
December 16, 2024 12:01
-
-
Save ZM-J/241fd39eb1699310fc9feb78d4295aaf to your computer and use it in GitHub Desktop.
原神圣遗物权重转换原始强化数据的 python 代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key, value = 'key', 'value' | |
attrIdMap = { | |
101021: { key: 'hpPlus', value: 23.899999618530273 }, | |
101022: { key: 'hpPlus', value: 29.8799991607666 }, | |
201021: { key: 'hpPlus', value: 50.189998626708984 }, | |
201022: { key: 'hpPlus', value: 60.95000076293945 }, | |
201023: { key: 'hpPlus', value: 71.69999694824219 }, | |
301021: { key: 'hpPlus', value: 100.37999725341797 }, | |
301022: { key: 'hpPlus', value: 114.7200012207031 }, | |
301023: { key: 'hpPlus', value: 129.05999755859375 }, | |
301024: { key: 'hpPlus', value: 143.39999389648438 }, | |
401021: { key: 'hpPlus', value: 167.3000030517578 }, | |
401022: { key: 'hpPlus', value: 191.1999969482422 }, | |
401023: { key: 'hpPlus', value: 215.1000061035156 }, | |
401024: { key: 'hpPlus', value: 239.0 }, | |
501021: { key: 'hpPlus', value: 209.1300048828125 }, | |
501022: { key: 'hpPlus', value: 239.0 }, | |
501023: { key: 'hpPlus', value: 268.8800048828125 }, | |
501024: { key: 'hpPlus', value: 298.75 }, | |
101031: { key: 'hp', value: 0.011699999682605267 }, | |
101032: { key: 'hp', value: 0.014600000344216824 }, | |
201031: { key: 'hp', value: 0.016300000250339508 }, | |
201032: { key: 'hp', value: 0.01979999989271164 }, | |
201033: { key: 'hp', value: 0.02329999953508377 }, | |
301031: { key: 'hp', value: 0.02449999935925007 }, | |
301032: { key: 'hp', value: 0.02800000086426735 }, | |
301033: { key: 'hp', value: 0.03150000050663948 }, | |
301034: { key: 'hp', value: 0.03500000014901161 }, | |
401031: { key: 'hp', value: 0.032600000500679016 }, | |
401032: { key: 'hp', value: 0.037300001829862595 }, | |
401033: { key: 'hp', value: 0.041999999433755875 }, | |
401034: { key: 'hp', value: 0.04659999907016754 }, | |
501031: { key: 'hp', value: 0.040800001472234726 }, | |
501032: { key: 'hp', value: 0.04659999907016754 }, | |
501033: { key: 'hp', value: 0.05249999836087227 }, | |
501034: { key: 'hp', value: 0.05829999968409538 }, | |
101051: { key: 'atkPlus', value: 1.559999942779541 }, | |
101052: { key: 'atkPlus', value: 1.9500000476837158 }, | |
201051: { key: 'atkPlus', value: 3.2699999809265137 }, | |
201052: { key: 'atkPlus', value: 3.9700000286102295 }, | |
201053: { key: 'atkPlus', value: 4.670000076293945 }, | |
301051: { key: 'atkPlus', value: 6.539999961853027 }, | |
301052: { key: 'atkPlus', value: 7.46999979019165 }, | |
301053: { key: 'atkPlus', value: 8.399999618530273 }, | |
301054: { key: 'atkPlus', value: 9.34000015258789 }, | |
401051: { key: 'atkPlus', value: 10.890000343322754 }, | |
401052: { key: 'atkPlus', value: 12.449999809265137 }, | |
401053: { key: 'atkPlus', value: 14.0 }, | |
401054: { key: 'atkPlus', value: 15.5600004196167 }, | |
501051: { key: 'atkPlus', value: 13.619999885559082 }, | |
501052: { key: 'atkPlus', value: 15.5600004196167 }, | |
501053: { key: 'atkPlus', value: 17.510000228881836 }, | |
501054: { key: 'atkPlus', value: 19.450000762939453 }, | |
101061: { key: 'atk', value: 0.011699999682605267 }, | |
101062: { key: 'atk', value: 0.014600000344216824 }, | |
201061: { key: 'atk', value: 0.016300000250339508 }, | |
201062: { key: 'atk', value: 0.01979999989271164 }, | |
201063: { key: 'atk', value: 0.02329999953508377 }, | |
301061: { key: 'atk', value: 0.02449999935925007 }, | |
301062: { key: 'atk', value: 0.02800000086426735 }, | |
301063: { key: 'atk', value: 0.03150000050663948 }, | |
301064: { key: 'atk', value: 0.03500000014901161 }, | |
401061: { key: 'atk', value: 0.032600000500679016 }, | |
401062: { key: 'atk', value: 0.037300001829862595 }, | |
401063: { key: 'atk', value: 0.041999999433755875 }, | |
401064: { key: 'atk', value: 0.04659999907016754 }, | |
501061: { key: 'atk', value: 0.040800001472234726 }, | |
501062: { key: 'atk', value: 0.04659999907016754 }, | |
501063: { key: 'atk', value: 0.05249999836087227 }, | |
501064: { key: 'atk', value: 0.05829999968409538 }, | |
101081: { key: 'defPlus', value: 1.850000023841858 }, | |
101082: { key: 'defPlus', value: 2.309999942779541 }, | |
201081: { key: 'defPlus', value: 3.890000104904175 }, | |
201082: { key: 'defPlus', value: 4.71999979019165 }, | |
201083: { key: 'defPlus', value: 5.559999942779541 }, | |
301081: { key: 'defPlus', value: 7.78000020980835 }, | |
301082: { key: 'defPlus', value: 8.890000343322754 }, | |
301083: { key: 'defPlus', value: 10.0 }, | |
301084: { key: 'defPlus', value: 11.109999656677246 }, | |
401081: { key: 'defPlus', value: 12.960000038146973 }, | |
401082: { key: 'defPlus', value: 14.819999694824219 }, | |
401083: { key: 'defPlus', value: 16.670000076293945 }, | |
401084: { key: 'defPlus', value: 18.520000457763672 }, | |
501081: { key: 'defPlus', value: 16.200000762939453 }, | |
501082: { key: 'defPlus', value: 18.520000457763672 }, | |
501083: { key: 'defPlus', value: 20.829999923706055 }, | |
501084: { key: 'defPlus', value: 23.149999618530273 }, | |
101091: { key: 'def', value: 0.014600000344216824 }, | |
101092: { key: 'def', value: 0.018200000748038292 }, | |
201091: { key: 'def', value: 0.020400000736117363 }, | |
201092: { key: 'def', value: 0.024800000712275505 }, | |
201093: { key: 'def', value: 0.029100000858306885 }, | |
301091: { key: 'def', value: 0.03060000017285347 }, | |
301092: { key: 'def', value: 0.03500000014901161 }, | |
301093: { key: 'def', value: 0.03929999843239784 }, | |
301094: { key: 'def', value: 0.043699998408555984 }, | |
401091: { key: 'def', value: 0.040800001472234726 }, | |
401092: { key: 'def', value: 0.04659999907016754 }, | |
401093: { key: 'def', value: 0.05249999836087227 }, | |
401094: { key: 'def', value: 0.05829999968409538 }, | |
501091: { key: 'def', value: 0.050999999046325684 }, | |
501092: { key: 'def', value: 0.05829999968409538 }, | |
501093: { key: 'def', value: 0.06560000032186508 }, | |
501094: { key: 'def', value: 0.07289999723434448 }, | |
101231: { key: 'recharge', value: 0.013000000268220901 }, | |
101232: { key: 'recharge', value: 0.016200000420212746 }, | |
201231: { key: 'recharge', value: 0.01810000091791153 }, | |
201232: { key: 'recharge', value: 0.02199999988079071 }, | |
201233: { key: 'recharge', value: 0.02590000070631504 }, | |
301231: { key: 'recharge', value: 0.0272000003606081 }, | |
301232: { key: 'recharge', value: 0.031099999323487282 }, | |
301233: { key: 'recharge', value: 0.03500000014901161 }, | |
301234: { key: 'recharge', value: 0.03889999911189079 }, | |
401231: { key: 'recharge', value: 0.03629999980330467 }, | |
401232: { key: 'recharge', value: 0.0414000004529953 }, | |
401233: { key: 'recharge', value: 0.04659999907016754 }, | |
401234: { key: 'recharge', value: 0.05180000141263008 }, | |
501231: { key: 'recharge', value: 0.04529999941587448 }, | |
501232: { key: 'recharge', value: 0.05180000141263008 }, | |
501233: { key: 'recharge', value: 0.05829999968409538 }, | |
501234: { key: 'recharge', value: 0.06480000168085098 }, | |
101241: { key: 'mastery', value: 4.659999847412109 }, | |
101242: { key: 'mastery', value: 5.829999923706055 }, | |
201241: { key: 'mastery', value: 6.53000020980835 }, | |
201242: { key: 'mastery', value: 7.929999828338623 }, | |
201243: { key: 'mastery', value: 9.329999923706055 }, | |
301241: { key: 'mastery', value: 9.789999961853027 }, | |
301242: { key: 'mastery', value: 11.1899995803833 }, | |
301243: { key: 'mastery', value: 12.59000015258789 }, | |
301244: { key: 'mastery', value: 13.989999771118164 }, | |
401241: { key: 'mastery', value: 13.0600004196167 }, | |
401242: { key: 'mastery', value: 14.920000076293945 }, | |
401243: { key: 'mastery', value: 16.790000915527344 }, | |
401244: { key: 'mastery', value: 18.649999618530273 }, | |
501241: { key: 'mastery', value: 16.31999969482422 }, | |
501242: { key: 'mastery', value: 18.649999618530273 }, | |
501243: { key: 'mastery', value: 20.979999542236328 }, | |
501244: { key: 'mastery', value: 23.309999465942383 }, | |
101201: { key: 'cpct', value: 0.007799999788403511 }, | |
101202: { key: 'cpct', value: 0.009700000286102295 }, | |
201201: { key: 'cpct', value: 0.010900000110268593 }, | |
201202: { key: 'cpct', value: 0.013199999928474426 }, | |
201203: { key: 'cpct', value: 0.01549999974668026 }, | |
301201: { key: 'cpct', value: 0.016300000250339508 }, | |
301202: { key: 'cpct', value: 0.01860000006854534 }, | |
301203: { key: 'cpct', value: 0.020999999716877937 }, | |
301204: { key: 'cpct', value: 0.02329999953508377 }, | |
401201: { key: 'cpct', value: 0.021800000220537186 }, | |
401202: { key: 'cpct', value: 0.024900000542402267 }, | |
401203: { key: 'cpct', value: 0.02800000086426735 }, | |
401204: { key: 'cpct', value: 0.031099999323487282 }, | |
501201: { key: 'cpct', value: 0.0272000003606081 }, | |
501202: { key: 'cpct', value: 0.031099999323487282 }, | |
501203: { key: 'cpct', value: 0.03500000014901161 }, | |
501204: { key: 'cpct', value: 0.03889999911189079 }, | |
101221: { key: 'cdmg', value: 0.01549999974668026 }, | |
101222: { key: 'cdmg', value: 0.01940000057220459 }, | |
201221: { key: 'cdmg', value: 0.021800000220537186 }, | |
201222: { key: 'cdmg', value: 0.026399999856948853 }, | |
201223: { key: 'cdmg', value: 0.031099999323487282 }, | |
301221: { key: 'cdmg', value: 0.032600000500679016 }, | |
301222: { key: 'cdmg', value: 0.037300001829862595 }, | |
301223: { key: 'cdmg', value: 0.041999999433755875 }, | |
301224: { key: 'cdmg', value: 0.04659999907016754 }, | |
401221: { key: 'cdmg', value: 0.04349999874830246 }, | |
401222: { key: 'cdmg', value: 0.04969999939203262 }, | |
401223: { key: 'cdmg', value: 0.0560000017285347 }, | |
401224: { key: 'cdmg', value: 0.062199998646974564 }, | |
501221: { key: 'cdmg', value: 0.0544000007212162 }, | |
501222: { key: 'cdmg', value: 0.062199998646974564 }, | |
501223: { key: 'cdmg', value: 0.06989999860525131 }, | |
501224: { key: 'cdmg', value: 0.07769999653100967 } | |
} | |
attr_names = sorted(list(set([x['key'] for x in attrIdMap.values()]))) | |
print(attr_names) | |
fixed_attr_names = [ | |
'hpPlus', | |
'defPlus', | |
'mastery', | |
'atkPlus', | |
] | |
attr_name2property_type = { | |
'atk': 6, | |
'atkPlus': 5, | |
'hp': 3, | |
'hpPlus': 2, | |
'def': 9, | |
'defPlus': 8, | |
'cpct': 20, | |
'cdmg': 22, | |
'recharge': 23, | |
'mastery': 28 | |
} | |
import itertools | |
result = {} | |
for rarity in '12345': | |
result[rarity] = {} | |
# Corner case: 初始 4 词条,且 5 次强化都中了同一词条 | |
for cur_time in range(int(rarity) + 1): | |
result[rarity][cur_time] = {} | |
for attr_name in attr_names: | |
value2err_arr = {} | |
cur_values = [(v['value'], k) for k, v in attrIdMap.items() \ | |
if str(k).startswith(rarity) and v['key'] == attr_name] | |
for cur_values_combination in itertools.product(cur_values, repeat=cur_time+1): | |
cur_value_sum = sum(v for v, attr_id in cur_values_combination) | |
cur_arr = [attr_id for v, attr_id in cur_values_combination] | |
if attr_name in fixed_attr_names: | |
amplifier = 1 | |
dest_value_sum_0_str = f'{cur_value_sum:.0f}' | |
perturbations = [-1, 0, 1] | |
dest_value_affix = '' | |
else: | |
amplifier = 100 | |
dest_value_sum_0_str = f'{100 * cur_value_sum:.1f}' | |
perturbations = [-0.1, 0, 0.1] | |
dest_value_affix = '%' | |
dest_value_sum_0 = float(dest_value_sum_0_str) | |
# Add perturbations to make it more robust | |
for perturbation in perturbations: | |
dest_value_sum = dest_value_sum_0 + perturbation | |
if attr_name in fixed_attr_names: | |
dest_value_sum_str = f'{dest_value_sum:.0f}' | |
else: | |
dest_value_sum_str = f'{dest_value_sum:.1f}' | |
err = abs(dest_value_sum - amplifier * cur_value_sum) | |
my_key = dest_value_sum_str + dest_value_affix | |
if my_key in value2err_arr: | |
prev_err, _ = value2err_arr[my_key] | |
if err < prev_err: | |
value2err_arr[my_key] = (err, cur_arr) | |
else: | |
value2err_arr[my_key] = (err, cur_arr) | |
value2arr = {k: arr for k, (err, arr) in value2err_arr.items()} | |
property_type = attr_name2property_type[attr_name] | |
result[rarity][cur_time][property_type] = value2arr | |
import json | |
with open('result.json', 'w') as f: | |
json.dump(result, f, indent=2) # , indent=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment