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

Cannot get earliest stored value (limit 1) #210

Open
klein0r opened this issue Nov 9, 2022 · 6 comments
Open

Cannot get earliest stored value (limit 1) #210

klein0r opened this issue Nov 9, 2022 · 6 comments

Comments

@klein0r
Copy link
Contributor

klein0r commented Nov 9, 2022

Describe the bug

I want to use sendTo to get the first value (with the lowest timestamp) in history database. But that is not possible:

To Reproduce

Idea:

  • Select all data since timestamp 0
  • Ordered by date ascending
  • Limit result to 1 value
sendTo('history.0', 'getHistory', {
    id: 'yr.0.forecastHourly.0h.air_temperature',
    options: {
        start: 0,
        end: Date.now(),
        aggregate: 'none',
        returnNewestEntries: false,
        limit: 1,
    }
}, async (historyData) => {
    if (historyData.result.length > 0) {
        let startTs = historyData.result[0].ts;
        console.log(`Earliest vlaue -> ${formatDate(startTs, 'DD.MM.YYYY hh:mm:ss')}`);
    }
});

The first value in my DB is from 1636560079478 -> 10.11.2021 (~ 1 year old).
But I receive: Earliest vlaue -> 09.11.2022 11:25:28 (today).

When I set the limit to 2000, the result is Earliest vlaue -> 13.08.2022 18:25:29.

Seems like the limit is applied to "the wrong side" of the result.

Versions:

  • Adapter version: 2.2.0
@klein0r
Copy link
Contributor Author

klein0r commented Nov 9, 2022

Same behaviour with beta version 2.2.4

@Apollon77
Copy link
Contributor

Yes this is because of the 0 as start ... this is handled as "not defined" ... try 1 (or use 1.1.2000 becausthe adapter was not exosting before that date at all)

@klein0r
Copy link
Contributor Author

klein0r commented Nov 9, 2022

Just checked the code start: 0 doesn't survive the option checks. start: 1 does the trick! Maybe you should check if options.start is a number.

ioBroker.history/main.js

Lines 1224 to 1226 in 24cb6c5

if (!options.start && options.count) {
options.returnNewestEntries = true;
}

@Apollon77
Copy link
Contributor

No idea if this would be breaking for some visus or such ... no idea if someone sends start=0 to actually trigger this behaviour as it is now ... :-(

@klein0r
Copy link
Contributor Author

klein0r commented Nov 9, 2022

Ok, got it :) Feel free to close this issue

@Apollon77
Copy link
Contributor

I leave open, maybe a README note might be an idea

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

No branches or pull requests

2 participants