-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
74 lines (57 loc) · 1.9 KB
/
app.py
File metadata and controls
74 lines (57 loc) · 1.9 KB
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
from flask import Flask
import schedule
import time
import threading
from upload import *
from recieve import retrieveAndConvertData
from processes import *
from upload import upload_fft_data
from detect import isGearFaulty
import httpx
app = Flask(__name__)
@app.route('/')
def home():
return 'Flask Server'
def fftComb(x,y,z,tx,ty,tz):
print("fft")
xfft = fft(x, 1000)
yfft = fft(y, 1000)
zfft = fft(z, 1000)
print("faulty")
faulty = isGearFaulty(x, y, z, xfft, yfft, zfft,tx,ty,tz)
upload_fft_data(xfft, yfft, zfft)
print(faulty)
uploadFaulty(faulty,1)
def upload_data():
retry_limit = 3 # Maximum number of retry attempts
retry_count = 0 # Current retry attempt count
while retry_count < retry_limit:
try:
# Call the uploadTestData() function here
uploadTestData(True)
x, y, z, id = retrieveAndConvertData()
print('Retrieved')
tx,ty,tz = upload_tsa_data(x, y, z)
fftComb(x, y, z,tx,ty,tz)
print("rest")
break # Break the loop if the code runs successfully
except httpx.WriteTimeout:
retry_count += 1
print(f"Retry attempt {retry_count} of {retry_limit} due to httpx.WriteTimeout")
except Exception as e:
print(f"An error occurred: {str(e)}")
break # Break the loop if an unexpected error occurs
if retry_count == retry_limit:
print(f"Maximum retry attempts reached. Failed to execute the function.")
schedule.every(10).seconds.do(upload_data)
# Create a separate thread to run the scheduled tasks
def run_scheduler():
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
# Start the scheduler thread
scheduler_thread = threading.Thread(target=run_scheduler)
scheduler_thread.start()
# Run the Flask server
app.run()