-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
51 lines (38 loc) · 1.06 KB
/
Copy pathbasic_usage.py
File metadata and controls
51 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Basic Hawk Python usage.
Install locally first:
maturin develop -m crates/hawk-python/Cargo.toml
Then run:
python examples/python/basic_usage.py
"""
from pathlib import Path
import shutil
import tempfile
import hawk_engine
def main():
root = Path(tempfile.gettempdir()) / "hawk-python-basic"
if root.exists():
shutil.rmtree(root)
csv_path = root.with_suffix(".csv")
csv_path.write_text(
"\n".join(
[
"score,category,time",
"0.1,billing,2024",
"0.2,billing,2024",
"-0.4,login,2025",
"-0.5,login,2025",
"0.3,search,2025",
]
)
+ "\n"
)
db = hawk_engine.HawkDB.create(str(root))
report = db.ingest(str(csv_path))
print(report)
print(db.query("COMPARE category BETWEEN time:2024 AND time:2025"))
print(db.query("TRACK category FROM time:2024"))
db.close()
shutil.rmtree(root, ignore_errors=True)
csv_path.unlink(missing_ok=True)
if __name__ == "__main__":
main()