|
1 | | -Querying Data |
2 | | -============= |
3 | | - |
4 | | -There are a couple of ways to query data in ActivityWatch. |
5 | | - |
6 | | -aw-server supplies a "/query" endpoint (also accessible via aw-client's query method) which supplies a basic scripting language which you can utilize to do transformations on the server-side. |
7 | | -This option is good for basic analysis and for lightweight clients (such as aw-webui). |
8 | | - |
9 | | -Another option is to fetch events from the "/buckets/bucketname/events" endpoint (also accessible via aw-client's get_events method) and either program your own transformations or use transformation methods available in the aw-analysis python library (which includes all transformations available in the query endpoint). This requires a lot of more work since you will likely have to reprogram transformations already available in the query API, but on the other hand it is much more flexible. |
10 | | - |
11 | | - |
12 | | -Writing a Query |
13 | | ---------------- |
| 1 | +Querying Data (Moved) |
| 2 | +==================== |
14 | 3 |
|
15 | 4 | .. note:: |
16 | | - This section is still WIP. |
17 | | - There is still no documentation of all the transform functions, but for most simple queries these examples should be enough. |
18 | | - |
19 | | -Queries are the easiest yet advanced way to get events from aw-server buckets in a format which fits most needs. |
20 | | -Queries can be done by doing a POST request to aw-server either manually or with the aw-client library. |
21 | | - |
22 | | -For an incomplete API reference of the transform functions, see the API reference for :py:mod:`aw_transform` and :py:mod:`aw_query`. |
23 | | - |
24 | | -In a query you start by getting events from a bucket and assign that collection of events to a variable, then there are multiple transform functions which you can use to for example filter, limit, sort, and merge events from a bucket. |
25 | | -After that you assign what you want to receive from the request to the RETURN variable. |
26 | | - |
27 | | -Magic Variables: |
28 | | - There is a magic variable ``__CATEGORIES__`` you can use in the web UI's Query Explorer to include your configured categories in your query. |
29 | | - |
30 | | - Here's an example of using this variable to find all events categorized as "Web Browsing" |
31 | | - |
32 | | - .. code-block:: python |
33 | | -
|
34 | | - events = flood(query_bucket(find_bucket("aw-watcher-window_"))); |
35 | | - not_afk = flood(query_bucket(find_bucket("aw-watcher-afk_"))); |
36 | | - not_afk = filter_keyvals(not_afk, "status", ["not-afk"]); |
37 | | - events = filter_period_intersect(events, not_afk); |
38 | | - events = categorize(events, __CATEGORIES__); |
39 | | - events = filter_keyvals(events, "$category", [["Work"]]); |
40 | | - RETURN = sort_by_duration(events); |
41 | | -
|
42 | | -Minimal example: |
43 | | - Minimal query which only gets events from a bucket and returns it: |
44 | | - |
45 | | - .. code-block:: bash |
46 | | -
|
47 | | - events = query_bucket("my_bucket"); |
48 | | - RETURN = events; |
49 | | -
|
50 | | -
|
51 | | -Example which arranges a hierarchy: |
52 | | - A query which merges events from a bucket in a key1->key2 hierarchy: |
53 | | - |
54 | | - .. code-block:: bash |
55 | | -
|
56 | | - events = query_bucket("my_bucket"); |
57 | | - events = merge_events_by_keys(events, "merged_key1", "merged_key2"); |
58 | | - RETURN = events; |
59 | | -
|
60 | | -
|
61 | | -Example combining window and AFK events: |
62 | | - A simplified query example of how to summarize what programs used while not afk. |
63 | | - The query intersects the not-afk events from the afk bucket with the events from the window bucket, merges keys from the result and sorts by duration. |
64 | | - |
65 | | - .. code-block:: bash |
66 | | -
|
67 | | - afk_events = query_bucket(find_bucket("aw-watcher-afk_")); |
68 | | - window_events = query_bucket(find_bucket("aw-watcher-window_")); |
69 | | - window_events = filter_period_intersect(window_events, filter_keyvals(afk_events, "status", ["not-afk"])); |
70 | | - merged_events = merge_events_by_keys(window_events, ["app", "title"]); |
71 | | - RETURN = sort_by_duration(merged_events); |
72 | | -
|
73 | | -Example including aw-client: |
74 | | - This is an example of how you can do analysis and aggregation with the query method in Python with aw-client. |
75 | | - You probably need to install the client library by following the instructions in its `repository <https://github.com/ActivityWatch/aw-client>`_. |
76 | | - |
77 | | - .. note:: This example runs the client in *testing* mode, which means that it will try to connect to an aw-server in testing mode on the port 5666 instead of the normal 5600. |
| 5 | + This page has been moved and significantly improved. |
| 6 | + |
| 7 | + **Please update your bookmarks to:** :doc:`working-with-data` |
78 | 8 |
|
79 | | - .. literalinclude:: query_client.py |
| 9 | +This page has been replaced by a more comprehensive guide: :doc:`working-with-data` |
80 | 10 |
|
81 | | -Fetching Raw Events |
82 | | -------------------- |
83 | | -It is possible to fetch the raw events from a bucket. This is useful if you want to do your own analysis on the data, or if you want to use the aw-analysis library to do transformations on the data. |
| 11 | +The new page covers: |
84 | 12 |
|
85 | | -Example fetching raw events from the "aw-watcher-window_" bucket: |
86 | | - This is an example that you can run in a Python to fetch raw events posted by the window watcher. |
87 | | - The scripts sums the time spent on each window title and showcases a data redaction use case. |
| 13 | +* **Canonical Events** (recommended) - Get processed activity data like the web UI |
| 14 | +* **Custom Queries** - Write your own analysis queries |
| 15 | +* **Raw Events** (advanced) - Direct bucket access for maximum flexibility |
| 16 | +* **Comprehensive Examples** - Safe, up-to-date examples from the aw-client repository |
88 | 17 |
|
89 | | - .. literalinclude:: raw_events.py |
| 18 | +**Automatic redirect:** You will be redirected in 5 seconds. |
90 | 19 |
|
| 20 | +.. raw:: html |
91 | 21 |
|
92 | | -.. TODO `Bucket REST API <./rest.html#get-events>`_ |
| 22 | + <script> |
| 23 | + setTimeout(function() { |
| 24 | + window.location.href = 'working-with-data.html'; |
| 25 | + }, 5000); |
| 26 | + </script> |
| 27 | + <meta http-equiv="refresh" content="5;url=working-with-data.html"> |
0 commit comments