Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recorder: 1 second period with 1 decimal place #3102

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

thyttan
Copy link
Collaborator

@thyttan thyttan commented Nov 16, 2023

This will make logs with 1 second periods record time with 1 decimal place precision.

EDIT3 - my first solution seemed to behave weirdly to me. But after sitting on it I realized it was probably just floating point number math doing what it does. The discussion that followed here no longer applies.

@thyttan
Copy link
Collaborator Author

thyttan commented Nov 17, 2023

So I guess it was just floating point math doing its thing, and not wrong per se. To get nicer formatting in the csv file, I've converted to string.

Seems to give good results now.

@thyttan thyttan force-pushed the recorder branch 2 times, most recently from 44c597b to d826fdf Compare November 17, 2023 21:33
@bobrippling
Copy link
Collaborator

Yeah that's floating point - there's no way to represent some numbers with that level of precision, and the nearest representable number might not be displayable in decimal (like how we can't write 1/3 in decimal)

So:

Math.round(n * 10) / 10

won't necessarily give you a number with a single decimal place. If you want that, you could try n.toFixed(1), which will give you exactly 1 decimal place (in a string), for popping into the CSV if you prefer

apps/recorder/widget.js Outdated Show resolved Hide resolved
@thyttan
Copy link
Collaborator Author

thyttan commented Nov 17, 2023

I tested the current code by recording just the time and battery status with periods 1 second and 2 seconds for ca 10 seconds each. Seems to work as it should.

EDIT: Also tried downloading the track with the recorder interface on the app loader and that also worked.

Thanks for the tips @bobrippling and for the feedback on #2819 @gfwilliams!

@thyttan thyttan marked this pull request as ready for review November 17, 2023 21:56
@bobrippling
Copy link
Collaborator

Nice - those changes LGTM, shall see if Gordon has anything to mention though 👀

@bobrippling
Copy link
Collaborator

I think let's merge - we can pick up other parts in #2819 if needed

@bobrippling bobrippling merged commit 0519375 into espruino:master Nov 22, 2023
1 check passed
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