Skip to content

Commit 325f25a

Browse files
authored
Merge pull request #16 from TaskarCenterAtUW/feature-performance-improvement
Performance Improvement
2 parents 8c5c8be + c1f79cf commit 325f25a

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
### 0.2.3
4+
- Performance improvement if there are any errors
5+
6+
37
### 0.2.2
48
- Added functionality to get the specific number of errors
59
```

src/example.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ASSETS_DIR = os.path.join(PARENT_DIR, 'tests/assets')
66
VALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'valid.zip')
77
INVALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'invalid.zip')
8+
INVALID_VANCOUVER_ZIP_FILE = os.path.join(ASSETS_DIR, 'vancouver-dataset.zip')
89
SCHEMA_DIR = os.path.join(PARENT_DIR, 'src/python_osw_validation/schema')
910
SCHEMA_FILE_PATH = os.path.join(SCHEMA_DIR, 'opensidewalks.schema.json')
1011

@@ -24,15 +25,21 @@ def valid_test_without_provided_schema():
2425
def invalid_test_with_provided_schema():
2526
validator = OSWValidation(zipfile_path=INVALID_ZIP_FILE, schema_file_path=SCHEMA_FILE_PATH)
2627
result = validator.validate()
27-
if not result.is_valid:
28-
for error in result.errors:
29-
print(error)
28+
print(f'Number of errors: {len(result.errors)}')
3029
print(f'Invalid Test With Provided Schema: {"Failed" if result.is_valid else "Passed"}')
3130

3231

3332
def invalid_test_without_provided_schema():
3433
validator = OSWValidation(zipfile_path=INVALID_ZIP_FILE)
35-
result = validator.validate()
34+
result = validator.validate(max_errors=10)
35+
print(f'Number of errors: {len(result.errors)}')
36+
print(f'Invalid Test With Provided Schema: {"Failed" if result.is_valid else "Passed"}')
37+
38+
39+
def invalid_test_vancouver_dataset():
40+
validator = OSWValidation(zipfile_path=INVALID_VANCOUVER_ZIP_FILE)
41+
result = validator.validate(max_errors=30)
42+
print(f'Number of errors: {len(result.errors)}')
3643
print(f'Invalid Test Without Schema: {"Failed" if result.is_valid else "Passed"}')
3744

3845

@@ -41,3 +48,4 @@ def invalid_test_without_provided_schema():
4148
valid_test_without_provided_schema()
4249
invalid_test_with_provided_schema()
4350
invalid_test_without_provided_schema()
51+
invalid_test_vancouver_dataset()

src/python_osw_validation/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ def validate_osw_errors(self, file_path: str, max_errors: int) -> bool:
152152
'''Validate OSW Data against the schema and process all errors'''
153153
geojson_data = self.load_osw_file(file_path)
154154
validator = jsonschema.Draft7Validator(self.load_osw_schema(self.schema_file_path))
155-
errors = list(validator.iter_errors(geojson_data))
156-
157-
if errors:
158-
for index, error in enumerate(errors):
159-
if index < max_errors:
160-
self.errors.append(f'Validation error: {error.message}')
161-
if len(self.errors) == max_errors:
162-
break
155+
156+
for error in validator.iter_errors(geojson_data):
157+
self.errors.append(f'Validation error: {error.message}')
158+
if len(self.errors) == max_errors:
159+
break
160+
161+
if len(self.errors) >= max_errors:
163162
return False
163+
164164
return True
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.2'
1+
__version__ = '0.2.3'

tests/assets/vancouver-dataset.zip

6.76 MB
Binary file not shown.

0 commit comments

Comments
 (0)