1
+ #!/usr/bin/env python
2
+ """Timing/Gap Test based on the IOOS QARTOD manuals."""
3
+
4
+ import logging
5
+ import warnings
6
+ from collections import namedtuple
7
+ from numbers import Real as N
8
+ from typing import Dict , List , Optional , Sequence , Tuple , Union
9
+ from datetime import datetime , timedelta
10
+ from enum import IntEnum
11
+ import numpy as np
12
+ import pandas as pd
13
+
14
+ try :
15
+ from numba .core .errors import NumbaTypeError
16
+ except ImportError :
17
+ NumbaTypeError = TypeError
18
+
19
+ from ioos_qc .utils import (
20
+ add_flag_metadata ,
21
+ great_circle_distance ,
22
+ isfixedlength ,
23
+ isnan ,
24
+ mapdates ,
25
+ )
26
+
27
+ L = logging .getLogger (__name__ )
28
+
29
+
30
+ class QartodFlags :
31
+ """Primary flags for QARTOD."""
32
+
33
+ GOOD = 1
34
+ UNKNOWN = 2
35
+ SUSPECT = 3
36
+ FAIL = 4
37
+ MISSING = 9
38
+
39
+
40
+ FLAGS = QartodFlags # Default name for all check modules
41
+ NOTEVAL_VALUE = QartodFlags .UNKNOWN
42
+
43
+ def timing_gap_test (tim_stmp : float , tim_inc : float ) -> np .ndarray :
44
+ """
45
+ Timing/Gap Test checks if the data has arrived within the expected time window.
46
+
47
+ Parameters
48
+ ----------
49
+ tim_stmp : float
50
+ Timestamp of the most recent data.
51
+ tim_inc : float
52
+ Allowed time increment or window for data to arrive (in seconds).
53
+
54
+ Returns
55
+ -------
56
+ flag_arr : np.ndarray
57
+ An array with the flag, 1 for Pass, 4 for Fail.
58
+ """
59
+
60
+ # Get the current timestamp
61
+ now = datetime .now ().timestamp ()
62
+
63
+ # Calculate the time difference between the current time and the data's timestamp
64
+ time_diff = now - tim_stmp
65
+
66
+ # Initialize flag array with a passing value
67
+ flag_arr = np .ma .ones (1 , dtype = "uint8" )
68
+
69
+ # If the time difference exceeds the allowed increment, flag as Fail
70
+ if time_diff > tim_inc :
71
+ flag_arr [0 ] = QartodFlags .FAIL
72
+
73
+ return flag_arr
0 commit comments