Skip to content

Commit

Permalink
feat: Cron for download examples nibbler (#237)
Browse files Browse the repository at this point in the history
* feat: cron for download examples nibbler
  • Loading branch information
Ciroye authored Dec 24, 2023
1 parent d6073de commit a6fc75d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions backend/app/api/endpoints/base/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def download_all_created_examples(
)


@router.post("/download_created_examples_every_day_in_s3", response_model={})
def download_created_examples_every_day_in_s3(
model: DownloadAllExamplesRequest,
):
return ExampleService().download_created_examples_every_day_in_s3(model.task_id)


@router.post("/download_created_examples_user", response_model={})
def download_created_examples_user(
model: DownloadExamplesRequest,
Expand Down
27 changes: 27 additions & 0 deletions backend/app/domain/services/base/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import zipfile

import boto3
import pytz
import requests
import yaml
from fastapi.encoders import jsonable_encoder
Expand All @@ -23,13 +24,15 @@
from app.domain.services.base.user import UserService
from app.domain.services.base.validation import ValidationService
from app.infrastructure.repositories.example import ExampleRepository
from app.infrastructure.repositories.task import TaskRepository


class ExampleService:
def __init__(self):
self.example_repository = ExampleRepository()
self.context_service = ContextService()
self.task_service = TaskService()
self.task_repository = TaskRepository()
self.round_service = RoundService()
self.round_user_example_info = RoundUserExampleInfoService()
self.user_service = UserService()
Expand Down Expand Up @@ -278,6 +281,30 @@ def download_all_created_examples(self, task_id: int) -> dict:
examples_data_list.append(example_necessary_info)
return json.dumps(examples_data_list, cls=CustomJSONEncoder)

def download_created_examples_every_day_in_s3(self, task_id: int) -> dict:
examples_data = self.example_repository.download_all_created_examples(task_id)
examples_data_list = []
for example in examples_data:
example_necessary_info = {}
example_info = example[0].__dict__
example_info["user_name"] = self.user_service.get_user_name_by_id(
example_info["uid"]
)[0]
example_necessary_info["example_info"] = example_info
example_necessary_info["context_info"] = example[1].__dict__
example_necessary_info["round_info"] = example[2]
examples_data_list.append(example_necessary_info)
examples_data = json.dumps(examples_data_list, cls=CustomJSONEncoder)
s3_bucket = self.task_repository.get_s3_bucket_by_task_id(task_id)[0]
task_code = self.task_repository.get_task_code_by_task_id(task_id)[0]
est_timezone = pytz.timezone("US/Eastern")
current_date = datetime.datetime.now(est_timezone).strftime("%Y-%m-%d")
print("current_date", current_date)
file_key = f"{task_code}/{current_date}.json"
print("file_key", file_key)
self.s3.put_object(Body=examples_data, Bucket=s3_bucket, Key=file_key)
return True

def download_created_examples_user(
self, task_id: int, user_id: int, amount: int
) -> dict:
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ cohere==4.27.0
anthropic==0.3.11
aleph_alpha_client==3.5.1
google-generativeai==0.2.1
replicate==0.15.4
replicate==0.15.4
pytz==2021.3
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const TaskModelLeaderboardRowFirstLevel: FC<
)}
</tr>
{secondExpanded &&
dataset.downstream_info &&
dataset.downstream_info.map((downstream: any, i: number) => (
<TaskModelLeaderboardRowSecondLevel
key={i}
Expand Down

0 comments on commit a6fc75d

Please sign in to comment.