Repository navigation
Expand file tree
/
Copy pathforecast.html
More file actions
2199 lines (2089 loc) · 122 KB
/
Copy pathforecast.html
File metadata and controls
2199 lines (2089 loc) · 122 KB
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forecast: Trendlines, Predictions, Anomaly Detection | Secutils.dev</title>
<meta name="description" content="Free in-browser trend forecaster. Paste a numeric series, fit linear / polynomial / exponential / logarithmic curves, smooth with SMA/EMA/WMA, project N periods ahead, and spot anomalies via peaks or residual z-score. Browser-only, no signup.">
<meta name="robots" content="index, follow, max-image-preview:large">
<link rel="canonical" href="https://{{TOOLS_HOST}}/forecast">
<meta name="su-tool-path" content="/forecast">
<meta name="su-tool-name" content="Forecast">
<meta name="su-tool-description" content="Fit trendlines, forecast future values, smooth noisy data, and spot anomalies in numeric series. Shareable URL state, no signup.">
<meta name="su-tool-promote" content="true">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Secutils.dev">
<meta property="og:title" content="Forecast: Trendlines, Predictions & Anomaly Detection">
<meta property="og:description" content="Free trend forecaster. Fit curves, smooth noise, project N periods ahead, and spot anomalies. Browser-only, no signup.">
<meta property="og:url" content="https://{{TOOLS_HOST}}/forecast">
<meta property="og:image" content="https://secutils.dev/docs/img/og/og-forecast.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Forecast on Secutils.dev: trendlines, predictions, and anomaly detection in your browser.">
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Forecast: Trendlines, Predictions & Anomaly Detection">
<meta name="twitter:description" content="Free trend forecaster. Fit curves, smooth noise, project N periods ahead, and spot anomalies. No signup.">
<meta name="twitter:image" content="https://secutils.dev/docs/img/og/og-forecast.png">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"Forecast","url":"https://{{TOOLS_HOST}}/forecast","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","isAccessibleForFree":true,"offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"publisher":{"@type":"Organization","name":"Secutils.dev","url":"https://secutils.dev"},"sameAs":"https://github.com/secutils-dev/secutils/blob/main/dev/tools/forecast.html","description":"Free in-browser trend forecaster. Paste a numeric series, fit linear / polynomial / exponential / logarithmic curves, smooth with SMA/EMA/WMA, project N periods ahead, and detect anomalies via peaks or residual z-score. Powered by the WASM-based micro-ml library, fully self-contained, no signup."}</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=Roboto+Mono:wght@400..700&display=swap" rel="stylesheet">
<!-- Privacy-friendly analytics by Plausible -->
<script defer src="https://tools.secutils.dev/js/script.js" fetchpriority="low"></script>
<script>
window.plausible = window.plausible || function () { (plausible.q = plausible.q || []).push(arguments) };
plausible.init = plausible.init || function (i) { plausible.o = i || {} };
plausible.init();
</script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* UA `[hidden] { display: none; }` rules lose to author `display: flex/block`
on the same element. The chart panes, output panel, and #chartActions all
declare `display: <something>` for layout, so we re-assert the UA rule at
author level (winning specificity ties) to keep `.hidden = true` working
from JS. */
[hidden] { display: none !important; }
:root, [data-theme="dark"] {
--bg: #141519; --surface: #1d1e24; --surface-hover: #2c2d33;
--border: #343741; --text: #dfe5ef; --text-muted: #98a2b3;
--primary: #fed047; --primary-hover: #fdc615;
--primary-text: #642340;
--primary-glow: rgba(254,208,71,0.10);
--accent: #642340;
--badge-bg: #2B394F; --badge-text: #98A8C3;
--radius: 12px;
--font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
--mono: 'Roboto Mono', 'SF Mono', 'Fira Code', Consolas, monospace;
--code-bg: #16171c;
--chart-grid: rgba(220,229,239,0.07);
--chart-axis: #475066;
--chart-raw: #6a93c8;
--chart-smooth: #2bb3bf;
--chart-fit: #fed047;
--chart-forecast: #ff7e3a;
--chart-anomaly: #e94f64;
}
[data-theme="light"] {
--bg: #f5f7fa; --surface: #ffffff; --surface-hover: #f1f3f5;
--border: #d3dae6; --text: #343741; --text-muted: #69707d;
--primary: #fed047; --primary-hover: #fdc615;
--primary-text: #642340;
--primary-glow: rgba(254,208,71,0.15);
--accent: #642340;
--badge-bg: #E3E8F2; --badge-text: #505F79;
--code-bg: #f6f8fa;
--chart-grid: rgba(52,55,65,0.08);
--chart-axis: #98a2b3;
--chart-raw: #4a76b3;
--chart-smooth: #1f8a94;
--chart-fit: #c89a1a;
--chart-forecast: #d96a1f;
--chart-anomaly: #c2384e;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; transition: background .25s, color .25s; }
header { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; height: 48px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; transition: background .25s, border-color .25s; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-svg { flex-shrink: 0; }
.logo-svg .logo-text-fill { fill: var(--text); }
.logo-badge { display: inline-flex; align-items: center; padding: 4px 16px; border-radius: 4px; border: none; background: var(--badge-bg); color: var(--badge-text); font-size: 12px; font-weight: 450; line-height: 16px; white-space: nowrap; }
.header-right { display: flex; gap: 8px; align-items: center; }
.btn { padding: 7px 14px; height: 29px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 13px/1 var(--font); cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--text-muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary-text); color: var(--primary-text); font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-sm { padding: 5px 10px; height: 24px; font-size: 12px; }
.theme-toggle { width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .2s; }
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.skill-link { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text-muted); font: 12px var(--font, system-ui), sans-serif; text-decoration: none; transition: all .15s; cursor: pointer; }
.skill-link:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface-hover); }
.skill-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; }
.su-more-tools { margin: 16px 0 0; padding: 12px 18px; text-align: center; border: 1px solid rgba(254, 208, 71, 0.35); border-radius: 12px; background: rgba(254, 208, 71, 0.06); font: 13px/1.55 var(--font); color: var(--text); transition: border-color .25s, background-color .25s, color .25s; }
.su-more-tools p { margin: 0; }
.su-more-tools a { color: var(--primary); font-weight: 700; text-decoration: none; white-space: nowrap; }
.su-more-tools a:hover { color: var(--primary-hover); text-decoration: underline; }
@media (max-width: 600px) { .su-more-tools { padding: 12px 14px; } .su-more-tools a { white-space: normal; } }
.su-noscript { max-width: 720px; margin: 24px auto; padding: 16px; border: 1px solid var(--border); border-radius: 8px; font: 14px/1.5 var(--font, system-ui), sans-serif; background: var(--surface); color: var(--text); }
main { flex: 1; padding: 24px 16px; max-width: 1280px; margin: 0 auto; width: 100%; }
.layout { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(420px, 2fr); gap: 16px; align-items: stretch; }
@media (max-width: 1000px) {
.layout { grid-template-columns: 1fr; }
}
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; transition: background .25s, border-color .25s; }
.panel-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; gap: 8px; border-bottom: 1px solid var(--border); }
.panel-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.yscale-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-right: -2px; }
.yscale-select { padding: 0 6px; min-width: 64px; }
.panel-label { font-size: 13px; font-weight: 600; color: var(--text); }
.link-btn { border: none; background: none; font: 12px var(--font); color: var(--text-muted); cursor: pointer; padding: 2px 4px; transition: color .15s; }
.link-btn:hover { color: var(--text); }
.stats-text { font: 11px var(--mono); color: var(--text-muted); white-space: nowrap; }
/* Input pane */
#inputPane { min-height: 240px; }
#dataInput { width: 100%; flex: 1; min-height: 220px; padding: 12px 14px; font: 13px/1.55 var(--mono); background: var(--surface); color: var(--text); border: none; outline: none; resize: vertical; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
#dataInput::placeholder { color: var(--text-muted); opacity: 0.7; }
/* Controls pane */
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; padding: 14px; }
.ctrl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctrl label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ctrl select, .ctrl input[type="number"] { width: 100%; padding: 6px 10px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 12px var(--font); transition: border-color .15s; }
.ctrl select:focus, .ctrl input:focus { outline: none; border-color: var(--primary); }
.ctrl-row { display: flex; align-items: center; gap: 8px; }
.ctrl-row input[type="range"] { flex: 1; accent-color: var(--primary); min-width: 0; }
.ctrl-row .range-value { font: 11px var(--mono); color: var(--text); min-width: 28px; text-align: right; }
.ctrl-row input[type="number"] { width: 70px; flex-shrink: 0; }
.ctrl.is-disabled { opacity: 0.45; pointer-events: none; }
.ctrl.is-disabled .range-value { color: var(--text-muted); }
@media (max-width: 480px) {
.controls-grid { grid-template-columns: 1fr; }
}
/* Chart pane */
#chartPanel { margin-top: 16px; }
#chartHost { flex: 1; min-height: 320px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
#chartSvg { flex: 1; width: 100%; min-height: 280px; display: block; }
#chartSvg .ax-line { stroke: var(--chart-axis); stroke-width: 1; }
#chartSvg .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
#chartSvg .ax-text { font: 10px var(--mono); fill: var(--text-muted); }
#chartSvg .series-raw { fill: none; stroke: var(--chart-raw); stroke-width: 1.5; stroke-linejoin: round; opacity: 0.85; }
#chartSvg .series-raw-dot { fill: var(--chart-raw); }
#chartSvg .series-smooth { fill: none; stroke: var(--chart-smooth); stroke-width: 2; stroke-linejoin: round; }
#chartSvg .series-fit { fill: none; stroke: var(--chart-fit); stroke-width: 2; stroke-linejoin: round; }
#chartSvg .series-forecast { fill: none; stroke: var(--chart-forecast); stroke-width: 2; stroke-dasharray: 6 4; stroke-linejoin: round; }
#chartSvg .forecast-band { fill: var(--chart-forecast); opacity: 0.12; }
#chartSvg .anomaly-marker { fill: var(--chart-anomaly); stroke: var(--surface); stroke-width: 1.5; }
#chartSvg .anomaly-marker:hover { stroke: var(--chart-anomaly); }
#chartSvg .forecast-divider { stroke: var(--chart-forecast); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.6; }
#chartSvg .backtest-divider { stroke: var(--chart-anomaly); stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.5; }
#chartSvg .backtest-pred-dot { fill: var(--chart-anomaly); stroke: var(--surface); stroke-width: 1; opacity: 0.7; }
#chartSvg .backtest-region { fill: var(--chart-anomaly); opacity: 0.04; }
/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 12px 16px; padding: 0 14px 8px; font-size: 11px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-swatch { width: 18px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend-swatch.dashed { background: transparent; border-top: 2px dashed currentColor; height: 0; border-radius: 0; }
.legend-item.raw .legend-swatch { background: var(--chart-raw); }
.legend-item.smooth .legend-swatch { background: var(--chart-smooth); }
.legend-item.fit .legend-swatch { background: var(--chart-fit); }
.legend-item.forecast .legend-swatch { color: var(--chart-forecast); }
.legend-item.anomaly .legend-swatch { width: 8px; height: 8px; border-radius: 50%; background: var(--chart-anomaly); }
.legend-item.backtest .backtest-swatch { width: 8px; height: 8px; border-radius: 50%; background: transparent; border: 1.5px solid var(--chart-anomaly); }
.legend-item.legend-hint { color: var(--text-muted); font-style: italic; cursor: help; }
/* Leaderboard occupies the full row of the output grid -- it has 7 numeric
* columns and is much denser than the other cards, so the auto-fit
* `minmax(220px, 1fr)` columns squeeze the Coverage column off-screen at
* typical desktop widths. */
.output-card.bt-card { grid-column: 1 / -1; }
.output-card .bt-scroll { overflow-x: auto; max-width: 100%; }
.output-card table.bt-table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 11px; }
.output-card table.bt-table th, .output-card table.bt-table td { text-align: right; padding: 3px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.output-card table.bt-table th:first-child, .output-card table.bt-table td:first-child { text-align: left; font-family: var(--mono); }
.output-card table.bt-table th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; }
.output-card table.bt-table tr.winner td { background: rgba(254, 208, 71, 0.10); font-weight: 600; }
.output-card table.bt-table tr.naive td { color: var(--text-muted); font-style: italic; }
.output-card table.bt-table td.warn { color: var(--chart-anomaly); }
/* Chart empty / loading / error states */
.chart-state { flex: 1; min-height: 280px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); padding: 32px; text-align: center; }
.chart-state .icon { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.6; }
.chart-state .title { font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.chart-state .sub { font-size: 12px; max-width: 360px; }
.chart-state .sub code { font-family: var(--mono); background: var(--surface-hover); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
/* Output panel */
#outputPanel { margin-top: 16px; }
.output-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; padding: 14px; }
.output-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; transition: border-color .15s; }
.output-card h3 { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.output-card p, .output-card li { font-size: 13px; color: var(--text); line-height: 1.5; }
.output-card .kv { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 12px; }
.output-card .kv .k { color: var(--text-muted); }
.output-card .kv .v { font-family: var(--mono); color: var(--text); }
.output-card pre { margin: 4px 0 0; font: 11px var(--mono); white-space: pre-wrap; word-break: break-all; color: var(--text-muted); background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.output-card ol, .output-card ul { padding-left: 18px; }
.output-card li { font-family: var(--mono); font-size: 11px; padding: 1px 0; }
.output-card.empty { opacity: 0.55; }
.output-card.callout { border-color: rgba(254, 208, 71, 0.4); background: rgba(254, 208, 71, 0.06); }
.output-card.warn { border-color: rgba(233, 79, 100, 0.4); background: rgba(233, 79, 100, 0.06); }
/* Examples dropdown (uses <details>; popover-anchored) */
.examples-anchor { position: relative; display: inline-flex; }
.examples-anchor summary { list-style: none; cursor: pointer; }
.examples-anchor summary::-webkit-details-marker { display: none; }
.examples-anchor[open] summary .chevron { transform: rotate(180deg); }
.examples-anchor .chevron { transition: transform .15s; }
.examples-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; min-width: 260px; max-width: calc(100vw - 24px); padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.35); }
@media (max-width: 480px) {
.examples-menu { left: auto; right: 0; }
}
.examples-group { padding: 6px 10px 4px; font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.example-item { display: block; width: 100%; padding: 7px 10px; border: none; background: transparent; color: var(--text); font: 12px var(--font); cursor: pointer; border-radius: 6px; text-align: left; transition: background .15s; }
.example-item:hover, .example-item:focus-visible { background: var(--surface-hover); outline: none; }
.example-item .ex-name { font-weight: 600; font-size: 13px; }
.example-item .ex-hint { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface); color: var(--text); padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; z-index: 200; box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.su-footer { text-align: center; padding: 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; transition: border-color .25s, color .25s; }
.su-footer p { margin: 0; }
.su-footer-fineprint { margin-top: 6px !important; font-size: 0.7rem; opacity: 0.75; }
.su-footer-link { background: none; border: none; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.su-footer-link:hover { color: var(--text); }
.su-dialog { max-width: 520px; width: calc(100% - 32px); max-height: calc(100% - 32px); inset: 0; margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.su-dialog::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.su-dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.su-dialog-header h2 { font-size: 1rem; font-weight: 600; }
.su-dialog-close { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .15s; }
.su-dialog-close:hover { background: var(--surface-hover); color: var(--text); }
.su-dialog-body { padding: 16px 18px; font-size: 0.875rem; line-height: 1.55; color: var(--text); }
.su-dialog-body p { margin-bottom: 12px; }
.su-dialog-body p:last-child { margin-bottom: 0; }
.su-dialog-body code { font-family: var(--mono); background: var(--surface-hover); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.su-dialog-body a { color: var(--primary); text-decoration: none; }
.su-dialog-body a:hover { text-decoration: underline; }
.su-dialog-fineprint { font-size: 0.8rem; color: var(--text-muted); }
.su-credits-list { margin: 0 0 12px; padding-left: 20px; }
.su-credits-list li { margin-bottom: 6px; }
.su-credits-list li:last-child { margin-bottom: 0; }
/* Typography polish (Baseline; selectors that don't exist in this tool are no-ops). See dev/tools/guides/chrome.md → "Typography polish". */
.page-title, .panel-label, .su-dialog-header h2, .card-header { text-wrap: balance; }
.su-dialog-body p, .su-more-tools p, .ex-hint, .chart-state .sub { text-wrap: pretty; }
/* Respect prefers-reduced-motion. See dev/tools/guides/chrome.md → "Reduced motion". */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
</style>
</head>
<body>
<noscript>
<p class="su-noscript"><strong>Forecast</strong>: fit trendlines, forecast future values, smooth noisy data, and spot anomalies in numeric series. Browser-only. Requires JavaScript; please enable it. Source on <a href="https://github.com/secutils-dev/secutils/blob/main/dev/tools/forecast.html">GitHub</a>.</p>
</noscript>
<header>
<a class="logo" href="https://secutils.dev" target="_blank" rel="noopener">
<svg class="logo-svg" height="24" role="img" viewBox="0 0 98 16" xmlns="http://www.w3.org/2000/svg">
<path d="m3 0h10c1.662 0 3 1.338 3 3v10c0 1.662-1.338 3-3 3h-10c-1.662 0-3-1.338-3-3v-10c0-1.662 1.338-3 3-3z" fill="#fed047"/>
<path aria-label="SU" d="m11.285 12q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667t1.216-0.26667 1.216 0.26667q0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50133-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832t0.46933 1.4613q0 0.69334-0.30933 1.2053-0.30933 0.50133-0.864 0.77867-0.55467 0.27733-1.312 0.27733z" fill="#642340"/>
<path class="logo-text-fill" aria-label="SECUTILS.DEV" d="m93.158 12.117-1.9733-7.7867h1.1733l1.2587 5.184q0.11733 0.46933 0.20267 0.91734 0.08533 0.448 0.128 0.69334 0.04267-0.24533 0.128-0.69334 0.096-0.45867 0.21333-0.928l1.2053-5.1733h1.184l-1.984 7.7867zm-7.8294 0v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-6.5174 0v-7.7867h2.176q0.768 0 1.3333 0.29867 0.56534 0.288 0.87467 0.832 0.32 0.53334 0.32 1.248v3.008q0 0.736-0.32 1.2693-0.30933 0.53334-0.87467 0.832-0.56534 0.29867-1.3333 0.29867zm1.152-1.0347h1.024q0.62934 0 1.0027-0.36267 0.37333-0.36267 0.37333-1.0027v-3.008q0-0.61867-0.37333-0.98134-0.37334-0.37333-1.0027-0.37333h-1.024zm-5.2374 1.1413q-0.416 0-0.68267-0.24533-0.256-0.256-0.256-0.672 0-0.416 0.256-0.672 0.26667-0.26667 0.68267-0.26667 0.416 0 0.672 0.26667 0.26667 0.256 0.26667 0.672 0 0.416-0.26667 0.672-0.256 0.24533-0.672 0.24533zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733zm-8.288-0.10667v-7.7867h1.152v6.7414h3.4027v1.0453zm-6.6987 0v-1.0453h1.568v-5.696h-1.568v-1.0453h4.32v1.0453h-1.5787v5.696h1.5787v1.0453zm-4.8214 0v-6.7414h-2.08v-1.0453h5.3227v1.0453h-2.0907v6.7414zm-5.824 0.10667q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.3147 0q-1.0987 0-1.7493-0.608-0.64-0.61867-0.64-1.664v-3.456q0-1.056 0.64-1.664 0.65067-0.608 1.7493-0.608 1.088 0 1.728 0.61867 0.65067 0.608 0.65067 1.6533h-1.152q0-0.608-0.33067-0.928-0.32-0.32-0.896-0.32-0.58667 0-0.91734 0.32-0.32 0.32-0.32 0.928v3.456q0 0.608 0.32 0.928 0.33067 0.32 0.91734 0.32 0.576 0 0.896-0.32 0.33067-0.32 0.33067-0.928h1.152q0 1.0453-0.65067 1.664-0.64 0.608-1.728 0.608zm-8.6827-0.10667v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-4.1707 0.10667q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667-0.23467-0.32-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34134-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733z"/>
</svg>
<span class="logo-badge">Forecast</span>
</a>
<div class="header-right">
<a id="skillLink" class="skill-link" href="https://{{TOOLS_HOST}}/forecast.md" target="_blank" rel="noopener"
title="View AI agent skill (skill.md, opens in new tab)"
aria-label="View AI agent skill (opens in new tab)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/>
<path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/>
</svg>
<span>Skill</span>
</a>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
<svg class="icon-sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8.5 15h-1v-2h1v2Zm-3.674-3.107-1.414 1.414-.707-.707 1.414-1.415.707.708Zm8.479.707-.707.707-1.414-1.414.707-.708 1.414 1.415Z"/><path fill-rule="evenodd" d="M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm0 1a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z" clip-rule="evenodd"/><path d="M3.005 8.505h-2v-1h2v1Zm12 0h-2v-1h2v1ZM4.82 4.114l-.708.707-1.414-1.414.707-.707L4.82 4.114Zm8.492-.707-1.414 1.414-.708-.707L12.605 2.7l.707.707ZM8.5 3h-1V1h1v2Z"/></svg>
<svg class="icon-moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.05 12.95A6.982 6.982 0 0 1 2 8c0-1.79.684-3.583 2.05-4.95A6.982 6.982 0 0 1 9 1a1 1 0 0 1 .708 1.707 4.982 4.982 0 0 0-1.465 3.536 4.98 4.98 0 0 0 1.465 3.535 4.98 4.98 0 0 0 3.535 1.465 1 1 0 0 1 .707 1.707A6.981 6.981 0 0 1 9 15a6.983 6.983 0 0 1-4.95-2.05Zm.708-.707A5.983 5.983 0 0 0 9 14c1.535 0 3.07-.586 4.242-1.757a5.98 5.98 0 0 1-4.018-1.545L9 10.485a5.982 5.982 0 0 1-1.758-4.242A5.986 5.986 0 0 1 9 2a5.983 5.983 0 0 0-4.243 1.757A5.98 5.98 0 0 0 3 8l.006.288a5.978 5.978 0 0 0 1.75 3.955Z"/></svg>
</button>
</div>
</header>
<main>
<div class="layout">
<section class="panel" id="inputPane" aria-labelledby="inputLabel">
<div class="panel-bar">
<span class="panel-label" id="inputLabel">Data</span>
<div class="panel-actions">
<details class="examples-anchor" id="examplesDetails">
<summary class="btn btn-sm" aria-haspopup="menu" aria-expanded="false">
Load example
<svg class="chevron" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true"><path d="M2 4l3 3 3-3" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
</summary>
<div class="examples-menu" role="menu" id="examplesMenu"></div>
</details>
<button type="button" class="btn btn-sm" id="clearBtn">Clear</button>
<button type="button" class="btn btn-sm btn-primary" id="shareBtn">Share</button>
</div>
</div>
<textarea id="dataInput" placeholder="Paste one number per line, two-column CSV (x,y), or a JSON array.
First line may be a header.
Examples:
42000
45000
48000
or:
date,value
2024-01,42000
2024-02,45000"
spellcheck="false" autocomplete="off"></textarea>
</section>
<section class="panel" id="controlsPane" aria-labelledby="controlsLabel">
<div class="panel-bar">
<span class="panel-label" id="controlsLabel">Analysis</span>
<span class="stats-text" id="dataStats" aria-live="polite"></span>
</div>
<div class="controls-grid">
<div class="ctrl">
<label for="fitSelect">Fit</label>
<select id="fitSelect">
<option value="none">None</option>
<option value="auto" selected>Auto (best R²)</option>
<option value="linear">Linear</option>
<option value="poly2">Polynomial (deg 2)</option>
<option value="poly3">Polynomial (deg 3)</option>
<option value="poly4">Polynomial (deg 4)</option>
<option value="exponential">Exponential</option>
<option value="logarithmic">Logarithmic</option>
<option value="power">Power</option>
</select>
</div>
<div class="ctrl">
<label for="smoothSelect">Smoothing</label>
<select id="smoothSelect">
<option value="none" selected>None</option>
<option value="sma">SMA</option>
<option value="ema">EMA</option>
<option value="wma">WMA</option>
</select>
</div>
<div class="ctrl">
<label for="smoothWindow">Smoothing window</label>
<div class="ctrl-row">
<input type="range" id="smoothWindow" min="2" max="30" step="1" value="5" aria-label="Smoothing window">
<span class="range-value" id="smoothWindowValue">5</span>
</div>
</div>
<div class="ctrl">
<label for="forecastHorizon">Forecast horizon</label>
<div class="ctrl-row">
<input type="range" id="forecastHorizon" min="0" max="50" step="1" value="0" aria-label="Forecast horizon">
<span class="range-value" id="forecastHorizonValue">0</span>
</div>
</div>
<div class="ctrl">
<label for="anomalySelect">Anomalies</label>
<select id="anomalySelect">
<option value="none" selected>None</option>
<option value="peaks">Peaks (findPeaks)</option>
<option value="troughs">Troughs (findTroughs)</option>
<option value="zscore">Residual z-score</option>
</select>
</div>
<div class="ctrl">
<label for="zThreshold">Z-score threshold</label>
<div class="ctrl-row">
<input type="range" id="zThreshold" min="1" max="5" step="0.1" value="2.5" aria-label="Z-score threshold">
<span class="range-value" id="zThresholdValue">2.5</span>
</div>
</div>
<div class="ctrl" style="grid-column: 1 / -1">
<label for="seasonalityToggle" style="display:flex;align-items:center;gap:8px;text-transform:none;letter-spacing:0;font-size:12px;color:var(--text);font-weight:500;cursor:pointer">
<input type="checkbox" id="seasonalityToggle" style="accent-color:var(--primary);cursor:pointer">
Auto-detect seasonality (detectSeasonality)
</label>
</div>
<div class="ctrl" style="grid-column: 1 / -1">
<label for="backtestToggle" style="display:flex;align-items:center;gap:8px;text-transform:none;letter-spacing:0;font-size:12px;color:var(--text);font-weight:500;cursor:pointer">
<input type="checkbox" id="backtestToggle" style="accent-color:var(--primary);cursor:pointer">
Walk-forward backtest + conformal prediction band
</label>
</div>
<div class="ctrl">
<label for="backtestHoldout">Hold-out (% of n)</label>
<div class="ctrl-row">
<input type="range" id="backtestHoldout" min="10" max="40" step="5" value="20" aria-label="Backtest hold-out percentage">
<span class="range-value" id="backtestHoldoutValue">20%</span>
</div>
</div>
<div class="ctrl">
<label for="backtestCoverage">Coverage target</label>
<div class="ctrl-row">
<input type="range" id="backtestCoverage" min="50" max="99" step="1" value="90" aria-label="Conformal coverage target">
<span class="range-value" id="backtestCoverageValue">90%</span>
</div>
</div>
</div>
</section>
</div>
<section class="panel" id="chartPanel" aria-labelledby="chartLabel">
<div class="panel-bar">
<span class="panel-label" id="chartLabel">Chart</span>
<div class="panel-actions" id="chartActions" hidden>
<label class="yscale-label" for="yScale" title="Y axis scale. Linear is the default; switch to Log10 for multi-decade series (e.g. exponential growth) where the lower values would otherwise be crushed near zero. Auto picks log10 when the data is strictly positive and spans more than 100x.">Y:</label>
<select id="yScale" class="btn btn-sm yscale-select" aria-label="Y axis scale">
<option value="linear" selected>Linear</option>
<option value="log">Log₁₀</option>
<option value="auto">Auto</option>
</select>
<button type="button" class="btn btn-sm" id="copyCsvBtn" title="Copy series as CSV">Copy CSV</button>
<button type="button" class="btn btn-sm" id="copyJsonBtn" title="Copy series as JSON">Copy JSON</button>
</div>
</div>
<div id="chartHost">
<div class="chart-state" id="chartEmpty">
<svg class="icon" viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M8 56h48"/>
<path d="M8 56V12"/>
<path d="M14 46l10-14 10 6 14-22"/>
<circle cx="48" cy="16" r="2.5" fill="currentColor"/>
</svg>
<div class="title">Paste some data, or pick an example</div>
<div class="sub">Numbers one per line, two-column CSV (<code>x,y</code>), or a JSON array. The first row may be a header.</div>
</div>
<svg id="chartSvg" hidden viewBox="0 0 800 320" preserveAspectRatio="none" aria-label="Forecast chart"></svg>
<div class="legend" id="chartLegend" hidden></div>
</div>
</section>
<section class="panel" id="outputPanel" aria-labelledby="outputLabel" hidden>
<div class="panel-bar">
<span class="panel-label" id="outputLabel">Results</span>
</div>
<div class="output-grid" id="outputGrid"></div>
</section>
<aside class="su-more-tools" aria-label="More free tools">
<p>Other free, no-signup Secutils.dev tools for JWT, SAML, certificates, Markdown, PDFs, HTTP echo, and more - <a href="https://{{TOOLS_HOST}}/">Browse all tools →</a></p>
</aside>
</main>
<footer class="su-footer">
<p>Fit trendlines, forecast future values, and spot anomalies, in your browser.</p>
<p class="su-footer-fineprint">
<button type="button" class="su-footer-link" id="privacyOpen">Privacy</button>
<span aria-hidden="true"> · </span>
<button type="button" class="su-footer-link" id="creditsOpen">Credits</button>
</p>
</footer>
<dialog id="creditsDialog" class="su-dialog" closedby="any" aria-labelledby="creditsDialogTitle">
<header class="su-dialog-header">
<h2 id="creditsDialogTitle">Credits</h2>
<button type="button" class="su-dialog-close" id="creditsClose" aria-label="Close">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>
</button>
</header>
<div class="su-dialog-body">
<p>This tool stands on these excellent open-source shoulders:</p>
<ul class="su-credits-list">
<li><a href="https://github.com/AdamPerlinski/micro-ml" target="_blank" rel="noopener noreferrer">micro-ml</a>: tiny Rust/WASM ML library (MIT) used for every regression / smoothing / forecasting / anomaly call. ~56 KB gzipped on its own; we ship a slightly larger self-contained build with the WASM payload inlined.</li>
</ul>
<p class="su-dialog-fineprint">All processing happens locally in your browser. See Privacy for details.</p>
</div>
</dialog>
<dialog id="privacyDialog" class="su-dialog" closedby="any" aria-labelledby="privacyDialogTitle">
<header class="su-dialog-header">
<h2 id="privacyDialogTitle">Privacy</h2>
<button type="button" class="su-dialog-close" id="privacyClose" aria-label="Close">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>
</button>
</header>
<div class="su-dialog-body">
<p><strong>Your data stays in your browser.</strong> Parsing, regression, smoothing, forecasting, and anomaly detection all run client-side inside a WebAssembly module bundled with the page. Numeric series are never sent to the Secutils.dev server. State that needs to survive a reload (or be shared) lives in the URL fragment (<code>#…</code>), which browsers never transmit.</p>
<p><strong>Anonymous usage analytics.</strong> We use <a href="https://plausible.io/" target="_blank" rel="noopener noreferrer">Plausible Analytics</a>, a privacy-first, GDPR-compliant tool, to collect aggregate usage data. No cookies, no personal data, no individual tracking.</p>
<p class="su-dialog-fineprint">See the full <a href="https://secutils.dev/privacy" target="_blank" rel="noopener noreferrer">Secutils.dev privacy policy</a> for details on the wider service.</p>
</div>
</dialog>
<!-- Lazy-loaded micro-ml WASM bundle. Empty placeholder; deploy.ts
inlines `dev/tools/js/micro-ml/dist/micro-ml.js` (gzip+base64'd)
into this script's text content. The runtime decompresses on
first user action so a search-result visitor pays the HTML cost
but never the WASM parse cost unless they hit "Load example" or
change a control. -->
<script id="su-bundle-micro-ml" type="text/plain"
data-su-bundle="micro-ml"
data-su-bundle-encoding="gzip-base64"></script>
<script>
'use strict';
// ---------------------------------------------------------------------------
// URL state encoding (canonical; same scheme every Secutils.dev tool uses).
// Layout: 4-byte LE u32 uncompressed length | raw-DEFLATE of UTF-8 string.
// ---------------------------------------------------------------------------
const utf8Enc = new TextEncoder();
const utf8Dec = new TextDecoder();
const toBase64Url = (bytes) => {
let s = '';
for (const b of bytes) s += String.fromCharCode(b);
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
};
const fromBase64Url = (str) => {
const b64 = str.replace(/-/g, '+').replace(/_/g, '/');
const padded = b64 + '==='.slice(0, (4 - b64.length % 4) % 4);
const bin = atob(padded);
const out = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
return out;
};
async function encodeState(text) {
const bytes = utf8Enc.encode(text);
const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream('deflate-raw'));
const deflated = new Uint8Array(await new Response(stream).arrayBuffer());
const out = new Uint8Array(4 + deflated.length);
new DataView(out.buffer).setUint32(0, bytes.length, true);
out.set(deflated, 4);
return toBase64Url(out);
}
async function decodeState(str) {
try {
const bytes = fromBase64Url(str);
if (bytes.length < 4) return null;
const stream = new Blob([bytes.subarray(4)]).stream()
.pipeThrough(new DecompressionStream('deflate-raw'));
const inflated = new Uint8Array(await new Response(stream).arrayBuffer());
return utf8Dec.decode(inflated);
} catch { return null; }
}
// ---------------------------------------------------------------------------
// Canonical loader for `data-su-bundle` placeholders. Handles both raw and
// gzip+base64 encodings. Lazy: first call decompresses and Blob-URLs the
// bundle, subsequent calls return the cached namespace.
// ---------------------------------------------------------------------------
let microMlPromise = null;
async function loadSuBundle(name) {
const el = document.getElementById(`su-bundle-${name}`);
if (!el?.textContent) throw new Error(`Bundle "${name}" is not loaded (placeholder is empty -- did the deploy run?).`);
const encoding = el.getAttribute('data-su-bundle-encoding');
let src = el.textContent.trim();
if (encoding === 'gzip-base64') {
const bin = atob(src);
const bytes = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'));
src = await new Response(stream).text();
}
const blob = new Blob([src], { type: 'text/javascript' });
return import(URL.createObjectURL(blob));
}
function loadMicroMl() {
if (!microMlPromise) microMlPromise = loadSuBundle('micro-ml');
return microMlPromise;
}
// ---------------------------------------------------------------------------
// Deterministic PRNG for example datasets that would otherwise be too long to
// list verbatim. mulberry32 -- 32-bit state, ~50 line-equivalent in source,
// good enough for visually-realistic data. Same seed always produces the same
// series so example URLs round-trip identically.
// ---------------------------------------------------------------------------
function mulberry32(seed) {
let a = seed >>> 0;
return function () {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// ---------------------------------------------------------------------------
// Examples catalogue. Each entry has a curated dataset + preset config that
// loads on click. The `data` field is rendered into the textarea verbatim
// (so the share URL faithfully round-trips the example), and `preset` is
// applied to the controls. Groups are rendered as disabled headers in the
// dropdown.
// ---------------------------------------------------------------------------
function genApiLatency() {
// 90 daily p95 latency samples around ~220ms with three incident spikes.
const r = mulberry32(0xC0FFEE);
const out = [];
for (let i = 0; i < 90; i++) {
let v = 220 + Math.sin(i / 6) * 18 + (r() - 0.5) * 14;
if (i === 23) v = 612;
if (i === 49) v = 540;
if (i === 77) v = 698;
out.push(Math.round(v * 10) / 10);
}
return out.join('\n');
}
function genLoginAttempts() {
// 168 hourly login counts with a credential-stuffing burst hours 80-85.
const r = mulberry32(0x5AFE5);
const out = [];
for (let i = 0; i < 168; i++) {
const hourOfDay = i % 24;
// Diurnal pattern: low at night, high midday.
let base = 40 + 35 * Math.sin((hourOfDay - 7) / 24 * Math.PI * 2 - Math.PI / 2);
if (base < 8) base = 8;
let v = base + (r() - 0.5) * 14;
if (i >= 80 && i <= 85) v += 220 + r() * 80;
out.push(Math.max(0, Math.round(v)));
}
return out.join('\n');
}
function genCiBuilds() {
// 120 build durations in seconds: slow upward drift + two outlier weeks.
const r = mulberry32(0xBAADF00D);
const out = [];
for (let i = 0; i < 120; i++) {
let v = 240 + i * 0.4 + (r() - 0.5) * 18;
if (i >= 42 && i <= 47) v += 95;
if (i >= 88 && i <= 91) v += 130;
out.push(Math.round(v));
}
return out.join('\n');
}
function genWebhookTraffic() {
// 7 days x 24 hours = 168 hourly webhook hits. Daily rhythm + Saturday dip.
const r = mulberry32(0xFEEDFACE);
const out = [];
for (let i = 0; i < 168; i++) {
const hourOfDay = i % 24;
const dayOfWeek = Math.floor(i / 24); // 0..6, day 5 = Saturday
let amp = 1.0;
if (dayOfWeek === 5) amp = 0.55;
let v = (180 + 110 * Math.sin((hourOfDay - 6) / 24 * Math.PI * 2 - Math.PI / 2)) * amp;
v += (r() - 0.5) * 22;
out.push(Math.max(0, Math.round(v)));
}
return out.join('\n');
}
// Box-Muller wrapper around a uniform PRNG, returning a standard-normal
// draw on each call. Used by the random-walk + heavy-tail examples below
// to produce statistically meaningful demonstrations of overfitting and
// non-Gaussian residuals.
function gaussian(r) {
const u1 = Math.max(1e-12, r());
const u2 = r();
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
}
function genRandomWalk() {
// 80-step Gaussian random walk anchored at 100 with σ_step = 2.5. No
// exploitable trend exists -- every regression family will overfit the
// in-sample wiggles, but the walk-forward backtest exposes that the
// *naive last-value* baseline beats every model. The "naive beats all"
// banner fires; in-sample R² for poly3/poly4 will look respectable
// (~0.5+) while their out-of-sample MAE is worse than just predicting
// y[t] = y[t-1]. This is the core lesson the tool now teaches.
const r = mulberry32(0x5EED5);
const out = [100];
for (let i = 1; i < 80; i++) out.push(out[i - 1] + gaussian(r) * 2.5);
return out.map((v) => v.toFixed(2)).join('\n');
}
function genHeavyTailResiduals() {
// Linear trend (y = 50 + 0.3·x) with a 90/10 mixture noise model:
// 90% of points: Gaussian noise σ = 4
// 10% of points: Gaussian noise σ = 18 (six-fold variance, positive
// bias to mimic latency-style "long tail" shocks)
//
// The empirical residual distribution has fatter tails than the normal
// approximation predicts, so the in-sample ±2σ band under-covers (the
// tool will report a Forecast band that misses several hold-out points).
// The conformal width is the 95th percentile of |residuals|, which
// adapts to the actual tail and meets the 90% coverage target. Pair
// this example side-by-side with backtest-trap to demonstrate the two
// failure modes of the legacy ±2σ heuristic.
const r = mulberry32(0xCAFEBABE);
const out = [];
for (let i = 0; i < 100; i++) {
const base = 50 + 0.3 * i;
const isOutlier = r() < 0.10;
const noise = isOutlier ? gaussian(r) * 18 + 12 : gaussian(r) * 4;
out.push(Math.max(0, Math.round((base + noise) * 10) / 10));
}
return out.join('\n');
}
const EXAMPLES = [
// --- Forecasting -----------------------------------------------------
{
id: 'monthly-sales',
group: 'Forecasting',
name: 'Monthly sales',
hint: 'Linear growth, project 3 months ahead.',
data: '42000\n45000\n48000\n52000\n55000\n58000\n62000\n65000\n68000\n72000\n75000\n79000',
preset: { fit: 'linear', smooth: 'none', window: 5, horizon: 3, anomaly: 'none', z: 2.5, seasonality: false },
},
{
id: 'user-growth',
group: 'Forecasting',
name: 'User growth (exponential)',
hint: 'Exponential signups; surfaces doubling time.',
data: '1000\n1500\n2200\n3300\n5000\n7500',
preset: { fit: 'exponential', smooth: 'none', window: 5, horizon: 6, anomaly: 'none', z: 2.5, seasonality: false },
},
{
id: 'training-completion',
group: 'Forecasting',
name: 'Phishing-training completion',
hint: 'Logarithmic curve approaching 100%.',
data: '12\n28\n44\n56\n65\n72\n78\n83\n86\n89\n91\n93',
preset: { fit: 'logarithmic', smooth: 'none', window: 5, horizon: 4, anomaly: 'none', z: 2.5, seasonality: false },
},
{
id: 'cloud-bill',
group: 'Forecasting',
name: 'Cloud bill projection',
hint: 'Mostly linear with a step-up at month 12.',
data: '1820\n1910\n1985\n2055\n2120\n2230\n2350\n2410\n2495\n2580\n2640\n3450\n3520\n3610\n3705\n3780\n3870\n3960',
preset: { fit: 'poly2', smooth: 'ema', window: 3, horizon: 6, anomaly: 'none', z: 2.5, seasonality: false },
},
// --- Anomaly detection -----------------------------------------------
{
id: 'api-latency',
group: 'Anomaly detection',
name: 'API p95 latency',
hint: 'EMA baseline + residual z-score flags 3 incident days.',
data: () => genApiLatency(),
preset: { fit: 'linear', smooth: 'ema', window: 7, horizon: 0, anomaly: 'zscore', z: 2.5, seasonality: false },
},
{
id: 'login-attempts',
group: 'Anomaly detection',
name: 'Login attempts / hour',
hint: 'Credential-stuffing burst around hours 80-85.',
data: () => genLoginAttempts(),
preset: { fit: 'none', smooth: 'none', window: 5, horizon: 0, anomaly: 'peaks', z: 2.5, seasonality: false },
},
{
id: 'ci-builds',
group: 'Anomaly detection',
name: 'CI build duration',
hint: 'Slow drift upward + outlier weeks.',
data: () => genCiBuilds(),
preset: { fit: 'linear', smooth: 'none', window: 5, horizon: 0, anomaly: 'zscore', z: 2.0, seasonality: false },
},
// --- Finance --------------------------------------------------------
{
id: 'compound-interest',
group: 'Finance',
name: 'Compound interest',
hint: '$10k at 5% APY, compounded monthly; exponential fit + doubling time.',
// Pre-computed so the user can eyeball the curve without doing the
// math: 12 monthly balances, principal $10,000, rate 5%/yr -> monthly
// factor 1.00416..., rounded to cents. Slow enough that linear fit
// is visibly wrong, exponential nails it, doublingTime() reads as
// ~167 months (~13.9 years -- the classic "Rule of 72" answer).
data: '10000.00\n10041.67\n10083.51\n10125.52\n10167.71\n10210.07\n10252.61\n10295.32\n10338.22\n10381.30\n10424.55\n10467.99',
preset: { fit: 'exponential', smooth: 'none', window: 5, horizon: 12, anomaly: 'none', z: 2.5, seasonality: false },
},
{
id: 'inflation',
group: 'Finance',
name: 'US inflation (CPI YoY %)',
hint: '1994-2024 annual CPI; residual z-score flags 2021-2022 spike.',
// Annual CPI-U change, US Bureau of Labor Statistics. Stable ~2% for
// most of the series with a 2008 bump and the unmistakable 2021/22
// post-pandemic spike. Linear baseline + z-score 1.8 cleanly
// surfaces the outlier years; a tighter threshold also flags 2009
// (negative inflation -- the only deflation year in the series).
data: '2.7\n2.5\n3.3\n1.7\n1.6\n2.7\n3.4\n1.6\n2.4\n1.9\n3.3\n3.4\n2.5\n4.1\n0.1\n2.7\n1.5\n3.0\n1.7\n1.5\n0.8\n0.7\n2.1\n2.1\n1.9\n2.3\n1.4\n7.0\n6.5\n3.4\n2.9',
preset: { fit: 'linear', smooth: 'none', window: 5, horizon: 0, anomaly: 'zscore', z: 1.8, seasonality: false },
},
// --- Smoothing & seasonality ----------------------------------------
{
id: 'webhook-traffic',
group: 'Smoothing & seasonality',
name: 'Webhook hourly traffic',
hint: 'Daily rhythm + Saturday dip; auto-detect seasonality.',
data: () => genWebhookTraffic(),
preset: { fit: 'none', smooth: 'ema', window: 6, horizon: 0, anomaly: 'none', z: 2.5, seasonality: true },
},
// --- Backtest & conformal -------------------------------------------
{
id: 'backtest-trap',
group: 'Backtest & conformal',
name: 'Random walk (naive beats all)',
hint: '80-step Gaussian random walk; the leaderboard exposes that no model beats "tomorrow = today".',
data: () => genRandomWalk(),
preset: { fit: 'auto', smooth: 'none', window: 5, horizon: 6, anomaly: 'none', z: 2.5, seasonality: false, backtest: true, backtestHoldout: 25, backtestCoverage: 90 },
},
{
id: 'conformal-coverage',
group: 'Backtest & conformal',
name: 'Heavy-tailed residuals (conformal vs ±2σ)',
hint: '100-point linear series with 10% outlier shocks; the conformal band widens past 2σ to hit the 90% target.',
data: () => genHeavyTailResiduals(),
preset: { fit: 'linear', smooth: 'none', window: 5, horizon: 8, anomaly: 'none', z: 2.5, seasonality: false, backtest: true, backtestHoldout: 25, backtestCoverage: 90 },
},
];
function findExample(id) { return EXAMPLES.find((e) => e.id === id); }
function exampleData(example) {
return typeof example.data === 'function' ? example.data() : example.data;
}
// ---------------------------------------------------------------------------
// Data parsing. Accepts:
// - One number per line (header line allowed, auto-skipped if non-numeric).
// - Two-column CSV `x,y` (x can be a number or any string -- when non-
// numeric, we use the implicit index `0,1,2,...` for the X axis and just
// keep the label for display).
// - JSON array (`[1,2,3]` or `[[x,y],...]`).
// Returns { x: number[], y: number[], xLabels: string[]|null } or null on
// parse failure.
// ---------------------------------------------------------------------------
function parseData(text) {
const trimmed = text.trim();
if (!trimmed) return null;
// JSON array?
if (trimmed.startsWith('[')) {
try {
const parsed = JSON.parse(trimmed);
if (!Array.isArray(parsed) || parsed.length === 0) return null;
if (Array.isArray(parsed[0])) {
const x = [], y = [];
for (const pair of parsed) {
if (!Array.isArray(pair) || pair.length < 2) return null;
const xn = Number(pair[0]); const yn = Number(pair[1]);
if (!Number.isFinite(xn) || !Number.isFinite(yn)) return null;
x.push(xn); y.push(yn);
}
return { x, y, xLabels: null };
}
const y = parsed.map(Number);
if (y.some((v) => !Number.isFinite(v))) return null;
return { x: y.map((_, i) => i), y, xLabels: null };
} catch { return null; }
}
// CSV / one-per-line.
const lines = trimmed.split(/\r?\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith('#'));
if (lines.length === 0) return null;
// Detect header: if the first line has non-numeric first cell, drop it.
const firstCells = lines[0].split(/[,;\t]/);
const firstIsHeader = firstCells.every((c) => !Number.isFinite(Number(c.trim())));
const dataLines = firstIsHeader ? lines.slice(1) : lines;
if (dataLines.length === 0) return null;
const xLabels = [];
const x = []; const y = [];
let anyXNumeric = true;
for (let i = 0; i < dataLines.length; i++) {
const cells = dataLines[i].split(/[,;\t]/).map((c) => c.trim());
if (cells.length === 1) {
const yn = Number(cells[0]);
if (!Number.isFinite(yn)) return null;
x.push(i); xLabels.push(String(i)); y.push(yn);
} else if (cells.length >= 2) {
const xn = Number(cells[0]); const yn = Number(cells[1]);
if (!Number.isFinite(yn)) return null;
xLabels.push(cells[0]);
if (Number.isFinite(xn)) {
x.push(xn);
} else {
anyXNumeric = false;
x.push(i);
}
y.push(yn);
} else {
return null;
}
}
return { x, y, xLabels: anyXNumeric ? null : xLabels };
}
// ---------------------------------------------------------------------------
// State + DOM refs.
// ---------------------------------------------------------------------------
const $ = (id) => document.getElementById(id);
// `<svg>` does NOT inherit the `hidden` IDL property from HTMLElement (it's
// declared on HTMLElement, not Element). Writing `svg.hidden = false` only
// creates a JS property -- the HTML attribute survives, and our
// `[hidden] { display: none !important }` rule keeps it invisible. Use
// attribute APIs throughout so the same helper works on every element type.
const setHidden = (el, hidden) => {
if (hidden) el.setAttribute('hidden', '');
else el.removeAttribute('hidden');
};
const refs = {
input: $('dataInput'),
stats: $('dataStats'),
examplesDetails: $('examplesDetails'),
examplesMenu: $('examplesMenu'),
clear: $('clearBtn'),
share: $('shareBtn'),
fit: $('fitSelect'),
smooth: $('smoothSelect'),
smoothWindow: $('smoothWindow'),
smoothWindowValue: $('smoothWindowValue'),
horizon: $('forecastHorizon'),
horizonValue: $('forecastHorizonValue'),
anomaly: $('anomalySelect'),
z: $('zThreshold'),
zValue: $('zThresholdValue'),
seasonality: $('seasonalityToggle'),
backtest: $('backtestToggle'),
backtestHoldout: $('backtestHoldout'),
backtestHoldoutValue: $('backtestHoldoutValue'),
backtestCoverage: $('backtestCoverage'),
backtestCoverageValue: $('backtestCoverageValue'),
chartHost: $('chartHost'),
chartEmpty: $('chartEmpty'),
chartSvg: $('chartSvg'),
chartLegend: $('chartLegend'),
chartActions: $('chartActions'),
yScale: $('yScale'),
outputPanel: $('outputPanel'),
outputGrid: $('outputGrid'),
copyCsv: $('copyCsvBtn'),
copyJson: $('copyJsonBtn'),
};
const state = {
parsed: null, // { x, y, xLabels }
smoothed: null, // y' array, length === y.length, with `null` for the leading window
fit: null, // { kind, eq, rSquared, predict(xArr): yArr, extras }
forecastY: null, // array of length horizon, y values
forecastBand: null, // { upper: y[], lower: y[], width: number, source: 'sigma2'|'conformal' }
anomalyIndices: [], // indices into y
seasonality: null, // { period, strength } | null
backtest: null, // { holdoutK, coverage, leaderboard: [{ kind, params, inSampleR2, adjR2, mape, mae, rmse, coverage, predicted, actual }], winnerKind, q: number, foldStart: number }
warnings: [],
};
let recomputeTimer = null;
function scheduleRecompute() {
clearTimeout(recomputeTimer);
recomputeTimer = setTimeout(recompute, 80);
}
// ---------------------------------------------------------------------------
// Toast.
// ---------------------------------------------------------------------------
let toastTimer = null;
function toast(msg) {
let el = document.querySelector('.toast');
if (!el) { el = document.createElement('div'); el.className = 'toast'; document.body.appendChild(el); }
el.textContent = msg;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => el.remove(), 2400);
}
// ---------------------------------------------------------------------------
// Wire the controls + examples dropdown.
// ---------------------------------------------------------------------------
function renderExamplesMenu() {
const html = [];
let currentGroup = null;
for (const ex of EXAMPLES) {
if (ex.group !== currentGroup) {
currentGroup = ex.group;
html.push(`<div class="examples-group">${escapeHtml(currentGroup)}</div>`);
}
html.push(
`<button type="button" class="example-item" role="menuitem" data-example-id="${ex.id}">` +
`<span class="ex-name">${escapeHtml(ex.name)}</span>` +
`<span class="ex-hint">${escapeHtml(ex.hint)}</span>` +
`</button>`,
);
}
refs.examplesMenu.innerHTML = html.join('');
refs.examplesMenu.addEventListener('click', (e) => {
const btn = e.target.closest('[data-example-id]');
if (!btn) return;
const ex = findExample(btn.dataset.exampleId);
if (ex) loadExample(ex);
refs.examplesDetails.open = false;
});
}
function escapeHtml(s) { return s.replace(/[&<>"']/g, (c) => ({ '&':'&','<':'<','>':'>','"':'"','\'':''' }[c])); }