From 8d7d6da73b991704a39605965ec101064ec418f8 Mon Sep 17 00:00:00 2001 From: "Sivaramalingam, Janani (PG/T - Comp Sci & Elec Eng)" <js03432@surrey.ac.uk> Date: Sat, 10 Aug 2024 22:56:09 +0000 Subject: [PATCH] Update val_sim.py --- val_sim.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/val_sim.py b/val_sim.py index c57c354..5251de7 100644 --- a/val_sim.py +++ b/val_sim.py @@ -5,26 +5,22 @@ import random from statistics import mean, stdev import json import sys -import cgitb -cgitb.enable() # Read input from stdin input_data = sys.stdin.read() - -# Parse the input data as JSON -event_dict = json.loads(input_data) +event = json.loads(input_data) # Extract the values from the event dictionary -dt = json.loads(event_dict['key1']) # List of dates -close = json.loads(event_dict['key2']) # List of close prices -buy = json.loads(event_dict['key3']) # List of buy signals -sell = json.loads(event_dict['key4']) # List of sell signals -h = int(event_dict['key5']) # History length -d = int(event_dict['key6']) # Number of shots -t = event_dict['key7'] # Trade type ('buy' or 'sell') +dt = eval(event['key1']) +close = eval(event['key2']) +buy = eval(event['key3']) +sell = eval(event['key4']) +h = int(event['key5']) +d = int(event['key6']) +t = event['key7'] -minhistory = int(h) -shots = int(d) +minhistory = h +shots = d var95_list = [] var99_list = [] @@ -65,6 +61,6 @@ response = { "var99_list": var99_list } -# Print the output as a JSON string, which is how CGI scripts return data +# Output result as JSON print("Content-Type: application/json\n") print(json.dumps(response)) -- GitLab