Skip to content

Commit

Permalink
feat: adjustments in data_model (#574)
Browse files Browse the repository at this point in the history
- adjust Cache model because the table definition has changed)
- adjust scorer_dump_data_eth_model_score command and test
- moved scorer_dump_data_eth_model_score command to data_model app
  • Loading branch information
nutrina authored Apr 22, 2024
1 parent d906ebd commit 7bfd133
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, file):
def write_batch(self, data):
for d in data:
try:
key = json.loads(d["key"])
key = d["key"]
value = d["value"]
address = key[1].lower()
self.file.write(
Expand Down Expand Up @@ -104,7 +104,9 @@ def handle(self, *args, **options):

try:
export_data_for_model(
Cache.objects.all(),
Cache.objects.filter(
key__0="predict"
), # This will only filter the scores for eth_stamp_model (v1)
"key",
batch_size,
get_writer(filename),
Expand Down
2 changes: 1 addition & 1 deletion api/data_model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class Cache(models.Model):
key = models.CharField(primary_key=True, max_length=128)
key = models.JSONField(primary_key=True)
value = models.JSONField()
updated_at = models.DateTimeField()

Expand Down
14 changes: 12 additions & 2 deletions api/data_model/test/test_cmd_scorer_dump_data_eth_model_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_dump_data_eth_model_score(self, mocker, create_cache_table):
address = f"0x{i}"
timestamp = datetime(2024, 4, 9, i, 0, 0, tzinfo=timezone.utc)
Cache.objects.create(
key=json.dumps(["predict", address]),
key=["predict", address],
value={
"data": {"human_probability": i},
"meta": {"version": "v1", "Training_date": "2023/12/27"},
Expand All @@ -74,9 +74,19 @@ def test_dump_data_eth_model_score(self, mocker, create_cache_table):
)
)
)
# Also add data to cache for other models (differet value in first element in key)
# The export command should filter correctly
Cache.objects.create(
key=["predict_nft", address],
value={
"data": {"human_probability": i},
"meta": {"version": "v1", "Training_date": "2023/12/27"},
},
updated_at=timestamp,
)

s3_upload_mock = mocker.patch(
"ceramic_cache.management.commands.scorer_dump_data_eth_model_score.upload_to_s3"
"data_model.management.commands.scorer_dump_data_eth_model_score.upload_to_s3"
)
call_command(
"scorer_dump_data_eth_model_score",
Expand Down

0 comments on commit 7bfd133

Please sign in to comment.