mirror of
https://github.com/sstent/aicyclingcoach-go.git
synced 2026-02-03 04:51:43 +00:00
sync
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"context7": {
|
||||
"command": "npx",
|
||||
"args": [
|
||||
"-y",
|
||||
"@upstash/context7-mcp"
|
||||
],
|
||||
"env": {
|
||||
"DEFAULT_MINIMUM_TOKENS": ""
|
||||
}
|
||||
},
|
||||
"penpot": {
|
||||
"command": "uvx",
|
||||
"args": ["penpot-mcp"],
|
||||
"env": {
|
||||
"PENPOT_API_URL": "https://design.penpot.app/api",
|
||||
"PENPOT_USERNAME": "stuart.stent@gmail.com",
|
||||
"PENPOT_PASSWORD": "Upriver!Magnetize!Bling2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
module github.com/sstent/fitness-tui
|
||||
|
||||
go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/bubbles v0.21.0
|
||||
github.com/charmbracelet/bubbletea v1.3.9
|
||||
github.com/charmbracelet/lipgloss v1.1.0
|
||||
github.com/go-resty/resty/v2 v2.16.5
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/viper v1.21.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
)
|
||||
|
||||
require github.com/sony/gobreaker v1.0.0
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||
github.com/charmbracelet/x/ansi v0.10.1 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.16.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sahilm/fuzzy v0.1.1 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
|
||||
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
|
||||
github.com/charmbracelet/bubbletea v1.3.9 h1:OBYdfRo6QnlIcXNmcoI2n1NNS65Nk6kI2L2FO1puS/4=
|
||||
github.com/charmbracelet/bubbletea v1.3.9/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
|
||||
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
|
||||
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||
github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
|
||||
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/sony/gobreaker v1.0.0 h1:feX5fGGXSl3dYd4aHZItw+FpHLvvoaqkawKjVNiFMNQ=
|
||||
github.com/sony/gobreaker v1.0.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -1,69 +0,0 @@
|
||||
package circuitbreaker
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CircuitBreaker struct {
|
||||
state string // "closed", "open", "half-open"
|
||||
failures int
|
||||
maxFailures int
|
||||
resetTimeout time.Duration
|
||||
lastFailure time.Time
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func New(maxFailures int, resetTimeout time.Duration) *CircuitBreaker {
|
||||
return &CircuitBreaker{
|
||||
state: "closed",
|
||||
maxFailures: maxFailures,
|
||||
resetTimeout: resetTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) AllowRequest() bool {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
if cb.state == "open" {
|
||||
if now.Sub(cb.lastFailure) < cb.resetTimeout {
|
||||
return false
|
||||
}
|
||||
// Timeout expired, transition to half-open
|
||||
cb.state = "half-open"
|
||||
log.Printf("Circuit breaker transitioning to half-open state")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) RecordSuccess() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
if cb.state == "half-open" {
|
||||
log.Printf("Circuit breaker test request succeeded, closing circuit")
|
||||
}
|
||||
cb.state = "closed"
|
||||
cb.failures = 0
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) RecordFailure() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
cb.failures++
|
||||
cb.lastFailure = now
|
||||
|
||||
if cb.state == "half-open" {
|
||||
// Immediately open the circuit on failure in half-open state
|
||||
log.Printf("Circuit breaker test request failed, reopening circuit")
|
||||
cb.state = "open"
|
||||
} else if cb.failures >= cb.maxFailures {
|
||||
log.Printf("Circuit breaker opened due to %d consecutive failures", cb.failures)
|
||||
cb.state = "open"
|
||||
}
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/sstent/fitness-tui/internal/types"
|
||||
)
|
||||
|
||||
// Chart represents an ASCII chart component
|
||||
type Chart struct {
|
||||
Data []float64
|
||||
Title string
|
||||
Width int
|
||||
Height int
|
||||
Color lipgloss.Color
|
||||
Min, Max float64
|
||||
Downsampled []types.DownsampledPoint
|
||||
Unit string
|
||||
Mode string // "bar" or "sparkline"
|
||||
XLabels []string
|
||||
YMax float64
|
||||
}
|
||||
|
||||
// NewChart creates a new chart instance
|
||||
func NewChart(data []float64, title, unit string, width, height int, color lipgloss.Color) *Chart {
|
||||
c := &Chart{
|
||||
Data: data,
|
||||
Title: title,
|
||||
Width: width,
|
||||
Height: height,
|
||||
Color: color,
|
||||
Unit: unit,
|
||||
Mode: "sparkline",
|
||||
}
|
||||
|
||||
if len(data) > 0 {
|
||||
// Use downsampled data for min/max to improve performance
|
||||
// Using empty timestamps array since we only need value downsampling
|
||||
downsampled := types.DownsampleLTTB(data, make([]time.Time, len(data)), width)
|
||||
c.Downsampled = downsampled
|
||||
values := make([]float64, len(downsampled))
|
||||
for i, point := range downsampled {
|
||||
values[i] = point.Value
|
||||
}
|
||||
c.Min, c.Max = minMax(values)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// NewBarChart creates a bar chart with axis labels
|
||||
func NewBarChart(data []float64, title string, width, height int, color lipgloss.Color, xLabels []string, yMax float64) *Chart {
|
||||
c := NewChart(data, title, "", width, height, color)
|
||||
c.Mode = "bar"
|
||||
c.XLabels = xLabels
|
||||
c.YMax = yMax
|
||||
return c
|
||||
}
|
||||
|
||||
// View renders the chart
|
||||
func (c *Chart) View() string {
|
||||
if len(c.Data) == 0 {
|
||||
return c.renderNoData()
|
||||
}
|
||||
|
||||
if c.Width <= 10 || c.Height <= 4 {
|
||||
return c.renderTooSmall()
|
||||
}
|
||||
|
||||
if c.Mode == "bar" && c.YMax == 0 {
|
||||
return c.renderNoData()
|
||||
}
|
||||
|
||||
// Recalculate if dimensions changed
|
||||
if len(c.Downsampled) != c.Width {
|
||||
c.Downsampled = types.DownsampleLTTB(c.Data, make([]time.Time, len(c.Data)), c.Width)
|
||||
values := make([]float64, len(c.Downsampled))
|
||||
for i, point := range c.Downsampled {
|
||||
values[i] = point.Value
|
||||
}
|
||||
c.Min, c.Max = minMax(values)
|
||||
}
|
||||
|
||||
return lipgloss.NewStyle().
|
||||
MaxWidth(c.Width).
|
||||
Render(c.renderTitle() + "\n" + c.renderChart())
|
||||
}
|
||||
|
||||
func (c *Chart) renderTitle() string {
|
||||
return lipgloss.NewStyle().
|
||||
Bold(true).
|
||||
Foreground(c.Color).
|
||||
Render(c.Title)
|
||||
}
|
||||
|
||||
func (c *Chart) renderChart() string {
|
||||
if c.Max == c.Min && c.Mode != "bar" {
|
||||
return c.renderConstantData()
|
||||
}
|
||||
|
||||
if c.Mode == "bar" {
|
||||
return c.renderBarChart()
|
||||
}
|
||||
return c.renderSparkline()
|
||||
}
|
||||
|
||||
func (c *Chart) renderBarChart() string {
|
||||
var sb strings.Builder
|
||||
chartHeight := c.Height - 3 // Reserve space for title and labels
|
||||
|
||||
// Calculate scaling factor
|
||||
maxValue := c.YMax
|
||||
if maxValue == 0 {
|
||||
maxValue = c.Max
|
||||
}
|
||||
scale := float64(chartHeight-1) / maxValue
|
||||
|
||||
// Y-axis labels
|
||||
yIncrement := maxValue / float64(chartHeight-1)
|
||||
for i := chartHeight - 1; i >= 0; i-- {
|
||||
label := fmt.Sprintf("%3.0f │", maxValue-(yIncrement*float64(i)))
|
||||
sb.WriteString(label)
|
||||
if i == 0 {
|
||||
sb.WriteString(" " + strings.Repeat("─", c.Width))
|
||||
break
|
||||
}
|
||||
|
||||
// Draw bars
|
||||
for _, point := range c.Downsampled {
|
||||
barHeight := int(math.Round(point.Value * scale))
|
||||
if barHeight >= i {
|
||||
sb.WriteString("#")
|
||||
} else {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
// X-axis labels
|
||||
sb.WriteString("\n ")
|
||||
for i, label := range c.XLabels {
|
||||
if i >= len(c.Downsampled) {
|
||||
break
|
||||
}
|
||||
if i == 0 {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("%-*s", c.Width/len(c.XLabels), label))
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (c *Chart) renderSparkline() string {
|
||||
var sb strings.Builder
|
||||
chartHeight := c.Height - 3 // Reserve rows for title and labels
|
||||
|
||||
minLabel := fmt.Sprintf("%.0f%s", c.Min, c.Unit)
|
||||
maxLabel := fmt.Sprintf("%.0f%s", c.Max, c.Unit)
|
||||
sb.WriteString(fmt.Sprintf("%5s ", maxLabel))
|
||||
|
||||
for i, point := range c.Downsampled {
|
||||
if i >= c.Width {
|
||||
break
|
||||
}
|
||||
|
||||
normalized := (point.Value - c.Min) / (c.Max - c.Min)
|
||||
barHeight := int(math.Round(normalized * float64(chartHeight-1)))
|
||||
sb.WriteString(c.renderBar(barHeight, chartHeight))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
|
||||
// Add X axis with min label
|
||||
sb.WriteString(fmt.Sprintf("%5s ", minLabel))
|
||||
sb.WriteString(strings.Repeat("─", c.Width))
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (c *Chart) renderBar(height, maxHeight int) string {
|
||||
if height <= 0 {
|
||||
return " "
|
||||
}
|
||||
|
||||
// Use Unicode block characters for better resolution
|
||||
blocks := []string{" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"}
|
||||
index := int(float64(height) / float64(maxHeight) * 8)
|
||||
if index >= len(blocks) {
|
||||
index = len(blocks) - 1
|
||||
}
|
||||
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(c.Color).
|
||||
Render(blocks[index])
|
||||
}
|
||||
|
||||
func (c *Chart) renderNoData() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("240")).
|
||||
Render(fmt.Sprintf("%s: No data", c.Title))
|
||||
}
|
||||
|
||||
func (c *Chart) renderTooSmall() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("196")).
|
||||
Render(fmt.Sprintf("%s: Terminal too small", c.Title))
|
||||
}
|
||||
|
||||
func (c *Chart) renderConstantData() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("214")).
|
||||
Render(fmt.Sprintf("%s: Constant value %.2f", c.Title, c.Data[0]))
|
||||
}
|
||||
|
||||
func minMax(data []float64) (min, max float64) {
|
||||
if len(data) == 0 {
|
||||
return 0, 0
|
||||
}
|
||||
min, max = data[0], data[0]
|
||||
for _, v := range data {
|
||||
if v < min {
|
||||
min = v
|
||||
}
|
||||
if v > max {
|
||||
max = v
|
||||
}
|
||||
}
|
||||
return min, max
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
type DownsampledPoint struct {
|
||||
Timestamp time.Time
|
||||
Value float64
|
||||
}
|
||||
|
||||
// DownsampleLTTB implements the Largest Triangle Three Buckets algorithm
|
||||
// for time series downsampling. This is a corrected version that properly
|
||||
// uses the current module path.
|
||||
func DownsampleLTTB(data []float64, timestamps []time.Time, threshold int) []DownsampledPoint {
|
||||
if len(data) != len(timestamps) {
|
||||
panic("data and timestamps must be same length")
|
||||
}
|
||||
|
||||
if threshold >= len(data) || threshold <= 0 {
|
||||
result := make([]DownsampledPoint, len(data))
|
||||
for i := range data {
|
||||
result[i] = DownsampledPoint{
|
||||
Timestamp: timestamps[i],
|
||||
Value: data[i],
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
sampled := make([]DownsampledPoint, threshold)
|
||||
sampled[0] = DownsampledPoint{Timestamp: timestamps[0], Value: data[0]}
|
||||
|
||||
bucketSize := float64(len(data)-2) / float64(threshold-2)
|
||||
a := 0
|
||||
|
||||
for i := 0; i < threshold-2; i++ {
|
||||
avgRangeStart := int(float64(i+1)*bucketSize) + 1
|
||||
avgRangeEnd := int(float64(i+2)*bucketSize) + 1
|
||||
if avgRangeEnd > len(data) {
|
||||
avgRangeEnd = len(data)
|
||||
}
|
||||
|
||||
var avgRange float64
|
||||
for j := avgRangeStart; j < avgRangeEnd; j++ {
|
||||
avgRange += data[j]
|
||||
}
|
||||
avgRange /= float64(avgRangeEnd - avgRangeStart)
|
||||
|
||||
rangeOffs := int(float64(i)*bucketSize) + 1
|
||||
rangeTo := int(float64(i+1)*bucketSize) + 1
|
||||
if rangeTo > len(data) {
|
||||
rangeTo = len(data)
|
||||
}
|
||||
|
||||
maxArea := -1.0
|
||||
nextAAt := 0
|
||||
for j := rangeOffs; j < rangeTo; j++ {
|
||||
area := areaSize(
|
||||
data[a],
|
||||
data[j],
|
||||
avgRange,
|
||||
)
|
||||
if area > maxArea {
|
||||
maxArea = area
|
||||
nextAAt = j
|
||||
}
|
||||
}
|
||||
|
||||
sampled[i+1] = DownsampledPoint{
|
||||
Timestamp: timestamps[nextAAt],
|
||||
Value: data[nextAAt],
|
||||
}
|
||||
a = nextAAt
|
||||
}
|
||||
|
||||
sampled[threshold-1] = DownsampledPoint{
|
||||
Timestamp: timestamps[len(timestamps)-1],
|
||||
Value: data[len(data)-1],
|
||||
}
|
||||
return sampled
|
||||
}
|
||||
|
||||
func areaSize(a, b, avg float64) float64 {
|
||||
return (a-avg)*(a-avg) + (b-avg)*(b-avg)
|
||||
}
|
||||
50
go.mod
50
go.mod
@@ -2,4 +2,52 @@ module github.com/sstent/fitness-tui
|
||||
|
||||
go 1.24.2
|
||||
|
||||
require github.com/sony/gobreaker v1.0.0 // indirect
|
||||
require (
|
||||
github.com/charmbracelet/bubbles v0.21.0
|
||||
github.com/charmbracelet/bubbletea v1.3.9
|
||||
github.com/charmbracelet/lipgloss v1.1.0
|
||||
github.com/go-resty/resty/v2 v2.16.5
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/viper v1.21.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
)
|
||||
|
||||
require github.com/sony/gobreaker v1.0.0
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
||||
github.com/charmbracelet/x/ansi v0.10.1 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.16.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sahilm/fuzzy v0.1.1 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
|
||||
110
go.sum
110
go.sum
@@ -1,6 +1,116 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
|
||||
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
|
||||
github.com/charmbracelet/bubbletea v1.3.9 h1:OBYdfRo6QnlIcXNmcoI2n1NNS65Nk6kI2L2FO1puS/4=
|
||||
github.com/charmbracelet/bubbletea v1.3.9/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
|
||||
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
|
||||
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
|
||||
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
|
||||
github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
|
||||
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||
github.com/sony/gobreaker v1.0.0 h1:feX5fGGXSl3dYd4aHZItw+FpHLvvoaqkawKjVNiFMNQ=
|
||||
github.com/sony/gobreaker v1.0.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
|
||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
|
||||
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
||||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
package circuitbreaker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sony/gobreaker"
|
||||
)
|
||||
|
||||
// CircuitBreaker wraps gobreaker.CircuitBreaker with context support
|
||||
type CircuitBreaker struct {
|
||||
cb *gobreaker.CircuitBreaker
|
||||
state string // "closed", "open", "half-open"
|
||||
failures int
|
||||
maxFailures int
|
||||
resetTimeout time.Duration
|
||||
lastFailure time.Time
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// New creates a new CircuitBreaker with the given name and settings
|
||||
func New(name string, st gobreaker.Settings) *CircuitBreaker {
|
||||
func New(maxFailures int, resetTimeout time.Duration) *CircuitBreaker {
|
||||
return &CircuitBreaker{
|
||||
cb: gobreaker.NewCircuitBreaker(st),
|
||||
state: "closed",
|
||||
maxFailures: maxFailures,
|
||||
resetTimeout: resetTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute runs the given function with circuit breaker protection
|
||||
func (c *CircuitBreaker) Execute(ctx context.Context, req func() (interface{}, error)) (interface{}, error) {
|
||||
// Check if context is already canceled
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
default:
|
||||
}
|
||||
func (cb *CircuitBreaker) AllowRequest() bool {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
resultChan := make(chan interface{}, 1)
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
go func() {
|
||||
res, err := c.cb.Execute(func() (interface{}, error) {
|
||||
return req()
|
||||
})
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
now := time.Now()
|
||||
if cb.state == "open" {
|
||||
if now.Sub(cb.lastFailure) < cb.resetTimeout {
|
||||
return false
|
||||
}
|
||||
resultChan <- res
|
||||
}()
|
||||
|
||||
select {
|
||||
case res := <-resultChan:
|
||||
return res, nil
|
||||
case err := <-errChan:
|
||||
return nil, err
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
// Timeout expired, transition to half-open
|
||||
cb.state = "half-open"
|
||||
log.Printf("Circuit breaker transitioning to half-open state")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// DefaultSettings returns sensible default circuit breaker settings
|
||||
func DefaultSettings(name string) gobreaker.Settings {
|
||||
return gobreaker.Settings{
|
||||
Name: name,
|
||||
MaxRequests: 3,
|
||||
Interval: 30 * time.Second,
|
||||
Timeout: 60 * time.Second,
|
||||
ReadyToTrip: func(counts gobreaker.Counts) bool {
|
||||
return counts.ConsecutiveFailures > 5
|
||||
},
|
||||
OnStateChange: func(name string, from gobreaker.State, to gobreaker.State) {
|
||||
// Log state changes for monitoring
|
||||
},
|
||||
func (cb *CircuitBreaker) RecordSuccess() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
if cb.state == "half-open" {
|
||||
log.Printf("Circuit breaker test request succeeded, closing circuit")
|
||||
}
|
||||
cb.state = "closed"
|
||||
cb.failures = 0
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) RecordFailure() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
cb.failures++
|
||||
cb.lastFailure = now
|
||||
|
||||
if cb.state == "half-open" {
|
||||
// Immediately open the circuit on failure in half-open state
|
||||
log.Printf("Circuit breaker test request failed, reopening circuit")
|
||||
cb.state = "open"
|
||||
} else if cb.failures >= cb.maxFailures {
|
||||
log.Printf("Circuit breaker opened due to %d consecutive failures", cb.failures)
|
||||
cb.state = "open"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/sstent/aicyclingcoach-go/fitness-tui/internal/types"
|
||||
"github.com/sstent/fitness-tui/internal/types"
|
||||
)
|
||||
|
||||
// Chart represents an ASCII chart component
|
||||
@@ -16,112 +17,209 @@ type Chart struct {
|
||||
Width int
|
||||
Height int
|
||||
Color lipgloss.Color
|
||||
downsampler *types.Downsampler
|
||||
Min, Max float64
|
||||
Downsampled []types.DownsampledPoint
|
||||
Unit string
|
||||
Mode string // "bar" or "sparkline"
|
||||
XLabels []string
|
||||
YMax float64
|
||||
}
|
||||
|
||||
// NewChart creates a new Chart instance
|
||||
func NewChart(data []float64, title string) *Chart {
|
||||
return &Chart{
|
||||
Data: data,
|
||||
Title: title,
|
||||
Width: 0, // Will be set based on terminal size
|
||||
Height: 10,
|
||||
Color: lipgloss.Color("39"), // Default blue
|
||||
downsampler: types.NewDownsampler(),
|
||||
// NewChart creates a new chart instance
|
||||
func NewChart(data []float64, title, unit string, width, height int, color lipgloss.Color) *Chart {
|
||||
c := &Chart{
|
||||
Data: data,
|
||||
Title: title,
|
||||
Width: width,
|
||||
Height: height,
|
||||
Color: color,
|
||||
Unit: unit,
|
||||
Mode: "sparkline",
|
||||
}
|
||||
}
|
||||
|
||||
// WithSize sets the chart dimensions
|
||||
func (c *Chart) WithSize(width, height int) *Chart {
|
||||
c.Width = width
|
||||
c.Height = height
|
||||
if len(data) > 0 {
|
||||
// Use downsampled data for min/max to improve performance
|
||||
// Using empty timestamps array since we only need value downsampling
|
||||
downsampled := types.DownsampleLTTB(data, make([]time.Time, len(data)), width)
|
||||
c.Downsampled = downsampled
|
||||
values := make([]float64, len(downsampled))
|
||||
for i, point := range downsampled {
|
||||
values[i] = point.Value
|
||||
}
|
||||
c.Min, c.Max = minMax(values)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// WithColor sets the chart color
|
||||
func (c *Chart) WithColor(color lipgloss.Color) *Chart {
|
||||
c.Color = color
|
||||
// NewBarChart creates a bar chart with axis labels
|
||||
func NewBarChart(data []float64, title string, width, height int, color lipgloss.Color, xLabels []string, yMax float64) *Chart {
|
||||
c := NewChart(data, title, "", width, height, color)
|
||||
c.Mode = "bar"
|
||||
c.XLabels = xLabels
|
||||
c.YMax = yMax
|
||||
return c
|
||||
}
|
||||
|
||||
// View renders the chart
|
||||
func (c *Chart) View() string {
|
||||
if len(c.Data) == 0 {
|
||||
return fmt.Sprintf("%s\nNo data available", c.Title)
|
||||
return c.renderNoData()
|
||||
}
|
||||
|
||||
// Downsample data if needed
|
||||
processedData := c.downsampler.Process(c.Data, c.Width)
|
||||
if c.Width <= 10 || c.Height <= 4 {
|
||||
return c.renderTooSmall()
|
||||
}
|
||||
|
||||
// Normalize data to chart height
|
||||
min, max := minMax(processedData)
|
||||
normalized := normalize(processedData, min, max, c.Height-1)
|
||||
if c.Mode == "bar" && c.YMax == 0 {
|
||||
return c.renderNoData()
|
||||
}
|
||||
|
||||
// Build chart
|
||||
// Recalculate if dimensions changed
|
||||
if len(c.Downsampled) != c.Width {
|
||||
c.Downsampled = types.DownsampleLTTB(c.Data, make([]time.Time, len(c.Data)), c.Width)
|
||||
values := make([]float64, len(c.Downsampled))
|
||||
for i, point := range c.Downsampled {
|
||||
values[i] = point.Value
|
||||
}
|
||||
c.Min, c.Max = minMax(values)
|
||||
}
|
||||
|
||||
return lipgloss.NewStyle().
|
||||
MaxWidth(c.Width).
|
||||
Render(c.renderTitle() + "\n" + c.renderChart())
|
||||
}
|
||||
|
||||
func (c *Chart) renderTitle() string {
|
||||
return lipgloss.NewStyle().
|
||||
Bold(true).
|
||||
Foreground(c.Color).
|
||||
Render(c.Title)
|
||||
}
|
||||
|
||||
func (c *Chart) renderChart() string {
|
||||
if c.Max == c.Min && c.Mode != "bar" {
|
||||
return c.renderConstantData()
|
||||
}
|
||||
|
||||
if c.Mode == "bar" {
|
||||
return c.renderBarChart()
|
||||
}
|
||||
return c.renderSparkline()
|
||||
}
|
||||
|
||||
func (c *Chart) renderBarChart() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(c.Title + "\n")
|
||||
chartHeight := c.Height - 3 // Reserve space for title and labels
|
||||
|
||||
// Create Y-axis labels
|
||||
yLabels := createYAxisLabels(min, max, c.Height-1)
|
||||
// Calculate scaling factor
|
||||
maxValue := c.YMax
|
||||
if maxValue == 0 {
|
||||
maxValue = c.Max
|
||||
}
|
||||
scale := float64(chartHeight-1) / maxValue
|
||||
|
||||
for i := c.Height - 1; i >= 0; i-- {
|
||||
// Y-axis labels
|
||||
yIncrement := maxValue / float64(chartHeight-1)
|
||||
for i := chartHeight - 1; i >= 0; i-- {
|
||||
label := fmt.Sprintf("%3.0f │", maxValue-(yIncrement*float64(i)))
|
||||
sb.WriteString(label)
|
||||
if i == 0 {
|
||||
sb.WriteString("└") // Bottom-left corner
|
||||
} else if i == c.Height-1 {
|
||||
sb.WriteString("↑") // Top axis indicator
|
||||
} else {
|
||||
sb.WriteString("│") // Y-axis line
|
||||
sb.WriteString(" " + strings.Repeat("─", c.Width))
|
||||
break
|
||||
}
|
||||
|
||||
// Add Y-axis label
|
||||
if i < len(yLabels) {
|
||||
sb.WriteString(yLabels[i])
|
||||
} else {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
|
||||
// Add chart bars
|
||||
for j := 0; j < len(normalized); j++ {
|
||||
if i == 0 {
|
||||
sb.WriteString("─") // X-axis
|
||||
// Draw bars
|
||||
for _, point := range c.Downsampled {
|
||||
barHeight := int(math.Round(point.Value * scale))
|
||||
if barHeight >= i {
|
||||
sb.WriteString("#")
|
||||
} else {
|
||||
if normalized[j] >= float64(i) {
|
||||
sb.WriteString("█") // Full block
|
||||
} else {
|
||||
// Gradient blocks based on fractional part
|
||||
frac := normalized[j] - math.Floor(normalized[j])
|
||||
if normalized[j] >= float64(i-1) && frac > 0.75 {
|
||||
sb.WriteString("▇")
|
||||
} else if normalized[j] >= float64(i-1) && frac > 0.5 {
|
||||
sb.WriteString("▅")
|
||||
} else if normalized[j] >= float64(i-1) && frac > 0.25 {
|
||||
sb.WriteString("▃")
|
||||
} else if normalized[j] >= float64(i-1) && frac > 0 {
|
||||
sb.WriteString("▁")
|
||||
} else {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
}
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
// Add X-axis title
|
||||
sb.WriteString(" " + strings.Repeat(" ", len(yLabels[0])+1) + "→ Time\n")
|
||||
// X-axis labels
|
||||
sb.WriteString("\n ")
|
||||
for i, label := range c.XLabels {
|
||||
if i >= len(c.Downsampled) {
|
||||
break
|
||||
}
|
||||
if i == 0 {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("%-*s", c.Width/len(c.XLabels), label))
|
||||
}
|
||||
|
||||
// Apply color styling
|
||||
style := lipgloss.NewStyle().Foreground(c.Color)
|
||||
return style.Render(sb.String())
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (c *Chart) renderSparkline() string {
|
||||
var sb strings.Builder
|
||||
chartHeight := c.Height - 3 // Reserve rows for title and labels
|
||||
|
||||
minLabel := fmt.Sprintf("%.0f%s", c.Min, c.Unit)
|
||||
maxLabel := fmt.Sprintf("%.0f%s", c.Max, c.Unit)
|
||||
sb.WriteString(fmt.Sprintf("%5s ", maxLabel))
|
||||
|
||||
for i, point := range c.Downsampled {
|
||||
if i >= c.Width {
|
||||
break
|
||||
}
|
||||
|
||||
normalized := (point.Value - c.Min) / (c.Max - c.Min)
|
||||
barHeight := int(math.Round(normalized * float64(chartHeight-1)))
|
||||
sb.WriteString(c.renderBar(barHeight, chartHeight))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
|
||||
// Add X axis with min label
|
||||
sb.WriteString(fmt.Sprintf("%5s ", minLabel))
|
||||
sb.WriteString(strings.Repeat("─", c.Width))
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (c *Chart) renderBar(height, maxHeight int) string {
|
||||
if height <= 0 {
|
||||
return " "
|
||||
}
|
||||
|
||||
// Use Unicode block characters for better resolution
|
||||
blocks := []string{" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"}
|
||||
index := int(float64(height) / float64(maxHeight) * 8)
|
||||
if index >= len(blocks) {
|
||||
index = len(blocks) - 1
|
||||
}
|
||||
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(c.Color).
|
||||
Render(blocks[index])
|
||||
}
|
||||
|
||||
func (c *Chart) renderNoData() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("240")).
|
||||
Render(fmt.Sprintf("%s: No data", c.Title))
|
||||
}
|
||||
|
||||
func (c *Chart) renderTooSmall() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("196")).
|
||||
Render(fmt.Sprintf("%s: Terminal too small", c.Title))
|
||||
}
|
||||
|
||||
func (c *Chart) renderConstantData() string {
|
||||
return lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("214")).
|
||||
Render(fmt.Sprintf("%s: Constant value %.2f", c.Title, c.Data[0]))
|
||||
}
|
||||
|
||||
// minMax finds min and max values in a slice
|
||||
func minMax(data []float64) (min, max float64) {
|
||||
if len(data) == 0 {
|
||||
return 0, 0
|
||||
}
|
||||
min = data[0]
|
||||
max = data[0]
|
||||
min, max = data[0], data[0]
|
||||
for _, v := range data {
|
||||
if v < min {
|
||||
min = v
|
||||
@@ -132,34 +230,3 @@ func minMax(data []float64) (min, max float64) {
|
||||
}
|
||||
return min, max
|
||||
}
|
||||
|
||||
// normalize scales values to fit within chart height
|
||||
func normalize(data []float64, min, max float64, height int) []float64 {
|
||||
if max == min || height <= 0 {
|
||||
return make([]float64, len(data))
|
||||
}
|
||||
|
||||
scale := float64(height) / (max - min)
|
||||
normalized := make([]float64, len(data))
|
||||
for i, v := range data {
|
||||
normalized[i] = (v - min) * scale
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
// createYAxisLabels creates labels for Y-axis
|
||||
func createYAxisLabels(min, max float64, height int) []string {
|
||||
labels := make([]string, height+1)
|
||||
step := (max - min) / float64(height)
|
||||
|
||||
for i := 0; i <= height; i++ {
|
||||
value := min + float64(i)*step
|
||||
label := fmt.Sprintf("%.0f", value)
|
||||
// Pad to consistent width (5 characters)
|
||||
if len(label) < 5 {
|
||||
label = strings.Repeat(" ", 5-len(label)) + label
|
||||
}
|
||||
labels[height-i] = label
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
@@ -1,63 +1,84 @@
|
||||
package types
|
||||
|
||||
// Downsampler implements the Largest-Triangle-Three-Buckets algorithm
|
||||
type Downsampler struct{}
|
||||
import "time"
|
||||
|
||||
// NewDownsampler creates a new Downsampler instance
|
||||
func NewDownsampler() *Downsampler {
|
||||
return &Downsampler{}
|
||||
type DownsampledPoint struct {
|
||||
Timestamp time.Time
|
||||
Value float64
|
||||
}
|
||||
|
||||
// Process downsamples data using Largest-Triangle-Three-Buckets algorithm
|
||||
func (d *Downsampler) Process(data []float64, threshold int) []float64 {
|
||||
if len(data) <= threshold || threshold <= 0 {
|
||||
return data
|
||||
// DownsampleLTTB implements the Largest Triangle Three Buckets algorithm
|
||||
// for time series downsampling. This is a corrected version that properly
|
||||
// uses the current module path.
|
||||
func DownsampleLTTB(data []float64, timestamps []time.Time, threshold int) []DownsampledPoint {
|
||||
if len(data) != len(timestamps) {
|
||||
panic("data and timestamps must be same length")
|
||||
}
|
||||
|
||||
sampled := make([]float64, 0, threshold)
|
||||
sampled = append(sampled, data[0]) // First point
|
||||
if threshold >= len(data) || threshold <= 0 {
|
||||
result := make([]DownsampledPoint, len(data))
|
||||
for i := range data {
|
||||
result[i] = DownsampledPoint{
|
||||
Timestamp: timestamps[i],
|
||||
Value: data[i],
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
sampled := make([]DownsampledPoint, threshold)
|
||||
sampled[0] = DownsampledPoint{Timestamp: timestamps[0], Value: data[0]}
|
||||
|
||||
bucketSize := float64(len(data)-2) / float64(threshold-2)
|
||||
a := 0
|
||||
|
||||
for i := 1; i < threshold-1; i++ {
|
||||
bucketStart := int(float64(i-1)*bucketSize) + 1
|
||||
bucketEnd := int(float64(i)*bucketSize) + 1
|
||||
for i := 0; i < threshold-2; i++ {
|
||||
avgRangeStart := int(float64(i+1)*bucketSize) + 1
|
||||
avgRangeEnd := int(float64(i+2)*bucketSize) + 1
|
||||
if avgRangeEnd > len(data) {
|
||||
avgRangeEnd = len(data)
|
||||
}
|
||||
|
||||
if bucketEnd >= len(data) {
|
||||
bucketEnd = len(data) - 1
|
||||
var avgRange float64
|
||||
for j := avgRangeStart; j < avgRangeEnd; j++ {
|
||||
avgRange += data[j]
|
||||
}
|
||||
avgRange /= float64(avgRangeEnd - avgRangeStart)
|
||||
|
||||
rangeOffs := int(float64(i)*bucketSize) + 1
|
||||
rangeTo := int(float64(i+1)*bucketSize) + 1
|
||||
if rangeTo > len(data) {
|
||||
rangeTo = len(data)
|
||||
}
|
||||
|
||||
maxArea := -1.0
|
||||
selectedPoint := data[bucketStart]
|
||||
|
||||
for j := bucketStart; j < bucketEnd; j++ {
|
||||
area := triangleArea(
|
||||
data[bucketStart-1],
|
||||
nextAAt := 0
|
||||
for j := rangeOffs; j < rangeTo; j++ {
|
||||
area := areaSize(
|
||||
data[a],
|
||||
data[j],
|
||||
data[bucketEnd],
|
||||
avgRange,
|
||||
)
|
||||
|
||||
if area > maxArea {
|
||||
maxArea = area
|
||||
selectedPoint = data[j]
|
||||
nextAAt = j
|
||||
}
|
||||
}
|
||||
|
||||
sampled = append(sampled, selectedPoint)
|
||||
sampled[i+1] = DownsampledPoint{
|
||||
Timestamp: timestamps[nextAAt],
|
||||
Value: data[nextAAt],
|
||||
}
|
||||
a = nextAAt
|
||||
}
|
||||
|
||||
sampled = append(sampled, data[len(data)-1]) // Last point
|
||||
sampled[threshold-1] = DownsampledPoint{
|
||||
Timestamp: timestamps[len(timestamps)-1],
|
||||
Value: data[len(data)-1],
|
||||
}
|
||||
return sampled
|
||||
}
|
||||
|
||||
// triangleArea calculates the area of a triangle formed by three points
|
||||
func triangleArea(a, b, c float64) float64 {
|
||||
return abs((a-b)*(c-b)-(b-c)*(a-c)) / 2
|
||||
}
|
||||
|
||||
func abs(x float64) float64 {
|
||||
if x < 0 {
|
||||
return -x
|
||||
}
|
||||
return x
|
||||
func areaSize(a, b, avg float64) float64 {
|
||||
return (a-avg)*(a-avg) + (b-avg)*(b-avg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user