Skip to content

Commit

Permalink
nov 29
Browse files Browse the repository at this point in the history
  • Loading branch information
Lhwhatever committed Nov 29, 2022
1 parent aab9a80 commit e2db08b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bots/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autograde:
python3 run-match.py
2 changes: 2 additions & 0 deletions bots/team1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
return 1
2 changes: 2 additions & 0 deletions bots/team2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
return 2
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Optional, Union

from fastapi import FastAPI, HTTPException, Response, status
from fastapi import FastAPI, HTTPException, Response, status, File
from pydantic import BaseModel, BaseSettings
import boto3
from dotenv import load_dotenv
Expand Down Expand Up @@ -127,17 +127,20 @@ def run_single_match(match: Match):


@app.post("/single_match_callback/")
def run_single_match_callback(match_replay_obj: MatchCallback):
def run_single_match_callback(file: bytes = File()):
"""
Callback URL called by Tango when single unranked scrimmage match has finished running.
Parses the resulting JSON object and places the returned replay file into S3 bucket.
Since match is unranked, no need to parse output / adjust rankings
"""
print("test")
print("file_size:", len(file))
print(file)
# TODO: figure out what format Tango returns the game info in; for now assume json with team names and replay info
storageHandler = StorageHandler(app.s3_resource)
storageHandler.upload_replay(match_replay_obj)
# storageHandler = StorageHandler(app.s3_resource)
# storageHandler.upload_replay(match_replay_obj)


@app.post("/scrimmage")
Expand Down
16 changes: 14 additions & 2 deletions server/match_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import requests.exceptions as reqexc
from typing import Any

from server.game_engine import ENGINE_NAME


COURSE_LAB = "awap"
MAKEFILE = "bots/autograde-Makefile"
Expand Down Expand Up @@ -72,6 +74,7 @@ def uploadFile(self, pathname: str) -> str:
headers=header,
)
response.raise_for_status()
print(response.json())
except reqexc.HTTPError as exc:
raise HTTPException(
status_code=500, detail="Could not connect to Tango"
Expand All @@ -96,10 +99,14 @@ def sendJob(self):
match_id = datetime.now().isoformat()

makefilename = self.uploadFile(MAKEFILE)
files = [{"localFile": makefilename, "destFile": makefilename}]
enginename = self.uploadFile("bots/run-match.py")
files = [
{"localFile": makefilename, "destFile": "Makefile"},
{"localFile": enginename, "destFile": enginename},
]

for i, submission in enumerate(self.match.user_submissions):
local_path = os.path.join(tempdir, f"team{i}.py")
local_path = os.path.join(tempdir, f"team{i+1}.py")
self.s3.download_file(
submission.s3_bucket_name, submission.s3_object_name, local_path
)
Expand All @@ -112,13 +119,18 @@ def sendJob(self):
"image": "awap_image",
"jobName": match_id,
"output_file": "output.json",
"timeout": 10,
"files": files,
"callback_url": "http://172.26.71.250:8000/single_match_callback/",
}

print(requestObj)

response = requests.post(
f"{self.hostname}:{self.tango_port}/addJob/{self.key}/{COURSE_LAB}/",
data=json.dumps(requestObj),
)
print(response.json())
response.raise_for_status()

except reqexc.HTTPError as exc:
Expand Down

0 comments on commit e2db08b

Please sign in to comment.