whytrend 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. whytrend-0.1.0/.github/workflows/ci.yml +38 -0
  2. whytrend-0.1.0/.gitignore +34 -0
  3. whytrend-0.1.0/LICENSE +201 -0
  4. whytrend-0.1.0/NOTICE +7 -0
  5. whytrend-0.1.0/PKG-INFO +226 -0
  6. whytrend-0.1.0/README.md +172 -0
  7. whytrend-0.1.0/To +0 -0
  8. whytrend-0.1.0/examples/mvp_demo.py +59 -0
  9. whytrend-0.1.0/pyproject.toml +83 -0
  10. whytrend-0.1.0/src/whytrend/__init__.py +33 -0
  11. whytrend-0.1.0/src/whytrend/collectors/__init__.py +9 -0
  12. whytrend-0.1.0/src/whytrend/collectors/_http.py +39 -0
  13. whytrend-0.1.0/src/whytrend/collectors/_utils.py +36 -0
  14. whytrend-0.1.0/src/whytrend/collectors/hacker_news.py +90 -0
  15. whytrend-0.1.0/src/whytrend/collectors/wikipedia.py +95 -0
  16. whytrend-0.1.0/src/whytrend/core/__init__.py +62 -0
  17. whytrend-0.1.0/src/whytrend/core/enums.py +22 -0
  18. whytrend-0.1.0/src/whytrend/core/models.py +150 -0
  19. whytrend-0.1.0/src/whytrend/core/protocols.py +198 -0
  20. whytrend-0.1.0/src/whytrend/core/series.py +166 -0
  21. whytrend-0.1.0/src/whytrend/detectors/__init__.py +9 -0
  22. whytrend-0.1.0/src/whytrend/detectors/_utils.py +34 -0
  23. whytrend-0.1.0/src/whytrend/detectors/prophet.py +102 -0
  24. whytrend-0.1.0/src/whytrend/detectors/zscore.py +93 -0
  25. whytrend-0.1.0/src/whytrend/events/__init__.py +5 -0
  26. whytrend-0.1.0/src/whytrend/events/builder.py +63 -0
  27. whytrend-0.1.0/src/whytrend/explainers/__init__.py +13 -0
  28. whytrend-0.1.0/src/whytrend/explainers/llm.py +25 -0
  29. whytrend-0.1.0/src/whytrend/explainers/ollama.py +30 -0
  30. whytrend-0.1.0/src/whytrend/explainers/openai.py +30 -0
  31. whytrend-0.1.0/src/whytrend/llm/__init__.py +11 -0
  32. whytrend-0.1.0/src/whytrend/llm/_parsing.py +81 -0
  33. whytrend-0.1.0/src/whytrend/llm/mock.py +44 -0
  34. whytrend-0.1.0/src/whytrend/llm/ollama.py +95 -0
  35. whytrend-0.1.0/src/whytrend/llm/openai.py +77 -0
  36. whytrend-0.1.0/src/whytrend/llm/prompts.py +61 -0
  37. whytrend-0.1.0/src/whytrend/pipeline.py +148 -0
  38. whytrend-0.1.0/src/whytrend/preprocessing/__init__.py +1 -0
  39. whytrend-0.1.0/src/whytrend/rankers/__init__.py +9 -0
  40. whytrend-0.1.0/src/whytrend/rankers/_bm25.py +65 -0
  41. whytrend-0.1.0/src/whytrend/rankers/_utils.py +49 -0
  42. whytrend-0.1.0/src/whytrend/rankers/bm25.py +47 -0
  43. whytrend-0.1.0/src/whytrend/rankers/embedding.py +82 -0
  44. whytrend-0.1.0/src/whytrend/report/__init__.py +9 -0
  45. whytrend-0.1.0/src/whytrend/report/json_renderer.py +25 -0
  46. whytrend-0.1.0/src/whytrend/report/markdown_renderer.py +81 -0
  47. whytrend-0.1.0/src/whytrend/sources/__init__.py +13 -0
  48. whytrend-0.1.0/src/whytrend/sources/_io.py +42 -0
  49. whytrend-0.1.0/src/whytrend/sources/csv.py +57 -0
  50. whytrend-0.1.0/src/whytrend/sources/google_trends.py +84 -0
  51. whytrend-0.1.0/src/whytrend/sources/pandas_source.py +47 -0
  52. whytrend-0.1.0/src/whytrend/sources/parquet.py +57 -0
  53. whytrend-0.1.0/tests/__init__.py +0 -0
  54. whytrend-0.1.0/tests/conftest.py +100 -0
  55. whytrend-0.1.0/tests/fixtures/python_interest.csv +6 -0
  56. whytrend-0.1.0/tests/stubs.py +113 -0
  57. whytrend-0.1.0/tests/test_collectors.py +125 -0
  58. whytrend-0.1.0/tests/test_core_models.py +94 -0
  59. whytrend-0.1.0/tests/test_core_series.py +56 -0
  60. whytrend-0.1.0/tests/test_detectors.py +100 -0
  61. whytrend-0.1.0/tests/test_event_builder.py +50 -0
  62. whytrend-0.1.0/tests/test_llm.py +186 -0
  63. whytrend-0.1.0/tests/test_pipeline.py +97 -0
  64. whytrend-0.1.0/tests/test_rankers.py +125 -0
  65. whytrend-0.1.0/tests/test_report.py +77 -0
  66. whytrend-0.1.0/tests/test_sources.py +110 -0
