weatherDB.lib package
weatherDB.lib.utils module
Some utilities functions and classes that are used in the module.
- weatherDB.lib.utils.get_ftp_file_list(ftp_conn, ftp_folders)
Get a list of files in the folders with their modification dates.
- Parameters
ftp_conn (ftplib.FTP) – Ftp connection.
ftp_folders (list of str or pathlike object) – The directories on the ftp server to look for files.
- Returns
A list of Tuples. Every tuple stands for one file. The tuple consists of (filepath, modification date).
- Return type
list of tuples of strs
- class weatherDB.lib.utils.TimestampPeriod(start, end)
Bases:
objectA class to save a Timespan with a minimal and maximal Timestamp.
- COMPARE = {'inner': {0: <built-in function max>, 1: <built-in function min>}, 'outer': {0: <built-in function min>, 1: <built-in function max>}}
- __init__(start, end)
Initiate a TimestampPeriod.
- Parameters
start (pd.Timestamp or similar) – The start of the Period.
end (pd.Timestamp or similar) – The end of the Period.
- union(other, how='inner')
Unite 2 TimestampPeriods to one.
Compares the Periods and computes a new one.
- Parameters
other (TimestampPeriod) – The other TimestampPeriod with whome to compare.
how (str, optional) – How to compare the 2 TimestampPeriods. Can be “inner” or “outer”. “inner”: the maximal Timespan for both is computed. “outer”: The minimal Timespan for both is computed. The default is “inner”.
- Returns
A new TimespanPeriod object uniting both TimestampPeriods.
- Return type
- get_period()
- has_NaT()
Has the TimestampPeriod at least one NaT.
This means that the start or end is not given. Normally this should never happen, because it makes no sense.
- Returns
True if the TimestampPeriod has at least on NaT. False if the TimestampPeriod has at least a start or a end.
- Return type
bool
- has_only_NaT()
Has the TimestampPeriod only NaT, meaning is empty.
This means that the start and end is not given.
- Returns
True if the TimestampPeriod is empty. False if the TimestampPeriod has a start and an end.
- Return type
bool
- is_empty()
Is the TimestampPeriod empty.
This means that the start and end is not given.
- Returns
True if the TimestampPeriod is empty. False if the TimestampPeriod has a start and an end.
- Return type
bool
- strftime(format='%Y-%m-%d %H:%M:%S')
Convert the TimestampPeriod to a list of strings.
Formates the Timestamp as a string.
- Parameters
format (str, optional) – The Timestamp-format to use. The Default is “%Y-%m-%d %H:%M:%S”
- Returns
A list of the start and end of the TimestampPeriod as formated string.
- Return type
list of 2 strings
- inside(other)
Is the TimestampPeriod inside another TimestampPeriod?
- Parameters
other (Timestampperiod or tuple of 2 Timestamp or Timestamp strings) – The other Timestamp to test against. Test if this TimestampPeriod is inside the other.
- Returns
True if this TimestampPeriod is inside the other. Meaning that the start is higher or equal than the others starts and the end is smaller than the others end.
- Return type
bool
- contains(other)
Does this TimestampPeriod contain another TimestampPeriod?
- Parameters
other (Timestampperiod or tuple of 2 Timestamp or Timestamp strings) – The other Timestamp to test against. Test if this TimestampPeriod contains the other.
- Returns
True if this TimestampPeriod contains the other. Meaning that the start is smaller or equal than the others starts and the end is higher than the others end.
- Return type
bool
- get_sql_format_dict(format="'%Y%m%d %H:%M'")
Get the dictionary to use in sql queries.
- Parameters
format (str, optional) – The Timestamp-format to use. The Default is “’%Y%m%d %H:%M’”
- Returns
a dictionary with 2 keys (min_tstp, max_tstp) and the corresponding Timestamp as formated string.
- Return type
dict
- get_interval()
Get the interval of the TimestampPeriod.
- Returns
The interval of this TimestampPeriod. E.G. Timedelta(2 days 12:30:12)
- Return type
pd.Timedelta
- copy()
Copy this TimestampPeriod.
- Returns
a new TimestampPeriod object that is equal to this one.
- Return type