Spaces:
Runtime error
Runtime error
Update data_types.py
Browse files- data_types.py +1 -58
data_types.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
from bitstring import BitString
|
| 3 |
from datetime import datetime
|
| 4 |
import math
|
| 5 |
import numpy as np
|
|
@@ -27,63 +26,7 @@ class RailNumber:
|
|
| 27 |
is_valid: bool = field(init=False, default=False)
|
| 28 |
|
| 29 |
def __post_init__(self):
|
| 30 |
-
|
| 31 |
-
self.decoding_flag = self.decode_hex()
|
| 32 |
-
if self.vehicle_number:
|
| 33 |
-
self.digits_vehicle_number = self.vehicle_number.replace(" ", "")
|
| 34 |
-
self.digits_vehicle_number = self.digits_vehicle_number.replace("-", "")
|
| 35 |
-
if len(self.digits_vehicle_number) >= 12:
|
| 36 |
-
self.vehicle_group = int(self.digits_vehicle_number[0:2])
|
| 37 |
-
self.country_id = int(self.digits_vehicle_number[2:4])
|
| 38 |
-
self.serial_number = int(self.digits_vehicle_number[4:11])
|
| 39 |
-
self.fleet_id = int(self.digits_vehicle_number[5:8])
|
| 40 |
-
self.fleet_member_id = int(self.digits_vehicle_number[8:11])
|
| 41 |
-
self.check_digit = int(self.digits_vehicle_number[11:])
|
| 42 |
-
self.is_valid = self.check_if_valid()
|
| 43 |
-
|
| 44 |
-
def decode_hex(self) -> int:
|
| 45 |
-
epc_binary_string = BitString(hex=self.hex_data).bin
|
| 46 |
-
epc_header = epc_binary_string[0:8] # epc header has length of 8 bits and for GIAI-96 should be 00110100
|
| 47 |
-
if not epc_header == '00110100':
|
| 48 |
-
return 1
|
| 49 |
-
epc_filter = epc_binary_string[8:11] # filter value has length 3, and can only be 001 which stands for rail
|
| 50 |
-
if not epc_filter == '001':
|
| 51 |
-
return 2
|
| 52 |
-
partition_value = int(epc_binary_string[11:14], base=2) # indicates len of comp. prefix and asset ref
|
| 53 |
-
# should check that 0<= partition value <= 6
|
| 54 |
-
if not 0 <= partition_value <= 6:
|
| 55 |
-
return 3
|
| 56 |
-
company_prefix_bits = 40 - (
|
| 57 |
-
3 * partition_value + math.floor(partition_value / 3)) # resolve parition value to bit length
|
| 58 |
-
company_digits = 12 - partition_value # resolve partition value to num of company prefix digits
|
| 59 |
-
# get num of bits according to partition value, then convert binary to int and get string of that int
|
| 60 |
-
epc_company_ref = str(int(epc_binary_string[14:14 + company_prefix_bits], base=2))
|
| 61 |
-
# now lets check that decoded company prefix digits have length that they are supposed to have
|
| 62 |
-
if not len(epc_company_ref) == company_digits:
|
| 63 |
-
return 4
|
| 64 |
-
self.company_ref = int(epc_company_ref)
|
| 65 |
-
# GIAI-96 has 96 bits, minus 14 bits for header, filter and partition leaves 82 bits for company prefix and asset ref
|
| 66 |
-
asset_reference_bits = 82 - company_prefix_bits
|
| 67 |
-
asset_reference_digits_max = 25 - company_digits # max. asset reference digits, max does not have to be reached!!
|
| 68 |
-
epc_asset_ref_binary = epc_binary_string[14 + company_prefix_bits:] # get binary part of epc string
|
| 69 |
-
if not len(epc_asset_ref_binary) == asset_reference_bits:
|
| 70 |
-
return 5
|
| 71 |
-
epc_asset_ref = str(int(epc_asset_ref_binary, base=2)) # whole asset ref num string
|
| 72 |
-
# now lets check that decoded company prefix digits have length that they are supposed to have
|
| 73 |
-
if not len(epc_asset_ref) <= asset_reference_digits_max:
|
| 74 |
-
return 6
|
| 75 |
-
## now follows the splitting of asset reference according to OTIF Einheitliche Technische Vorschriften
|
| 76 |
-
direction_flag = epc_asset_ref[0:1]
|
| 77 |
-
self.direction = int(direction_flag)
|
| 78 |
-
rail_asset_number = epc_asset_ref[1:] # get whole asset number to calculate and cross check the check digit
|
| 79 |
-
self.vehicle_number = " ".join([rail_asset_number[0:2], rail_asset_number[2:4],
|
| 80 |
-
rail_asset_number[4:11], rail_asset_number[11:]])
|
| 81 |
-
if not 1 <= self.direction <= 2:
|
| 82 |
-
return 7
|
| 83 |
-
elif not len(rail_asset_number) == 12:
|
| 84 |
-
return 8
|
| 85 |
-
else:
|
| 86 |
-
return 0
|
| 87 |
|
| 88 |
def check_if_valid(self) -> bool:
|
| 89 |
check_sum = 0
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
import math
|
| 4 |
import numpy as np
|
|
|
|
| 26 |
is_valid: bool = field(init=False, default=False)
|
| 27 |
|
| 28 |
def __post_init__(self):
|
| 29 |
+
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def check_if_valid(self) -> bool:
|
| 32 |
check_sum = 0
|