-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 2 more online JSON datasets for testing
- Loading branch information
Showing
2 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
City Lots San Francisco dataset (https://github.com/zemirco/sf-city-lots-json) | ||
""" | ||
import json | ||
from datetime import datetime | ||
|
||
try: | ||
from tqdm import tqdm | ||
except ImportError: | ||
tqdm = lambda x, **kwargs: x | ||
from json_to_models.generator import MetadataGenerator | ||
from json_to_models.models import compose_models | ||
from json_to_models.models.attr import AttrsModelCodeGenerator | ||
from json_to_models.models.base import generate_code | ||
from json_to_models.registry import ModelRegistry | ||
import requests | ||
|
||
URL = "https://raw.githubusercontent.com/zemirco/sf-city-lots-json/master/citylots.json" | ||
|
||
|
||
def load_data() -> dict: | ||
r = requests.get(URL, stream=True) | ||
total_size = int(r.headers.get('content-length', 0)) | ||
block_size = 1024 * 1024 | ||
bytes_data = b"" | ||
print(f"Start downloading data (total size {total_size / block_size:.2f}Mb)") | ||
for data in tqdm(r.iter_content(block_size), total=total_size // block_size, unit='Mb', unit_scale=True): | ||
bytes_data += data | ||
data = bytes_data.decode("utf-8") | ||
return json.loads(data) | ||
|
||
|
||
def main(): | ||
data = load_data() | ||
|
||
start_t = datetime.now() | ||
gen = MetadataGenerator() | ||
reg = ModelRegistry() | ||
print("Start generating metadata...") | ||
fields = gen.generate(data) | ||
print("Start generating models tree...") | ||
reg.process_meta_data(fields, model_name="Cities") | ||
print("Merging models...") | ||
reg.merge_models(generator=gen) | ||
print("Generating names...") | ||
reg.generate_names() | ||
|
||
print("Generating structure...") | ||
structure = compose_models(reg.models_map) | ||
print("Generating final code...") | ||
code = generate_code(structure, AttrsModelCodeGenerator) | ||
print(code) | ||
print(f"{(datetime.now() - start_t).total_seconds():.4f} seconds") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters