Colleagues, good afternoon. I ask for help in writing the optimal algorithm for a recursive API call.
The essence is as follows - there is an API method ( getProductType ), which allows you to get the rest of products of different types ( productType ):
"stats": [ { "label": "Окна", "segment": "productType==Окна", "count": 11, }, { "label": "Двери", "segment": "productType==Двери", "count": 22, }, { "label": "Плинтуса", "segment": "productType==Плинтуса", "count":33 }, { "label": "Шторы", "segment": "productType==Шторы", "count": 44, } ] And also there are methods that allow you to get the remnants of the goods in the context of:
- colors - productColors ( getColors method),
- states - productCondition (new or used) ( getCondition method),
- textures
- etc.
Each api method has an input parameter (optional) - filter . It allows you to filter the values that match the specified expression. Moreover, it can take several expressions at the same time, all of them will be combined by a logical "AND", i.e. for example, to get the rest of the products in the "color" section, for which the product type is "Doors" and the state is "New" , you can call the following method: getColors(filter="productType==Двери;productCondition==Новый")
When receiving statistics, in each dictionary we have the key segment , which can be used in the input parameter ( filter ) of any of the available API methods.
The task is to get the output table with nesting, which can be dynamic (a large number of different API methods), for example, see the slice "Product type -> Color -> State" (productType -> productColour -> productCondition):
"stats": [ { "label": "Окна", "segment": "productType==Окна", "count": 11, "getColors": [ {"label": "Зеленый", "segment": "productColour==Зеленый", "count": 11, "getCondition": [ { "label": "Новый", "segment": "productCondition==Новый", "count": 22, }, { "label": "БУ", "segment": "productCondition==БУ", "count":33 }, ] }, { "label": "Красный", "segment": "productColour==Красный", "count": 11, "getCondition": [ { "label": "Новый", "segment": "productCondition==Новый", "count": 22, }, { "label": "БУ", "segment": "productCondition==БУ", "count":33 }, ] } ] }, { "label": "Двери", "segment": "productType==Двери", "count": 22, "getColors": [ {"label": "Рыжий", "segment": "productColour==Рыжий", "count": 11, "getCondition": [ { "label": "Новый", "segment": "productCondition==Новый", "count": 22, }, { "label": "БУ", "segment": "productCondition==БУ", "count":33 }, ] } ] }, { "label": "Плинтуса", "segment": "productType==Плинтуса", "count":33, ... }, { "label": "Шторы", "segment": "productType==Шторы", "count": 44, ... } , ... ] Those. in essence, you first need to obtain data on the first level (Item Type), then in the first object from statistics, tear out the key "segment", and call the second method with the filter input parameter containing this key. Then, for the statistics obtained, do the same to get the third level, using filter = " segment from level 1 ; segment from second level ", and so on by recursion.
I would be grateful for any hint.