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

wrong time on chart component #324

Closed
guiguid opened this issue May 20, 2024 · 12 comments
Closed

wrong time on chart component #324

guiguid opened this issue May 20, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@guiguid
Copy link
Contributor

guiguid commented May 20, 2024

Introduction

There is a gap in the time in SQLITE, and "chart" component ( True as TIME ).

To Reproduce

List of steps to reproduce the behavior. Include the sql file you are using and the eventual relevant parts of your database schema

select 
dt                      as date
FROM balance
ORDER BY balance.dt DESC LIMIT 1;
-- RETURN
-- 2024-05-20 08:26:49

others component works (timeline component) :

select 
    'timeline' as component,
    TRUE       as simple;
select 
    'Last Update at ' as title,
    dt                      as date
FROM balance
ORDER BY balance.dt DESC LIMIT 1;

image

Actual behavior

chart component display wrong time :

select 
    'chart'             as component,
    'Balance History' as title,
    'area'              as type,
    'indigo'            as color,
    5                   as marker,
    TRUE                as time;

select 
    dt as x,
    balance                     as y 
FROM balance
ORDER BY balance.dt DESC LIMIT 60;

image

Expected behavior

The time displayed by "chart" component should be the same as SQLITE and others components.

Version information

  • OS: NixOS
  • Database : SQLite
  • SQLPage Version : 0.20.5

Additional context

Local Time: GMT +1 (Paris) + Summer.

more

Thanks for this amazing tool!

@guiguid guiguid added the bug Something isn't working label May 20, 2024
@DSMejantel
Copy link

DSMejantel commented May 20, 2024

Bonjour,

You need ISO datetimes who are parsed and displayed in a readable format.
I use this expression : strftime('%Y-%m-%dT%H:%M:%fZ',date_created) as x

select 
    'chart' as component,
    'Historique du solde' as title,
    'area'  as type,
    'red'   as color,
    1 as marker,
    TRUE as time,
    1000 as ymax;   
select 
    strftime('%Y-%m-%dT%H:%M:%fZ',date_created) as x,
    printf("%.2f",(SUM(prix) OVER(order by date_created))) as y
    FROM finances; 

@guiguid
Copy link
Contributor Author

guiguid commented May 20, 2024

Thanks, this hack works!
image

But the documentation should be updated if not internally fixed in sqlpage it self.

@DSMejantel
Copy link

Re,
C'est dans la documentation de SQLPage comme suggéré avec l'exemple 1.

image

Mais cela nécessite quelques connaissances dépassant SQLpage pour s'adapter le cas échéant au format des données de sa base. Cela pourrait être rappelé avec un autre exemple.

@guiguid
Copy link
Contributor Author

guiguid commented May 20, 2024

Nice, I don't notice the subtility of " and ISO datetime are ....".
Thx

@DSMejantel : Mais d'un autre coté, si "chart" n'accepte que des dates ISO, pourquoi ne pas forcer la conversion via sqlpage ?
Car tout autre format de date sera sans interet. Pourquoi laisser ceci coté code utilisateur ?

@lovasoa
Copy link
Owner

lovasoa commented May 20, 2024

Hello @guiguid, and welcome to SQLPage !
Out of curiosity: what is the application you are building ?

The provided datetime string does not have timezone information, and SQLPage interprets it as a local datetime, but displays it as UTC on the x axis by default. I do agree that this behavior is surprising and should be changed.

The default behavior should be to display the data in the user's local timezone when no timezone info is provided. I will change that for the next version of SQLPage.

However, if I may give a piece of unsolicited advice: you probably should not store local datetime strings without timezone information in your database. Such strings are inherently ambiguous. You may want to store either a datetime string with timezone information (such as 2024-05-20 08:26:49+02:00), or a much more concise unix timestamp (unixepoch(), 1716196946)

@guiguid
Copy link
Contributor Author

guiguid commented May 20, 2024

Hi @lovasoa ,
I write a little web frontend for a mining wallet.
remote host <-> ssh <-> periodic nuShell scripts for data processing (in and out) <-> SQLITE DB <-> SQLPage as Gui frontend.

As all my users are ( for now) in the same TZ, I basically store datetime in local time in SQLITE db (Yes, KISS for now...)

CREATE TABLE balance (
    dt DATE DEFAULT (datetime('now','localtime')),
    ....
 );

I'll give a try to your advise.
Thanks

@lovasoa
Copy link
Owner

lovasoa commented May 20, 2024

The behavior of SQLPage concerning x axes in time series plots was changed.
You can have a look at the next (unreleased) version in lovasoa/sqlpage:main on docker.

@lovasoa
Copy link
Owner

lovasoa commented May 20, 2024

Your app sounds cool! Do you have a link? Have you written about it?

@guiguid
Copy link
Contributor Author

guiguid commented May 21, 2024

Not now. It's a private usage only, but I could write something about, that's a good idea.

@lovasoa
Copy link
Owner

lovasoa commented May 22, 2024

I would love to read about it. And if you have pain points while learning SQLPage, I'm very interested in that too, I'm currently trying to simplify and clarify the website and documentation.

@guiguid
Copy link
Contributor Author

guiguid commented May 22, 2024

I've point some things:

  • How to draw a multilines charts (the purpose of "series" is un clear for me , and I have not found examples.
  • Is it possible to add a "cron" feature in order to execute a .sql at given time or delay? (Perhaps in the file stored inside the DB with an additional column ?)
  • make file stored inside the DB compatible with sqlar native format. It makes easy to store sql file in db with no extra cost. Thanks SQLite ! ( just rename sqlpage_files to sqlar, and add 2 columns) . So update sql file in main SQLite DB will be as easy as : sqlite3 sqlpage/sslpage.db -Au *.sql

Maybe I have to open issue for each items above ?

@lovasoa
Copy link
Owner

lovasoa commented May 22, 2024

Thank you for the feedback!

1.I'll add a multi line plot example.

  1. For cron, that could be a good idea. In the meantime, it's easy to just use the native cron with curl to execute a SQLPage page at regular intervals.

  2. I didn't know sqlar, I'll look into it.

lovasoa added a commit that referenced this issue Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants