From df6417e3eaaad0339bbcd430afbaa409c9b22a11 Mon Sep 17 00:00:00 2001 From: Lukian Date: Sat, 18 Jan 2025 21:36:48 +0100 Subject: [PATCH] Reduce sleep duration and optimize share emission and purchase logic; add .gitignore for virtual environment --- .gitignore | 1 + client/company/main.py | 9 ++++----- client/shareholder/main.py | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b694934 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv \ No newline at end of file diff --git a/client/company/main.py b/client/company/main.py index ef938ed..07aa11a 100644 --- a/client/company/main.py +++ b/client/company/main.py @@ -43,10 +43,9 @@ if __name__ == "__main__": while True: companies = getCompanies() - for company in companies: - price = randint(20, 2000) - for i in range(randint(0, 10)): - emitShare(company["id"], price) + price = randint(20, 2000) + for i in range(randint(0, 4)): + emitShare(randint(0, len(companies) - 1), price) - sleep(30) + sleep(4) diff --git a/client/shareholder/main.py b/client/shareholder/main.py index b76765d..4153673 100644 --- a/client/shareholder/main.py +++ b/client/shareholder/main.py @@ -59,9 +59,8 @@ if __name__ == "__main__": shareholders = getAllBuyers() shares = getAllShares() - for shareholder in shareholders: - shareId = randint(0, len(shares) - 1) - buyShare(shareholder["id"], shareId, shares[shareId]["price"] + randint(-20, 20)) + shareId = randint(0, len(shares) - 1) + buyShare(randint(0, len(shareholders) - 1), shareId, shares[shareId]["price"] + randint(-20, 20)) - sleep(30) + sleep(4)