I'm looking for a solution that would help me do the following.
Suppose I have to generate HTML code using hand-drawn design. I got element type, x, y coordination width, and height as NumPy array. I need to sort these arrays according to the y coordination if the two elements are in the same value then sort according to the y value. Then I need to group the elements in the same type.
I created array like this :
import numpy
s = numpy.array([
#element type, x,y,width,height
["hyperlink", 5, 150, 25, 10],
["paragraph", 20, 60, 10, 10],
["image", 85, 150, 25, 10],
["radio", 20, 60, 10, 10],
["radio", 85, 150, 25, 10],
["button", 20, 60, 10, 10],
["text_field", 20, 40, 25, 10],
["label", 10, 10, 20, 10]])
print(s)
lists = s.tolist()
print([{"element_type ": x[0] , "x": x[1], "y": x[2], "width":x[3], "height" :x[4]} for i, x in enumerate(lists)])
I'd like to sort it such that my points are ordered by y-coordinate, and then by x in cases where their coordinate is the same.
Then I need to group the elements such as two radio buttons as in the above example. I expected output as follows.
{
'element_type ': 'hyperlink',
'group_id' :"1",
'x': '5',
'y': '150',
'width': '25',
'height': '10'
},
{
'element_type ': 'image',
'group_id' :"3",
'x': '85',
'y': '150',
'width': '25',
'height': '10'
},
{'element_type ': 'radio',
'group_id' :"4",
'x': '20',
'y': '60',
'width': '10',
'height': '10'
},
{
'element_type ': 'radio',
'group_id' :"4",
'x': '85',
'y': '150',
'width': '25',
'height': '10'
},
{
'element_type ': 'text_field',
'group_id' :"5",
'x': '20',
'y': '40',
'width': '25',
'height': '10'
},
{'element_type ': 'label',
**group_id :"5",**
'x': '10',
'y': '10',
'width': '20',
'height': '10'
}]
Can I get an idea for this? I used python.