|
1 | 1 | import json |
2 | | -import uuid |
3 | | -import logging |
4 | | -from datetime import datetime as dt |
5 | | -from math import cos, sin, atan2, sqrt, radians, degrees |
6 | 2 |
|
7 | | -from esdl import Notes, Line, Point, Polygon, Note |
8 | 3 | from flask import request, Response |
9 | 4 | from flask_restx import Resource |
10 | 5 |
|
11 | 6 | from esdlvalidator.api import app |
12 | 7 | from esdlvalidator.api.controller import validationService |
13 | 8 | from esdlvalidator.core.exceptions import SchemaNotFound |
14 | | -from esdlvalidator.validation.functions import utils |
15 | 9 |
|
16 | 10 | parser = app.api.parser() |
17 | 11 | parser.add_argument("data", type=str, required=True) |
18 | | -parser.add_argument("schemas", type=str, required=True) |
| 12 | +parser.add_argument("schemas", type=str, help="List of schema id's, comma separated", required=True) |
19 | 13 |
|
20 | 14 |
|
21 | 15 | @app.ns_validation_to_msgs.route('/') |
@@ -83,77 +77,3 @@ def set_messages(result, asset, msgs): |
83 | 77 | return result |
84 | 78 | result.append({"assetID": asset, "messages": msgs}) |
85 | 79 | return result |
86 | | - |
87 | | - def update_esdl(self, resource, results: dict): |
88 | | - asset_notes = {} |
89 | | - now = dt.now() |
90 | | - |
91 | | - notes = Notes() |
92 | | - notes.id = str(uuid.uuid4()) |
93 | | - notes.name = "Validation Notes" |
94 | | - |
95 | | - for schema in results['schemas']: |
96 | | - for validation in schema['validations']: |
97 | | - if "errors" in validation: |
98 | | - for error in validation['errors']: |
99 | | - if isinstance(error, dict): |
100 | | - asset_id = error["offending_asset"] |
101 | | - message = error["message"] |
102 | | - if asset_id in asset_notes: |
103 | | - note = asset_notes[asset_id] |
104 | | - note.text = note.text + "\nERROR: {}".format(message) |
105 | | - else: |
106 | | - asset = resource.uuid_dict[asset_id] |
107 | | - p = self.get_center_point(asset) |
108 | | - note = Note(id=str(uuid.uuid4()), mapLocation=p, author="ESDLValidatorService", |
109 | | - title=asset_id, text="ERROR: {}".format(message), date=now) |
110 | | - asset_notes[asset_id] = note |
111 | | - if "warnings" in validation: |
112 | | - for warning in validation['warnings']: |
113 | | - if isinstance(warning, dict): |
114 | | - asset_id = warning["offending_asset"] |
115 | | - message = warning["message"] |
116 | | - if asset_id in asset_notes: |
117 | | - note = asset_notes[asset_id] |
118 | | - note.text = note.text + "\nWARNING: {}".format(message) |
119 | | - else: |
120 | | - asset = resource.uuid_dict[asset_id] |
121 | | - p = self.get_center_point(asset) |
122 | | - note = Note(id=str(uuid.uuid4()), mapLocation=p, author="ESDLValidatorService", |
123 | | - title=asset_id, text="WARNING: {}".format(message), date=now) |
124 | | - asset_notes[asset_id] = note |
125 | | - for n in asset_notes.values(): |
126 | | - notes.note.append(n) |
127 | | - |
128 | | - return notes |
129 | | - |
130 | | - @staticmethod |
131 | | - def get_center_point(asset): |
132 | | - a = asset |
133 | | - while not utils.has_attribute(a, 'geometry'): |
134 | | - a = a.eContainer() |
135 | | - geometry = a.geometry |
136 | | - points = None |
137 | | - if isinstance(geometry, Polygon): |
138 | | - points = geometry.exterior[0:2] |
139 | | - elif isinstance(geometry, Line): |
140 | | - points = geometry.point[0:2] |
141 | | - elif isinstance(geometry, Point): |
142 | | - points = [geometry] |
143 | | - x = [] |
144 | | - y = [] |
145 | | - z = [] |
146 | | - for p in points: |
147 | | - x.append(cos(radians(p.lat)) * cos(radians(p.lon))) |
148 | | - y.append(cos(radians(p.lat)) * sin(radians(p.lon))) |
149 | | - z.append(sin(radians(p.lat))) |
150 | | - |
151 | | - x_avg = (sum(x) / len(x)) |
152 | | - y_avg = (sum(y) / len(y)) |
153 | | - z_avg = (sum(z) / len(z)) |
154 | | - |
155 | | - lon = atan2(y_avg, x_avg) |
156 | | - hyp = sqrt(x_avg * x_avg + y_avg * y_avg) |
157 | | - lat = atan2(z_avg, hyp) |
158 | | - |
159 | | - return Point(lat=degrees(lat), lon=degrees(lon)) |
0 commit comments