import plotly.graph_objects as go
import plotly.io as pio

# Data from the provided JSON, but mapping to continuous days 1-7
# Original days: [1, 2, 27, 28, 29, 30, 31] → mapped to [1, 2, 3, 4, 5, 6, 7]
day_numbers_mapped = [1, 2, 3, 4, 5, 6, 7]
habit_yes_scores = [39.846154, 33.066667, 35.5, 36.333333, 37.083333, 33.833333, 36.285714]
habit_no_scores = [37.714286, 33.0, 32.5, 35.0, 36.25, 35.875, 36.666667]

# Create the figure
fig = go.Figure()

# Add line for Habit Performed: Yes (using green)
fig.add_trace(go.Scatter(
    x=day_numbers_mapped,
    y=habit_yes_scores,
    mode='lines+markers',
    name='Habit: Yes',
    line=dict(color='green'),
    marker=dict(color='green'),
    cliponaxis=False
))

# Add line for Habit Performed: No (using red)
fig.add_trace(go.Scatter(
    x=day_numbers_mapped,
    y=habit_no_scores,
    mode='lines+markers',
    name='Habit: No',
    line=dict(color='red'),
    marker=dict(color='red'),
    cliponaxis=False
))

# Update layout
fig.update_layout(
    title='RENSS Wellbeing Scores by Habit Performance Across Days',
    xaxis_title='Day Number',
    yaxis_title='RENSS Score',
    legend=dict(orientation='h', yanchor='bottom', y=1.05, xanchor='center', x=0.5)
)

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