import plotly.graph_objects as go
import plotly.express as px

# Data from the provided JSON
dates = ["2025-05-27", "2025-05-28", "2025-05-29", "2025-05-30", "2025-05-31", "2025-06-01", "2025-06-02"]
object_yes = [60.0, 73.333333, 61.111111, 60.0, 75.0, 73.333333, 68.75]
object_no = [100.0, 80.0, 50.0, 60.0, 50.0, 40.0, 100.0]

# Create the grouped bar chart
fig = go.Figure()

# Add bars for Object in Position: Yes
fig.add_trace(go.Bar(
    x=dates,
    y=object_yes,
    name='Object: Yes',
    marker_color='#1FB8CD',
    cliponaxis=False
))

# Add bars for Object in Position: No  
fig.add_trace(go.Bar(
    x=dates,
    y=object_no,
    name='Object: No',
    marker_color='#FFC185',
    cliponaxis=False
))

# Update layout
fig.update_layout(
    title='Habit Completion by Object Placement',
    xaxis_title='Date',
    yaxis_title='Completion %',
    barmode='group',
    legend=dict(orientation='h', yanchor='bottom', y=1.05, xanchor='center', x=0.5)
)

# Update y-axis to show 0-100% range
fig.update_yaxes(range=[0, 100])

# Save the chart
fig.write_image('habit_completion_chart.png')