
committed by
GitHub

parent
8bc59aeae6
commit
7d8b34210c
10
resources/decision_log2.csv
Normal file
10
resources/decision_log2.csv
Normal file
@ -0,0 +1,10 @@
|
||||
client_id,decision
|
||||
cdd60b2d-34eb-4db4-9d5e-8e903bbb4057,Accept
|
||||
7b48afa1-6db3-4762-8faf-e73b5158f6b0,Accept
|
||||
32eeffdc-91ab-4518-8dc6-4d805c5e4aed,Accept
|
||||
1b97cefc-48ab-437f-8cd0-ffd4eaa707df,Accept
|
||||
5471d561-b89b-4317-b3ed-499b5334e424,Accept
|
||||
a482b28b-6f4c-4f2d-a167-42c071a92470,Accept
|
||||
2d7d0293-291c-46ec-91fb-75351be347f8,Accept
|
||||
3006006d-1060-4b53-afd3-b702a8fc2358,Accept
|
||||
f4a42e3e-75a8-43dc-92fe-e38fe23b1d82,Accept
|
|
@ -5,7 +5,7 @@ from typing import Literal, Dict, Any
|
||||
import config
|
||||
from dto.requests import GameStartRequestDTO, GameDecisionRequestDTO
|
||||
from services.julius_baer_api_client import JuliusBaerApiClient
|
||||
from utils.storage.game_files_manager import store_game_round_data
|
||||
from utils.storage.game_files_manager import store_game_round_data, store_decision
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -34,21 +34,29 @@ class Player:
|
||||
start_response = self.client.start_game(payload)
|
||||
log.info('game started, session id: %s', start_response.session_id)
|
||||
|
||||
status = ''
|
||||
decision = self.make_decision(start_response.client_data)
|
||||
|
||||
decision_counter = 0
|
||||
client_id = start_response.client_id
|
||||
|
||||
while status not in ['gameover', 'complete']:
|
||||
is_game_running = True
|
||||
while is_game_running:
|
||||
payload = GameDecisionRequestDTO(
|
||||
decision=decision,
|
||||
session_id=start_response.session_id,
|
||||
client_id=start_response.client_id,
|
||||
client_id=client_id,
|
||||
)
|
||||
|
||||
log.info('client id: %s', client_id)
|
||||
decision_response = self.client.send_decision(payload)
|
||||
log.info(f'decision: {decision}, response status: {decision_response.status}, score: {decision_response.score}')
|
||||
|
||||
status = decision_response.status
|
||||
is_game_running = status not in ['gameover', 'complete']
|
||||
if is_game_running:
|
||||
store_decision(str(client_id), decision)
|
||||
client_id = decision_response.client_id
|
||||
|
||||
decision = self.make_decision(decision_response.client_data)
|
||||
|
||||
# Handle first response from game initialization logic
|
||||
@ -60,22 +68,12 @@ class Player:
|
||||
store_game_round_data(decision, decision_response, decision_counter, str(start_response.session_id), status)
|
||||
|
||||
decision_counter += 1
|
||||
time.sleep(1.5)
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def make_decision(self, client_data: Dict[str, Any]) -> Literal["Accept", "Reject"]:
|
||||
# Do your magic!
|
||||
|
||||
return 'Accept'
|
||||
|
||||
# import random
|
||||
# return random.choice(["Accept", "Reject"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
player = Player()
|
||||
player.start()
|
||||
return 'Accept' # Replace me!!
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,8 @@ import logging
|
||||
import config
|
||||
import json
|
||||
from typing import Dict, Any
|
||||
import csv
|
||||
from pathlib import Path
|
||||
|
||||
from dto.responses import GameStartResponseDTO, GameDecisionResponseDTO
|
||||
|
||||
@ -74,3 +76,16 @@ def store_game_round_data(decision: str, response: GameStartResponseDTO | GameDe
|
||||
logging.info(f"[+] Successfully saved API response JSON to: {json_file_path}")
|
||||
except Exception as e:
|
||||
logging.error(f"[!] Failed to save API response JSON: {e}")
|
||||
|
||||
|
||||
def store_decision(client_id: str, decision: str):
|
||||
path = Path('./resources/decision_log2.csv') # TODO clean me!!
|
||||
|
||||
path.parent.mkdir(parents=True, exist_ok=True) # create dirs if needed
|
||||
|
||||
exists = path.exists()
|
||||
with open(path, 'a', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
if not exists:
|
||||
writer.writerow(['client_id', 'decision']) # header
|
||||
writer.writerow([client_id, decision])
|
||||
|
Reference in New Issue
Block a user