how can i count how many hits the solve endpoint handles and responds to a second? I…
- User
how can i count how many hits the solve endpoint handles and responds to a second? I want it to live uptdate the window title aswell
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } return jsonify(data)
if name == "main": threads = 0
if len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads} ~ cps {"""sovles/second"""}\a\"") app.run(debug=False) - Assistant
To count the number of hits that the solve endpoint handles and responds to in a second, you can use the
timemodule to calculate the time elapsed between hits. Here's an updated version of your code with the required changes:import time hit_count = 0 @app.route('/api/solve', methods=['GET']) def solve_endpoint(): global hit_count # Increment hit count hit_count += 1 data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } return jsonify(data) def update_window_title(): global hit_count # Get hits per second hits_per_second = hit_count # Reset hit count hit_count = 0 # Update window title window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {hits_per_second}" system(f"echo \"\033]0;{window_title}\a\"") if __name__ == "__main__": threads = 0 if len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") exit() for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() # Start a background thread to update the window title every second threading.Timer(1.0, update_window_title).start() app.run(debug=False)In this updated code, I've added a
hit_countvariable that keeps track of the number of hits to the solve endpoint. Every time the endpoint is called, thehit_countis incremented by one. I've also added a new functionupdate_window_title()that calculates the hits per second (hits_per_second) based on the value ofhit_count. Theupdate_window_title()function is called every second in a separate background thread usingthreading.Timer().Please note that you'll need to import the necessary modules (
threadingandtime) at the beginning of your script. - User
did I do something wrong? it allways shows up as 0
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): global solve_count data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } solve_count+=1 return jsonify(data)
def update_cps(): global solve_count
window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {solve_count}" solve_count = 0 system(f"echo \"\033]0;{window_title}\a\"")if name == "main": global solve_count solve_count = 0 threads = 0
if len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") threading.Timer(1.0, update_cps).start() app.run(debug=False) - Assistant
I apologize for the oversight. There seems to be an issue with your code. The problem lies in the line
global solve_countwithin theif __name__ == "__main__"block. Since you are definingsolve_countoutside any function, you don't need to declare it as global.Here's the corrected version of your code:
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): global solve_count data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } solve_count += 1 return jsonify(data) def update_cps(): global solve_count window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {solve_count}" solve_count = 0 system(f"echo \"\033]0;{window_title}\a\"") if __name__ == "__main__": solve_count = 0 threads = 0 if len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") exit() for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") threading.Timer(1.0, update_cps).start() app.run(debug=False)By removing the
global solve_countdeclaration within theif __name__ == "__main__"block, thesolve_countvariable will retain its global scope defined in the previous line.Hopefully, this resolves the issue and allows you to count the number of hits correctly.
- User
it still shows up as 0 @app.route('/api/solve', methods=['GET']) def solve_endpoint(): global solve_count data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } solve_count+=1 return jsonify(data)
def update_cps(): global solve_count
window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {solve_count}" solve_count = 0 system(f"echo \"\033]0;{window_title}\a\"")if name == "main": solve_count = 0 threads = 0
if len(sys.argv) < 1: print("""Usage python3 api.py -t=8""") for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") threading.Timer(1.0, update_cps).start() app.run(debug=False) - Assistant
I apologize for the confusion. The issue lies in the line
if len(sys.argv) < 1:. The condition should be changed toif len(sys.argv) < 2:because the first argument in thesys.argvlist is the script name itself.Here's the corrected version of your code:
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): global solve_count data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } solve_count += 1 return jsonify(data) def update_cps(): global solve_count window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {solve_count}" solve_count = 0 system(f"echo \"\033]0;{window_title}\a\"") if __name__ == "__main__": solve_count = 0 threads = 0 if len(sys.argv) < 2: print("""Usage python3 api.py -t=8""") exit() for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") threading.Timer(1.0, update_cps).start() app.run(debug=False)Now, when you pass the
-t=option to the script, it should correctly start counting the hits and update the window title accordingly. - User
thats not the issue, its that it shows up as 0 cps in the title
- Assistant
I apologize for the confusion. The issue lies in the placement of the
solve_count = 0statement. Currently, it is being executed before theupdate_cpsfunction is called. To fix this, you need to move thesolve_count = 0statement inside theupdate_cpsfunction, after updating the window title.Here's the updated code with the necessary change:
@app.route('/api/solve', methods=['GET']) def solve_endpoint(): global solve_count data = request.get_json() out = solve(data.get('token'), data.get('user-agent')) data = { 'message': out[1], 'status': out[0], 'data': [ {'': ''} ] } solve_count += 1 return jsonify(data) def update_cps(): global solve_count window_title = f"Arkose labs solver ~ Threads: {threads} ~ cps {solve_count}" system(f"echo \"\033]0;{window_title}\a\"") solve_count = 0 if __name__ == "__main__": solve_count = 0 threads = 0 if len(sys.argv) < 2: print("""Usage python3 api.py -t=8""") exit() for i in range(1, len(sys.argv)): if sys.argv[i].startswith("-t="): threads = int(sys.argv[i].replace("-t=", "")) else: print("Invalid option:", sys.argv[i]) exit() if threads <= 0 or threads >= 1000: print(f"you cant run a python solver on {threads} threads") exit() system(f"echo \"\033]0;Arkose labs solver ~ Threads: {threads}\a\"") threading.Timer(1.0, update_cps).start() app.run(debug=False)By moving the
solve_count = 0statement inside theupdate_cpsfunction, it will reset thesolve_countto 0 after updating the window title. This should ensure that the CPS (solves per second) value is correctly displayed in the title.