Repository: marcua/datools (language: python)

Issue:
Dummy dataset for testing



Discussion / hints:

Fix patch:
diff --git a/datools/scorpion/hypotheses.py b/datools/scorpion/explanations.py
similarity index 87%
rename from datools/scorpion/hypotheses.py
rename to datools/scorpion/explanations.py
index a17ecb9..e5a9a55 100644
--- a/datools/scorpion/hypotheses.py
+++ b/datools/scorpion/explanations.py
@@ -1,5 +1,7 @@
 from typing import Tuple
 
+from sqlalchemy.engine import Engine
+
 from datools.models import Aggregate
 from datools.models import Column
 from datools.models import Operator
@@ -8,15 +10,15 @@
 from datools.models import Table
 
 
-def generate_hypotheses(
-        connection,
+def generate_explanations(
+        engine: Engine,
         table: Table,
         group_bys: Tuple[Column, ...],
         aggregate: Tuple[Aggregate, ...],
         outlier_predicates: Tuple[Predicate, ...],
         holdout_predicates: Tuple[Predicate, ...]
 ) -> Tuple[Predicate, ...]:
-    """Generates hypothesis predicates based on Scorpion (Wu & Madden,
+    """Generates explanation predicates based on Scorpion (Wu & Madden,
     VLDB 2013) that cause an aggregate to be different in an outlier
     set than a holdout set.
 
diff --git a/setup.py b/setup.py
index 002abec..b8c4026 100644
--- a/setup.py
+++ b/setup.py
@@ -13,6 +13,7 @@
 requirements = [
     'Click>=7.0',
     'dataclasses==0.8; python_version<"3.7"',
+    'sqlalchemy==1.4.17'
 ]
 
 setup_requirements = ['pytest-runner', ]


Test patch:
diff --git a/tests/fixtures.py b/tests/fixtures.py
new file mode 100644
index 0000000..4f8056d
--- /dev/null
+++ b/tests/fixtures.py
@@ -0,0 +1,52 @@
+from datetime import datetime
+
+from sqlalchemy import create_engine
+from sqlalchemy import DateTime
+from sqlalchemy import Float
+from sqlalchemy import Integer
+from sqlalchemy import MetaData
+from sqlalchemy import String
+from sqlalchemy.engine import Engine
+from sqlalchemy.schema import Column
+from sqlalchemy.schema import Table
+
+
+def generate_testdb() -> Engine:
+    """Create a test DB from Table 1 of the Scorpion paper.
+
+    Rather than make sensor_id a foreign key, we make it a character
+    type to test a wider variety of column types.
+    """
+    engine = create_engine('sqlite://')
+    conn = engine.connect()
+    metadata = MetaData()
+    sensor_readings = Table(
+        'sensor_readings', metadata,
+        Column('id', Integer, primary_key=True),
+        Column('created_at', DateTime, nullable=False),
+        Column('sensor_id', String, nullable=False),
+        Column('voltage', Float, nullable=False),
+        Column('humidity', Float, nullable=False),
+        Column('temperature', Float, nullable=False),
+    )
+    metadata.create_all(engine)
+    values = [
+        (datetime(2021, 5, 5, 11), '1', 2.64, 0.4, 34),
+        (datetime(2021, 5, 5, 11), '2', 2.65, 0.5, 35),
+        (datetime(2021, 5, 5, 11), '3', 2.63, 0.4, 35),
+        (datetime(2021, 5, 5, 12), '1', 2.7, 0.3, 35),
+        (datetime(2021, 5, 5, 12), '2', 2.7, 0.5, 35),
+        (datetime(2021, 5, 5, 12), '3', 2.3, 0.4, 100),
+        (datetime(2021, 5, 5, 13), '1', 2.7, 0.3, 35),
+        (datetime(2021, 5, 5, 13), '2', 2.7, 0.5, 35),
+        (datetime(2021, 5, 5, 13), '3', 2.3, 0.5, 80),
+    ]
+    conn.execute(sensor_readings.insert(), [
+        {'created_at': created_at,
+         'sensor_id': sensor_id,
+         'voltage': voltage,
+         'humidity': humidity,
+         'temperature': temperature}
+        for (created_at, sensor_id, voltage, humidity, temperature) in values
+    ])
+    return engine
diff --git a/tests/test_scorpion.py b/tests/test_scorpion.py
index 3ee1cf2..e4e4cca 100644
--- a/tests/test_scorpion.py
+++ b/tests/test_scorpion.py
@@ -7,13 +7,15 @@
 from datools.models import Predicate
 from datools.models import StringConstant
 from datools.models import Table
-from datools.scorpion.hypotheses import generate_hypotheses
+from datools.scorpion.explanations import generate_explanations
+from .fixtures import generate_testdb
 
 
 def test_scorpion():
+    engine = generate_testdb()
     assert(
-        generate_hypotheses(
-            None,
+        generate_explanations(
+            engine,
             Table('table'),
             (Column('group'), ),
             (Aggregate(AggregateFunction.AVERAGE, Column('agg')), ),