Git Product home page Git Product logo

aw-server's Introduction

aw-server

Build Status Coverage Status

ActivityWatch server, for secure storage and retrieval of all your Quantified Self data.

Note: In the future this will no longer be the default server used by ActivityWatch, instead we will be using aw-server-rust. The fate of this repo is uncertain, but it will likely be around and maintained for a while (as a reference implementation, for prototyping, etc).

Build and Install

To install program and dependencies, Poetry is required. You'll want to activate a venv before building.

make build

The aw-server binary should now be available to you in your PATH (if it is set correctly).

Usage

Run aw-server:

aw-server

Development

If you want to run aw-server in development, you probably want to run a development instance beside your personal (stable) instance. You can do this by giving aw-server the --testing flag. This will start the server on another port and use a separate datastore.

aw-server --testing

API Examples

You can also get a very decent API browser by browsing to localhost:5600 after starting the server.

There are also some API examples in the documentation.

aw-server's People

Contributors

alwinator avatar belked avatar dependabot[bot] avatar erikbjare avatar exoji2e avatar huantianad avatar iloveitaly avatar jamesa avatar johan-bjareholt avatar justinddavis avatar lgtm-com[bot] avatar oscar-king avatar sacline avatar shootingking-am avatar victorwinberg avatar xylix avatar yumemio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aw-server's Issues

Opt-out for window title tracking

