Giter VIP home page Giter VIP logo

Comments (13)

adriangibbons avatar adriangibbons commented on August 17, 2024

Hey Bru :)

I'm in Australia and hadn't noticed any issues with my files from Garmin devices. Have a look at the Mountain-Biking demo - would be keen to know whether the lap info is out?

Please could you also see if when using Raw units (i.e. no conversion applied) the first lat/lon matches up with the start_position_lat and lon?

$pFFA = new adriangibbons\phpFITFileAnalysis('my_fit_file.fit', ['units' => 'raw']);

By default, the data is converted from semicircles, which you can read about here, to degrees. The formula for conversion is:

degrees = semicircles * ( 180 / 2^31 )

The same formula is applied whether the data is an array or not. Typically information in record fields is an array; and single values in lap and session fields.

// convert from semicircles to degress

// convert from semicircles to degress

So laps/sessions are probably being being processed by line 1925 or 1978, depending if you are using statute or metric units. (Yes, I should probably put it in a function, but inline duplicated code seems to work much quicker in PHP where the same algorithm is followed many times over!)

If you want a quick and easy fix, you could add something along the lines of:

// subtract the lat values from 180 to get the correct -ve value
// replace lines 1925 and 1978 with all of the below
if ($field === 'start_position_lat') {  // probably end_position_lat too?
    $this->data_mesgs[$message][$field] = 180.0 - round($this->data_mesgs[$message][$field] * (180.0 / pow(2, 31)), 5);
} else {
    $this->data_mesgs[$message][$field] = round($this->data_mesgs[$message][$field] * (180.0 / pow(2, 31)), 5);
}

Hope this helps, please let me know the results of using raw units! 👍

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

I've done some exploring and have discovered a problem that doesn't seem to be anything to do with the php-fit-file-analysis code. In fact I haven't touched the php-fit-file-analysis code at all.

The original test that I did that was giving me strange latitude values was done with an executable image that I had build using RapidEXE (http://deneskellner.com/sw/rapidexe).

I modified my code to optionally support the 'units'=>'raw' and made the test above using an .exe as before.

Doing more testing I find that if I run the PHP file from the command line I get:

>> php Fitdump.php /lap test.fit
[lap] Array
(
    [timestamp] => 1535774092
    [start_time] => 1535762315
    [start_position_lat] => -40.76535
    [start_position_long] => 175.16942
    [end_position_lat] => -40.65072
    [end_position_long] => 175.25716

i.e. correct negative latitudes for NZ.

If I create an executable using RapidEXE I get:

>> FitDump /lap test.fit
[lap] Array
(
    [timestamp] => 1535774092
    [start_time] => 1535762315
    [start_position_lat] => 220.76535
    [start_position_long] => 175.16942
    [end_position_lat] => 220.65072
    [end_position_long] => 175.25716

i.e. incorrect values for latitude. That's really weird given that all of the latitude values in [position_lat] are negative and correct.

The same phpFITFileAnalysis.php file is used in both cases.

Any thoughts?

Fjeldfross

from php-fit-file-analysis.

adriangibbons avatar adriangibbons commented on August 17, 2024

Sounds like the problem lies with RapidEXE, which looks like quite an interesting utility - I may have a use for something like that in future!

My first thoughts are that perhaps it is something to do with the way it is handling floats. From the article I shared:

degrees = semicircles * ( 180 / 2^31 )

What do you get if you output the following, using both with RapidEXE and without?

$my_const = 180.0 / pow(2, 31);
var_dump($my_const);

$start_position_lat_semicircles = -381356420;
var_dump($start_position_lat_semicircles);

$start_position_lat_degrees = $start_position_lat_semicircles * $my_const;
var_dump($start_position_lat_degrees);

from php-fit-file-analysis.

DenesKellner avatar DenesKellner commented on August 17, 2024

Hi, I'm the author of RapidEXE and I'd like to help.
Can you make a minimal php file to me that still produces this weird phenomenon?
Also, which PHP version are you using with the compiler?

from php-fit-file-analysis.

adriangibbons avatar adriangibbons commented on August 17, 2024

Hi @DenesKellner - will need @Fjeldfross to supply.
Adrian

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

Hello Dénes,
I did send you a message when I first came across this problem. I can't track the message down now. Anyway...
I'd be happy to send you a copy of my code. It's not very large but you'd also need the code from this repo too. I could also send you a FIT file to play with.
At the moment that's the best that I can do. I've been running flat out on other things and haven't had time to do even the test that Adrian suggested above.
Would that help?
I'm currently using PHP Version 5.6.23.

Fjeldfross.

from php-fit-file-analysis.

DenesKellner avatar DenesKellner commented on August 17, 2024

Hi Fjeldfross,

please do send all necessary files to me, I'm gonna take a look at it! Meanwhile, you might want to try it out using PHP 7.2 which is RapidEXE's default engine; I'm not expecting any difference but one can never know.

developer at deneskellner dot com is the way.

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

@adriangibbons

What do you get if you output the following, using both with RapidEXE and without?

$my_const = 180.0 / pow(2, 31);
var_dump($my_const);

$start_position_lat_semicircles = -381356420;
var_dump($start_position_lat_semicircles);

$start_position_lat_degrees = $start_position_lat_semicircles * $my_const;

So running your test with PHP Version 5.6.23:

FIT File Utilities>php AG_Test\AG_Test.php
float(8.3819031715393E-8)
int(-381356420)
float(-31.964925862849)

FIT File Utilities>AG_Test\AG_Test.exe
float(8.3819031715393E-8)
int(-381356420)
float(-31.964925862849)

I can't see a difference between the two.

All the best,
Fjeldfross

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

@DenesKellner

I'll gather together the files and e-mail them to you. It'll probably be a couple of days.

Thank you.

All the best,
Fjeldfross

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

@DenesKellner

I'v just e-mailed a package of files to you for you to explore. I hope that helps. I'm interested in what you find.

All the best,
Fjeldfross

from php-fit-file-analysis.

Fjeldfross avatar Fjeldfross commented on August 17, 2024

Oops. I didn't mean to close the issue. sorry.

from php-fit-file-analysis.

DenesKellner avatar DenesKellner commented on August 17, 2024

So, it turns out that by the time I had a chance to open the code samples, the issue has already been resolved; it was about PHP versions. I'm glad I didn't screw up any floating point numbers today :)

Also thanks for the improvement tips, @Fjeldfross !

from php-fit-file-analysis.

Related Issues (20)

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.