Skip to content

Implemented import API endpoint#41

Merged
johan-bjareholt merged 11 commits intomasterfrom
dev/import
Mar 2, 2019
Merged

Implemented import API endpoint#41
johan-bjareholt merged 11 commits intomasterfrom
dev/import

Conversation

@ErikBjare
Copy link
Member

@ErikBjare ErikBjare commented Apr 1, 2018

Stuff left to do:

  • REST API endpoint
  • Proper testing
    • Try importing an old valid export
    • Import an export and compare
  • Implement an import dialog in the web UI (not in this PR)

Depends on ActivityWatch/aw-core#69

@ghost ghost assigned ErikBjare Apr 1, 2018
@ghost ghost added the review label Apr 1, 2018
@ErikBjare ErikBjare mentioned this pull request Aug 29, 2018
4 tasks
@ErikBjare
Copy link
Member Author

Just wrote https://github.com/ErikBjare/smartertime2activitywatch that should convert a SmarterTime export into an importable ActivityWatch bucket.

@ErikBjare
Copy link
Member Author

With the latest commit I was able to import a SmarterTime export through the API!

@johan-bjareholt
Copy link
Member

This does not follow the format used in /api/0/export (which is already on master) where the format is {"bucketname": {bucketdata}} while this expects {"buckets": [{bucket_A}, [bucket_B]]}

@johan-bjareholt
Copy link
Member

I fixed it locally and imported my current database on my desktop. For my export of 94mb it took 19minutes to import in aw-server with peewee. In aw-server-rust it took less than 2 minutes lol.

@ghost ghost assigned johan-bjareholt Feb 26, 2019
@johan-bjareholt
Copy link
Member

johan-bjareholt commented Feb 26, 2019

As we have a export schema in aw-core I decided to break backwards compatibility and use that everywhere.
The export button in the web-ui is still worthless anyway as it doesn't care about metadata and only gets all the events which is stupid.
It is also now no longer possible to import from aw-server-rust as the datastructure has changed.

@ErikBjare
Copy link
Member Author

I think {"buckets": [{bucket_A}, [bucket_B]]} may be a better format though. What do you think?

I thought I fixed the export button?

@johan-bjareholt
Copy link
Member

@ErikBjare Pretty much everything is inconsistent. Export button doesn't have metadata, we use different formats in /0/api/export and /0/api/import. I now try to use {"buckets":[{bucket1}, {bucket2}]} everywhere.

@ErikBjare
Copy link
Member Author

What is differing between the formats? Perhaps we should start versioning the exports? (using a version of 0 until stabilized)

Perhaps the best is to have the export-all format be {"buckets": {bucket1.id: bucket1, ...}}, the current export-all format just seems to be [bucket1, bucket2, ...].

Also, apparently I had almost fixed the export button: https://github.com/ActivityWatch/aw-webui/blob/eb56c6194e65ce73ab29b868ea8121d936ba5144/src/views/Buckets.vue#L33

Anyway, the most urgent issue should be to implement the import view (both for imports and export of the whole-instance and specific buckets).

@johan-bjareholt
Copy link
Member

Perhaps the best is to have the export-all format be {"buckets": {bucket1.id: bucket1, ...}}, the current export-all format just seems to be [bucket1, bucket2, ...].

The current format is {"buckets": [{bucket1}, {bucket2}]}

The export format was {"buckets": {bucket1.id: bucket1, ...}} which seemed like the best option to me as well, but in aw-core you created a schema which is the same as the import format.

Also, apparently I had almost fixed the export button: https://github.com/ActivityWatch/aw-webui/blob/eb56c6194e65ce73ab29b868ea8121d936ba5144/src/views/Buckets.vue#L33

That's a comment, not a fix. IMO it doesn't make sense to even have a button for it if we know that we will change the format, just makes it confusing for the end-user since the exported data won't be able to be imported anyway.

Anyway, the most urgent issue should be to implement the import view

Why do we need a view for this? What's wrong with just having a "Export all" and "Import bucket" buttons in the buckets view?

