Exemple #1
0
 def _insert(app_name):
     """
     This REST endpoint allows an application to append rows to their database by submitting a JSON 
     object in the `payload` field.
     """
     payload = loads(request.params.get("payload"))
     insert_payload(api.config['storage_dir'], app_name, payload)
     return ""
Exemple #2
0
def create_dummy_dataset(storage_dir):
    from sklearn.datasets import load_wine
    
    wine_dataset = load_wine()
    wine_dataset.feature_names = [k.replace("/", "_") for k in wine_dataset.feature_names]

    register_app(storage_dir, "dummy", {
        "wine": {
            "description": "Rows sampled from the Wine classification dataset.",
            "columns": {x: {"type": "float", "description": x} for x in wine_dataset.feature_names}
        }
    })

    i = randint(0, len(wine_dataset.data)-1)
    insert_payload(storage_dir, "dummy", {
        "wine": [
            {k: v for k, v in zip(wine_dataset.feature_names, wine_dataset.data[i])}
        ]
    })
Exemple #3
0
def test_handle_task(tmpdir):
    storage.initialize(tmpdir)
    storage.register_app(
        tmpdir, "example_app", {
            "tableA": {
                "description": "This table contains A.",
                "columns": {
                    "some_var": {
                        "type": "float",
                        "description": "This column contains 1."
                    }
                }
            }
        })
    storage.insert_payload(
        tmpdir, "example_app", {
            "tableA": [
                {
                    "some_var": 1.0
                },
                {
                    "some_var": 2.0
                },
                {
                    "some_var": 3.0
                },
                {
                    "some_var": 4.0
                },
                {
                    "some_var": 5.0
                },
            ]
        })

    task = {
        "type": "basic",
        "epsilon": 1.0,
        "featurizer": "SELECT sum(some_var) FROM example_app.tableA",
        "aggregator": "mean"
    }
    result, err = handler.handle_task(tmpdir, task)
    assert result[0] == 15.0
Exemple #4
0
def test_insert_payload_1(tmpdir):
    storage.initialize(tmpdir)
    storage.register_app(
        tmpdir, "example_app", {
            "tableA": {
                "description": "This table contains A.",
                "columns": {
                    "some_var": {
                        "type": "float",
                        "description": "This column contains 1."
                    },
                    "other_var": {
                        "type": "float",
                        "description": "This column contains 2."
                    }
                }
            }
        })
    storage.insert_payload(
        tmpdir, "example_app", {
            "tableA": [
                {
                    "some_var": 0.0,
                    "other_var": 1.0
                },
                {
                    "some_var": 10.0,
                    "other_var": 1.0
                },
            ]
        })
    data = storage.execute_sql(tmpdir, "SELECT * FROM example_app.tableA")
    assert len(data) == 2, "Expected two rows of data"
    for row in data:
        assert "some_var" in row
        assert "other_var" in row
    assert sum(row["some_var"] for row in data) == 10.0
    assert sum(row["other_var"] for row in data) == 2.0
Exemple #5
0
def create_synthetic_dataset(storage_dir):
    register_app(storage_dir, "profile", {
        "demographics": {
            "description": "",
            "columns": {
                "age": {"type": "float", "description": ""},
                "gender": {"type": "float", "description": ""},
                "income": {"type": "float", "description": ""},
                "city": {"type": "float", "description": ""},
                "state": {"type": "float", "description": ""},
                "zipcode": {"type": "float", "description": ""},
            }
        }
    })
    profile = sample_profile()
    insert_payload(storage_dir, "profile", profile)

    register_app(storage_dir, "browsing", {
        "history": {
            "description": "",
            "columns": {
                "timestamp": {"type": "float", "description": "When the website was opened"},
                "domain": {"type": "float", "description": "The domain (i.e. everything up to `.com`, `.net`, etc.)"},
            }
        },
    })
    insert_payload(storage_dir, "browsing", sample_browsing(profile))

    register_app(storage_dir, "screen_time", {
        "events": {
            "description": "",
            "columns": {
                "timestamp": {"type": "float", "description": "When the event occurred."},
                "event_type": {"type": "string", "description": "Whether the application was opened or closed."},
                "application_name": {"type": "string", "description": "Standardized name for the application."},
            }
        },
        "types": {
            "description": "",
            "columns": {
                "application_name": {"type": "string", "description": "Standardized name for the application."},
                "application_type": {"type": "string", "description": "Whether the application is for web browsing, software development, or communicaation."},
            }
        },
    })
    insert_payload(storage_dir, "screen_time", sample_screen_time(profile))
Exemple #6
0
def test_insert_payload_2(tmpdir):
    storage.initialize(tmpdir)

    storage.register_app(
        tmpdir, "app1", {
            "tableA": {
                "description": "This table contains A.",
                "columns": {
                    "some_var": {
                        "type": "float",
                        "description": "This column contains 1."
                    }
                }
            }
        })
    storage.insert_payload(
        tmpdir, "app1", {
            "tableA": [
                {
                    "some_var": 1.0
                },
                {
                    "some_var": 2.0
                },
                {
                    "some_var": 3.0
                },
                {
                    "some_var": 4.0
                },
                {
                    "some_var": 5.0
                },
            ]
        })

    storage.register_app(
        tmpdir, "app2", {
            "tableA": {
                "description": "This table contains A.",
                "columns": {
                    "some_var": {
                        "type": "float",
                        "description": "This column contains 1."
                    }
                }
            },
            "tableB": {
                "description": "This table contains B.",
                "columns": {
                    "some_var": {
                        "type": "float",
                        "description": "This column contains 1."
                    },
                    "other_var": {
                        "type": "float",
                        "description": "This column contains 2."
                    }
                }
            },
        })
    storage.insert_payload(
        tmpdir, "app2", {
            "tableA": [
                {
                    "some_var": 3.0
                },
            ],
            "tableB": [
                {
                    "some_var": 0.0,
                    "other_var": 1.0
                },
                {
                    "some_var": 10.0,
                    "other_var": 1.0
                },
            ]
        })

    data = storage.execute_sql(tmpdir, "SELECT * FROM app1.tableA")
    assert len(data) == 5, "Expected five rows of data"

    data = storage.execute_sql(tmpdir, "SELECT * FROM app2.tableA")
    assert len(data) == 1, "Expected one row of data"

    data = storage.execute_sql(tmpdir, "SELECT * FROM app2.tableB")
    assert len(data) == 2, "Expected two rows of data"