-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.py
More file actions
140 lines (100 loc) · 4.14 KB
/
upload.py
File metadata and controls
140 lines (100 loc) · 4.14 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import httpx
import json
import numpy as np
import matplotlib.pyplot as plt
import matlab.engine
import scipy.io
import json
import os
from supabase import create_client, Client
import math
import random
from processes import *
def simulate(input):
eng = matlab.engine.start_matlab()
faulty, noFaulty = eng.simulate(nargout=2)
if input:
return np.asarray(faulty[0])
else:
return np.asarray(noFaulty[0])
def uploadTestData(faulty):
accelerometer_data = []
n = 0
# Simulate x-axis data
x_data = simulate(faulty).tolist()[0]
print(len(x_data))
# Simulate y-axis data
y_data = simulate(faulty).tolist()[0]
for i in range(len(x_data)):
# Calculate time for the current reading
# Calculate the rotation angle for the current time
# Calculate acceleration values based on the rotation angle
x = x_data[i]
y = y_data[i]
z = random.uniform(0.0, 2.0)
# Create a reading dictionary
reading = {
'pos': n,
'x': x,
'y': y,
'z': z
}
# Append the reading to the data list
accelerometer_data.append(reading)
n += 1
# Convert accelerometer data to JSON format
json_data = json.dumps(accelerometer_data)
# Upload data to Supabase
url = "https://ljzrkwoyewivcfhthral.supabase.co"
key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxqenJrd295ZXdpdmNmaHRocmFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA1NzU3NzcsImV4cCI6MjAxNjE1MTc3N30.bSMt5zZF012w-YVjnLTKJO0yAeMonr7VgserYfadoPM"
supabase = create_client(url, key)
data, count = supabase.table('Raw').insert({
"measurement": json_data,
"average_temperature": str(random.randint(25, 42)),
"sampling_frequency": "1000"
}).execute()
return data, count
def upload_fft_data(x_values, y_values, z_values):
# Create a dictionary to store the FFT result
fft_json = {
'x': x_values,
'y': y_values,
'z': z_values
}
json_string = json.dumps(fft_json)
url = "https://ljzrkwoyewivcfhthral.supabase.co"
key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxqenJrd295ZXdpdmNmaHRocmFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA1NzU3NzcsImV4cCI6MjAxNjE1MTc3N30.bSMt5zZF012w-YVjnLTKJO0yAeMonr7VgserYfadoPM"
supabase = create_client(url, key)
data, count = supabase.table('FFT').insert({"measurement": json_string}).execute()
if count == 1:
print("FFT data uploaded successfully.")
else:
print("Error uploading FFT data.")
def uploadFaulty(faulty,id):
url = "https://ljzrkwoyewivcfhthral.supabase.co"
key= "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxqenJrd295ZXdpdmNmaHRocmFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA1NzU3NzcsImV4cCI6MjAxNjE1MTc3N30.bSMt5zZF012w-YVjnLTKJO0yAeMonr7VgserYfadoPM"
supabase = create_client(url, key)
data, count = supabase.table('detection').insert({'id':id, "faulty": faulty}).execute()
def upload_tsa_data(x_values, y_values, z_values):
# Create an instance of the Processes class
# Run the TSA process for each axis
tsa_result_x = TSA(x_values, 1000.0, 13.0, 35.0, 22.5)
tsa_result_y = TSA(y_values, 1000.0, 13.0, 35.0, 22.5)
tsa_result_z = TSA(z_values, 1000.0, 13.0, 35.0, 22.5)
# Convert the TSA results to JSON
tsa_json = {
'x': JSONconvert(tsa_result_x),
'y': JSONconvert(tsa_result_y),
'z': JSONconvert(tsa_result_z)
}
json_string = json.dumps(tsa_json)
url = "https://ljzrkwoyewivcfhthral.supabase.co"
key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImxqenJrd295ZXdpdmNmaHRocmFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA1NzU3NzcsImV4cCI6MjAxNjE1MTc3N30.bSMt5zZF012w-YVjnLTKJO0yAeMonr7VgserYfadoPM"
supabase = create_client(url, key)
data, count = supabase.table('TSA').insert({"measurement": json_string}).execute()
if count == 1:
print("TSA data uploaded successfully.")
else:
print("Error uploading TSA data.")
return tsa_result_x, tsa_result_y, tsa_result_z
# Example usage: