readme and fixed length/size

This commit is contained in:
randonauts-llc 2020-09-17 21:02:14 +02:00
parent 5fa44c5278
commit 8e76ded4a3
2 changed files with 27 additions and 75 deletions

View file

@ -18,70 +18,23 @@ Usage Example
### REST API ### REST API
http://localhost:62456/api/randint32 http://localhost:62456/api/randint32?length=3
< -1741405968 < {"type": "string", "format": "int32", "length": 3, "data": [1524492492, -1194151004, 1365408501], "success": "true"}
http://localhost:62456/api/randuniform http://localhost:62456/api/randuniform?length=2
< 0.20340009994 < {"type": "string", "format": "uniform", "length": 2, "data": [0.07230273403292031, 0.733570206706375], "success": "true"}
http://localhost:62456/api/randnormal http://localhost:62456/api/randnormal?length=1
< 1.02206840644 < {"type": "string", "format": "normal", "length": 1, "data": [0.6430985466029758], "success": "true"}
http://localhost:62456/api/randbytes?length=16 http://localhost:62456/api/randhex?length=2&size=5
< <20><><EFBFBD>E<EFBFBD><45>s_<73>b<EFBFBD><62><EFBFBD><EFBFBD>G<EFBFBD> < {"type": "string", "format": "hex", "length": 2, "size": 5, "data": ["b90e1b01bc", "b59374fc0e"], "success": "true"}
### WebSocket API
ws://localhost:62456/ws
> RANDINT32
< 585865374
> RANDUNIFORM
< 0.70137183786
> RANDNORMAL
< -1.6120135370
> RANDBYTES 32
< <20><><EFBFBD><EFBFBD><EFBFBD>9L).<2E>!:<3A><><EFBFBD>@Nh<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>d<EFBFBD><EFBFBD><EFBFBD><EFBFBD>_q<EFBFBD>
> SUBSCRIBEINT32
< 1361330636
< -604581511
< 1510923919
< ...
> UNSUBSCRIBE
< UNSUBSCRIBED
> SUBSCRIBEUNIFORM
< 0.54623951886
< 0.67567578799
< 0.09746421443
< ...
> UNSUBSCRIBE
< UNSUBSCRIBED
> SUBSCRIBENORMAL
< -1.6120135370
< 0.02943381135
< -0.9883458007
< ...
> UNSUBSCRIBE
< UNSUBSCRIBED
> SUBSCRIBEBYTES 8
< <20>K<EFBFBD><4B><EFBFBD><EFBFBD>{<7B>
< I]<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
< <20><><EFBFBD>.<2E>t<EFBFBD>U
< ...
> UNSUBSCRIBE
< UNSUBSCRIBED
License License
------- -------
Copyright (c) 2020 Andika Wasisto Copyright (c) 2020 Andika Wasisto
Modified by Tobias Raayoni Last / Randonauts Co.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -31,7 +31,6 @@ from geventwebsocket.handler import WebSocketHandler
from quanttp.data.qng_wrapper_linux import QngWrapperLinux from quanttp.data.qng_wrapper_linux import QngWrapperLinux
from quanttp.data.qng_wrapper_windows import QngWrapperWindows from quanttp.data.qng_wrapper_windows import QngWrapperWindows
app = Flask(__name__) app = Flask(__name__)
sockets = Sockets(app) sockets = Sockets(app)
@ -40,39 +39,39 @@ qng_wrapper = QngWrapperWindows() if (os.name == 'nt') else QngWrapperLinux()
@app.route('/api/randint32') @app.route('/api/randint32')
def randint32(): def randint32():
try: try:
size = int(request.args.get('size')) length = int(request.args.get('length'))
if size < 1: if length < 1:
return Response('size must be greater than 0', status=400, content_type='text/plain') return Response('length must be greater than 0', status=400, content_type='text/plain')
int32array = [] int32array = []
for x in range(0, size): for x in range(0, length):
int32array.append(qng_wrapper.randint32()) int32array.append(qng_wrapper.randint32())
return Response(json.dumps({"type": "string", "format": "int32", "length":1, "data": int32array, "success": "true"}), content_type='text/plain') return Response(json.dumps({"type": "string", "format": "int32", "length":length, "data": int32array, "success": "true"}), content_type='text/plain')
except (TypeError, ValueError) as e: except (TypeError, ValueError) as e:
return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain')
@app.route('/api/randuniform') @app.route('/api/randuniform')
def randuniform(): def randuniform():
try: try:
size = int(request.args.get('size')) length = int(request.args.get('length'))
if size < 1: if length < 1:
return Response('size must be greater than 0', status=400, content_type='text/plain') return Response('length must be greater than 0', status=400, content_type='text/plain')
uniformarray = [] uniformarray = []
for x in range(0, size): for x in range(0, length):
uniformarray.append(qng_wrapper.randuniform()) uniformarray.append(qng_wrapper.randuniform())
return Response(json.dumps({"type": "string", "format": "uniform", "length":1, "data": uniformarray, "success": "true"}), content_type='text/plain') return Response(json.dumps({"type": "string", "format": "uniform", "length":length, "data": uniformarray, "success": "true"}), content_type='text/plain')
except (TypeError, ValueError) as e: except (TypeError, ValueError) as e:
return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain')
@app.route('/api/randnormal') @app.route('/api/randnormal')
def randnormal(): def randnormal():
try: try:
size = int(request.args.get('size')) length = int(request.args.get('length'))
if size < 1: if length < 1:
return Response('size must be greater than 0', status=400, content_type='text/plain') return Response('length must be greater than 0', status=400, content_type='text/plain')
normarray = [] normarray = []
for x in range(0, size): for x in range(0, length):
normarray.append(qng_wrapper.randnormal()) normarray.append(qng_wrapper.randnormal())
return Response(json.dumps({"type": "string", "format": "normal", "length":1, "data": normarray, "success": "true"}), content_type='text/plain') return Response(json.dumps({"type": "string", "format": "normal", "length":length, "data": normarray, "success": "true"}), content_type='text/plain')
except (TypeError, ValueError) as e: except (TypeError, ValueError) as e:
return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain')
@ -86,9 +85,9 @@ def randhex():
if size < 1: if size < 1:
return Response('size must be greater than 0', status=400, content_type='text/plain') return Response('size must be greater than 0', status=400, content_type='text/plain')
hexarray = [] hexarray = []
for x in range(0, size): for x in range(0, length):
hexarray.append(qng_wrapper.randbytes(length).hex()) hexarray.append(qng_wrapper.randbytes(size).hex())
return Response(json.dumps({"type": "string", "format": "hex", "length":1, "size": length, "data": hexarray, "success": "true"}), content_type='text/plain') return Response(json.dumps({"type": "string", "format": "hex", "length":length, "size": size, "data": hexarray, "success": "true"}), content_type='text/plain')
except (TypeError, ValueError) as e: except (TypeError, ValueError) as e:
return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain') return Response(json.dumps({"error": str(e), "success":"false"}), status=400, content_type='text/plain')