ConsecutiveValues ( )

Function stats

Average user rating
37
124
9999
Support
FileMaker 8.5 +
Date posted
08 December 2008
Last updated
15 May 2009
Version
Recursive function
Yes

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

ConsecutiveValues  ( _valueList;   _dataType;   _interval;   _numberOfValues )


Parameters

_valueList  


_dataType  


_interval  a number, describing the interval between two values


_numberOfValues  the number of consecutive values you want to find


Description

Tags:  Timestamp   Time   Number   List   Filter   Date  

Finds consecutive items in a list of values and returns the first of each group.
Designed to find a free time slice in an agenda, for example.

_valueList is a list of availables values
_dataType can be number, date, time, or timestamp
_interval is a number describing the interval between values of the list (for a list of timestamps where an item is a quarter of an hour, this should be set to 900 (60*15)
_numberOfValues is the number of consecutive items you want to find.

error is returned if datatype is incorrect or if the list is invalid (not matching the datatype and the interval)

Examples

Sample input

ConsecutiveValues ( "05/01/2009 11:30¶05/01/2009 11:45¶05/01/2009 12:00¶05/01/2009 12:15¶05/01/2009 12:30¶05/01/2009 12:45¶05/01/2009 13:15¶05/01/2009 13:30¶05/01/2009 13:45¶05/01/2009 14:00¶05/01/2009 14:15¶05/01/2009 14:30¶05/01/2009 14:45¶05/01/2009 17:30¶05/01/2009 17:45" ; "timeStamp" ; 900 ; 6 )


Sample output

05/01/2009 11:30¶05/01/2009 13:15¶05/01/2009 13:30 (the 3 first of 6 consecutive values incremented by 900 seconds - 15 minutes)

 

Function code

/* ConsecutiveValues ( _valueList ; _dataType ; _interval ; _numberOfValues )

Fabrice Nordmann
on a Ugo Di Luca idea

v.ß1.6 - Dec 2008
- if _numberOfValues is 0 or 1, simply returns _valueList
v.ß1.5 - Dec 2008


Finds consecutive items in a list of values and returns the first of each group.
Designed to find a free time slice in an agenda, for example.

_valueList is a list of availables values
_dataType can be number, date, time, or timestamp
_interval is a number describing the interval between values of the list (for a list of timestamps where an item is a quarter of an hour, this should be set to 900 (60*15)
_numberOfValues is the number of consecutive items you want to find.

error is returned if datatype is incorrect or if the list is invalid (not matching the datatype and the interval)

*/
Case ( _numberOfValues < 2 ; _valueList ;
Case ( $$cf_cv_counter < ValueCount ( _valueList ) ;

Let ( [
$$cf_cv_counter = $$cf_cv_counter + 1
; _value = Evaluate ( "Getas" & _dataType & "(" & Quote ( GetValue ( _valueList ; $$cf_cv_counter )) & ")" )
; $$cf_cv_firstValue = Case ( $$cf_cv_counter = 1 ; _value ; $$cf_cv_firstValue ) // for error handling
; _numberOfValues = Max ( _numberOfValues ; 1 )
; _error = Case (
$$cf_cv_counter = 1 and IsEmpty ( FilterValues ( List ( "number" ; "date" ; "time" ; "timestamp" ) ; _dataType )) ; "ERROR -- CONSECUTIVEVALUES() -- Invalid data type : " & _dataType
; Mod ( _value - $$cf_cv_firstValue ; _interval ) ; "ERROR -- CONSECUTIVEVALUES() -- Invalid list : value #" & $$cf_cv_counter & " (" & _value & ") is not compatible with interval (" & _interval & ")" )
; _endValue = Evaluate ( "Getas" & _dataType & "(" & Quote ( GetValue ( _valueList ; $$cf_cv_counter + ( _numberOfValues - 1 ))) & ")" )
; _expected = _value + _interval * ( _numberOfValues - 1 )
; $$cf_cv_result = List ( $$cf_cv_result ; Case ( not IsEmpty ( _endValue ) and _endValue = _expected ; _value ))
];

/* DEBUG
"Value : " & _value & " | Expected : " & _expected " | EndValue: " & _endValue & " | " & Case ( not IsEmpty ( _endValue ) and _endValue = _expected ; "X" )) & ¶ & ConsecutiveValues ( _valueList ; _dataType ; _interval ; _numberOfValues )
*/

Case ( not IsEmpty ( _error ) ; Let ([ _result = $$cf_cv_result ; $$cf_cv_result = "" ; $$cf_cv_counter = "" ; $$cf_cv_firstValue = "" ]; _error ) ;
ConsecutiveValues ( _valueList ; _dataType ; _interval ; _numberOfValues )
)
)
// initialise variables on the last iteration
; Let ([ _result = $$cf_cv_result ; $$cf_cv_result = "" ; $$cf_cv_counter = "" ; $$cf_cv_firstValue = "" ]; _result )
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/124

    Prototype: ConsecutiveValues( _valueList; _dataType; _interval; _numberOfValues )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 15 May 2009
    Version: 1.5

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (7)