Skip to content

Commit b2f2b1d

Browse files
committed
docs: enhance query language examples and reference existing query_client.py
- Add detailed magic variables example with __CATEGORIES__ usage - Include minimal and hierarchy query examples from original docs - Reference the existing query_client.py practical example - Improve query language documentation while maintaining safety focus
1 parent 7692b59 commit b2f2b1d

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/examples/working-with-data.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,44 @@ The web UI provides special variables you can use:
123123
* ``__CATEGORIES__`` - Your configured categorization rules
124124
* ``find_bucket(pattern)`` - Find bucket names matching a pattern
125125

126+
Example using categories to filter work activities:
127+
128+
.. code-block:: javascript
129+
130+
events = flood(query_bucket(find_bucket("aw-watcher-window_")));
131+
not_afk = flood(query_bucket(find_bucket("aw-watcher-afk_")));
132+
not_afk = filter_keyvals(not_afk, "status", ["not-afk"]);
133+
events = filter_period_intersect(events, not_afk);
134+
events = categorize(events, __CATEGORIES__);
135+
events = filter_keyvals(events, "$category", [["Work"]]);
136+
RETURN = sort_by_duration(events);
137+
138+
Query Examples
139+
~~~~~~~~~~~~~~
140+
141+
**Minimal example** - Get events from a bucket:
142+
143+
.. code-block:: javascript
144+
145+
events = query_bucket("my_bucket");
146+
RETURN = events;
147+
148+
**Hierarchy example** - Create app→title hierarchy:
149+
150+
.. code-block:: javascript
151+
152+
events = query_bucket("my_bucket");
153+
events = merge_events_by_keys(events, ["app", "title"]);
154+
RETURN = events;
155+
156+
**Practical Python example** - The `query_client.py <query_client.py>`_ file demonstrates:
157+
158+
* Creating test buckets and data
159+
* Writing queries with transformations
160+
* Using merge_events_by_keys for grouping
161+
* Time period filtering
162+
* Safe cleanup with testing mode
163+
126164
Complete Example
127165
~~~~~~~~~~~~~~~~
128166

@@ -209,4 +247,4 @@ API Reference
209247
For low-level API access, see:
210248

211249
* :doc:`../api/rest` - HTTP REST API documentation
212-
* :doc:`../api/python` - Python client library API
250+
* :doc:`../api/python` - Python client library API

0 commit comments

Comments
 (0)