Skip to content

Commit 164a41d

Browse files
committed
chore: Remove commented code and unused imports in mapper-evaluation-single-pod.py and test.py
1 parent 7438fbb commit 164a41d

6 files changed

Lines changed: 493 additions & 27 deletions

File tree

mapper/e.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
4+
# Dummy data
5+
data_with_aggregator = {
6+
'seconds_to_monitor': [10, 20, 30],
7+
'stream_reader': [15, 25, 35],
8+
'stream_processor': [20, 30, 40]
9+
}
10+
11+
data_without_aggregator = {
12+
'seconds_to_monitor': [10, 20, 30],
13+
'stream_reader': [10, 20, 30],
14+
'stream_processor': [18, 28, 38]
15+
}
16+
17+
# Create DataFrames from dummy data
18+
df_with_aggregator = pd.DataFrame(data_with_aggregator)
19+
df_without_aggregator = pd.DataFrame(data_without_aggregator)
20+
21+
# Set the index to 'seconds_to_monitor' for plotting
22+
df_with_aggregator.set_index('seconds_to_monitor', inplace=True)
23+
df_without_aggregator.set_index('seconds_to_monitor', inplace=True)
24+
25+
# Plotting a stacked bar plot
26+
fig, ax = plt.subplots()
27+
28+
# Stacked bar plot for 'stream_reader' and 'stream_processor' for each seconds_to_monitor
29+
df_with_aggregator.plot(kind='bar', stacked=True, ax=ax, color=['blue', 'orange'], width=0.4, position=1.5)
30+
df_without_aggregator.plot(kind='bar', stacked=True, ax=ax, color=['green', 'red'], width=0.4, position=-0.5)
31+
32+
plt.xlabel('Seconds to Monitor')
33+
plt.ylabel('Latency')
34+
plt.title('Comparison of Latency with and without Aggregator')
35+
plt.legend(['Reader with Aggregator', 'Processor with Aggregator', 'Reader without Aggregator', 'Processor without Aggregator'])
36+
plt.xticks(rotation=45)
37+
plt.tight_layout()
38+
39+
# Show the plot
40+
plt.show()

mapper/mapper-evaluation-single-pod.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import logging
2-
import sys
31
from datetime import datetime
42
import pandas as pandas
53
import pytz
64

75
# configure logging
8-
logger = logging.getLogger(__name__)
9-
logger.setLevel(logging.DEBUG)
10-
handler = logging.StreamHandler(sys.stdout)
11-
handler.setLevel(logging.DEBUG)
12-
formatter = logging.Formatter(
13-
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
14-
handler.setFormatter(formatter)
15-
logger.addHandler(handler)
6+
# logger = logging.getLogger(__name__)
7+
# logger.setLevel(logging.DEBUG)
8+
# handler = logging.StreamHandler(sys.stdout)
9+
# handler.setLevel(logging.DEBUG)
10+
# formatter = logging.Formatter(
11+
# '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
12+
# handler.setFormatter(formatter)
13+
# logger.addHandler(handler)
1614

1715
# template definitions
1816
TEMPLATE_TIME_MS = '<TIME_MS>'
@@ -304,15 +302,21 @@ def remove_whitespace(given_str):
304302
return ' '.join(given_str.split())
305303

306304

307-
def map_feather(file, sensors_to_map):
305+
def map_feather(file, sensors_to_map, number_of_events, sample_rate):
306+
counter = 0
308307
file = pandas.read_feather(file)
309308
for sensor in sensors_to_map:
310309
df = file[file['Metric'] == sensor]
310+
df['Sampling-Timestamp'] = pandas.to_datetime(df['Timestamp'].astype(str))
311+
df.set_index('Sampling-Timestamp', inplace=True)
312+
df.index = pandas.to_datetime(df.index)
311313
for index in df.index:
312-
source = (df['Sensor'][index])
313-
metric = (df['Metric'][index])
314-
value = (df['Value'][index])
315-
timestamp = (df['Timestamp'][index])
314+
# df_resampled = df.resample(f'{sample_rate}S').first().reset_index()
315+
df_resampled = df
316+
source = (df_resampled['Sensor'][index])
317+
metric = (df_resampled['Metric'][index])
318+
value = (df_resampled['Value'][index])
319+
timestamp = (df_resampled['Timestamp'][index])
316320
timestamp_str = str(timestamp)
317321
hour = timestamp_str[0:2]
318322
minute = timestamp_str[3:5]
@@ -323,7 +327,6 @@ def map_feather(file, sensors_to_map):
323327
else:
324328
millisecond = timestamp_str[9:13] + 'Z'
325329

326-
327330
current_time = datetime.now()
328331
year = current_time.strftime("%Y")
329332
month = current_time.strftime("%m")
@@ -340,13 +343,18 @@ def map_feather(file, sensors_to_map):
340343
'value': value,
341344
'timestamp': time_value
342345
}
343-
result = annotate_event(event)
344-
345-
with open('/home/kush/Code/feather-RDF-mapper/data/rdfData/participant6.nt', 'a') as file:
346+
result = annotate_event(event)
347+
with open('/home/kush/Code/feather-RDF-mapper/data/rdfData/accelerometer/acc-x-2min.nt', 'a') as file:
346348
pass
347-
file.write('\n')
348-
file.write(result)
349+
counter = counter + 1
350+
if counter > number_of_events:
351+
break
352+
else:
353+
file.write('\n')
354+
file.write(result)
349355
if __name__ == '__main__':
350356
file = 'data/dataset_participant6.feather'
351-
sensors = ['wearable.bvp']
352-
map_feather(file= file, sensors_to_map= sensors)
357+
# sensors = ['wearable.bvp']
358+
# sensors = ['org.dyamand.types.health.SpO2']
359+
sensors = ['wearable.acceleration.x']
360+
map_feather(file= file, sensors_to_map= sensors, number_of_events= 120*32, sample_rate= 2)

mapper/read.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import pandas as pd
3+
4+
# Initialize an empty DataFrame to store the final results
5+
final_dataframe = pd.DataFrame()
6+
7+
# Define the folder path
8+
folder_path = '/home/kush/Dataset/protego_day/Protego_anom/'
9+
10+
# Iterate through each folder
11+
for foldername in os.listdir(folder_path):
12+
folder = os.path.join(folder_path, foldername)
13+
14+
# Check if it's a directory
15+
if os.path.isdir(folder):
16+
file_path = os.path.join(folder, 'data.feather')
17+
18+
# Check if the data.feather file exists
19+
if os.path.exists(file_path):
20+
# Read the feather file into a DataFrame
21+
df = pd.read_feather(file_path)
22+
print(df)
23+
24+
# Filter for 'org.dyamand.types.health.SpO2' in the 'Metric' column
25+
filtered_data = df[df['Metric'] == 'org.dyamand.types.health.SpO2']
26+
27+
# Append the filtered data to the final DataFrame
28+
final_dataframe = final_dataframe.concat(filtered_data)
29+
30+
# Display the final DataFrame
31+
print(final_dataframe)

0 commit comments

Comments
 (0)