-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemperature_plot.py
More file actions
81 lines (63 loc) · 2.19 KB
/
Copy pathtemperature_plot.py
File metadata and controls
81 lines (63 loc) · 2.19 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
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime
def parse_temperature_log(file_path):
# Lists to store the data
timestamps = []
temperatures = []
# Read the file line by line
with open(file_path, 'r') as file:
for line in file:
# Skip empty lines
if not line.strip():
continue
try:
# Split the line into timestamp and temperature
timestamp_str, temp_str = line.strip().split()
# Parse timestamp
timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d_%H:%M:%S')
# Parse temperature (remove 'temp=' and '\'C')
temperature = float(temp_str.split('=')[1].replace('\'C', ''))
timestamps.append(timestamp)
temperatures.append(temperature)
except (ValueError, IndexError) as e:
print(f"Skipping invalid line: {line.strip()}")
continue
# Create a DataFrame
df = pd.DataFrame({
'timestamp': timestamps,
'temperature': temperatures
})
return df
def create_interactive_plot(df):
# Create the figure
fig = go.Figure()
# Add the temperature trace
fig.add_trace(go.Scatter(
x=df['timestamp'],
y=df['temperature'],
mode='lines',
name='Temperature',
line=dict(color='red', width=2)
))
# Update layout
fig.update_layout(
title='Temperature Over Time',
xaxis_title='Date and Time',
yaxis_title='Temperature (°C)',
hovermode='x unified',
showlegend=True
)
# Configure zoom and pan options without range slider
fig.update_xaxes(rangeslider_visible=False)
# Show the plot
fig.show()
def main():
# Replace with your file path
file_path = '/home/chmamai/Documents/proxyconf/temperature.log'
# Parse the data
df = parse_temperature_log(file_path)
# Create and display the interactive plot
create_interactive_plot(df)
if __name__ == "__main__":
main()