Skip to content

Commit 3253c34

Browse files
Merge pull request #124 from burinc/pyodide-time-series-fixes
Fix Time Series demo and improve Pyodide article layout
2 parents c5e5c09 + 477e1d9 commit 3253c34

3 files changed

Lines changed: 357 additions & 264 deletions

File tree

src/scittle/pyodide/interactive_data_analysis.cljs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,16 @@
488488
(defonce init-done?
489489
(do
490490
(js/console.log "🚀 Interactive Data Analysis demo mounted")
491-
;; Initialize Pyodide first
492-
(-> (pyodide/init!)
493-
(.then (fn []
494-
(js/console.log "✓ Pyodide ready, loading pandas...")
495-
(load-pandas!))))
491+
;; Wait for Pyodide to be ready, then load pandas
492+
(letfn [(try-load []
493+
(if (pyodide/ready?)
494+
(do
495+
(js/console.log "✓ Pyodide ready, loading pandas...")
496+
(load-pandas!))
497+
(do
498+
(js/console.log "⏳ Pyodide not ready, retrying in 500ms...")
499+
(js/setTimeout try-load 500))))]
500+
(js/setTimeout try-load 100))
496501
true))
497502

498503
(rdom/render [main-component] (js/document.getElementById "interactive-data-analysis"))

