|
15 | 15 | schema = []
|
16 | 16 |
|
17 | 17 | ## Data Level 1: Traces
|
18 |
| -# Add trace dictionaries to schema array. |
| 18 | +# Add dictionaries to schema array. |
19 | 19 | # The trace dictionary include name: trace name, permalink: reference/#trace-name, and description if applicable.
|
20 | 20 |
|
21 | 21 | for i in p['schema']['traces']:
|
|
27 | 27 | else: pass
|
28 | 28 | schema.append(trace)
|
29 | 29 |
|
30 |
| -## Data Level 2: Nested Attributes |
31 |
| - |
32 |
| -for i in p['schema']['traces']: |
33 |
| - for att1 in p['schema']['traces'][i]['attributes']: |
34 |
| - if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
35 |
| - try: |
36 |
| - attribute = {} |
37 |
| - attribute ['name'] = i+' > '+att1 |
38 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1 |
39 |
| - attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1]['description']).replace('*', '"') |
40 |
| - schema.append(attribute) |
41 |
| - except: |
42 |
| - attribute = {} |
43 |
| - attribute ['name'] = i+' > '+att1 |
44 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1 |
45 |
| - attribute ['description'] = 'Properties for '+att1 |
46 |
| - schema.append(attribute) |
47 |
| - for att2 in p['schema']['traces'][i]['attributes'][att1]: |
48 |
| - if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
49 |
| - try: |
50 |
| - if isinstance(p['schema']['traces'][i]['attributes'][att1][att2], dict): |
51 |
| - try: |
52 |
| - attribute = {} |
53 |
| - attribute ['name'] = i+' > '+att1+' > '+att2 |
54 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2 |
55 |
| - attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2]['description']).replace('*', '"') |
56 |
| - schema.append(attribute) |
57 |
| - except: |
58 |
| - attribute = {} |
59 |
| - attribute ['name'] = i+' > '+att1+' > '+att2 |
60 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2 |
61 |
| - attribute ['description'] = 'Properties for '+att2 |
62 |
| - schema.append(attribute) |
63 |
| - except: |
64 |
| - pass |
65 |
| - try: |
66 |
| - for att3 in p['schema']['traces'][i]['attributes'][att1][att2]: |
67 |
| - if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
68 |
| - try: |
69 |
| - if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3], dict): |
70 |
| - try: |
71 |
| - attribute = {} |
72 |
| - attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3 |
73 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3 |
74 |
| - attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3]['description']).replace('*', '"') |
75 |
| - schema.append(attribute) |
76 |
| - except: |
77 |
| - attribute = {} |
78 |
| - attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3 |
79 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3 |
80 |
| - attribute ['description'] = 'Properties for '+att3 |
81 |
| - schema.append(attribute) |
82 |
| - except: |
83 |
| - pass |
84 |
| - try: |
85 |
| - for att4 in p['schema']['traces'][i]['attributes'][att1][att2][att3]: |
86 |
| - if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
87 |
| - try: |
88 |
| - if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3][att4], dict): |
89 |
| - try: |
90 |
| - attribute = {} |
91 |
| - attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4 |
92 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4 |
93 |
| - attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3][att4]['description']).replace('*', '"') |
94 |
| - schema.append(attribute) |
95 |
| - except: |
96 |
| - attribute = {} |
97 |
| - attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4 |
98 |
| - attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4 |
99 |
| - attribute ['description'] = 'Properties for '+att4 |
100 |
| - schema.append(attribute) |
101 |
| - except: |
102 |
| - pass |
103 |
| - except: |
104 |
| - pass |
105 |
| - except: |
106 |
| - pass |
107 |
| - |
108 |
| -## Layout Attributes |
109 |
| - |
110 |
| -for att1 in p['schema']['layout']['layoutAttributes']: |
111 |
| - if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
| 30 | +def next_level(previous_level,chain_dict): |
| 31 | + for sub_attr in previous_level: |
112 | 32 | try:
|
113 |
| - attribute = {} |
114 |
| - attribute ['name'] = 'Layout > '+att1 |
115 |
| - attribute ['permalink'] = 'reference/#layout-'+att1 |
116 |
| - attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1]['description']).replace('*', '"') |
117 |
| - schema.append(attribute) |
118 |
| - except: |
119 |
| - attribute = {} |
120 |
| - attribute ['name'] = 'Layout > '+att1 |
121 |
| - attribute ['permalink'] = 'reference/#layout-'+att1 |
122 |
| - attribute ['description'] = 'Properties for '+att1 |
123 |
| - schema.append(attribute) |
124 |
| - for att2 in p['schema']['layout']['layoutAttributes'][att1]: |
125 |
| - if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
126 |
| - try: |
127 |
| - if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2], dict): |
| 33 | + if isinstance(previous_level[sub_attr],dict): |
| 34 | + if not any(value in sub_attr for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
128 | 35 | try:
|
129 | 36 | attribute = {}
|
130 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2 |
131 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2 |
132 |
| - attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2]['description']).replace('*', '"') |
| 37 | + attribute ['name'] = chain_dict['name']+' > '+sub_attr |
| 38 | + attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr |
| 39 | + attribute ['description'] = (previous_level[sub_attr]['description']).replace('*', '"') |
133 | 40 | schema.append(attribute)
|
| 41 | + next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']}) |
134 | 42 | except:
|
135 | 43 | attribute = {}
|
136 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2 |
137 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2 |
138 |
| - attribute ['description'] = 'Properties for '+att2 |
| 44 | + attribute ['name'] = chain_dict['name']+' > '+sub_attr |
| 45 | + attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr |
| 46 | + attribute ['description'] = 'Properties for '+sub_attr |
139 | 47 | schema.append(attribute)
|
140 |
| - except: |
141 |
| - pass |
142 |
| - try: |
143 |
| - for att3 in p['schema']['layout']['layoutAttributes'][att1][att2]: |
144 |
| - if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
145 |
| - if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3], dict): |
146 |
| - try: |
147 |
| - attribute = {} |
148 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3 |
149 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3 |
150 |
| - attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3]['description']).replace('*', '"') |
151 |
| - schema.append(attribute) |
152 |
| - except: |
153 |
| - attribute = {} |
154 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3 |
155 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3 |
156 |
| - attribute ['description'] = 'Properties for '+att3 |
157 |
| - schema.append(attribute) |
158 |
| - try: |
159 |
| - for att4 in p['schema']['layout']['layoutAttributes'][att1][att2][att3]: |
160 |
| - if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")): |
161 |
| - if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4], dict): |
162 |
| - try: |
163 |
| - attribute = {} |
164 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4 |
165 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4 |
166 |
| - attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4]['description']).replace('*', '"') |
167 |
| - schema.append(attribute) |
168 |
| - except: |
169 |
| - attribute = {} |
170 |
| - attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4 |
171 |
| - attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4 |
172 |
| - attribute ['description'] = 'Properties for '+att4 |
173 |
| - schema.append(attribute) |
174 |
| - except: |
175 |
| - pass |
176 |
| - except: |
177 |
| - pass |
| 48 | + next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']}) |
| 49 | + except: |
| 50 | + pass |
| 51 | + |
| 52 | +layout_chain_dict = {'name':'Layout', 'permalink':'reference/#layout'} |
| 53 | + |
| 54 | +# recursively add trace attributes to schema |
| 55 | +for i in p['schema']['traces']: |
| 56 | + chain_dict = {'name':i, 'permalink':'reference/#'+i } |
| 57 | + next_level(p['schema']['traces'][i]['attributes'], chain_dict) |
| 58 | + |
| 59 | + # if there are layoutAttributes in the trace add them too. |
| 60 | + if p['schema']['traces'][i].get('layoutAttributes'): |
| 61 | + next_level(p['schema']['traces'][i]['layoutAttributes'], layout_chain_dict) |
| 62 | + |
| 63 | +# recursively add layout attributes to schema |
| 64 | +next_level(p['schema']['layout']['layoutAttributes'], layout_chain_dict) |
178 | 65 |
|
179 | 66 | ## Send to Algolia
|
180 | 67 |
|
|
0 commit comments