Skip to content

Add trend, segmentMinDuration, and segmentMaxDuration functions#756

Merged
mschoema merged 2 commits intoMobilityDB:masterfrom
estebanzimanyi:trend
Feb 6, 2026
Merged

Add trend, segmentMinDuration, and segmentMaxDuration functions#756
mschoema merged 2 commits intoMobilityDB:masterfrom
estebanzimanyi:trend

Conversation

@estebanzimanyi
Copy link
Copy Markdown
Member

@estebanzimanyi estebanzimanyi commented Jan 29, 2026

We give below the documentation of these functions in the MobilityDB Manual

  • trend: Return the trend of a temporal float with linear interpolation, which states whether its value is increasing, constant, or decreasing, represented, respectively, by 1, 0, and -1.
trend(tfloat) → tint

Note that the trend is NULL for instantaneous sequences.

SELECT trend(tfloat '[1@2001-01-01, 2@2001-01-02, 4@2001-01-03, 4@2001-01-04, 3@2001-01-05, 2@2001-01-06]');
-- [1@2001-01-01, 0@2001-01-03, -1@2001-01-04, -1@2001-01-06]
SELECT trend(tfloat '[1@2001-01-01]');
-- NULL
  • segmentMinDuration, segmentMaxDuration: Return a temporal boolean stating whether each segment of a continuous temporal sequence (set) has, respectively, at least or at most a given duration
segmentMinDuration(temp,interval,bool strict=true) → tbool
segmentMaxDuration(temp,interval,bool strict=true) → tbool

If strict is not specified, the value true is assumed by default, and therefore the function checks whether the segment
duration is strictly less than or greater than the interval. If the argument is set to false, the function checks whether the
segment duration is less/greater than or equal to the interval.

SELECT segmentMinDuration(tfloat '[1@2001-01-01, 0@2001-01-03, -1@2001-01-04,-1@2001-01-06]', '1 day');
-- {[t@2001-01-01, f@2001-01-03, t@2001-01-04, t@2001-01-06)}
SELECT segmentMinDuration(tfloat '[1@2001-01-01, 0@2001-01-03, -1@2001-01-04,-1@2001-01-06]', '1 day', false);
-- {[t@2001-01-01, t@2001-01-06)}
SELECT segmentMaxDuration(tfloat '[1@2001-01-01, 0@2001-01-03, -1@2001-01-04,-1@2001-01-06]', '1 day');
-- {[f@2001-01-01 00:00:00+01, f@2001-01-06 00:00:00+01)}
SELECT segmentMaxDuration(tfloat '[1@2001-01-01, 0@2001-01-03, -1@2001-01-04,-1@2001-01-06]', '1 day', false);
-- {[f@2001-01-01, t@2001-01-03, f@2001-01-04, f@2001-01-06)}

@mschoema
Copy link
Copy Markdown
Member

mschoema commented Feb 1, 2026

I'm not opposed to adding such functions, but could you add a some explanation of the functions and their use, that I could put as a commit message?

@mschoema mschoema merged commit d4ddd30 into MobilityDB:master Feb 6, 2026
18 checks passed
@mschoema mschoema deleted the trend branch February 6, 2026 19:58
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