Skip to content

Commit

Permalink
updates for cli to work
Browse files Browse the repository at this point in the history
  • Loading branch information
cholmes committed Jul 25, 2023
1 parent a82f129 commit 1e5612d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 110 deletions.
103 changes: 96 additions & 7 deletions open_buildings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,104 @@ def main():
"""Console script for open_buildings."""
pass

def handle_comma_separated(ctx, param, value):
return value.split(',')

@main.command()
@click.argument('name')
def convert(name):
"""Create a new building with the given name."""
click.echo(f"Creating a new building: {name}")
# Add your logic to create a new building here
@main.command('benchmark')
@click.argument('input_path', type=click.Path(exists=True))
@click.argument('output_directory', type=click.Path(exists=True))
@click.option(
'--processes',
callback=handle_comma_separated,
default='duckdb,pandas,ogr',
help="The processing methods to use.",
)
@click.option(
'--formats',
callback=handle_comma_separated,
default='fgb,parquet,shp,gpkg',
help="The output formats.",
)
@click.option(
'--skip-split-multis',
is_flag=True,
help="Whether to keep multipolygons as they are without splitting into their component polygons.",
)
@click.option('--no-gpq', is_flag=True, help="Disable GPQ conversion.")
@click.option(
'--verbose', is_flag=True, help="Whether to print detailed processing information."
)
@click.option(
'--output-format',
default='ascii',
help="The format of the output. Options: ascii, csv, json.",
)
def benchmark(
input_path,
output_directory,
processes,
formats,
skip_split_multis,
no_gpq,
verbose,
output_format,
):
results = process_benchmark(
input_path, output_directory, processes, formats, not skip_split_multis, verbose
)

df = pd.DataFrame(results)
df = df.pivot(index='process', columns='format', values='execution_time')

if output_format == 'ascii':
print(
tabulate(df, headers="keys", tablefmt="fancy_grid")
) # or "grid" if you prefer
elif output_format == 'csv':
print(df.to_csv(index=False))
elif output_format == 'json':
print(df.to_json(orient='split', indent=4))
else:
raise ValueError('Invalid output format')

@main.command('convert')
@click.argument('input_path', type=click.Path(exists=True))
@click.argument('output_directory', type=click.Path(exists=True))
@click.option(
'--format',
type=click.Choice(['fgb', 'parquet', 'gpkg', 'shp']),
default='fgb',
help="The output format.",
)
@click.option(
'--overwrite', is_flag=True, help="Whether to overwrite existing output files."
)
@click.option(
'--process',
type=click.Choice(['duckdb', 'pandas', 'ogr']),
default='pandas',
help="The processing method to use.",
)
@click.option(
'--skip-split-multis',
is_flag=True,
help="Whether to keep multipolygons as they are without splitting into their component polygons.",
)
@click.option(
'--verbose', is_flag=True, help="Whether to print detailed processing information."
)
def convert(
input_path, output_directory, format, overwrite, process, skip_split_multis, verbose
):
process_geometries(
input_path,
output_directory,
format,
overwrite,
process,
not skip_split_multis,
verbose,
)

@main.command()
@click.argument('building_id')
Expand All @@ -25,6 +115,5 @@ def info(building_id):
click.echo("More info...")
# Add your logic to fetch building information here


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
103 changes: 0 additions & 103 deletions open_buildings/open_buildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,108 +464,5 @@ def process_benchmark(
)
return results


def handle_comma_separated(ctx, param, value):
return value.split(',')


@cli.command('convert')
@click.argument('input_path', type=click.Path(exists=True))
@click.argument('output_directory', type=click.Path(exists=True))
@click.option(
'--format',
type=click.Choice(['fgb', 'parquet', 'gpkg', 'shp']),
default='fgb',
help="The output format.",
)
@click.option(
'--overwrite', is_flag=True, help="Whether to overwrite existing output files."
)
@click.option(
'--process',
type=click.Choice(['duckdb', 'pandas', 'ogr']),
default='pandas',
help="The processing method to use.",
)
@click.option(
'--skip-split-multis',
is_flag=True,
help="Whether to keep multipolygons as they are without splitting into their component polygons.",
)
@click.option(
'--verbose', is_flag=True, help="Whether to print detailed processing information."
)
def convert(
input_path, output_directory, format, overwrite, process, skip_split_multis, verbose
):
process_geometries(
input_path,
output_directory,
format,
overwrite,
process,
not skip_split_multis,
verbose,
)


@cli.command('benchmark')
@click.argument('input_path', type=click.Path(exists=True))
@click.argument('output_directory', type=click.Path(exists=True))
@click.option(
'--processes',
callback=handle_comma_separated,
default='duckdb,pandas,ogr',
help="The processing methods to use.",
)
@click.option(
'--formats',
callback=handle_comma_separated,
default='fgb,parquet,shp,gpkg',
help="The output formats.",
)
@click.option(
'--skip-split-multis',
is_flag=True,
help="Whether to keep multipolygons as they are without splitting into their component polygons.",
)
@click.option('--no-gpq', is_flag=True, help="Disable GPQ conversion.")
@click.option(
'--verbose', is_flag=True, help="Whether to print detailed processing information."
)
@click.option(
'--output-format',
default='ascii',
help="The format of the output. Options: ascii, csv, json.",
)
def benchmark(
input_path,
output_directory,
processes,
formats,
skip_split_multis,
no_gpq,
verbose,
output_format,
):
results = process_benchmark(
input_path, output_directory, processes, formats, not skip_split_multis, verbose
)

df = pd.DataFrame(results)
df = df.pivot(index='process', columns='format', values='execution_time')

if output_format == 'ascii':
print(
tabulate(df, headers="keys", tablefmt="fancy_grid")
) # or "grid" if you prefer
elif output_format == 'csv':
print(df.to_csv(index=False))
elif output_format == 'json':
print(df.to_json(orient='split', indent=4))
else:
raise ValueError('Invalid output format')


if __name__ == "__main__":
cli()

0 comments on commit 1e5612d

Please sign in to comment.