Skip to content

tapmap.ui.daily_activity_report_view

tapmap.ui.daily_activity_report_view

Daily Activity Report view rendering for the TapMap UI.

HISTORY_WINDOW_DAYS = 30 module-attribute

MIN_APPENDIX_HISTORY_DAYS = 8 module-attribute

_MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, 'Courier New', monospace" module-attribute

DailyReportData

Bases: TypedDict

Aggregated data for the daily activity report.

Source code in src/tapmap/state/daily_report.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class DailyReportData(TypedDict):
    """Aggregated data for the daily activity report."""

    history_days: int
    intro_text: str
    today_text: str
    activity_pattern_text: str
    application_total: int
    application_counts: dict[str, int]
    recurrence_labels: dict[str, str]
    recurrence_examples: list[RecurrenceExample]
    applications_summary: str
    provider_concentration: ProviderConcentration
    providers_summary: str
    country_total: int
    countries_summary: str
    country_map_points: list[CountryMapPoint]

_build_applications_figure(application_counts)

Source code in src/tapmap/ui/daily_activity_report_view.py
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
def _build_applications_figure(
    application_counts: dict[str, int],
) -> go.Figure:
    categories = list(application_counts.keys())
    values = list(application_counts.values())

    fig = go.Figure(
        go.Bar(
            x=values,
            y=categories,
            orientation="h",
            marker_color="rgba(0,160,68,0.55)",
            marker_line_color="rgba(0,80,30,0.9)",
            marker_line_width=2,
        )
    )
    fig.update_layout(
        paper_bgcolor="#020602",
        plot_bgcolor="#010401",
        font=dict(family=_MONO, color="#00ff66"),
        height=320,
        margin=dict(l=140, r=40, t=20, b=40),
        yaxis=dict(
            automargin=True,
            ticklabelstandoff=20,
            gridcolor="rgba(0,170,68,0.15)",
            tickcolor="#00ff66",
            fixedrange=True,
        ),
        xaxis=dict(
            title="Number of applications",
            showgrid=True,
            gridcolor="rgba(0,170,68,0.35)",
            gridwidth=1,
            zerolinecolor="rgba(0,170,68,0.5)",
            tickcolor="#00ff66",
            fixedrange=True,
        ),
    )
    return fig

_build_concentration_figure(total_providers, cumulative_pcts)

Source code in src/tapmap/ui/daily_activity_report_view.py
 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
def _build_concentration_figure(
    total_providers: int,
    cumulative_pcts: list[float],
) -> go.Figure:
    fig = go.Figure()

    if total_providers > 0:
        fig.add_trace(
            go.Scatter(
                x=list(range(1, total_providers + 1)),
                y=cumulative_pcts,
                mode="lines",
                line=dict(color="rgba(0,220,88,0.90)", width=2),
                fill="tozeroy",
                fillcolor="rgba(0,160,68,0.12)",
                hovertemplate="Top %{x} providers: %{y:.0f}%<extra></extra>",
                showlegend=False,
            )
        )

    fig.update_layout(
        paper_bgcolor="#020602",
        plot_bgcolor="#010401",
        font=dict(family=_MONO, color="#00ff66"),
        height=220,
        margin=dict(l=60, r=20, t=10, b=50),
        showlegend=False,
        shapes=[
            dict(
                type="line",
                x0=0,
                x1=max(total_providers, 1),
                y0=80,
                y1=80,
                line=dict(color="rgba(0,200,80,0.75)", width=1.5, dash="dot"),
            )
        ],
        annotations=[
            dict(
                x=1,
                y=80,
                xref="paper",
                yref="y",
                text="80%",
                showarrow=False,
                xanchor="right",
                yanchor="bottom",
                xshift=-12,
                font=dict(size=9, color="rgba(0,210,84,0.88)", family=_MONO),
            )
        ],
        xaxis=dict(
            title=dict(text="Providers (sorted by activity)", font=dict(color="#00ff66")),
            showgrid=True,
            gridcolor="rgba(0,170,68,0.35)",
            gridwidth=1,
            showline=True,
            linecolor="rgba(0,170,68,0.5)",
            tickcolor="#00ff66",
            tickfont=dict(color="#00ff66"),
            zeroline=False,
            fixedrange=True,
        ),
        yaxis=dict(
            title=dict(text="Activity covered", font=dict(color="#00ff66")),
            range=[0, 100],
            showgrid=True,
            gridcolor="rgba(0,170,68,0.35)",
            gridwidth=1,
            showline=True,
            linecolor="rgba(0,170,68,0.5)",
            tickcolor="#00ff66",
            tickfont=dict(color="#00ff66"),
            zeroline=False,
            ticksuffix="%",
            fixedrange=True,
        ),
    )
    return fig

_build_countries_figure(country_map_points)