Window titles, especially in browsers, tend to leak a lot of private data (e.g. Gmail's <title> exposing e-mails, all text editors exposing document names, etc.).

An easy-to-configure "kill switch" flag to discard any "window title" data from watchers would solve this issue and be arguably even more suitable if enabled by default for most users.

[Windows] Import doesn't work

AW: 0.11.0.
OS: Windows 10 LTSC (version 1809) x64.
Browser: ungoogled-chromium 92.0.4515.107.

Today I've updated ungoogled-chromium from 89.0.4389.114-1 to 92.0.4515.107, that's theoretically built from the same source code by other developer + "Safe Browser" functionality isn't cut off.

I didn't expected that the settings will be lost 'cause I didn't change my browser, but they were lost.

Luckily I had exported settings but importing them doesn't show any activity or difference - there is even no activity in the Network tab of Chrome DevTools. Logs also doesn't contain any records about import.

Here's the attached and pretty-printed settings (some sensitive info has been cut off w/o loss in constistency)

aw-server processing freezes build

As the title states, running make build on the source code works fine until it reaches

Processing /Users/user/Desktop/activitywatch/aw-server

Upon which it has been frozen for like 10 minutes.
I have tried rerunning the program yet nothing has changed.

API to delete multiple events

We have the endpoint DELETE /0/buckets/{bucket_id}/events/{event_id} which can delete a single event, it would be useful with a DELETE /0/buckets/{bucket_id}/events/which simply just takes an array of event_ids.

aw-server shared library error

I got this in the AW webui:

Error: Network Error. See dev console (F12) and/or server logs for more info.

When I ran aw-server or aw-qt I got:

[28038] Error loading Python lib '/usr/bin/libpython3.6m.so.1.0': dlopen: /usr/bin/libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

It seems /opt/activitywatch/libpython3.6m.so.1.0 exists though

API ability to get "leading" events for query period

First I'd like to express again my thanks for such a wonderful and helpful project!

I've been using ActivityWatch for about two weeks now, and have also implemented a few very custom watchers for my own use cases. I'm currently running off of the latest tag, v0.8.0b7.

One thing I've noticed though that is a bit annoying to me is the Events and Query API behavior (and corresponding UI behavior) for long events that begin prior to the query period being cut off. For example, if I was AFK for a long amount of time until 30 minutes ago, and query for events in the last hour (or pull up the Timeline view in the UI for the last hour), I only see the "not-afk" event that started 30 minutes ago... and blank space leading up to it.

It seems to me like it would be really helpful if the events and query API endpoints had an option to return a "leading" event, if there's an event that started before the start of the query period but ended during the query period. I could also see this being represented in the timeline view with some sort of special icon or left border, indicating that the event began prior to the currently-viewed period.

Add the desktop entry to /usr/share/applications upon installation on linux

Hi, firstly - I'm very impressed by the project and am taking notes from the documentation, code, design, project structure to benefit my own projects, props to the team! I already have some extension ideas and would love to contribute to the project.

A quick fix for the AUR install (would be applicable for any other linux packages) - the .desktop entry should be added to /usr/share/applications too, in order to appear in the desktop environment app search.

Implement the Bucket API

Bucket endpoint should return metadata about buckets.

  • Storage and retrieval of bucket metadata need to be supported by aw_datastore

Mongo DB Config

I need to use the aw-server in a Docker env.

Can't just use localhost for mongo db config.

How can I change the mongo connection config?

Setup CI/CD for ActivityWatch Server Docker building

Hey, activitywatch server doesnt seem to have a consistently updated docker image on dockerhub. The most recent image on dockerhub (not sure if official) was last updated 2 years ago. I believe that by using CI/CD and automating the docker build process so that a docker image is built for a new release, this would allow the dockerhub images to be kept up to date with any new releases/commits.

Search results for `Tools > Search` or `Tools > Query` don't include urls

Tab urls (collected through aw-watcher-web) do not show up in search results for Tools > Search or Tools > Query (only the app name and app title show up).
Possible cause:

  1. The bucket for aw-watcher-web is not included in the search
  2. Somewhere in aw-core the url is filtered out
  3. Somewhere in aw-server the url is filtered out

I've tried this query with raw json output but the urls are missing. I thought if I include browser_events, the urls would show up.

afk_events = query_bucket(find_bucket("aw-watcher-afk_"));
window_events = query_bucket(find_bucket("aw-watcher-window_"));
browser_events = query_bucket(find_bucket("aw-watcher-web-firefox"));
window_events = filter_period_intersect(window_events, afk_events);
window_events = filter_period_intersect(window_events, browser_events);
merged_events = merge_events_by_keys(window_events, ["app", "title"]);
RETURN = sort_by_duration(merged_events);

Workaround: I can do the queries I need directly on peewee-sqlite.v2.db in the terminal but I thought if the search/query functionality is already present in the UI then I could use it:

awuser@box:/aw/data/activitywatch/aw-server$ sqlite3 peewee-sqlite.v2.db 'select timestamp, datastr from eventmodel;' | sed -e 's/|{/",/ ; s/^/{"time": "/' | grep -i "github" | tail -3
{"time": "2021-10-21 03:16:11.200000+00:00","url": "https://github.com/ActivityWatch/aw-server/issues/85", "title": "Search results for `Tools > Search` or `Tools > Query` don't include urls \u00b7 Issue #85 \u00b7 ActivityWatch/aw-server", "audible": false, "incognito": false, "tabCount": 16}
{"time": "2021-10-21 03:16:12.827000+00:00","url": "https://github.com/ActivityWatch/aw-core/", "title": "ActivityWatch/aw-core: Core library for ActivityWatch", "audible": false, "incognito": false, "tabCount": 16}
{"time": "2021-10-21 03:16:15.641000+00:00","url": "https://github.com/ActivityWatch/aw-server/issues/85", "title": "Search results for `Tools > Search` or `Tools > Query` don't include urls \u00b7 Issue #85 \u00b7 ActivityWatch/aw-server", "audible": false, "incognito": false, "tabCount": 15}

`404` error when loading the dashboard

After running the latest beta version (v0.12.3b5) of aw-server, the dashboard is not accessible.


Screenshot
$ /Applications/ActivityWatch.app/Contents/MacOS/aw-server
2023-07-21 12:21:04 [INFO ]: Using storage method: peewee  (aw_server.main:33)
2023-07-21 12:21:04 [INFO ]: Starting up...  (aw_server.main:41)
2023-07-21 12:21:04 [INFO ]: Using database file: /Users/BelKed/Library/Application Support/activitywatch/aw-server/peewee-sqlite.v2.db  (aw_datastore.storages.peewee:150)
 * Serving Flask app 'aw-server'
 * Debug mode: off
2023-07-21 12:21:04 [INFO ]: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://localhost:5600  (werkzeug:187)
2023-07-21 12:21:04 [INFO ]: Press CTRL+C to quit  (werkzeug:187)
2023-07-21 12:21:06 [INFO ]: 404 (127.0.0.1): GET / HTTP/1.1  (flask:25)

Implement rewrite last event

This is useful as a method for heartbeats. Such as if a user just became non-afk and now the duration of the non-afk period wants to be updated every x minutes until the user becomes afk again.

It's not the full heartbeats API we are planning for, but it's a lot easier do and is expected to work well enough for now.

API needs authentication or to stop using POST

Arbitrary websites can request localhost urls unless they have the appropriate headers, and this only protects against some request types. Specifically, POST is not blocked by a lack of an Access-Control-Allow-Origin header. ActivityWatch does not appear to have one, so the browser should block requests from webpages loaded from remote urls.

$ curl -vv -H "Origin: http://attacker.com" http://localhost:5600
*   Trying 127.0.0.1:5600...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5600 (#0)
> GET / HTTP/1.1
> Host: localhost:5600
> User-Agent: curl/7.68.0
> Accept: */*
> Origin: http://attacker.com
> 
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: Werkzeug/2.1.2 Python/3.9.14
< Date: Mon, 26 Jun 2023 15:13:41 GMT
< Content-Disposition: inline; filename=index.html
< Content-Type: text/html; charset=utf-8
< Content-Length: 1683
< Last-Modified: Mon, 26 Sep 2022 19:14:27 GMT
< Cache-Control: no-cache
< Date: Mon, 26 Jun 2023 15:13:41 GMT
< Connection: close

https://about.gitlab.com/blog/2021/09/07/why-are-developers-vulnerable-to-driveby-attacks/

404 (127.0.0.1): GET /img/icons/apple-touch-icon-152x152.png HTTP/1.1 (flask:25)

AW: 0.11.0.2
OS: Archlinux x64.
Browser: Firefox

In my ~/.cache/activitywatch/log/aw-server/aw-server_2021-xxxx.log with following log for aw-server:

2021-08-02 04:50:39 [INFO ]: Using storage method: peewee  (aw_server.main:32)
2021-08-02 04:50:39 [INFO ]: Starting up...  (aw_server.main:37)
2021-08-02 04:50:40 [INFO ]: Using database file: /home/mizho/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db  (aw_datastore.storages.peewee:116)
2021-08-02 04:50:40 [INFO ]:  * Running on http://localhost:5600/ (Press CTRL+C to quit)  (werkzeug:113)
2021-08-02 04:50:41 [INFO ]: Creating bucket 'aw-watcher-window_ZANM'  (aw_datastore.datastore.Datastore:52)
2021-08-02 04:50:41 [INFO ]: Creating bucket 'aw-watcher-afk_ZANM'  (aw_datastore.datastore.Datastore:52)
2021-08-02 04:50:51 [INFO ]: Received heartbeat, but bucket was previously empty, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:274)
2021-08-02 04:50:51 [INFO ]: Received heartbeat, but bucket was previously empty, inserting as new event. (bucket: aw-watcher-afk_ZANM)  (aw_server.api:274)
2021-08-02 04:51:08 [INFO ]: 404 (127.0.0.1): �[33mGET /img/icons/apple-touch-icon-152x152.png HTTP/1.1�[0m  (flask:25)
2021-08-02 04:54:10 [INFO ]: Creating bucket 'aw-watcher-web-firefox'  (aw_datastore.datastore.Datastore:52)
2021-08-02 04:54:14 [INFO ]: Received heartbeat, but bucket was previously empty, inserting as new event. (bucket: aw-watcher-web-firefox)  (aw_server.api:274)
2021-08-02 04:56:22 [INFO ]: Creating bucket 'aw-watcher-vim_ZANM'  (aw_datastore.datastore.Datastore:52)
2021-08-02 04:56:22 [INFO ]: Received heartbeat, but bucket was previously empty, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:274)
2021-08-02 05:00:23 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 05:03:20 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 05:05:07 [INFO ]: Creating bucket 'aw-watcher-web-chrome'  (aw_datastore.datastore.Datastore:52)
2021-08-02 05:05:12 [INFO ]: Received heartbeat, but bucket was previously empty, inserting as new event. (bucket: aw-watcher-web-chrome)  (aw_server.api:274)
2021-08-02 05:05:33 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 05:05:34 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 05:11:03 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 05:18:02 [INFO ]: Creating bucket 'aw-stopwatch'  (aw_datastore.datastore.Datastore:52)
2021-08-02 05:30:50 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 05:41:37 [INFO ]: 404 (127.0.0.1): �[33mGET /img/icons/android-chrome-192x192.png HTTP/1.1�[0m  (flask:25)
2021-08-02 05:46:57 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 05:55:37 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 06:01:14 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 06:10:34 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 06:14:19 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 06:17:14 [INFO ]: 404 (127.0.0.1): �[33mGET /img/icons/apple-touch-icon-152x152.png HTTP/1.1�[0m  (flask:25)
2021-08-02 06:22:40 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 06:23:09 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 06:33:59 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-window_ZANM)  (aw_server.api:262)
2021-08-02 06:34:40 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)
2021-08-02 06:35:36 [INFO ]: Received heartbeat after pulse window, inserting as new event. (bucket: aw-watcher-vim_ZANM)  (aw_server.api:262)

I've errors in the localhost:5600 UI such as:
TypeError: t is undefined. See dev console (F12) and/or server logs for more info.

TypeError: t is undefined
    datasets TimelineBarChart.vue:99
    Lodash 10
    value TimelineBarChart.vue:99
    value TimelineBarChart.vue:45
    VueJS 12
vue.runtime.esm.js:1888:12

The only probably relevant thing that it may contribute to this is I have custom (very simple) categorize which I have to each time export the latest and then import again.

First, is the 404 error in aw-server log related here, and how can I fix the seemingly vu.js icon issue?
Second, is there a better way than export/import the categories (if relevant)

How to implement test cases for watchers

I am currently writing a few test cases for aw-watcher-terminal and therefore want to check if the events were successfully sent to the server.

In my implementation I need to start aw-server (--testing) and aw-watcher-terminal (--testing). After these are started the python test file then adds a unique id to the event, then fetches the latest 100 events and filters out all events with this id. (Then I can check if all properties of this event are correct)

Do you have a better way to do this?

Logs filled up my disk for the second time

  File "Xlib/protocol/rq.py", line 1367, in __init__
  File "Xlib/protocol/display.py", line 355, in send_request
  File "aw_watcher_window/main.py", line 74, in heartbeat_loop
  File "aw_watcher_window/lib.py", line 53, in get_current_window
  File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
  File "aw_watcher_window/xlib.py", line 37, in get_current_window
  File "aw_watcher_window/xlib.py", line 20, in _get_current_window_id
  File "Xlib/xobject/drawable.py", line 472, in get_full_property
  File "Xlib/xobject/drawable.py", line 455, in get_property
.rw-rw-r--  45G agent agent 12 Feb 19:00 aw-watcher-window_2023-02-12T09-48-54.log

QueryParseException when semicolon in expression

Trying to run a query with the following line:

events = categorize(events, [[["AW GitHub"], {"type": "regex", "regex": "github.com/ActivityWatch;AW"}]]);

Gives:

2023-08-10 12:06:24 [WARNING] 400 Client Error: BAD REQUEST for url: http://127.0.0.1:5600/api/0/query/
2023-08-10 12:06:24 [WARNING] Error message received: {'type': 'QueryParseException', 'message': 'Invalid syntax for value to assign'}

This is probably due to the ; in one of the rules.

Add functionality to redact/filter sensitive data

We need a model to filter out sensitive data by default.

For example if a window title contains: "[title] - Firefox (Private Browsing)" we should redact [title] to some magic string such as "REDACTED".

For some cases we might want to filter the window out entirely, giving 0 information about which window is running, better catch too much than too little.

It should be the goal that every user has a set of "clean" data. The filtering should also be able to be run on an existing database of data, so that cleaner data can be output. Preferably, the data should be so clean that there is little (or even no) reason not to share it (which would be great since easy access to a large dataset could make research in some areas a lot easier!).

The question left is where this processing step should take place. We want the filtering/redacting to happen before data is sent anywhere but it should also be able to be enforceable on a server (if the server owner doesn't trust the servers security, if in the cloud for example) and have clients notified of this so that they can do the filtering on their side, removing the need to send sensitive data at all. It might therefore be prudent to write a module in aw-core that implements this functionality since it should be useable from the server and all clients (which transmit sensitive data).

This feature should be on by default, we don't need anything advanced yet, first priority is to redact titles from Incognito/Private Browsing, that's a good step in the right direction.

This should have a far higher priority than Zero-Knowledge storage right now, because it's a lot easier and is more user friendly (In ZK storage: if you lose your keys you lose your data).

High amount of I/O usage

Hello, I've been using AW and I love it.
However, just today, I checked my I/O accumulated stats using iotop -ao
It seems like aw-server used about 1GB/5mins. That, for a consumer SSD, is way above the the average daily usage, which is probably about 20-40GB/day.

It could also be that I'm running many applications, with the browser plugin enabled which in turn is the cause for so much I/O usage. But, still, I think the team should try and do something about it...

One, we could increase the default hearbeat/data-send intervals, or we could store the data to a temporary place and update it on disk every 10mins or so. I think the 2nd could be provided as a configuration option, if not given already.

It's possible to do the 2nd one manually, but I still hope it's something to consider. Either for this, or for the upcoming aw-server-rust rewrite!

image

That is the data usage for about 2mins of monitoring( time manually measured ). For firefox, there's an config option which can hugely reduce its usage( which I'll go do after this ), but I'm not sure if anything similar exists for aw-server or its' plugins

Build errors on AWS linux

Hi all - can't build aw-server.
I get many errors of this nature:

/////////////////////////////////////////////////////////////
cargo build --release --bin aw-server
Compiling plex v0.2.5
Compiling url v2.3.1
error[E0658]: use of unstable library feature 'proc_macro_diagnostic'
--> /home/ec2-user/.cargo/registry/src/github.com-1ecc6299db9ec823/plex-0.2.5/src/lexer.rs:176:26
|
176 | .error(format!("invalid regular expression: {}", e))
| ^^^^^
|
= note: see issue #54140 rust-lang/rust#54140 for more information
... [ + many similar errors]
/////////////////////////////////////////////////////////////
Debugging info:

(venv) [ec2-user@ip-172-31-62-148 activitywatch]$ ./checkversions.sh
git version 2.39.1
GNU Make 3.82
Built for x86_64-koji-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Python 3.8.16
Poetry (version 1.3.2)
v16.19.1 (node)
8.19.3 (npm)
rustc 1.67.1 (d5a82bbd2 2023-02-07)
cargo 1.67.1 (8ecd4f20a 2023-01-10)
/////////////////////////////////////////////////////////////
(venv) [ec2-user@ip-172-31-62-148 activitywatch]$ uname -a
Linux ip-172-31-62-148.us-west-2.compute.internal 4.14.304-226.531.amzn2.x86_64 #1 SMP Wed Feb 1 21:34:38 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
/////////////////////////////////////////////////////////////

I believe I have all the right pre-requisites and versions and have followed your build instructions carefully.

Best regards,

Chris.

Implement WebSocket broadcast

Would be a simpler way to extend functionality depending on incoming data. Don't integrate them with the server but just enable which data that the server receives should be broadcast.

For example:
A Python program could listen to the websocket and when a AFK or no-longer-AFK event is received then do a notify-send, informing the user that the afkwatcher now thinks that the user is AFK (or not). Would be handy to detect errors in logging without having to actively check logs.

When aw-qt crashes, aw-server does not shut down

Same issue as ActivityWatch/aw-qt#19, only this process is a Flask server, and run is inherited from Flask, so I can't put a if os.getppid() == 1 inside it.

Flask has ways to shut itself down, but typically by setting up a /shutdown page that sends the shutdown call when requested, here we don't want to rely on requests, more like setup a watchdog. Here gives similar options. There my questions is asked, and most of the answer is "app.run() is only meant for development", not too helpful.

Now, does the server really have to be restarted ? Should aw-qt test whether the server is already up, and maybe connect to it rather than start it, if it's already alive ?

Strange freeze

I've now, on more than one occasion, gotten a strange freeze where aw-server does not respond to any requests.

The first time was a couple days ago, the second time I noticed this morning as the web UI didn't load any data. I restarted the server through aw-qt, still frozen (but it seemed to have processed some requests before freezing). Restarted again through the terminal, now it worked and started processing the 2 day watcher backlog.

I have no idea what is causing this, but it's a critical bug.

Add "version" to /info endpoint

Might be nice, if the version would be visible in aw-webui it would also make it easier for users to know which version of aw they are running.

WakaTime support

WakaTime has a settings file that enables setting a api_url and api_key. This can be used to effectively route all WakaTime requests directly to another entity (probably for debugging purposes). There is even an example config file called paranoid.cfg used in testing.

It would be nice to have a way to receive the heartbeats that WakaTime sends out so we can collect the data.

Now, to the matter on how that would be done in a nice way. Bundling it into the actwa-server core seems nasty to me, but creating plugins that are initialized with a reference to the flask app object and then set up the routes on it's own shouldn't be too involved. For prototyping it might be best to just bundle it into actwa-server directly (but keep it in it's own file so it will be easy to refactor into a seperate package and repo later).

The API is documented here: https://wakatime.com/developers/

Prometheus + Grafana?

Since we still don't have a way to collect data from all devices into a single location, has anyone thought about storing data into Prometheus or Influx and visualizing with Grafana?

Malformed sqlite database

So it happened, I have on that data from the end of 2019 and I was sad to delete but it is possible to recover the data on it.

sqlite3 /home/[your-user]/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db ".dump" > dump.sql
rm -f /home/[your-user]/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db
sqlite3 -init dump.sql /home/[your-user]/.local/share/activitywatch/aw-server/peewee-sqlite.v2.db
.quit

With this commands I was able to recreate a database and now activity watch starts. In case of this issue you have aw-qt reporting an error, if you press restart server aw-qt crashes...
With the more details button you see the error on peewee about the malformed database, so you need to do those commands and restart aw-qt.

Views not working in testing mode

First off, it simply didn't work, so I got hold of the request URL from the aw-server log and found the response to be:

URL: http://127.0.0.1:5666/api/0/views/aw-webui_windowactivity_summary_erb-main2-arch%3Flimit=-1&start=2017-03-12T00%253A00%253A00%252B01%253A00&end=2017-03-13T00%253A00%253A00%252B01%253A00

{
    "msg": "There's no view with the name 'aw-webui_windowactivity_summary_erb-main2-arch?limit=-1&start=2017-03-12T00%3A00%3A00%2B01%3A00&end=2017-03-13T00%3A00%3A00%2B01%3A00'"
}

So, after handcrafting the URL into the following I get another error:

URL: http://127.0.0.1:5666/api/0/views/aw-webui_windowactivity_timeline_erb-main2-arch?limit=-1&start=2017-03-12T00:00:00%2B01:00&end=2017-03-13T00:00:00%2B01:00

{
    "msg": "Cannot query bucket that doesn't exist in transform: 'aw-watcher-window_erb-main2-arch'"
}

And indeed, aw-watcher-window does not exist since I'm running in testing mode, surely it should work in testing mode as well.

And also, "that doesn't exist in transform" confused me, I thought the bucket was not in the transform, which made no sense to me. Now I realize that what the message tried to say was that the bucket specified in the transform does not exist in the database, which makes sense.

Requesting data from server too "quickly" results in `sqlite3.OperationalError`

Related to ActivityWatch/aw-webui#392.
Seems like the database gets locked when requesting another request before the current one is finished.

2023-01-24 22:28:31 [ERROR]: Exception on /api/0/buckets/aw-watcher-window_BelKeds-MBP/events [GET]  (aw-server:1449)
Traceback (most recent call last):
  File "peewee.py", line 3237, in execute_sql
sqlite3.OperationalError: database is locked

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "flask/app.py", line 1517, in full_dispatch_request
  File "flask/app.py", line 1503, in dispatch_request
  File "aw_server/rest.py", line 46, in decorator
  File "flask_restx/api.py", line 405, in wrapper
  File "flask/views.py", line 84, in view
  File "flask_restx/resource.py", line 46, in dispatch_request
  File "aw_server/rest.py", line 208, in get
  File "aw_server/api.py", line 43, in g
  File "aw_server/api.py", line 191, in get_events
  File "aw_datastore/datastore.py", line 101, in get
  File "aw_datastore/storages/peewee.py", line 304, in get_events
  File "peewee.py", line 1962, in inner
  File "peewee.py", line 2033, in execute
  File "peewee.py", line 2206, in _execute
  File "peewee.py", line 3250, in execute
  File "peewee.py", line 3244, in execute_sql
  File "peewee.py", line 3010, in __exit__
  File "peewee.py", line 192, in reraise
  File "peewee.py", line 3237, in execute_sql
peewee.OperationalError: database is locked

Improving performance when performing summary over a day and over a time period

From my understanding of the code, and documentation, every time the localhost page reloads, the top activities in all categories are recalculated from the beginning. If you have a lot of events, that can lead to a timeout( ActivityWatch/activitywatch#217). I think performance could be improved by creating a new table in the database where you store the summarized events. The columns would be:

Key(URLs, domains, app_events, title_events), Value(i.e github.com, localhost:5600), Duration, and Day.

Thus every time the page reloads, it only summarizes the new events, then adds the new domains/urls/etc and updates the existing ones. Then you just retrieve the results. This has two advantages:

  1. Decreases the time to calculate the summary for the day, as you perform a lot fewer calculations.
  2. Makes analyzing statistics for a week, month, year a lot faster since the table will have a summary of the events for every day. Therefore, you just retrieve the right amount of days and perform analysis on them.

@ErikBjare , @johan-bjareholt, what do you guys think? Are there any current initiatives like this already in the works? If not, I can start working on it

[Suggestion] Oracle Cloud Setup Tutorial

Matrix.org has a tutorial to make a free small server for their service: https://matrix.org/docs/guides/free-small-matrix-server/

Is there a simple setup like this that could be used for ActivityWatch? If so, could someone write one such tutorial, or do you just need to run the python program?

Even if not, the pricing comparison they show could be useful to have somewhere:

Vendor Time-limit Count RAM (GB) Storage (GB) Transfer (GB)
AWS 12 months 1 t2.micro 1 30 15
Azure 12 months 1 B1S 1 2x 64 15
GCP no limit 1 f1-micro 0.6 30 1
Oracle no limit 2 VM.Standard.E2.1.Micro 1 100 10000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.