@@ -82,21 +82,36 @@ def parse_netdata_url(url):
82
82
df_chart_order = pd .DataFrame .from_dict (data_chart_order ).transpose ().reset_index ()
83
83
df_chart_order .columns = ['chart' , 'priority' , 'context' ]
84
84
df_chart_order = df_chart_order [['context' , 'chart' , 'priority' ]].sort_values ('priority' )
85
+ df_chart_order ['menu' ] = df_chart_order ['context' ].str .split ('.' ).str [0 ]
85
86
86
87
#%%
87
88
88
89
weights_data = requests .get (url_weights ).json ()
89
90
91
+ #%%
92
+
93
+ df_menu_weights = pd .DataFrame (
94
+ [(context .split ('.' )[0 ], weights_data ['contexts' ][context ]['weight' ]) for context in weights_data ['contexts' ]],
95
+ columns = ['menu' , 'weight' ]
96
+ )
97
+ menu_weights_dict = df_menu_weights .groupby ('menu' ).mean ().to_dict (orient = 'index' )
98
+
99
+ #%%
100
+
90
101
data = OrderedDict ()
91
- for context in df_chart_order ['context' ].unique ():
92
- context_key = f"{ context } : { round (weights_data ['contexts' ][context ]['weight' ],2 )} "
93
- data [context_key ] = dict ()
94
- for chart in df_chart_order [df_chart_order ['context' ] == context ]['chart' ].unique ():
95
- chart_key = f"{ chart } : { round (weights_data ['contexts' ][context ]['charts' ][chart ]['weight' ],2 )} "
96
- data [context_key ][chart_key ] = dict ()
97
- for dim in weights_data ['contexts' ][context ]['charts' ][chart ]['dimensions' ]:
98
- dim_key = dim
99
- data [context_key ][chart_key ][dim_key ] = round (weights_data ['contexts' ][context ]['charts' ][chart ]['dimensions' ][dim ], 2 )
102
+ for menu in df_chart_order ['menu' ].unique ():
103
+ menu_key = f"{ menu } : { round (menu_weights_dict [menu ]['weight' ]* 1 ,2 )} %"
104
+ data [menu_key ] = dict ()
105
+ for context in df_chart_order ['context' ].unique ():
106
+ if context .startswith (menu ):
107
+ context_key = f"{ context } : { round (weights_data ['contexts' ][context ]['weight' ]* 1 ,2 )} %"
108
+ data [menu_key ][context_key ] = dict ()
109
+ for chart in df_chart_order [df_chart_order ['context' ] == context ]['chart' ].unique ():
110
+ chart_key = f"{ chart } : { round (weights_data ['contexts' ][context ]['charts' ][chart ]['weight' ],2 )} %"
111
+ data [menu_key ][context_key ][chart_key ] = dict ()
112
+ for dim in weights_data ['contexts' ][context ]['charts' ][chart ]['dimensions' ]:
113
+ dim_key = dim
114
+ data [menu_key ][context_key ][chart_key ][dim_key ] = f"{ round (weights_data ['contexts' ][context ]['charts' ][chart ]['dimensions' ][dim ]* 1 , 2 )} %"
100
115
101
116
st .json (
102
117
data ,
0 commit comments