-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
58 lines (42 loc) · 1.85 KB
/
example.py
File metadata and controls
58 lines (42 loc) · 1.85 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
52
53
54
55
56
57
#!/usr/bin/env python3
# example.py
# -----------------------------------------------------------------------------
# Demonstration script that imports the 'synthetic_table_gen' package
# and shows a short example of EVERY table schema defined in TABLE_SCHEMAS.
# -----------------------------------------------------------------------------
"""
example.py
This script imports the 'synthetic_table_gen' package and loops over
all table schemas. For each schema, it generates a few rows of data
and prints the table plus JSON output to stdout.
Usage:
python example.py
Adjust the number of rows (n_rows) as needed to reduce output size.
"""
import numpy as np
# Import the dictionary of table schemas, which contains the generator function
# references and column definitions:
from synthetic_table_gen.schemas import TABLE_SCHEMAS
# Import the main function that generates and prints a table + JSON:
from synthetic_table_gen.main import generate_table_with_json_labels
def main():
"""
Loop over all schemas in TABLE_SCHEMAS, generate 3 rows from each,
and print the resulting table and JSON output.
"""
# Create a random generator with a fixed seed so examples are reproducible:
rng = np.random.default_rng(seed=12345)
# We iterate over each table name in TABLE_SCHEMAS.
# For each schema, we generate 3 rows, then print them out.
for table_name in TABLE_SCHEMAS.keys():
print(f"=== Demonstrating Schema: {table_name} ===\n")
# Generate 3 rows for this schema
result_str = generate_table_with_json_labels(table_name, n_rows=3, rng=rng)
# Print the output, which includes:
# 1) A randomly chosen table title
# 2) A formatted ASCII table
# 3) A JSON block
print(result_str)
print("\n" + "-"*80 + "\n") # A separator between tables
if __name__ == "__main__":
main()