jonasoreland / runnerup

A open source run tracker
GNU General Public License v3.0
744 stars 274 forks source link

Wrong activity type uploaded to Runalyze #547

Closed craftyguy closed 7 years ago

craftyguy commented 7 years ago

Expected behavior:

A bicycling activity recorded with RunnerUp should be uploaded to Runalyze as a cycling/biking activity

Actual behavior:

A biking activity is uploaded from RunnerUp to Runalyze as a 'running' activity

Configuration info

Runalyze server: runalyze.com

RunnerUp version: 1.56

@rickyepoderi, please let me know if I can provide anything else to help!

rickyepoderi commented 7 years ago

Ok, as I said in the general runalyze bug the biking activity is done this way:

  1. It is read as column Constants.DB.ACTIVITY.SPORT from table Constants.DB.ACTIVITY.TABLE (see here ).
  2. It is transformed in a Sport doing Sport sport = Sport.valueOf(dbValue) (see here ).
  3. Then if sport.IsCycling() a "3" is returned (see here ).
  4. Finally that number is set as the field "sportid" in the POST to runalyze. (see here ).

So, at the end, if I'm not missing anything the post is sent to runalyze with sportid=3.

@mipapo Could you confirm that in runalyze.com the sport with id 3 is Biking?

I continue being very busy but I'll try to take a look to this issue.

mipapo commented 7 years ago

@rickyepoderi No, that is the Id from the database and it will be always different for each user. You have to recognize and map the sport by the name. (which can be different for each user (language reasons))

rickyepoderi commented 7 years ago

But is there a way to know which id to send? (Some page to request for example) Or can I send a string instead of a number?

mipapo commented 7 years ago

@rickyepoderi No you can't. Guess the sport type by the name with (a language name) mapping like this. Go through all the sport names and if a name maps against a name then you know if it's running, biking or whatever https://github.com/Runalyze/Runalyze/blob/e0fe1ec9ae915de8c064d2acc57a9e69349a7037/inc/import/parser/class.ParserAbstractSingle.php#L184

rickyepoderi commented 7 years ago

I have just realized that the sportid and typeid are defined by each user in runalyze. I thought that they were global values and they didn't depend on user. So I suppose that the synchronizer always passes a wrong number and at the end the sport is running because this is the default in runalyze somehow.

In runnerup the type of the sport is very well known, I don't have to guess it. It is one of the following values of this enum:

https://github.com/jonasoreland/runnerup/blob/master/app/src/org/runnerup/workout/Sport.java

I think the only thing that the syhnchronizer can do is request the page for the form ("/activity/add") and parse the select for the sportid:

<select name="sportid" id="sportid" ">
  <option value="1" selected data-kcal="880" data-running="true" data-outside="true" data-distances="true">Running</option>
  <option value="2" data-kcal="743" data-distances="true">Swimming</option>
  <option value="3" data-kcal="770" data-outside="true" data-distances="true" data-power="true">Biking</option>
  <option value="4" data-kcal="280">Gymnastics</option>
  <option value="5" data-kcal="500">Other</option>
</select>

Besides this way I can also do the same for the typeid:

<select name="typeid" id="typeid" ">
  <option value="0" data-sport="all">---- select type</option>
  <option value="1" data-sport="1">Jogging</option>
  <option value="2" data-sport="1">Fartlek</option>
  <option value="3" data-sport="1">Interval training</option>
  <option value="4" data-sport="1">Tempo Run</option>
  <option value="5" data-sport="1">Race</option>
  <option value="6" data-sport="1">Regeneration Run</option>
  <option value="7" data-sport="1">Long Slow Distance</option>
  <option value="8" data-sport="1">Warm-up</option>
</select>

But obviously this is a horrible workaround. I'm going to wait a little just to see if anybody else has another idea

craftyguy commented 7 years ago

I have just realized that the sportid and typeid are defined by each user in runalyze. I thought that they were global values and they didn't depend on user.

I'm not sure I understand, there doesn't seem to be any way for me to define sportid and typeid in runalyze, else I could try to make them match what is being sent by runnerup!

rickyepoderi commented 7 years ago

I'm not sure I understand, there doesn't seem to be any way for me to define sportid and typeid in runalyze, else I could try to make them match what is being sent by runnerup!

You're right. The user just can add sports and types and the ids are assigned automatically. My idea is requesting the add page and parsing the html selects to get the names and the ids. Then I'll select the id doing some comparison over the name. But it is a very nasty and tedious thing. I'll try to do it in the next weeks.

rickyepoderi commented 7 years ago

I have added the parsing and all the things today. It is in my repo, this commit: https://github.com/rickyepoderi/runnerup/commit/6bd8a5fa2be0b9f071acf5bc4f368d989984a0b1

@craftyguy I have upload the apk in my repo. I have tested it but with running activities. It would be nice if you test it with biking activities. At the moment the sport in runalyze should contain the name of the activity in runnerup no matter the case (in you case "biking"). By default in runalyze there is a "Biking" so it is enough.

https://github.com/rickyepoderi/runnerup/releases/tag/v1.57-alpha

Please make a backup of the application (Settings -> Maintenance -> Export) and then install my apk. After that import it again (Settings -> Maintenance -> Import) and try the synchronization.

@mipapo Don't change a lot the /activity/add page. :wink:

mipapo commented 7 years ago

@rickyepoderi Not in the next release

craftyguy commented 7 years ago

@rickyepoderi

Awesome! I will try to take a look at this over the weekend. It might actually be nice enough over here to go on a long bike ride :)

craftyguy commented 7 years ago

@rickyepoderi

Just tested out your apk, and it correctly uploads a biking event in Runnerup, and shows as a biking event in Runalyze!

rickyepoderi commented 7 years ago

Ok, perfect. I want to test the same with my server (it is version 3.0 or 3.1, I don't remember it right now) and if it also works I'll submit the pull. I know I have to upgrade my server more often but I have no much free time.

@VCleemput @Marx2 With this change the synchronization also sends a typeid if defined, it sends the first one (the one with the smallest id). So it would also fix the the VDOT issue.

gerhardol commented 7 years ago

Included in v1.58