python-osw-validation 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ class OSWValidation:
45
45
 
46
46
  return is_valid, list(duplicates)
47
47
 
48
- def validate(self) -> ValidationResult:
48
+ def validate(self, max_errors=20) -> ValidationResult:
49
49
  try:
50
50
  # Extract the zipfile
51
51
  zip_handler = ZipFileHandler(self.zipfile_path)
@@ -62,7 +62,8 @@ class OSWValidation:
62
62
  return ValidationResult(False, self.errors)
63
63
  for file in validator.files:
64
64
  file_path = os.path.join(file)
65
- is_valid = self.validate_osw_errors(file_path)
65
+ if not self.validate_osw_errors(file_path, max_errors):
66
+ break
66
67
 
67
68
  if self.errors:
68
69
  zip_handler.remove_extracted_files()
@@ -119,7 +120,7 @@ class OSWValidation:
119
120
 
120
121
  # Geometry validation: check geometry type in each file and test if coordinates make a shape that is reasonable geometric shape according to the Simple Feature Access standard
121
122
  for osw_file in OSW_dataset:
122
- invalid_geojson = OSW_dataset[osw_file][(OSW_dataset[osw_file].geometry.type != OSW_dataset_files[osw_file]['geometry']) | (OSW_dataset[osw_file].is_valid==False)]
123
+ invalid_geojson = OSW_dataset[osw_file][(OSW_dataset[osw_file].geometry.type != OSW_dataset_files[osw_file]['geometry']) | (OSW_dataset[osw_file].is_valid == False)]
123
124
  is_valid = len(invalid_geojson) == 0
124
125
  if not is_valid:
125
126
  self.errors.append(f"Invalid {osw_file} geometries found, id's of invalid geometries: {set(invalid_geojson['_id'])}")
@@ -128,7 +129,7 @@ class OSWValidation:
128
129
  for file in validator.externalExtensions:
129
130
  file_path = os.path.join(file)
130
131
  extensionFile = gpd.read_file(file_path)
131
- invalid_geojson = extensionFile[extensionFile.is_valid==False]
132
+ invalid_geojson = extensionFile[extensionFile.is_valid == False]
132
133
  is_valid = len(invalid_geojson) == 0
133
134
  if not is_valid:
134
135
  self.errors.append(f"Invalid geometries found in extension file {file}, list of invalid geometries: {invalid_geojson.to_json()}")
@@ -147,14 +148,17 @@ class OSWValidation:
147
148
  with open(graph_geojson_path, 'r') as file:
148
149
  return json.load(file)
149
150
 
150
- def validate_osw_errors(self, file_path: str) -> bool:
151
+ def validate_osw_errors(self, file_path: str, max_errors: int) -> bool:
151
152
  '''Validate OSW Data against the schema and process all errors'''
152
153
  geojson_data = self.load_osw_file(file_path)
153
154
  validator = jsonschema.Draft7Validator(self.load_osw_schema(self.schema_file_path))
154
155
  errors = list(validator.iter_errors(geojson_data))
155
156
 
156
157
  if errors:
157
- for error in errors:
158
- self.errors.append(f'Validation error: {error.message}')
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
159
163
  return False
160
164
  return True
@@ -1 +1 @@
1
- __version__ = '0.2.0'
1
+ __version__ = '0.2.2'
@@ -50,11 +50,20 @@ class ZipFileHandler:
50
50
  if len(zip_ref.namelist()) == 0:
51
51
  raise Exception('ZIP file is empty')
52
52
 
53
- first_item = zip_ref.namelist()[0]
54
-
55
- return f'{self.extracted_dir}/{first_item}'
53
+ internal_folder_name = self.find_internal_folder(zip_ref)
54
+ return os.path.join(self.extracted_dir,internal_folder_name)
56
55
  except Exception as e:
57
56
  self.error = f'Error extracting ZIP file: {e}'
57
+
58
+ # finds the first folder available in the extracted folder.
59
+ # returns empty if there are no folders inside
60
+ def find_internal_folder(self, zip_ref: zipfile.ZipFile)-> str:
61
+ for filename in zip_ref.namelist():
62
+ path = os.path.join(self.extracted_dir,filename)
63
+ if(os.path.isdir(path)):
64
+ return filename
65
+ return ''
66
+
58
67
 
59
68
  def remove_extracted_files(self) -> None:
60
69
  if self.extracted_dir and os.path.exists(self.extracted_dir):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-osw-validation
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Python library for OSW validation
5
5
  Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
6
  Author: Sujata Misra
@@ -49,9 +49,13 @@ This package validates the OSW geojson file. Package requires a OSW zip file pat
49
49
  from python_osw_validation import OSWValidation
50
50
 
51
51
  validator = OSWValidation(zipfile_path='<Zip file path>')
52
- result = validator.validate()
52
+ result = validator.validate()
53
53
  print(result.is_valid)
54
- print(result.errors)
54
+ print(result.errors) # will return first 20 errors by default if there are errors
55
+
56
+ result = validator.validate(max_errors=10)
57
+ print(result.is_valid)
58
+ print(result.errors) # will return first 10 errors depending on the max_errors parameter
55
59
 
56
60
  ```
57
61
 
@@ -0,0 +1,10 @@
1
+ python_osw_validation/__init__.py,sha256=eSbO0YrIk58FTqx8qfXT4fdfCEumDBL31xIWWrNpzvg,7390
2
+ python_osw_validation/extracted_data_validator.py,sha256=Tdo3I5xz9bmzlZh9OH7Fp8WOcM88VZe4kCrzR2WwVWY,3894
3
+ python_osw_validation/version.py,sha256=pKh2_hmFNUwG0JxbL18qxdmi_nmFpgRbR8X6IPZr08o,21
4
+ python_osw_validation/zipfile_handler.py,sha256=lCRraGcysxelVKswQw1r-i_9kGQGvRQk7hJkWUwiAPk,2692
5
+ python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
6
+ python_osw_validation-0.2.2.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
7
+ python_osw_validation-0.2.2.dist-info/METADATA,sha256=WpcdgiPau8t_FSI5jCDgFIH1YMXmBDTPKV-_lY-pNyc,6172
8
+ python_osw_validation-0.2.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
9
+ python_osw_validation-0.2.2.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
10
+ python_osw_validation-0.2.2.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- python_osw_validation/__init__.py,sha256=FcnVfsmppFObut-sj6iNz2DyJp5qGRaxeooiQ72mWIE,7173
2
- python_osw_validation/extracted_data_validator.py,sha256=Tdo3I5xz9bmzlZh9OH7Fp8WOcM88VZe4kCrzR2WwVWY,3894
3
- python_osw_validation/version.py,sha256=clN3TnyYyt5T_wUJLVBmutS2kYLLBET4JFB2QXnRm2Q,21
4
- python_osw_validation/zipfile_handler.py,sha256=BPaEdKH-8RSeFAjMdLfJxPAhTG4Up3R6qZkAgoPfRh4,2271
5
- python_osw_validation/schema/opensidewalks.schema.json,sha256=i0iJwb_4Tq20BVUpkpgyM_7fm4SW_d_HNXKw0xul7OA,240987
6
- python_osw_validation-0.2.0.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
7
- python_osw_validation-0.2.0.dist-info/METADATA,sha256=ztNx_Lj4CP3Z9_PMmfv8kULoIfPHKw6mrf7XJLY1Ac0,5951
8
- python_osw_validation-0.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
9
- python_osw_validation-0.2.0.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
10
- python_osw_validation-0.2.0.dist-info/RECORD,,