SXP: Add missing tags to binding origins tests
[integration/test.git] / csit / scripts / generate_dashVis.py
1 # SPDX-License-Identifier: EPL-1.0
2 ##############################################################################
3 # Copyright (c) 2018 The Linux Foundation and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ##############################################################################
10 import yaml
11 import copy
12
13 import json
14
15
16 def p(x):
17     print(json.dumps(x, indent=4, sort_keys=False))
18
19
20 class panelsJSON:
21     def __init__(self):
22         self.content = {
23             'gridData': {
24                 'h': None,
25                 'i': None,
26                 'w': None,
27                 'x': None,
28                 'y': None
29             },
30             'id': None,
31             'panelIndex': None,
32             'type': 'visualization',
33             'version': '6.2.4'
34         }
35
36         self.counter = 0
37
38     def create(self, co_ords, id):
39         self.counter += 1
40         temp = copy.deepcopy(self.content)
41         temp['gridData']['h'] = co_ords['h']
42         temp['gridData']['i'] = str(self.counter)
43         temp['gridData']['w'] = co_ords['w']
44         temp['gridData']['x'] = co_ords['x']
45         temp['gridData']['y'] = co_ords['y']
46
47         temp['id'] = id
48         temp['panelIndex'] = str(self.counter)
49
50         return temp
51
52
53 def generate(viz_config):
54     dash = panelsJSON()
55     viz = [dash.create(i['co_ords'], i['id']) for _, i in viz_config.items()]
56     return viz
57
58
59 if __name__ == '__main__':
60     with open('dashboard.yaml', 'r') as f:
61         config = yaml.safe_load(f)
62         p(generate(config['dashboard']['viz']))