IMO the most important thing is that the data is actually consistent, because otherwise everything else is simply unusable.

@ErikBjare
Copy link
Member Author

ErikBjare commented Feb 26, 2019

The export format was {"buckets": {bucket1.id: bucket1, ...}} which seemed like the best option to me as well, but in aw-core you created a schema which is the same as the import format.

Edit the schema, it's not like we use it for anything. The schema should be the specification (edit: On second thought, maybe not, it wasn't quite as expressive that I'd like it to be iirc).

IMO it doesn't make sense to even have a button for it if we know that we will change the format, just makes it confusing for the end-user since the exported data won't be able to be imported anyway.

We should settle on a format, and a button would help us validate through usage that they are working properly.

Why do we need a view for this? What's wrong with just having a "Export all" and "Import bucket" buttons in the buckets view?

That'd be preferable, yes.

IMO the most important thing is that the data is actually consistent, because otherwise everything else is simply unusable.

Even inconsistent exports have some value (for those seeking to use the data outside ActivityWatch, for example), but I get what you saying. We should finalize the export schema and test it asap, sorry that I did such a sloppy job last time.


In addition, getting export/import to work on Android requires some extra work (both because of aw-server-rust, but also due to how the WebView needs special code to handle downloads/uploads) but once it works it would enable easily performed (but inconvenient) manual sync through the export/import cycle. This should help us prepare the web UI for cross-device functionality.

@johan-bjareholt
Copy link
Member

johan-bjareholt commented Feb 27, 2019

Alright, when I get back home I'll revert it so it's back to the {"buckets": {bucket1.id: bucket1, ...}} format again. I will use the same format to export a single bucket. Any objections?

Even inconsistent exports have some value (for those seeking to use the data outside ActivityWatch, for example), but I get what you saying. We should finalize the export schema and test it asap, sorry that I did such a sloppy job last time.

Yes it has some some value, but I don't think it's worth the price of people later starting asking "why doesn't my buckets get imported?". If someone wants to export without the export button they could do that through the API and if they did it from the current web-ui button they'd have to know programming to parse the export anyway so at that point they'd probably either ask how to export or be able to find out how to do it themselves.

In addition, getting export/import to work on Android requires some extra work (both because of aw-server-rust, but also due to how the WebView needs special code to handle downloads/uploads) but once it works it would enable easily performed (but inconvenient) manual sync through the export/import cycle. This should help us prepare the web UI for cross-device functionality.

I'd assume that importing/exporting from files would be a rarely used feature on a smartphone, IMO we should prioritize getting sync working instead of spending time on this.

@johan-bjareholt
Copy link
Member

I have now tested:

  • Exporting all buckets with /api/0/export
  • Importing all buckets with /api/0/import
  • Exporting one bucket /api/0/buckets/bid/export
  • Importing one bucket /api/0/import

The format is now {"buckets": {bucket1.id: bucket1, ...}} for everything.

buckets = data["buckets"]
return app.api.import_all(buckets), 200
# If import comes from a form in th web-ui
if len(request.files) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure how I'm supposed to add support for this in aw-server-rust, I will have to investigate that.

@ErikBjare
Copy link
Member Author

Also, apparently I did fix the export button thing, but the fix is in this PR: https://github.com/ActivityWatch/aw-webui/pull/119/files#diff-32c6cbf8ae7a966f7e41ec78a6d775cbR16

@johan-bjareholt
Copy link
Member

johan-bjareholt commented Feb 28, 2019

@ErikBjare Looks identical to the code I wrote so I assume it has the same issue with browsers showing the preview of the JSON instead of prompting a file download?

@johan-bjareholt
Copy link
Member

@ErikBjare Was able to fix the issue with it not being downloaded as a file by adding a header in this commit daa9e0b

Copy link
Member Author

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (Can't approve my own PR)

@johan-bjareholt johan-bjareholt merged commit f7b5103 into master Mar 2, 2019
@ghost ghost removed the review label Mar 2, 2019
@johan-bjareholt johan-bjareholt deleted the dev/import branch March 2, 2019 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants