forked from hamer1818/socket-numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_handlers.py
77 lines (57 loc) · 1.9 KB
/
socket_handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from fastapi import FastAPI
from fastapi_socketio import SocketManager
from fastapi.middleware.cors import CORSMiddleware
import numpy as np
# terminalin arkaplan renkerlini ayarlayan ANSI kodları
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
app = FastAPI()
sio = SocketManager(app=app)
yukseltme2Sayi = 0
yukseltme1Sayi = 0
@app.get("/")
async def main():
return {"message": "Hello World"}
@app.sio.on('join')
async def handle_join(sid, *args, **kwargs):
print("Bağlantı gerçekleşti...")
await sio.emit('lobby', 'User joined')
@sio.on('2x2determinant')
async def test(sid,*args, **kwargs):
sayılar = args[0]
print(sayılar)
print (np.linalg.det(sayılar).round(2))
await sio.emit('2x2determinant', np.linalg.det(sayılar).round(2))
@sio.on('3x3determinant')
async def test(sid,*args, **kwargs):
sayılar = args[0]
print(sayılar)
print (np.linalg.det(sayılar).round(2))
await sio.emit('3x3determinant', np.linalg.det(sayılar).round(2))
@sio.on('4x4determinant')
async def test(sid,*args, **kwargs):
sayılar = args[0]
print(sayılar)
print (np.linalg.det(sayılar).round(2))
await sio.emit('4x4determinant', np.linalg.det(sayılar).round(2))
@sio.on('random')
async def test(sid,*args, **kwargs):
print("gelen sayı: ", args[0])
randomSayi = np.random.randint(1,args[0])
print(randomSayi)
await sio.emit('random', randomSayi)
if __name__ == '__main__':
import logging
import sys
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
import uvicorn
uvicorn.run("socket_handlers:app", host='127.0.0.1', port=8081, reload=True)