Source code in src/tapmap/ui/daily_activity_report_view.py
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
def _build_countries_figure(
    country_map_points: list[dict[str, Any]],
) -> go.Figure:
    def _scale(active_days: int) -> float:
        return 40 * (active_days / HISTORY_WINDOW_DAYS) ** 0.5

    lats = [p["lat"] for p in country_map_points]
    lons = [p["lon"] for p in country_map_points]
    days = [p["active_days"] for p in country_map_points]
    codes = [p["code"] for p in country_map_points]

    fig = go.Figure(
        go.Scattergeo(
            lat=lats,
            lon=lons,
            mode="markers",
            marker=dict(
                size=[_scale(d) for d in days],
                color="#00cc52",
                opacity=0.75,
                line=dict(width=1.5, color="rgba(0,60,20,0.85)"),
            ),
            hovertemplate="<b>%{customdata[0]}</b>: %{customdata[1]}d<extra></extra>",
            customdata=list(zip(codes, days, strict=True)),
        )
    )
    fig.update_layout(
        paper_bgcolor="#010201",
        height=420,
        margin=dict(l=0, r=0, t=10, b=0),
        showlegend=False,
        geo=dict(
            bgcolor="#010201",
            showframe=False,
            showcoastlines=True,
            coastlinecolor="#145214",
            showland=True,
            landcolor="#0f4a0f",
            showocean=True,
            oceancolor="#010201",
            showlakes=False,
            showcountries=False,
            projection_type="natural earth",
            lataxis_range=[-60, 85],
        ),
        dragmode=False,
    )
    return fig

_render_recurrence_examples(recurrence_examples, recurrence_labels, history_days)

Source code in src/tapmap/ui/daily_activity_report_view.py
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
def _render_recurrence_examples(
    recurrence_examples: list[Any],
    recurrence_labels: dict[str, str],
    history_days: int,
) -> list[Any]:
    if history_days < MIN_APPENDIX_HISTORY_DAYS:
        return [
            html.P(
                f"Recurrence grouping and patterns are shown once "
                f"{MIN_APPENDIX_HISTORY_DAYS} days of connection history are available.",
                style={
                    "fontSize": "11px",
                    "color": "rgba(0,220,88,0.55)",
                    "marginLeft": "140px",
                    "fontStyle": "italic",
                },
            )
        ]

    rows = []
    for cat, name, days in recurrence_examples:
        label_span = html.Span(
            recurrence_labels.get(cat, cat),
            className="rpt-cat-label",
        )
        if name is not None:
            detail: list[Any] = [
                html.Span(
                    name,
                    style={"color": "rgba(0,220,88,0.85)", "fontSize": "11px"},
                ),
                html.Div(
                    [
                        html.Span(
                            "\u25a0" if active else "\u25a1",
                            className="rpt-day--on" if active else "rpt-day--off",
                        )
                        for active in days
                    ],
                    className="rpt-day-strip",
                ),
            ]
        else:
            detail = [
                html.Span(
                    "no examples yet",
                    style={
                        "color": "rgba(0,180,70,0.45)",
                        "fontSize": "11px",
                        "fontStyle": "italic",
                    },
                )
            ]

        rows.append(html.Div([label_span, *detail], style={"marginBottom": "6px"}))

    return [
        html.Div(
            [
                html.P(
                    "Example recurrence patterns",
                    style={
                        "fontSize": "12px",
                        "fontWeight": "600",
                        "color": "rgba(0,220,88,0.90)",
                        "margin": "0 0 10px 0",
                        "letterSpacing": "0.02em",
                    },
                ),
                *rows,
                html.P(
                    "Each square represents one day, with today on the right. "
                    "Filled squares show days where activity was recorded.",
                    style={
                        "fontSize": "11px",
                        "color": "rgba(0,220,88,0.85)",
                        "margin": "14px 0 0 0",
                        "lineHeight": "1.35",
                    },
                ),
            ],
            className="rpt-recurrence",
        )
    ]

render_daily_activity_report(report)

Render the Daily Activity Report modal content from pre-computed data.

Source code in src/tapmap/ui/daily_activity_report_view.py
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
def render_daily_activity_report(
    report: DailyReportData,
) -> list[Any]:
    """Render the Daily Activity Report modal content from pre-computed data."""
    history_days = report["history_days"]
    concentration = report["provider_concentration"]

    applications_figure = _build_applications_figure(report["application_counts"])
    concentration_figure = _build_concentration_figure(
        concentration["total_providers"],
        concentration["cumulative_pcts"],
    )
    countries_figure = _build_countries_figure(report["country_map_points"])

    children: list[Any] = [
        html.H1("Daily Activity Report"),
        html.P(report["intro_text"]),
        html.P(report["today_text"]),
    ]

    if report["activity_pattern_text"]:
        children.append(html.P(report["activity_pattern_text"]))

    children += [
        html.H2("Applications", className="rpt-h2"),
        html.P(report["applications_summary"]),
        dcc.Graph(figure=applications_figure, config={"displayModeBar": False}),
        *_render_recurrence_examples(
            report["recurrence_examples"],
            report["recurrence_labels"],
            history_days,
        ),
        html.H2("Providers", className="rpt-h2"),
        html.P(report["providers_summary"]),
        dcc.Graph(
            figure=concentration_figure,
            config={"displayModeBar": False},
        ),
        html.H2("Countries", className="rpt-h2"),
        html.P(report["countries_summary"]),
        dcc.Graph(figure=countries_figure, config={"displayModeBar": False}),
        html.P(
            "Dot size reflects how many days each country was observed in the connection history.",
            className="modal-subtitle",
        ),
    ]

    children += [
        html.H2("Log", className="rpt-h2"),
        html.P(
            "The detailed log includes complete activity timelines for "
            "applications, providers, countries and ports."
        ),
        html.Button(
            "Open detailed log",
            id="btn_view_log",
            n_clicks=0,
            className="mx-btn mx-btn--primary mx-btn--nowrap",
            type="button",
        ),
    ]

    return children