Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ bt_venv/
ENV/
env.bak/
venv.bak/
bt_venv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I forgot about this! Good catch :)


# Spyder project settings
.spyderproject
Expand Down
3 changes: 2 additions & 1 deletion simulation/validator/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from simulation.validator.miner_data_handler import MinerDataHandler
from simulation.validator.moving_average import compute_weighted_averages
from simulation.validator.price_data_provider import PriceDataProvider
from simulation.validator.response_validation import validate_responses
from simulation.validator.reward import get_rewards


Expand Down Expand Up @@ -249,7 +250,7 @@ async def _query_available_miners_and_save_responses(

miner_predictions = {}
for i, response in enumerate(responses):
if response is None or len(response) == 0:
if validate_responses(response, simulation_input) is False:
continue
miner_id = miner_uids[i]
miner_predictions[miner_id] = response
Expand Down
48 changes: 48 additions & 0 deletions simulation/validator/response_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
from datetime import datetime, timedelta


from simulation.simulation_input import SimulationInput


def validate_responses(response, simulation_input: SimulationInput) -> bool:
"""
Validate responses from miners.

Return False if response is incorrect.
"""
if response is None or len(response) == 0:
return False

# assuming `response` is in json
response = json.loads(response)

# check the number of paths
if len(response) != simulation_input.num_simulations:
return False

for path in response:
# check the number of time points
if (
len(path)
!= simulation_input.time_length // simulation_input.time_increment
):
return False

# check the start time
if path[0]["time"] != simulation_input.start_time:
return False

for i in range(1, len(path)):
# check the time increment
i_minus_one_time = datetime.fromisoformat(path[i - 1]["time"])
i_time = datetime.fromisoformat(path[i]["time"])
expected_delta = timedelta(seconds=simulation_input.time_increment)
if i_time - i_minus_one_time != expected_delta:
return False

# check the price format
if not isinstance(path[i]["price"], (int, float)):
return False

return True
Loading