починил авторизацию, ускорил систему с помощью сервера, сделал спрайты по правильному
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
from fastapi import responses, status
|
||||
from DB import UseDB
|
||||
from secrets import compare_digest
|
||||
|
||||
|
||||
def authorization(login, password):
|
||||
db = UseDB("accounts")
|
||||
response = db.find_document({"login": login})
|
||||
if not response:
|
||||
return responses.JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content="Нет такого логина")
|
||||
if not compare_digest(response[0]["password"], password):
|
||||
return responses.JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content="Ошибка пароля")
|
||||
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=" ")
|
||||
@@ -0,0 +1,15 @@
|
||||
import random
|
||||
from fastapi import responses, status
|
||||
from DB import UseDB
|
||||
from fastapi import Response
|
||||
import json
|
||||
|
||||
|
||||
def get_random_event_func():
|
||||
db = UseDB("events")
|
||||
response = db.find_document({})
|
||||
random_event = random.choices([i["_id"] for i in response],
|
||||
weights=[i["probability"] for i in response])
|
||||
|
||||
json_str = json.dumps(db.find_document({"_id": random_event[0]})[0], indent=4, default=str)
|
||||
return Response(content=json_str, media_type='application/json')
|
||||
@@ -0,0 +1,27 @@
|
||||
from DB import UseDB
|
||||
|
||||
|
||||
def recalculation_events_func(difficulty, well):
|
||||
difficulties = {
|
||||
"Простая": [5, 5],
|
||||
"Средняя": [5, 2],
|
||||
"Сложная": [5, 1],
|
||||
"Проигрывать весело": [10, 1]
|
||||
}
|
||||
db = UseDB("events")
|
||||
not_well_events = db.find_document({"well": False})
|
||||
well_events = db.find_document({"well": True})
|
||||
if well:
|
||||
for i in not_well_events:
|
||||
db.update_document({"_id": i["_id"]},
|
||||
{"probability": i["probability"] + difficulties[difficulty][0]})
|
||||
ratio = len(not_well_events) * difficulties[difficulty][0] / len(well_events)
|
||||
for i in well_events:
|
||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
||||
else:
|
||||
for i in well_events:
|
||||
db.update_document({"_id": i["_id"]},
|
||||
{"probability": i["probability"] + difficulties[difficulty][1]})
|
||||
ratio = len(well_events) * difficulties[difficulty][1] / len(not_well_events)
|
||||
for i in not_well_events:
|
||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
||||
Reference in New Issue
Block a user