|
4 | 4 | import json |
5 | 5 | import os |
6 | 6 | import pathlib |
| 7 | +import traceback |
7 | 8 | from typing import Optional, List, Dict, Any |
8 | 9 | import sys |
9 | 10 | from pathlib import Path |
|
12 | 13 | src_path = Path(__file__).parent.parent / "src" |
13 | 14 | sys.path.insert(0, str(src_path)) |
14 | 15 |
|
15 | | -from energyml.utils.validation import validate_epc |
| 16 | +from energyml.utils.validation import ErrorType, validate_epc |
16 | 17 |
|
17 | 18 | from energyml.utils.constants import get_property_kind_dict_path_as_xml |
18 | 19 | from energyml.utils.data.datasets_io import CSVFileReader, HDF5FileWriter, ParquetFileWriter, DATFileReader |
19 | 20 | from energyml.utils.data.mesh import MeshFileFormat, export_multiple_data, export_obj, read_mesh_object |
20 | 21 | from energyml.utils.epc import Epc, gen_energyml_object_path |
21 | 22 | from energyml.utils.introspection import ( |
22 | 23 | get_class_from_simple_name, |
| 24 | + get_enum_values, |
23 | 25 | get_module_name_and_type_from_content_or_qualified_type, |
24 | 26 | random_value_from_class, |
25 | 27 | search_class_in_module_from_partial_name, |
@@ -548,6 +550,26 @@ def validate_files(): |
548 | 550 | parser = argparse.ArgumentParser() |
549 | 551 | # parser.add_argument("--folder", type=str, help="Input folder") |
550 | 552 | parser.add_argument("--file", "-f", type=str, help="Input file (json or xml or epc)") |
| 553 | + parser.add_argument( |
| 554 | + "--ignore-err-type", |
| 555 | + "-i", |
| 556 | + type=str, |
| 557 | + help=f"Error types to ignore. Possible values {get_enum_values(ErrorType)}", |
| 558 | + nargs="*", |
| 559 | + ) |
| 560 | + |
| 561 | + parser.add_argument( |
| 562 | + "--ignore-prodml-version-errs", |
| 563 | + action="store_false", |
| 564 | + dest="ignore_prodml_version_errs", |
| 565 | + help="Disable ignoring errors related to Prodml version (by default, these errors are ignored)", |
| 566 | + ) |
| 567 | + |
| 568 | + parser.add_argument( |
| 569 | + "--group-by-err-class", |
| 570 | + action="store_true", |
| 571 | + help="Group errors by their class (e.g. all validation errors together, all parsing errors together, etc.)", |
| 572 | + ) |
551 | 573 |
|
552 | 574 | args = parser.parse_args() |
553 | 575 |
|
@@ -615,14 +637,36 @@ def validate_files(): |
615 | 637 | else: |
616 | 638 | print(f"File {filename} is NOT a valid EnergyML EPC file: Empty EPC") |
617 | 639 | except Exception as e: |
| 640 | + traceback.print_exc() |
618 | 641 | print(f"File {filename} is NOT a valid EnergyML EPC file: {e}") |
619 | 642 |
|
620 | 643 | epc = Epc() |
621 | 644 | epc.energyml_objects = objects |
622 | 645 |
|
623 | | - err_json = [err.toJson() for err in validate_epc(epc)] |
| 646 | + err_json = [ |
| 647 | + err.toJson() |
| 648 | + for err in validate_epc(epc) |
| 649 | + if str(err.error_type).lower() not in (et.lower() for et in (args.ignore_err_type or [])) |
| 650 | + ] |
624 | 651 |
|
625 | | - print(json.dumps(err_json, indent=4)) |
| 652 | + err_json_sorted = sorted( |
| 653 | + err_json, key=lambda x: (x["err_class"], x["error_type"], x["object_uuid"] if "object_uuid" in x else "") |
| 654 | + ) |
| 655 | + |
| 656 | + if args.ignore_prodml_version_errs: |
| 657 | + err_json_sorted = [err for err in err_json_sorted if not ("prodml23" in err.get("msg", ""))] |
| 658 | + |
| 659 | + if args.group_by_err_class: |
| 660 | + err_json_grouped = {} |
| 661 | + for err in err_json_sorted: |
| 662 | + err_class = err.get("err_class", "UnknownErrorClass") |
| 663 | + if err_class not in err_json_grouped: |
| 664 | + err_json_grouped[err_class] = [] |
| 665 | + err_json_grouped[err_class].append(err) |
| 666 | + print(json.dumps(err_json_grouped, indent=4)) |
| 667 | + else: |
| 668 | + # print(json.dumps(err_json, indent=4)) |
| 669 | + print(json.dumps(err_json_sorted, indent=4)) |
626 | 670 |
|
627 | 671 |
|
628 | 672 | # def export_wavefront(): |
|
0 commit comments