src/scittle/pyodide/pyodide_integration.clj

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
^:kindly/hide-code
23
^{:kindly/options {:html/deps [:scittle :reagent]}
34
:clay {:title "Python + ClojureScript: Pyodide Integration with Scittle"
@@ -61,6 +62,20 @@
6162

6263
;; **Think of it as Python's REPL, but in your browser.**
6364

65+
;; ## Loading Pyodide
66+
67+
;; Before we can run any demos, we need to load Pyodide once. This happens automatically
68+
;; when you visit this page - the scripts below will load Pyodide from the CDN and
69+
;; initialize our shared bridge that all demos will use.
70+
71+
^:kindly/hide-code
72+
(kind/html
73+
"<script src=\"https://cdn.jsdelivr.net/pyodide/v0.28.3/full/pyodide.js\"></script>")
74+
75+
^:kindly/hide-code
76+
(kind/html
77+
"<script type=\"application/x-scittle\" src=\"pyodide_bridge.cljs\"></script>")
78+
6479
;; ## Simple Example: Hello Python
6580

6681
;; Let's start with the simplest possible example - loading Pyodide and running Python code.
@@ -74,14 +89,10 @@
7489

7590
;; ### Try It Live
7691

92+
^:kindly/hide-code
7793
(kind/hiccup
7894
[:div#hello-python-demo {:style {:min-height "400px"}}
79-
;; Load Pyodide CDN first - this provides js/loadPyodide
80-
[:script {:src "https://cdn.jsdelivr.net/pyodide/v0.28.3/full/pyodide.js"}]
81-
;; Then load the shared Pyodide bridge
82-
[:script {:type "application/x-scittle"
83-
:src "pyodide_bridge.cljs"}]
84-
;; Finally load the demo
95+
;; Load the demo (Pyodide and bridge already loaded globally)
8596
[:script {:type "application/x-scittle"
8697
:src "hello_python.cljs"}]])
8798

@@ -108,6 +119,7 @@
108119

109120
;; ### Try It Live
110121

122+
^:kindly/hide-code
111123
(kind/hiccup
112124
[:div#code-editor-demo {:style {:min-height "500px"}}
113125
;; Load the code editor (Pyodide is already loaded from first demo)
@@ -127,6 +139,7 @@
127139

128140
;; ### Try It Live
129141

142+
^:kindly/hide-code
130143
(kind/hiccup
131144
[:div#data-visualization-demo {:style {:min-height "700px"}}
132145
;; Load the data visualization demo (uses already-loaded Pyodide)
@@ -155,6 +168,7 @@
155168

156169
;; ### Try It Live
157170

171+
^:kindly/hide-code
158172
(kind/hiccup
159173
[:div#pandas-demo {:style {:min-height "700px"}}
160174
;; Load the pandas demo (uses already-loaded Pyodide)
@@ -214,12 +228,89 @@
214228

215229
;; ### Try It Live
216230

231+
^:kindly/hide-code
217232
(kind/hiccup
218233
[:div#pandas-viz-demo {:style {:min-height "800px"}}
219234
;; Load the combined pandas + matplotlib workflow demo
220235
[:script {:type "application/x-scittle"
221236
:src "pandas_viz_demo.cljs"}]])
222237

238+
;; ## Interactive Data Analysis
239+
240+
;; Want to analyze your own data? Upload CSV files and explore them interactively with Pandas!
241+
242+
;; ### Key Features
243+
244+
;; - **CSV Upload** - Drag & drop or click to upload your data files
245+
;; - **Data Preview** - See your data in formatted tables
246+
;; - **Statistical Summary** - Automatic descriptive statistics
247+
;; - **Data Info** - Column types, null counts, memory usage
248+
;; - **Export Results** - Download processed data as CSV
249+
250+
;; ### What You Can Do
251+
252+
;; The demo processes your CSV data through Pandas and displays:
253+
254+
;; - First 10 rows of your dataset
255+
;; - Complete statistical summary (mean, std, min, max, quartiles)
256+
;; - Data types for each column
257+
;; - Null value counts
258+
;; - Memory usage information
259+
260+
;; Perfect for quick exploratory data analysis without installing anything!
261+
262+
;; ### Try It Live
263+
264+
^:kindly/hide-code
265+
(kind/hiccup
266+
[:div#interactive-data-analysis
267+
;; Load the interactive data analysis demo (uses already-loaded Pyodide)
268+
[:script {:type "application/x-scittle"
269+
:src "interactive_data_analysis.cljs"}]])
270+
271+
;; ## Time Series Analysis
272+
273+
;; Analyze temporal patterns with moving averages, trends, and volatility using Pandas and Matplotlib!
274+
275+
;; ### Two Complete Examples
276+
277+
;; **📈 Stock Market Analysis:**
278+
279+
;; - Price trends with 5-day and 10-day moving averages
280+
;; - Daily returns (percentage changes)
281+
;; - Trading volume analysis
282+
;; - 5-day rolling volatility (risk measurement)
283+
284+
;; **🌡️ Sensor Data Analysis:**
285+
286+
;; - Temperature and humidity patterns over 24 hours
287+
;; - 3-hour moving averages for trend smoothing
288+
;; - Correlation analysis (temperature vs humidity)
289+
;; - Daily pattern visualization
290+
291+
;; ### Time Series Techniques
292+
293+
;; - **Moving Averages** - Smooth out noise to reveal trends
294+
;; - **Returns Analysis** - Calculate daily percentage changes
295+
;; - **Volatility Metrics** - Measure fluctuation using rolling standard deviation
296+
;; - **Correlation Analysis** - Understand relationships between variables
297+
;; - **Pattern Recognition** - Detect daily/seasonal patterns
298+
299+
;; ### What You'll Learn
300+
301+
;; - How to calculate and visualize moving averages
302+
;; - Identifying trend direction and potential reversals
303+
;; - Measuring market/data stability and risk
304+
;; - Understanding inverse correlations in environmental data
305+
;; - Analyzing complete 24-hour cycles
306+
307+
^:kindly/hide-code
308+
(kind/hiccup
309+
[:div#time-series-analysis
310+
;; Load the time series analysis demo (uses already-loaded Pyodide)
311+
[:script {:type "application/x-scittle"
312+
:src "time_series_demo.cljs"}]])
313+
223314
;; ## What's Possible?
224315

225316
;; With Pyodide + Scittle, you can:
@@ -230,23 +321,33 @@
230321
;; - 🐼 **Data Analysis** - Process and analyze data with Pandas DataFrames
231322
;; - 📈 **Statistical Analysis** - Descriptive statistics, correlations, grouping
232323
;; - 🎯 **Complete Workflows** - Combine pandas analysis with matplotlib visualizations
324+
;; - 📂 **File Upload & Processing** - Analyze your own CSV data files
325+
;; - 📉 **Time Series Analysis** - Moving averages, trends, volatility, and patterns
233326
;; - 🎨 **Custom UIs** - Wrap Python functionality in beautiful ClojureScript UIs
234327

235328
;; ## Next Steps
236329

237-
;; Explore more advanced features:
330+
;; Want to dive deeper? Try:
331+
332+
;; - Experimenting with the Interactive Data Analysis demo above - upload your own CSV files!
333+
;; - Exploring the Time Series Analysis demo - switch between stock and sensor data
334+
;; - Modifying the code in any demo to create your own visualizations
238335

239-
;; - Advanced pandas operations (joins, pivots, time series)
240-
;; - Interactive data exploration with dynamic filtering
336+
;; Or explore advanced topics:
337+
338+
;; - Advanced pandas operations (joins, pivots, time series decomposition)
241339
;; - Machine learning with scikit-learn
242340
;; - Custom Python packages and modules
341+
;; - Building complete data science applications
243342

244343
;; ---
245344

246345
;; ## Acknowledgments
247346

248347
;; A special thanks to [Timothy Pratley](https://github.com/timothypratley) for creating ClojureCivitas - a welcoming space where the Clojure community can come together to share knowledge, experiences, and our collective love for the Clojure/ClojureScript ecosystem. Projects like this thrive when we have platforms to showcase what's possible and inspire others to explore.
249348

349+
;; Huge appreciation to [Daniel Slutsky](https://github.com/daslu) for co-creating and maintaining the incredible [Scicloj](https://scicloj.github.io/) ecosystem of tools - including Clay, Kindly, and many other libraries that make sharing and exploring data in Clojure not just easier, but genuinely fun. This article wouldn't exist without Clay's elegant approach to literate programming and data visualization.
350+
250351
;; ---
251352

252353
;; **Questions?** Find me on Clojurians Slack (@agilecreativity)

0 commit comments

Comments
 (0)