@@ -0,0 +1,38 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ quality:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.11", "3.12"]
16
+
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -e ".[dev]"
30
+
31
+ - name: Ruff
32
+ run: ruff check src tests examples
33
+
34
+ - name: Mypy
35
+ run: mypy src/whytrend
36
+
37
+ - name: Pytest
38
+ run: pytest
@@ -0,0 +1,34 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ .eggs/
7
+ dist/
8
+ build/
9
+ *.egg
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Tooling
17
+ uv.lock
18
+ .mypy_cache/
19
+ .ruff_cache/
20
+ .pytest_cache/
21
+ .coverage
22
+ htmlcov/
23
+
24
+ # IDE
25
+ .idea/
26
+ .vscode/
27
+ *.swp
28
+
29
+ # Environment & secrets
30
+ .env
31
+ .env.*
32
+
33
+ # OS
34
+ .DS_Store
whytrend-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Alexander Provatorov
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
whytrend-0.1.0/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ WhyTrend
2
+ Copyright 2026 Alexander Provatorov
3
+
4
+ Created and maintained by Alexander Provatorov (https://github.com/AlexProvatorov).
5
+
6
+ Licensed under the Apache License, Version 2.0.
7
+ See the LICENSE file for the full license text.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: whytrend
3
+ Version: 0.1.0
4
+ Summary: Open Source Framework for Explainable Time Series Analysis
5
+ Project-URL: Homepage, https://github.com/AlexProvatorov/WhyTrend
6
+ Project-URL: Documentation, https://github.com/AlexProvatorov/WhyTrend#readme
7
+ Project-URL: Repository, https://github.com/AlexProvatorov/WhyTrend
8
+ Project-URL: Issues, https://github.com/AlexProvatorov/WhyTrend/issues
9
+ Author-email: Alexander Provatorov <sasha.provatorov@gmail.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: anomaly-detection,changepoint,explainability,llm,time-series
14
+ Classifier: Development Status :: 2 - Pre-Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: httpx>=0.27
24
+ Requires-Dist: pandas>=2.0
25
+ Requires-Dist: pydantic>=2.0
26
+ Provides-Extra: all
27
+ Requires-Dist: openai>=1.0; extra == 'all'
28
+ Requires-Dist: prophet>=1.1; extra == 'all'
29
+ Requires-Dist: pyarrow>=15.0; extra == 'all'
30
+ Requires-Dist: pytrends>=4.9; extra == 'all'
31
+ Requires-Dist: ruptures>=1.1; extra == 'all'
32
+ Requires-Dist: sentence-transformers>=3.0; extra == 'all'
33
+ Provides-Extra: dev
34
+ Requires-Dist: mypy>=1.13; extra == 'dev'
35
+ Requires-Dist: pandas-stubs>=2.0; extra == 'dev'
36
+ Requires-Dist: pyarrow>=15.0; extra == 'dev'
37
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
38
+ Requires-Dist: pytest>=8.0; extra == 'dev'
39
+ Requires-Dist: pytrends>=4.9; extra == 'dev'
40
+ Requires-Dist: ruff>=0.8; extra == 'dev'
41
+ Provides-Extra: openai
42
+ Requires-Dist: openai>=1.0; extra == 'openai'
43
+ Provides-Extra: parquet
44
+ Requires-Dist: pyarrow>=15.0; extra == 'parquet'
45
+ Provides-Extra: prophet
46
+ Requires-Dist: prophet>=1.1; extra == 'prophet'
47
+ Provides-Extra: ranking
48
+ Requires-Dist: sentence-transformers>=3.0; extra == 'ranking'
49
+ Provides-Extra: ruptures
50
+ Requires-Dist: ruptures>=1.1; extra == 'ruptures'
51
+ Provides-Extra: trends
52
+ Requires-Dist: pytrends>=4.9; extra == 'trends'
53
+ Description-Content-Type: text/markdown
54
+
55
+ # WhyTrend
56
+
57
+ [![CI](https://github.com/AlexProvatorov/WhyTrend/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexProvatorov/WhyTrend/actions/workflows/ci.yml)
58
+ [![PyPI](https://img.shields.io/pypi/v/whytrend.svg)](https://pypi.org/project/whytrend/)
59
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
60
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
61
+
62
+ **Open Source Framework for Explainable Time Series Analysis**
63
+
64
+ WhyTrend detects anomalies, change points, and trend shifts in time series — then automatically explains *why* they happened using external context and LLMs.
65
+
66
+ If this project is useful to you, consider giving it a **star** on GitHub — it helps others discover the project. Forks and pull requests are welcome.
67
+
68
+ ## Features
69
+
70
+ - Fluent `Pipeline` API for source → detection → collection → ranking → explanation
71
+ - Pluggable sources, detectors, collectors, rankers, and LLM providers
72
+ - Structured `Report` output (JSON and Markdown)
73
+ - Async collectors and LLM calls
74
+ - Works offline with `MockLLMProvider` and local models via `OllamaExplainer`
75
+
76
+ ## Installation
77
+
78
+ ### From PyPI
79
+
80
+ ```bash
81
+ pip install whytrend
82
+ ```
83
+
84
+ ### Optional extras
85
+
86
+ ```bash
87
+ pip install "whytrend[openai]" # OpenAI API
88
+ pip install "whytrend[trends]" # Google Trends
89
+ pip install "whytrend[prophet]" # Prophet detector
90
+ pip install "whytrend[ranking]" # Embedding ranker
91
+ pip install "whytrend[all]" # everything
92
+ ```
93
+
94
+ ### From source (development)
95
+
96
+ ```bash
97
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
98
+ cd WhyTrend
99
+ python -m venv .venv
100
+ source .venv/bin/activate
101
+ pip install -e ".[dev]"
102
+ ```
103
+
104
+ ## Quickstart (CSV, no API keys)
105
+
106
+ ```python
107
+ from whytrend import (
108
+ BM25Ranker,
109
+ CSVSource,
110
+ LLMExplainer,
111
+ MockLLMProvider,
112
+ Pipeline,
113
+ ZScoreDetector,
114
+ )
115
+
116
+ pipeline = (
117
+ Pipeline(window_days=3)
118
+ .add_source(CSVSource("your_series.csv", keyword="Python"))
119
+ .add_detector(ZScoreDetector(threshold=1.0))
120
+ .add_ranker(BM25Ranker(top_k=5))
121
+ .add_explainer(LLMExplainer(MockLLMProvider()))
122
+ )
123
+
124
+ report = pipeline.run()
125
+ print(report.executive_summary)
126
+ print(report.to_markdown())
127
+ ```
128
+
129
+ CSV must have `timestamp` and `value` columns. When developing from a clone, you can use
130
+ `tests/fixtures/python_interest.csv` as sample data.
131
+
132
+ Run the full demo (requires a repository clone):
133
+
134
+ ```bash
135
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
136
+ cd WhyTrend
137
+ pip install -e ".[dev]"
138
+ python examples/mvp_demo.py
139
+ ```
140
+
141
+ ## Production-style example
142
+
143
+ ```python
144
+ from whytrend import (
145
+ GoogleTrends,
146
+ OpenAIExplainer,
147
+ Pipeline,
148
+ ProphetDetector,
149
+ )
150
+ from whytrend.collectors import HackerNewsCollector, WikipediaCollector
151
+ from whytrend.rankers import BM25Ranker
152
+
153
+ pipeline = (
154
+ Pipeline()
155
+ .add_source(GoogleTrends("Python"))
156
+ .add_detector(ProphetDetector())
157
+ .add_collector(HackerNewsCollector())
158
+ .add_collector(WikipediaCollector())
159
+ .add_ranker(BM25Ranker())
160
+ .add_explainer(OpenAIExplainer()) # OPENAI_API_KEY env var or api_key="..."
161
+ )
162
+
163
+ report = pipeline.run()
164
+ print(report.executive_summary)
165
+ ```
166
+
167
+ Use `OllamaExplainer(model="llama3.2")` for a local LLM instead of OpenAI.
168
+
169
+ For OpenAI, pass a key explicitly or set the environment variable:
170
+
171
+ ```python
172
+ OpenAIExplainer(api_key="sk-...")
173
+ # or: export OPENAI_API_KEY=sk-...
174
+ ```
175
+
176
+ ## Architecture
177
+
178
+ ```
179
+ Source → Detector → Event Builder → Collectors → Ranker → Explainer → Report
180
+ ```
181
+
182
+ ## Roadmap
183
+
184
+ Core MVP is in place. Next focus: **integrations and ecosystem**.
185
+
186
+ ### v0.2 — More collectors
187
+ - [ ] Google News
188
+ - [ ] Reddit
189
+ - [ ] GitHub Releases
190
+ - [ ] RSS / Stack Overflow
191
+
192
+ ### v0.3 — More detectors
193
+ - [ ] Ruptures (change-point)
194
+ - [ ] River / streaming detectors
195
+
196
+ ### v0.4 — More LLM providers
197
+ - [ ] Anthropic, Gemini, DeepSeek
198
+ - [ ] Azure OpenAI, OpenRouter
199
+
200
+ ### v0.5 — Reports and DX
201
+ - [ ] HTML / PDF reports
202
+ - [ ] CLI (`whytrend analyze ...`)
203
+ - [ ] Plugin registry (entry points)
204
+
205
+ Track progress in [GitHub Issues](https://github.com/AlexProvatorov/WhyTrend/issues).
206
+
207
+ ## Development
208
+
209
+ Requires a repository clone:
210
+
211
+ ```bash
212
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
213
+ cd WhyTrend
214
+ pip install -e ".[dev]"
215
+ ruff check src tests
216
+ mypy src/whytrend
217
+ pytest
218
+ ```
219
+
220
+ ## Author
221
+
222
+ **Alexander Provatorov** — [GitHub @AlexProvatorov](https://github.com/AlexProvatorov)
223
+
224
+ ## License
225
+
226
+ Licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,172 @@
1
+ # WhyTrend
2
+
3
+ [![CI](https://github.com/AlexProvatorov/WhyTrend/actions/workflows/ci.yml/badge.svg)](https://github.com/AlexProvatorov/WhyTrend/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/whytrend.svg)](https://pypi.org/project/whytrend/)
5
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
6
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
7
+
8
+ **Open Source Framework for Explainable Time Series Analysis**
9
+
10
+ WhyTrend detects anomalies, change points, and trend shifts in time series — then automatically explains *why* they happened using external context and LLMs.
11
+
12
+ If this project is useful to you, consider giving it a **star** on GitHub — it helps others discover the project. Forks and pull requests are welcome.
13
+
14
+ ## Features
15
+
16
+ - Fluent `Pipeline` API for source → detection → collection → ranking → explanation
17
+ - Pluggable sources, detectors, collectors, rankers, and LLM providers
18
+ - Structured `Report` output (JSON and Markdown)
19
+ - Async collectors and LLM calls
20
+ - Works offline with `MockLLMProvider` and local models via `OllamaExplainer`
21
+
22
+ ## Installation
23
+
24
+ ### From PyPI
25
+
26
+ ```bash
27
+ pip install whytrend
28
+ ```
29
+
30
+ ### Optional extras
31
+
32
+ ```bash
33
+ pip install "whytrend[openai]" # OpenAI API
34
+ pip install "whytrend[trends]" # Google Trends
35
+ pip install "whytrend[prophet]" # Prophet detector
36
+ pip install "whytrend[ranking]" # Embedding ranker
37
+ pip install "whytrend[all]" # everything
38
+ ```
39
+
40
+ ### From source (development)
41
+
42
+ ```bash
43
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
44
+ cd WhyTrend
45
+ python -m venv .venv
46
+ source .venv/bin/activate
47
+ pip install -e ".[dev]"
48
+ ```
49
+
50
+ ## Quickstart (CSV, no API keys)
51
+
52
+ ```python
53
+ from whytrend import (
54
+ BM25Ranker,
55
+ CSVSource,
56
+ LLMExplainer,
57
+ MockLLMProvider,
58
+ Pipeline,
59
+ ZScoreDetector,
60
+ )
61
+
62
+ pipeline = (
63
+ Pipeline(window_days=3)
64
+ .add_source(CSVSource("your_series.csv", keyword="Python"))
65
+ .add_detector(ZScoreDetector(threshold=1.0))
66
+ .add_ranker(BM25Ranker(top_k=5))
67
+ .add_explainer(LLMExplainer(MockLLMProvider()))
68
+ )
69
+
70
+ report = pipeline.run()
71
+ print(report.executive_summary)
72
+ print(report.to_markdown())
73
+ ```
74
+
75
+ CSV must have `timestamp` and `value` columns. When developing from a clone, you can use
76
+ `tests/fixtures/python_interest.csv` as sample data.
77
+
78
+ Run the full demo (requires a repository clone):
79
+
80
+ ```bash
81
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
82
+ cd WhyTrend
83
+ pip install -e ".[dev]"
84
+ python examples/mvp_demo.py
85
+ ```
86
+
87
+ ## Production-style example
88
+
89
+ ```python
90
+ from whytrend import (
91
+ GoogleTrends,
92
+ OpenAIExplainer,
93
+ Pipeline,
94
+ ProphetDetector,
95
+ )
96
+ from whytrend.collectors import HackerNewsCollector, WikipediaCollector
97
+ from whytrend.rankers import BM25Ranker
98
+
99
+ pipeline = (
100
+ Pipeline()
101
+ .add_source(GoogleTrends("Python"))
102
+ .add_detector(ProphetDetector())
103
+ .add_collector(HackerNewsCollector())
104
+ .add_collector(WikipediaCollector())
105
+ .add_ranker(BM25Ranker())
106
+ .add_explainer(OpenAIExplainer()) # OPENAI_API_KEY env var or api_key="..."
107
+ )
108
+
109
+ report = pipeline.run()
110
+ print(report.executive_summary)
111
+ ```
112
+
113
+ Use `OllamaExplainer(model="llama3.2")` for a local LLM instead of OpenAI.
114
+
115
+ For OpenAI, pass a key explicitly or set the environment variable:
116
+
117
+ ```python
118
+ OpenAIExplainer(api_key="sk-...")
119
+ # or: export OPENAI_API_KEY=sk-...
120
+ ```
121
+
122
+ ## Architecture
123
+
124
+ ```
125
+ Source → Detector → Event Builder → Collectors → Ranker → Explainer → Report
126
+ ```
127
+
128
+ ## Roadmap
129
+
130
+ Core MVP is in place. Next focus: **integrations and ecosystem**.
131
+
132
+ ### v0.2 — More collectors
133
+ - [ ] Google News
134
+ - [ ] Reddit
135
+ - [ ] GitHub Releases
136
+ - [ ] RSS / Stack Overflow
137
+
138
+ ### v0.3 — More detectors
139
+ - [ ] Ruptures (change-point)
140
+ - [ ] River / streaming detectors
141
+
142
+ ### v0.4 — More LLM providers
143
+ - [ ] Anthropic, Gemini, DeepSeek
144
+ - [ ] Azure OpenAI, OpenRouter
145
+
146
+ ### v0.5 — Reports and DX
147
+ - [ ] HTML / PDF reports
148
+ - [ ] CLI (`whytrend analyze ...`)
149
+ - [ ] Plugin registry (entry points)
150
+
151
+ Track progress in [GitHub Issues](https://github.com/AlexProvatorov/WhyTrend/issues).
152
+
153
+ ## Development
154
+
155
+ Requires a repository clone:
156
+
157
+ ```bash
158
+ git clone https://github.com/AlexProvatorov/WhyTrend.git
159
+ cd WhyTrend
160
+ pip install -e ".[dev]"
161
+ ruff check src tests
162
+ mypy src/whytrend
163
+ pytest
164
+ ```
165
+
166
+ ## Author
167
+
168
+ **Alexander Provatorov** — [GitHub @AlexProvatorov](https://github.com/AlexProvatorov)
169
+
170
+ ## License
171
+
172
+ Licensed under the [Apache License, Version 2.0](LICENSE).
whytrend-0.1.0/To ADDED
File without changes