File size: 13,094 Bytes
8848efa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import streamlit as st
from gsheet_loader import get_data
import pandas as pd
import plotly.express as px
import plotly.figure_factory as ff
import plotly.graph_objects as go
import datetime as dt

st.set_page_config(
    page_title="Catalog Data Dashboard",
    layout="wide",
    page_icon="πŸ“Š",
)

st.title("πŸ“Š Catalog Data Dashboard")
st.markdown(
    """

    This dashboard combines live [Google Sheets data](https://docs.google.com/spreadsheets/d/10nGgqXxunGXo_GI1LxybvsAr1TYSDdNiqqZX6DSTbDA) for:

    - catalog onboarding  

    - metadata completeness  

    - mapping/scraping status  

    """
)

cat_onboarding_df, cat_metadata_df, cat_status_df = get_data()

tab0, tab1, tab2, tab3, tab4 = st.tabs(["Overview", "Static Data", "Onboarding Status", "Metadata Completeness", "Mapping Status"])

# =========================================================================================================================
# Tab 0 - Overview
# =========================================================================================================================

with tab0:
    st.header("Overiew")
    if st.button("πŸ”„ Refresh Data"):
        st.cache_data.clear()
        st.toast("Refreshing data...", icon="πŸ”„")
        st.rerun()

    st.markdown("---")
    st.subheader("Quick Data Preview")

    col1, col2, col3 = st.columns(3)
    with col1:
        st.dataframe(cat_onboarding_df.head(5))
    with col2:
        st.dataframe(cat_metadata_df.head(5))
    with col3:
        st.dataframe(cat_status_df.head(5))

# =========================================================================================================================
# Tab 0 - Static stuff
# =========================================================================================================================

with tab1:
    st.header("Static Data Preview")

    full_countries_df = pd.read_csv('countries.csv')
    full_languages_df = pd.read_csv('languages.csv')

    # countries map 
    fig = px.choropleth(
    full_countries_df,
    locations="country_name",
    locationmode="country names",
    color="log_count",
    color_continuous_scale="Purples",
    hover_name="country_name",
    hover_data={"count": True, "log_count": False},
    projection="natural earth",
    title="Programs' availabilities by Country (Log Scale)"
    )

    fig.update_geos(showcountries=True, showcoastlines=True, showland=True, landcolor="white", projection_type="natural earth")
    fig.update_layout(
        width=1400,
        height=700,
        margin=dict(l=0, r=0, t=100, b=0),
        title_y=0.95
    )

    st.plotly_chart(fig, use_container_width=True)

    # languages map
    fig1 = px.choropleth(
    full_languages_df,
    locations="country_name",
    locationmode="country names",
    color="log_count",
    color_continuous_scale="Purples",
    hover_name="country_name",
    hover_data={"count": True, "log_count": False},
    projection="natural earth",
    title="Programs by Languages (Log Scale)"
    )

    fig1.update_geos(showcountries=True, showcoastlines=True, showland=True, landcolor="white", projection_type="natural earth")
    fig1.update_layout(
        width=1400,
        height=700,
        margin=dict(l=0, r=0, t=100, b=0),
        title_y=0.95
    )

    st.plotly_chart(fig1, use_container_width=True)


    # Completeness evaluation
    catalog_scores = pd.read_csv("catalog_scores.csv")
    colorscale = [
    [0.0,  "#ffffff"],
    [0.1,  "#dcd6f7"],
    [0.3,  "#a29bfe"],
    [0.6,  "#6c5ce7"],
    [1.0,  "#341f97"]
    ]

    fig_completeness = px.bar(
        catalog_scores,
        x="Total",
        y="Catalog",
        orientation="h",
        color="Total",
        color_continuous_scale=colorscale,
        title="Catalog Metadata Completeness Score",
    )
    fig_completeness.update_layout(yaxis={'categoryorder':'total ascending'}, template="plotly_dark", height=1000)
    st.plotly_chart(fig_completeness, use_container_width=True)


    # ### completeness score broken down
    subcols = ["movie", "show", "season", "episode", "sport"]

    # Compute sum of raw subscores
    catalog_scores["raw_sum"] = catalog_scores[subcols].sum(axis=1)

    # Build the figure
    fig_completeness2 = go.Figure()

    for col in subcols:

        # normalized height of this bar segment
        norm_vals = (catalog_scores[col] / catalog_scores["raw_sum"]) * catalog_scores["Total"]

        fig_completeness2.add_trace(
            go.Bar(
                y=catalog_scores["Catalog"],
                x=norm_vals,                  # BAR SIZE = normalized values
                name=col.capitalize(),
                orientation="h",
                customdata=catalog_scores[col],    # RAW values for hover
                hovertemplate=(
                    "<b>%{y}</b><br>" +
                    f"{col.capitalize()}: <b>%{{customdata}}</b><br>" +   # RAW value
                    "Normalized: %{x:.2f}<extra></extra>"
                )
            )
        )

    fig_completeness2.update_layout(
        barmode="stack",
        title="Subscore Contribution per Catalog (Scaled to Total Score)",
        xaxis_title="Total Score",
        template="plotly_dark",
        height=1200,
        yaxis={'categoryorder':'total ascending'}
    )

    st.plotly_chart(fig_completeness2, use_container_width=True)


    #scatter plot
    fig_scatter = px.scatter(
    catalog_scores,
    x="Total",
    y="Number of programs",
    size="Number of programs",
    color="Total",
    hover_name="Catalog",
    color_continuous_scale="Viridis",
    size_max=50
    )

    st.plotly_chart(fig_scatter, use_container_width=True)



