Uploaded by Ram Arunachalam

data visualization code

advertisement
import plotly.graph_objects as go
from pymongo import MongoClient
# Connect to MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['your_database']
collection = db['your_collection']
# Retrieve data from MongoDB
data = collection.find({}, {'timestamp': 1, 'hard_acceleration_count': 1, 'driver_score': 1})
timestamps = []
acceleration_counts = []
driver_scores = []
for document in data:
timestamps.append(document['timestamp'])
acceleration_counts.append(document['hard_acceleration_count'])
driver_scores.append(document['driver_score'])
# Create visualization using Plotly
fig = go.Figure()
fig.add_trace(go.Scatter(x=timestamps, y=acceleration_counts, name='Hard Acceleration Count'))
fig.add_trace(go.Scatter(x=timestamps, y=driver_scores, name='Driver Score'))
fig.update_layout(title='Real-time Data Visualization',
xaxis_title='Timestamp',
yaxis_title='Count/Score')
fig.show()
Download