-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import csv | ||
import os | ||
|
||
from pdr_backend.subgraph.prediction import mock_daily_predictions | ||
from pdr_backend.util.csvs import save_analysis_csv, save_prediction_csv | ||
|
||
|
||
def test_save_analysis_csv(tmpdir): | ||
predictions = mock_daily_predictions() | ||
key = ( | ||
predictions[0].pair.replace("/", "-") | ||
+ predictions[0].timeframe | ||
+ predictions[0].source | ||
) | ||
save_analysis_csv(predictions, str(tmpdir)) | ||
|
||
with open(os.path.join(str(tmpdir), key + ".csv")) as f: | ||
data = csv.DictReader(f) | ||
data_rows = list(data) | ||
|
||
assert data_rows[0]["Predicted Value"] == str(predictions[0].prediction) | ||
assert data_rows[0]["True Value"] == str(predictions[0].trueval) | ||
assert data_rows[0]["Timestamp"] == str(predictions[0].timestamp) | ||
assert list(data_rows[0].keys()) == [ | ||
"PredictionID", | ||
"Timestamp", | ||
"Slot", | ||
"Stake", | ||
"Wallet", | ||
"Payout", | ||
"True Value", | ||
"Predicted Value", | ||
] | ||
|
||
|
||
def test_save_prediction_csv(tmpdir): | ||
predictions = mock_daily_predictions() | ||
key = ( | ||
predictions[0].pair.replace("/", "-") | ||
+ predictions[0].timeframe | ||
+ predictions[0].source | ||
) | ||
save_prediction_csv(predictions, str(tmpdir)) | ||
|
||
with open(os.path.join(str(tmpdir), key + ".csv")) as f: | ||
data = csv.DictReader(f) | ||
data_rows = list(row for row in data) | ||
|
||
assert data_rows[0]["Predicted Value"] == str(predictions[0].prediction) | ||
assert data_rows[0]["True Value"] == str(predictions[0].trueval) | ||
assert data_rows[0]["Timestamp"] == str(predictions[0].timestamp) | ||
assert list(data_rows[0].keys()) == [ | ||
"Predicted Value", | ||
"True Value", | ||
"Timestamp", | ||
"Stake", | ||
"Payout", | ||
] |