# =========================================================================================================================
# Tab 2 - Onboarding sheet
# =========================================================================================================================

with tab2:
    st.header("Catalog Onboarding Status")

        # Convert onboarding date to datetime (e.g., 21/11 β†’ 2025-11-21)
    cat_onboarding_df["Onboarding date"] = pd.to_datetime(
        cat_onboarding_df["Onboarding date"], format="%d/%m", errors="coerce"
    )
    cat_onboarding_df["Onboarding date"] = cat_onboarding_df["Onboarding date"].apply(
        lambda d: d.replace(year=2025) if pd.notna(d) else d
    )

    # Map textual months to end-of-month dates
    month_map = {
        "November 2025": dt.datetime(2025, 11, 30),
        "December 2025": dt.datetime(2025, 12, 31),
        "January 2026": dt.datetime(2026, 1, 31),
        "February 2026": dt.datetime(2026, 2, 28),
        "March 2026": dt.datetime(2026, 3, 31),
        "April 2026": dt.datetime(2026, 4, 30),
        "TBD": None,
    }
    cat_onboarding_df["Go live parsed"] = cat_onboarding_df["Go live (customer)"].map(month_map)

    # Drop missing
    timeline_df = cat_onboarding_df.dropna(subset=["Onboarding date", "Go live parsed"])

    fig_timeline = px.timeline(
    timeline_df,
    x_start="Onboarding date",
    x_end="Go live parsed",
    y="NAME",
    color="Onboarding Status",
    hover_data=["Client", "Priority"],
    title="Onboarding β†’ Go-Live Timeline",
    )
    fig_timeline.update_yaxes(autorange="reversed")

    st.plotly_chart(fig_timeline, use_container_width=True)

    # bar chart 1
    summary = (
    cat_onboarding_df.groupby(["Client", "Onboarding Status"])
    .size()
    .reset_index(name="Count")
    )

    fig_client = px.bar(
        summary,
        x="Client",
        y="Count",
        color="Onboarding Status",
        text_auto=True,
        title="Catalogs per Client (by Onboarding Status)",
    )
    fig_client.update_layout(barmode="stack", xaxis_title="Client", yaxis_title="Catalog Count")

    st.plotly_chart(fig_client, use_container_width=True)

    # bar chart 2
    summary = (
    cat_onboarding_df.groupby(["Client", "Priority"])
    .size()
    .reset_index(name="Count")
    )

    fig_client1 = px.bar(
        summary,
        x="Client",
        y="Count",
        color="Priority",
        text_auto=True,
        title="Catalogs per Client (by Priority)",
    )
    fig_client1.update_layout(barmode="stack", xaxis_title="Client", yaxis_title="Catalog Count")

    st.plotly_chart(fig_client1, use_container_width=True)

    # bar chart 3

    summary = (
    cat_onboarding_df.groupby(["Onboarding Status", "Priority"])
    .size()
    .reset_index(name="Count")
    )

    fig_client2 = px.bar(
        summary,
        x="Onboarding Status",
        y="Count",
        color="Priority",
        text_auto=True,
        title="Catalogs per Onboarding Status (by Priority)",
    )
    fig_client2.update_layout(barmode="stack", xaxis_title="Onboarding Status", yaxis_title="Catalog Count")

    st.plotly_chart(fig_client2, use_container_width=True)

