alex-hhh / ActivityLog2

Analyze data from swim, bike and run activities
https://alex-hhh.github.io/
GNU General Public License v3.0
339 stars 25 forks source link

Failed to import activity #42

Closed airon111 closed 5 years ago

airon111 commented 5 years ago

i just build from source with no problems...When i try to import a new activity from a FIT file directly downloaded from garmin connect i get an error:

Failed to import 3321552521.fit: #(struct:exn:fail query-exec: cannot convert given value to SQL type given: '#(267 1661746798 1931485408 1256318200 692797698) type: parameter dialect: SQLite #)

i have no clue about that one. someone can point me out? thanks Aaron

alex-hhh commented 5 years ago

(Sorry, I closed this by clicking the wrong button, reopening it)

Can you share that activity, so I can have a look? Either attach it to this issue, or send it to me directly at AlexHarsanyi@gmail.com. I have a large collection of "odd" FIT files for testing, but it seems that there is always a new one, which breaks...

Also, does this activity contain data collected using a "Connect IQ" application? (support for these is new).

airon111 commented 5 years ago

Yes the activity contains data from a connect iq data field...it is a multi data field in one page using stock data field showed...and the Garmin connect iq power field.

All my activities since years have this kind of data because I use this all in one data field .

In fact I tried to import also other activities and none worked.. ( Sorry I closed also by mistake clicking in phone...reopened)

alex-hhh commented 5 years ago

The patch below will avoid inserting the multi-value field in the database, and the activity will import correctly (without that field being added). You will still be able to see the running power data.

I will push a fix later today (I want to do some more testing), but meanwhile, you can apply the patch below, by saving it to a file (make sure you use UNIX line endings) and using "git apply". A;ternatively, you can open the "rkt/database.rkt" file in a text editor, find the xdata-store-values and xdata-store-summary-values functions and replace the "(when val" lines with "(when (and val (or (number? val) (string? val) (bytes? val)))".

Also, how does Garmin Connect display this field in its GUI? I am not sure there is enough information in the FIT file itself to display it properly...

 rkt/database.rkt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rkt/database.rkt b/rkt/database.rkt
index 154ceea..157bb46 100644
--- a/rkt/database.rkt
+++ b/rkt/database.rkt
@@ -364,7 +364,7 @@
 (define (xdata-store-values db record id xdata-fields)
   (for (([field-key field-id] (in-hash xdata-fields)))
     (define val (dict-ref record field-key #f))
-    (when val
+    (when (and val (or (number? val) (string? val) (bytes? val)))
       (query-exec db sql-insert-xdata-value id field-id val))))

 (define sql-insert-xdata-summary-value
@@ -379,7 +379,7 @@
 (define (xdata-store-summary-values db record id xdata-fields)
   (for (([field-key field-id] (in-hash xdata-fields)))
     (define val (dict-ref record field-key #f))
-    (when val
+    (when (and val (or (number? val) (string? val) (bytes? val)))
       (query-exec db sql-insert-xdata-summary-value id field-id val))))
alex-hhh commented 5 years ago

Hi @airon111 , I updated the master branch with a fix for this issue. Can you please fetch the latest sources, rebuild the application and try to import again? Thanks, Alex.

airon111 commented 5 years ago

Pulled latest sources and tried it, working perfectly... Thank you very much