Skip to content

Commit

Permalink
milestones
Browse files Browse the repository at this point in the history
  • Loading branch information
Amichay Oren committed Sep 2, 2023
1 parent 808cacc commit caaf2d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions apigateway/get_missions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def process_mission(account_balance: int, mission_details: Mission) -> dict:
"name": mission_details.data["name"],
"strategy": mission_details.data["strategy"],
"milestones": mission_details.calculate_milestones(account_balance),
"currentBalance": account_balance,
}

return payload
Expand Down
2 changes: 1 addition & 1 deletion apigateway/get_missions/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1623,5 +1623,5 @@ zipp==3.15.0 \


--extra-index-url https://us-east4-python.pkg.dev/development-380917/python-repos/simple/
infra==0.1.108 \
infra==0.1.109 \
--hash=sha256:d8964a8de539b848551bb1590ba3679dd9e2dbe89729135d67462d06575bfa0f
18 changes: 14 additions & 4 deletions infra/infra/data/missions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


class Mission:
# TODO: move to database
level_step: dict = {
0: 0,
200: 25,
1000: 50,
2500: 100,
Expand Down Expand Up @@ -59,13 +61,21 @@ def forecaster(self, bins: int = 30) -> list:
return new_df.values.tolist()

def calculate_milestones(self, account_size: int) -> list[int]:
level = min(
self.level_step.keys(), key=lambda x: abs(x - account_size)
keys = list(self.level_step.keys())
index = min(
range(len(keys)), key=lambda i: abs(keys[i] - account_size)
)
level = keys[index + 1]

print(level)
past_milestone = (
account_size // self.level_step[level]
) * self.level_step[level]

return []
next_milestones = [
past_milestone + (i + 1) * self.level_step[level] for i in range(3)
]

return [past_milestone, *next_milestones]


class Missions:
Expand Down
2 changes: 1 addition & 1 deletion infra/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license = {text = "MIT"}
name = "infra"
readme = "README.md"
requires-python = ">=3.11"
version = "0.1.108"
version = "0.1.109"

[build-system]
build-backend = "pdm.backend"
Expand Down

0 comments on commit caaf2d8

Please sign in to comment.