Skip to content

Commit

Permalink
Merge pull request #51 from assembler-financial/rahul/saddle-block-me…
Browse files Browse the repository at this point in the history
…tadata

(fix): Updated views due to bug in code for getAllMetadata endpoint a…
  • Loading branch information
rahulbrahmal authored Jul 22, 2021
2 parents 459a2e8 + f9acaa1 commit 7935177
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
40 changes: 40 additions & 0 deletions orchestrator/migrations/0002_data_migration_for_block_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,45 @@ def seed_blocks_into_registry(apps, schema_editor):
},
).save()

BlockRegistry(
block_type="SIGNAL_BLOCK",
block_id=2,
block_name="Saddle",
inputs=[
{
"fieldData": {"base": "/saddleType", "method": "GET"},
"fieldName": "Saddle Type",
"fieldType": "dropdown",
"fieldVariableName": "saddle_type",
},
{
"fieldData": {"base": "/eventAction", "method": "GET"},
"fieldName": "Event Action",
"fieldType": "dropdown",
"fieldVariableName": "event_action",
},
{
"fieldName": "Consecutive Up",
"fieldVariableName": "consecutive_up",
"fieldType": "input",
},
{
"fieldName": "Consecutive Down",
"fieldVariableName": "consecutive_down",
"fieldType": "input",
},
],
validations={
"input": {
"required": [{"blockType": "COMPUTATIONAL_BLOCK", "number": 1}],
"allowed_blocks": [
{"blockId": "1", "blockType": "COMPUTATIONAL_BLOCK"}
],
},
"output": [{"blockType": "SIGNAL_BLOCK", "number": 2}],
},
).save()

BlockRegistry(
block_type="STRATEGY_BLOCK",
block_id=1,
Expand Down Expand Up @@ -148,6 +187,7 @@ def seed_blocks_into_registry(apps, schema_editor):
],
"allowed_blocks": [
{"blockId": "1", "blockType": "SIGNAL_BLOCK"},
{"blockId": "2", "blockType": "SIGNAL_BLOCK"},
{"blockId": "1", "blockType": "DATA_BLOCK"},
],
},
Expand Down
14 changes: 9 additions & 5 deletions orchestrator/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ def test_ok(self):
"DATA_BLOCK": {
"1": {
"blockName": "Raw Data",
"blockMetadata": "/orchestration/$DATA_BLOCK/$1/",
"blockMetadata": "/orchestration/DATA_BLOCK/1/",
}
},
"COMPUTATIONAL_BLOCK": {
"1": {
"blockName": "Technical Analysis",
"blockMetadata": "/orchestration/$COMPUTATIONAL_BLOCK/$1/",
"blockMetadata": "/orchestration/COMPUTATIONAL_BLOCK/1/",
}
},
"SIGNAL_BLOCK": {
"1": {
"blockName": "Event",
"blockMetadata": "/orchestration/$SIGNAL_BLOCK/$1/",
}
"blockMetadata": "/orchestration/SIGNAL_BLOCK/1/",
},
"2": {
"blockName": "Saddle",
"blockMetadata": "/orchestration/SIGNAL_BLOCK/2/",
},
},
"STRATEGY_BLOCK": {
"1": {
"blockName": "Backtest",
"blockMetadata": "/orchestration/$STRATEGY_BLOCK/$1/",
"blockMetadata": "/orchestration/STRATEGY_BLOCK/1/",
}
},
}
Expand Down
23 changes: 8 additions & 15 deletions orchestrator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ def get(self, request):

response = {}
for block_registry in all_blocks_from_registry:
response = {
**response,
block_registry.block_type: {
block_registry.block_id: {
"blockName": block_registry.block_name,
"blockMetadata": f"/orchestration/${block_registry.block_type}/${block_registry.block_id}/",
}
},
}
if block_registry.block_type not in response:
response[block_registry.block_type] = {}

if block_registry.block_id not in response[block_registry.block_type]:
response[block_registry.block_type][block_registry.block_id] = {
"blockName": block_registry.block_name,
"blockMetadata": f"/orchestration/{block_registry.block_type}/{block_registry.block_id}/",
}

return JsonResponse({"response": response})

Expand All @@ -43,12 +42,6 @@ class MetadataView(APIView):

def get(self, request, block_type, block_id):
try:
# block_registry = (
# BlockRegistry.objects.all()
# .filter(block_type=block_type)
# .filter(block_id=block_id)[0]
# )

block_registry = BlockRegistry.objects.get(
block_type=block_type, block_id=block_id
)
Expand Down

0 comments on commit 7935177

Please sign in to comment.