Skip to content

Commit

Permalink
highscore response as list of dict with name
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Feb 3, 2024
1 parent fbe1103 commit ed59e70
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 54 deletions.
95 changes: 47 additions & 48 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
version: '3'
services:
kafka:
container_name: kafka
image: bitnami/kafka:3.5.1-debian-11-r3
environment:
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
# volumes:
# - ./kafka:/bitnami/kafka:rw
ports:
- 9094:9094
- 9092:9092
healthcheck:
test: ["CMD", "kafka-topics.sh", "--list", "--bootstrap-server", "localhost:9092"]
interval: 30s
timeout: 10s
retries: 5
networks:
- botdetector-network
# kafka:
# container_name: kafka
# image: bitnami/kafka:3.5.1-debian-11-r3
# environment:
# - ALLOW_PLAINTEXT_LISTENER=yes
# - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
# - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT
# - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094
# - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
# # volumes:
# # - ./kafka:/bitnami/kafka:rw
# ports:
# - 9094:9094
# - 9092:9092
# healthcheck:
# test: ["CMD", "kafka-topics.sh", "--list", "--bootstrap-server", "localhost:9092"]
# interval: 30s
# timeout: 10s
# retries: 5
# networks:
# - botdetector-network

kafdrop:
container_name: kafdrop
image: obsidiandynamics/kafdrop:latest
environment:
- KAFKA_BROKERCONNECT=kafka:9092
- JVM_OPTS=-Xms32M -Xmx64M
- SERVER_SERVLET_CONTEXTPATH=/
ports:
- 9000:9000
restart: on-failure
networks:
- botdetector-network
depends_on:
kafka:
condition: service_healthy
# kafdrop:
# container_name: kafdrop
# image: obsidiandynamics/kafdrop:latest
# environment:
# - KAFKA_BROKERCONNECT=kafka:9092
# - JVM_OPTS=-Xms32M -Xmx64M
# - SERVER_SERVLET_CONTEXTPATH=/
# ports:
# - 9000:9000
# restart: on-failure
# networks:
# - botdetector-network
# depends_on:
# kafka:
# condition: service_healthy

kafka_setup:
container_name: kafka_setup
build:
context: ./kafka_setup
environment:
- KAFKA_BROKER=kafka:9092
networks:
- botdetector-network
depends_on:
kafka:
condition: service_healthy
# kafka_setup:
# container_name: kafka_setup
# build:
# context: ./kafka_setup
# environment:
# - KAFKA_BROKER=kafka:9092
# networks:
# - botdetector-network
# depends_on:
# kafka:
# condition: service_healthy

mysql:
container_name: database
Expand Down Expand Up @@ -92,7 +92,6 @@ services:
volumes:
- ./src:/project/src
depends_on:
- kafka_setup
- mysql

networks:
Expand Down
9 changes: 3 additions & 6 deletions src/app/repositories/highscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ async def get(self, id: int):
sql = sql.join(target=Player, onclause=self.table.Player_id == Player.id)
sql = sql.where(self.table.Player_id == id)
data: list[dict] = await self._simple_execute(sql)
for d in data:
d["PlayerHiscoreDataLatest"]["name"] = d.pop("name")
d = d["PlayerHiscoreDataLatest"]
data = [{"name": d.pop("name"), **d["PlayerHiscoreDataLatest"]} for d in data]
return data

async def get_many(self, start: int, limit: int = 5000):
Expand All @@ -42,9 +40,8 @@ async def get_many(self, start: int, limit: int = 5000):
sql = sql.where(self.table.Player_id > start)
sql = sql.limit(limit)
data: list[dict] = await self._simple_execute(sql)
for d in data:
d["PlayerHiscoreDataLatest"]["name"] = d.pop("name")
d = d["PlayerHiscoreDataLatest"]
# data = [{"PlayerHiscoreDataLatest":{"total": int, ...}, "name": str}]
data = [{"name": d.pop("name"), **d["PlayerHiscoreDataLatest"]} for d in data]
return data

async def delete(self, id):
Expand Down

0 comments on commit ed59e70

Please sign in to comment.