52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
from enum import Enum
|
|
from helix.constants.system_type import SystemType
|
|
|
|
|
|
class FileValidationMessage(Enum):
|
|
Generic = 'Input file has invalid data'
|
|
InvalidHeaders = 'Input file has less than 5 headers'
|
|
InvalidRowCount = 'Input file has no data'
|
|
DualTiltWindZone = 'Invalid wind zone for Dual Tilt System'
|
|
SingleTiltWindZone = 'Invalid wind zone for Single Tilt System'
|
|
PanelTypeOutOfBounds = 'Invalid Panel Type (Not in 1-4)'
|
|
PanelTypeTooFewCornersSingleTilt = 'Input file must have at least 4 corner modules per subarray'
|
|
PanelTypeTooFewCornersDualTilt = 'Input file must have at least 2 corner modules per subarray'
|
|
UnknownFileUploaded = 'Please upload a valid .txt or .dxf file'
|
|
ExpectedTxtFile = 'Invalid file uploaded. Please upload a valid .txt file.'
|
|
ExpectedDxfFile = 'Invalid file uploaded. Please upload a valid .dxf file.'
|
|
OldDxfFormat = 'Invalid Aurora format uploaded. Please upload a new format.'
|
|
PanelsTooClose = 'It appears that the panel coordinates are too close together. Please ensure that panel spacing is correct and that you have selected the correct configuration.'
|
|
|
|
@classmethod
|
|
def invalid_wind_zones(cls, system_type):
|
|
if system_type == SystemType.singleTilt:
|
|
return cls.SingleTiltWindZone
|
|
else:
|
|
return cls.DualTiltWindZone
|
|
|
|
@classmethod
|
|
def panel_type_too_few_corners(cls, system_type):
|
|
return {
|
|
SystemType.singleTilt: cls.PanelTypeTooFewCornersSingleTilt,
|
|
SystemType.dualTilt: cls.PanelTypeTooFewCornersDualTilt,
|
|
}[system_type]
|
|
|
|
|
|
class FileValidationError(object):
|
|
def __init__(self, validation_message, row_number):
|
|
self.row_number = row_number
|
|
self.validation_message = validation_message
|
|
|
|
def format_error_message(self):
|
|
if self.row_number:
|
|
return self.validation_message.value + ' on line ' + str(self.row_number)
|
|
return self.validation_message.value
|
|
|
|
def __repr__(self):
|
|
return "<ValidationError: " + self.format_error_message() + ">"
|
|
|
|
def __eq__(self, other):
|
|
if self.__class__ != other.__class__:
|
|
return False
|
|
return self.row_number == other.row_number and self.validation_message == other.validation_message
|