arcan3 commited on
Commit
27ebbbd
·
1 Parent(s): 7cd7e7f

adding the corrected animation with proper passing of upsampling window value

Browse files
Files changed (3) hide show
  1. app.py +13 -10
  2. funcs/convertors.py +3 -3
  3. funcs/processor.py +2 -3
app.py CHANGED
@@ -178,7 +178,10 @@ def scores_to_dataframe(scores, start_time='2022-07-01 09:15:00+05:30', start_sc
178
  return df
179
 
180
  def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_slider, reducer=reducer10d, cluster=cluster_som):
181
- processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box = process_data(csv_file_box, slice_size_slider, sample_rate, window_size_slider)
 
 
 
182
  print('finished processing')
183
  try:
184
  if json_file_box is None:
@@ -225,15 +228,15 @@ def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_sli
225
  csv_writer.writerow(header)
226
  csv_writer.writerows(processed_data)
227
 
228
- # os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output animation.mp4')
229
- #with hhtp requests
230
- url = "https://metric-space.ngrok.io/generate"
231
- file = {'csv_file': open('animation_table.csv', 'rb')}
232
- response = requests.post(url, files=file)
233
-
234
- # The response will contain the binary data of the MP4 file. You can write it to a file like this:
235
- with open('animation.mp4', 'wb') as f:
236
- f.write(response.content)
237
 
238
  # prediction = cluster_som.predict(embedding10d)
239
  som_video = cluster.plot_activation(embedding10d)
 
178
  return df
179
 
180
  def get_som_mp4_v2(csv_file_box, slice_size_slider, sample_rate, window_size_slider, reducer=reducer10d, cluster=cluster_som):
181
+ processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice, slice_json_box = process_data(csv_file_box,
182
+ slice_size_slider,
183
+ sample_rate,
184
+ window_size_slider)
185
  print('finished processing')
186
  try:
187
  if json_file_box is None:
 
228
  csv_writer.writerow(header)
229
  csv_writer.writerows(processed_data)
230
 
231
+ os.system('curl -X POST -F "csv_file=@animation_table.csv" https://metric-space.ngrok.io/generate --output animation.mp4')
232
+ # #with hhtp requests
233
+ # url = "https://metric-space.ngrok.io/generate"
234
+ # file = {'csv_file': open('animation_table.csv', 'rb')}
235
+ # response = requests.post(url, files=file)
236
+
237
+ # # The response will contain the binary data of the MP4 file. You can write it to a file like this:
238
+ # with open('animation.mp4', 'wb') as f:
239
+ # f.write(response.content)
240
 
241
  # prediction = cluster_som.predict(embedding10d)
242
  som_video = cluster.plot_activation(embedding10d)
funcs/convertors.py CHANGED
@@ -11,9 +11,9 @@ import numpy as np
11
  import pandas as pd
12
 
13
  def slice_csv_to_json(input_file, slice_size=64, min_slice_size=16, sample_rate=20, window_size=20, debug=False):
14
- data = pd.read_csv(input_file, delimiter=";", index_col=0)
15
- original_data = data.copy()
16
- data = fill_missing_values(data, window_size=10)
17
  data.fillna(0, inplace=True)
18
 
19
  gz_columns = [col for col in data.columns if col.startswith("GZ")]
 
11
  import pandas as pd
12
 
13
  def slice_csv_to_json(input_file, slice_size=64, min_slice_size=16, sample_rate=20, window_size=20, debug=False):
14
+ data = pd.read_csv(input_file, delimiter=";", index_col=0)
15
+ original_data = data.copy()
16
+ data = fill_missing_values(data, window_size=10)
17
  data.fillna(0, inplace=True)
18
 
19
  gz_columns = [col for col in data.columns if col.startswith("GZ")]
funcs/processor.py CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
5
  from funcs.convertors import slice_csv_to_json, slice_csv_to_json_v2
6
  from funcs.plot_func import plot_sensor_data_from_json
7
 
8
- def process_data(input_file, slice_size=64, min_slice_size=10, sample_rate=20, window_size=40, threshold=1000, span_limit=10000000):
9
  # Read the data from the file, including the CRC column
10
  try:
11
  if input_file.name is None:
@@ -16,7 +16,6 @@ def process_data(input_file, slice_size=64, min_slice_size=10, sample_rate=20, w
16
  return None, None, None, None, None, None, None, None, None
17
  data = pd.read_csv(input_file, delimiter=";", index_col="NR", usecols=["NR", "TS", "LEG", "GX", "GY", "GZ", "AX", "AY", "AZ", "CRC"])
18
 
19
-
20
  # Replace the values with NaN when the CRC value is not zero
21
  data.loc[data["CRC"] != 0, ["GX", "GY", "GZ", "AX", "AY", "AZ"]] = np.nan
22
 
@@ -77,7 +76,7 @@ def process_data(input_file, slice_size=64, min_slice_size=10, sample_rate=20, w
77
  file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
78
  # file, len_ = slice_csv_to_json_v2('output.csv', slice_size, min_slice_size, sample_rate)
79
  # get the plot automatically
80
- sensor_fig, slice_fig, get_all_slice, slice_json, overlay_fig = plot_sensor_data_from_json(file, "GZ1")
81
  # overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"])
82
 
83
  return 'output.csv', file, f'num of slices found: {len_}', sensor_fig, overlay_fig, gr.Slider.update(interactive=True, maximum=len_, minimum=1, value=1), slice_fig, get_all_slice, slice_json
 
5
  from funcs.convertors import slice_csv_to_json, slice_csv_to_json_v2
6
  from funcs.plot_func import plot_sensor_data_from_json
7
 
8
+ def process_data(input_file, slice_size=64, sample_rate=20, window_size=40, min_slice_size=10, threshold=1000, span_limit=10000000):
9
  # Read the data from the file, including the CRC column
10
  try:
11
  if input_file.name is None:
 
16
  return None, None, None, None, None, None, None, None, None
17
  data = pd.read_csv(input_file, delimiter=";", index_col="NR", usecols=["NR", "TS", "LEG", "GX", "GY", "GZ", "AX", "AY", "AZ", "CRC"])
18
 
 
19
  # Replace the values with NaN when the CRC value is not zero
20
  data.loc[data["CRC"] != 0, ["GX", "GY", "GZ", "AX", "AY", "AZ"]] = np.nan
21
 
 
76
  file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
77
  # file, len_ = slice_csv_to_json_v2('output.csv', slice_size, min_slice_size, sample_rate)
78
  # get the plot automatically
79
+ sensor_fig, slice_fig, get_all_slice, slice_json, overlay_fig = plot_sensor_data_from_json(file, "GZ1") # with the csv file
80
  # overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"])
81
 
82
  return 'output.csv', file, f'num of slices found: {len_}', sensor_fig, overlay_fig, gr.Slider.update(interactive=True, maximum=len_, minimum=1, value=1), slice_fig, get_all_slice, slice_json