# =========================================================================================================================
# Tab 3 - Metadata completeness
# =========================================================================================================================

with tab3:
    st.header("Catalog Metadata Completeness")

    cat_df = cat_metadata_df.copy()
    meta_cols = [col for col in cat_df.columns if col not in ["Catalog name"]]

    score_map = {"Yes": 1.0, "Some": 0.5, "No": 0.0, "None": 0.0, "": 0.0}

    cat_df_numeric = cat_df.copy()
    cat_df_numeric[meta_cols] = cat_df_numeric[meta_cols].replace(score_map)

    # force conversion to numeric (anything else becomes NaN)
    cat_df_numeric[meta_cols] = cat_df_numeric[meta_cols].apply(pd.to_numeric, errors="coerce")

    cat_df_numeric["Completeness Score"] = cat_df_numeric[meta_cols].mean(axis=1)
    cat_df_numeric_sorted = cat_df_numeric.sort_values("Completeness Score", ascending=False)

    #graph 1
    fig_completeness = px.bar(
    cat_df_numeric_sorted,
    x="Completeness Score",
    y="Catalog name",
    orientation="h",
    color="Completeness Score",
    color_continuous_scale="Greens",
    title="Catalog Metadata Completeness Score",
    )
    fig_completeness.update_layout(yaxis={'categoryorder':'total ascending'})

    st.plotly_chart(fig_completeness, use_container_width=True)

    # graph 2
    coverage = cat_df_numeric[meta_cols].mean().sort_values(ascending=False).reset_index()
    coverage.columns = ["Metadata Field", "Average Score"]

    fig_field_coverage = px.bar(
        coverage,
        x="Average Score",
        y="Metadata Field",
        orientation="h",
        color="Average Score",
        color_continuous_scale="Blues",
        title="Metadata Field Coverage Across All Catalogs",
    )
    fig_field_coverage.update_layout(yaxis={'categoryorder':'total ascending'})

    st.plotly_chart(fig_field_coverage, use_container_width=True)

    # heatmap 1
        # Prepare data
    z = cat_df_numeric[meta_cols].astype(float).to_numpy()
    x = list(meta_cols)
    y = list(cat_df_numeric["Catalog name"].astype(str))

    # Build the heatmap (no annotation_text)
    fig_heatmap = ff.create_annotated_heatmap(
        z=z,
        x=x,
        y=y,
        showscale=True,
        colorscale=[
            [0.0, "rgb(255,77,77)"],     # red for 0 (No)
            [0.5, "rgb(255,204,0)"],     # yellow for 0.5 (Some)
            [1.0, "rgb(0,204,102)"]      # green for 1 (Yes)
        ],
        annotation_text=None   # removes numbers
    )

    # Layout adjustments
    fig_heatmap.update_layout(
        title="Metadata Completeness Heatmap (Catalog vs Field)",
        xaxis_title="Metadata Field",
        yaxis_title="Catalog Name",
        width=1600,   # make it wide
        height=1000,  # make it tall so names fit
        margin=dict(l=200, r=50, t=80, b=150),  # spacing for labels
    )

    # Tweak label angles for readability
    fig_heatmap.update_xaxes(tickangle=-45)
    fig_heatmap.update_yaxes(automargin=True)

    st.plotly_chart(fig_heatmap, use_container_width=True)


    # heatmap 2

    fig_heatmap1 = px.imshow(
    cat_df_numeric[meta_cols],
    labels=dict(x="Metadata Field", y="Catalog Name", color="Completeness"),
    x=meta_cols,
    y=cat_df_numeric["Catalog name"],
    color_continuous_scale=[
        [0.0, "rgb(255,77,77)"],
        [0.5, "rgb(255,204,0)"],
        [1.0, "rgb(0,204,102)"]
    ],
    )

    fig_heatmap1.update_layout(
        title="Metadata Completeness Heatmap (Catalog vs Field)",
        width=1600,
        height=1000,
        margin=dict(l=200, r=50, t=80, b=150),
    )
    fig_heatmap1.update_xaxes(tickangle=-45)

    st.plotly_chart(fig_heatmap1, use_container_width=True)



with tab4:
    st.header("Catalog Mapping status")