# Copyright 2021 The SQLNet Company GmbH
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
"""
Contains a wrapper around connect.
"""
import sqlite3
from .contains import _contains
from .count_above_mean import _CountAboveMean
from .count_below_mean import _CountBelowMean
from .count_distinct_over_count import _CountDistinctOverCount
from .email_domain import _email_domain
from .ewma import (
_EWMA1S,
_EWMA1M,
_EWMA1H,
_EWMA1D,
_EWMA7D,
_EWMA30D,
_EWMA90D,
_EWMA365D,
)
from .first import _First
from .get_word import _get_word
from .kurtosis import _Kurtosis
from .last import _Last
from .median import _Median
from .mode import _Mode
from .num_max import _NumMax
from .num_min import _NumMin
from .num_words import _num_words
from .quantiles import (
_Q1,
_Q5,
_Q10,
_Q25,
_Q75,
_Q90,
_Q95,
_Q99,
)
from .skew import _Skew
from .stddev import _Stddev
from .time_since_first_maximum import _TimeSinceFirstMaximum
from .time_since_first_minimum import _TimeSinceFirstMinimum
from .time_since_last_maximum import _TimeSinceLastMaximum
from .time_since_last_minimum import _TimeSinceLastMinimum
from .trend import _Trend
from .var import _Var
from .variation_coefficient import _VariationCoefficient
[docs]def connect(database):
"""
Generates a new sqlite3 connection.
This connection contains all customized aggregations
and transformation functions needed to execute the
SQL pipeline generated by getML. Other than that
it behaves just like a normal sqlite3 connection from
the Python standard library.
Args:
database (str):
Filename of the database. Use ':memory:' to
create an in-memory database.
"""
if not isinstance(database, str):
raise TypeError("'database' must be of type str")
if sqlite3.sqlite_version < "3.33.0":
raise ValueError(
"getML requires SQLite version 3.33.0 or above. Found version "
+ sqlite3.sqlite_version
+ ". Please upgrade Python and/or the Python sqlite3 package."
)
conn = sqlite3.connect(database)
conn.create_function("contains", 2, _contains)
conn.create_function("email_domain", 1, _email_domain)
conn.create_function("get_word", 2, _get_word)
conn.create_function("num_words", 1, _num_words)
conn.create_aggregate("COUNT_ABOVE_MEAN", 1, _CountAboveMean)
conn.create_aggregate("COUNT_BELOW_MEAN", 1, _CountBelowMean)
conn.create_aggregate("COUNT_DISTINCT_OVER_COUNT", 1, _CountDistinctOverCount)
conn.create_aggregate("EWMA_1S", 2, _EWMA1S)
conn.create_aggregate("EWMA_1M", 2, _EWMA1M)
conn.create_aggregate("EWMA_1H", 2, _EWMA1H)
conn.create_aggregate("EWMA_1D", 2, _EWMA1D)
conn.create_aggregate("EWMA_7D", 2, _EWMA7D)
conn.create_aggregate("EWMA_30D", 2, _EWMA30D)
conn.create_aggregate("EWMA_90D", 2, _EWMA90D)
conn.create_aggregate("EWMA_365D", 2, _EWMA365D)
conn.create_aggregate("FIRST", 2, _First)
conn.create_aggregate("KURTOSIS", 1, _Kurtosis)
conn.create_aggregate("LAST", 2, _Last)
conn.create_aggregate("MEDIAN", 1, _Median)
conn.create_aggregate("MODE", 1, _Mode)
conn.create_aggregate("NUM_MAX", 1, _NumMax)
conn.create_aggregate("NUM_MIN", 1, _NumMin)
conn.create_aggregate("Q1", 1, _Q1)
conn.create_aggregate("Q5", 1, _Q5)
conn.create_aggregate("Q10", 1, _Q10)
conn.create_aggregate("Q25", 1, _Q25)
conn.create_aggregate("Q75", 1, _Q75)
conn.create_aggregate("Q90", 1, _Q90)
conn.create_aggregate("Q95", 1, _Q95)
conn.create_aggregate("Q99", 1, _Q99)
conn.create_aggregate("SKEW", 1, _Skew)
conn.create_aggregate("STDDEV", 1, _Stddev)
conn.create_aggregate("TIME_SINCE_FIRST_MAXIMUM", 2, _TimeSinceFirstMaximum)
conn.create_aggregate("TIME_SINCE_FIRST_MINIMUM", 2, _TimeSinceFirstMinimum)
conn.create_aggregate("TIME_SINCE_LAST_MAXIMUM", 2, _TimeSinceLastMaximum)
conn.create_aggregate("TIME_SINCE_LAST_MINIMUM", 2, _TimeSinceLastMinimum)
conn.create_aggregate("TREND", 2, _Trend)
conn.create_aggregate("VAR", 1, _Var)
conn.create_aggregate("VARIATION_COEFFICIENT", 1, _VariationCoefficient)
return conn