2020-02-03 17:25:54 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class stackoverflow_question_20528081_test_case(unittest.TestCase):
|
|
|
|
def test_stackoverflow_question_20528081(self):
|
|
|
|
"""
|
|
|
|
https://stackoverflow.com/questions/20528081/performance-of-calculations-on-large-flattened-dictionary-with-implied-hierarchy
|
|
|
|
"""
|
2020-02-06 14:19:01 +00:00
|
|
|
from benedict import benedict as bdict
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
d = {
|
2022-10-14 14:26:01 +00:00
|
|
|
"guy1_arm_param1": 23.0,
|
|
|
|
"guy1_arm_param2_low": 2.0,
|
|
|
|
"guy1_arm_param2_high": 3.0,
|
|
|
|
"guy1_arm_param3": 20.0,
|
|
|
|
"guy1_leg_param1": 40.0,
|
|
|
|
"guy1_leg_param2_low": 2.0,
|
|
|
|
"guy1_leg_param2_high": 3.0,
|
|
|
|
"guy1_leg_param3": 20.0,
|
|
|
|
"guy2_arm_param1": 23.0,
|
|
|
|
"guy2_arm_param2_low": 2.0,
|
|
|
|
"guy2_arm_param2_high": 3.0,
|
|
|
|
"guy2_arm_param3": 20.0,
|
|
|
|
"guy2_leg_param1": 40.0,
|
|
|
|
"guy2_leg_param2_low": 2.0,
|
|
|
|
"guy2_leg_param2_high": 3.0,
|
|
|
|
"guy2_leg_param3": 20.0,
|
|
|
|
"another_guy_param1": 3.0,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
b = bdict(d)
|
|
|
|
u = b.unflatten()
|
|
|
|
# print(u.dump())
|
|
|
|
r = {
|
|
|
|
"another": {
|
|
|
|
"guy": {
|
|
|
|
"param1": 3.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"guy1": {
|
|
|
|
"arm": {
|
|
|
|
"param1": 23.0,
|
|
|
|
"param2": {
|
|
|
|
"high": 3.0,
|
|
|
|
"low": 2.0,
|
|
|
|
},
|
|
|
|
"param3": 20.0,
|
|
|
|
},
|
|
|
|
"leg": {
|
|
|
|
"param1": 40.0,
|
|
|
|
"param2": {
|
|
|
|
"high": 3.0,
|
|
|
|
"low": 2.0,
|
|
|
|
},
|
|
|
|
"param3": 20.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"guy2": {
|
|
|
|
"arm": {
|
|
|
|
"param1": 23.0,
|
|
|
|
"param2": {
|
|
|
|
"high": 3.0,
|
|
|
|
"low": 2.0,
|
|
|
|
},
|
|
|
|
"param3": 20.0,
|
|
|
|
},
|
|
|
|
"leg": {
|
|
|
|
"param1": 40.0,
|
|
|
|
"param2": {
|
|
|
|
"high": 3.0,
|
|
|
|
"low": 2.0,
|
|
|
|
},
|
|
|
|
"param3": 20.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
self.assertEqual(u, r)
|