unewersal teg analazer
This commit is contained in:
238
main1.py
238
main1.py
@@ -1,5 +1,5 @@
|
|||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
data=[]
|
data=[]
|
||||||
class Data_farame():
|
class Data_farame():
|
||||||
@@ -13,115 +13,136 @@ class Data_farame():
|
|||||||
self.availability_coordinates = availability_coordinates #наличие координат
|
self.availability_coordinates = availability_coordinates #наличие координат
|
||||||
self.explanations = explanations #Пояснения
|
self.explanations = explanations #Пояснения
|
||||||
|
|
||||||
class CadastralErrorsParcels():
|
|
||||||
|
|
||||||
def chec_koordinat(self,CadastralErrorParcel):
|
class super_visor():
|
||||||
if 'EntitySpatial' in CadastralErrorParcel:
|
|
||||||
if 'SpatialElement' in CadastralErrorParcel['EntitySpatial'][0]:
|
def find_best_match(self,input_str: str) -> str:
|
||||||
|
keywords = {
|
||||||
|
"FormParcels":"Образование ЗУ",
|
||||||
|
"SpecifyParcels":"Уточнение ЗУ",
|
||||||
|
"CadastralErrorsParcels":"Исправление ЗУ",
|
||||||
|
"ExistObjectsRealty":"Уточнение ОКС",
|
||||||
|
"CadastralErrorsOKS":"Исправление ОКС"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Сравниваем коэффициент схожести (0.0 - 1.0) строки с каждым ключевым словом
|
||||||
|
best_match = max(keywords, key=lambda word: SequenceMatcher(None, input_str, word.lower()).ratio())
|
||||||
|
return keywords[best_match]
|
||||||
|
|
||||||
|
def chec_kad_number(self,atrebut):
|
||||||
|
if '@attributes' in atrebut:
|
||||||
|
if 'CadastralNumber' in atrebut['@attributes']:
|
||||||
|
return atrebut['@attributes']['CadastralNumber']
|
||||||
|
if 'CadastralNumber' in atrebut:
|
||||||
|
if '#text' in atrebut['CadastralNumber'][0]:
|
||||||
|
return atrebut['CadastralNumber'][0]['#text']
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def get_cad_block(self,cad_block):
|
||||||
|
temp = ""
|
||||||
|
for item in cad_block:
|
||||||
|
temp += f"{item['#text']}, "
|
||||||
|
return temp
|
||||||
|
|
||||||
|
def chec_cad_block(self, atrebut):
|
||||||
|
if 'CadastralBlocks' in atrebut:
|
||||||
|
if 'CadastralBlock' in atrebut['CadastralBlocks'][0]:
|
||||||
|
return self.get_cad_block(atrebut['CadastralBlocks'][0]['CadastralBlock'])
|
||||||
|
if 'CadastralBlock' in atrebut:
|
||||||
|
return atrebut['CadastralBlock'][0]['#text']
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def get_object_type(self,type:str):
|
||||||
|
if type == "002001002000":
|
||||||
|
return "Здание"
|
||||||
|
if type == "002001004000":
|
||||||
|
return "Сооружение"
|
||||||
|
if type == "002001005000":
|
||||||
|
return "Объект"
|
||||||
|
|
||||||
|
def chec_object_type(self, atrebut):
|
||||||
|
if 'ObjectType' in atrebut:
|
||||||
|
return self.get_object_type(atrebut['ObjectType'][0]['#text'])
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def chec_area(self,atrebut):
|
||||||
|
if "Area" in atrebut:
|
||||||
|
if "Area" in atrebut['Area'][0]:
|
||||||
|
if '#text' in atrebut['Area'][0]['Area'][0]:
|
||||||
|
return atrebut['Area'][0]['Area'][0]['#text']
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def chec_inaccuracy(self, atrebut):
|
||||||
|
if "Area" in atrebut:
|
||||||
|
if "Inaccuracy" in atrebut['Area'][0]:
|
||||||
|
if '#text' in atrebut['Area'][0]['Inaccuracy'][0]:
|
||||||
|
return atrebut['Area'][0]['Inaccuracy'][0]['#text']
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def chec_koordinat(self,atrebut):
|
||||||
|
if 'EntitySpatial' in atrebut:
|
||||||
|
if 'SpatialElement' in atrebut['EntitySpatial'][0]:
|
||||||
return "да"
|
return "да"
|
||||||
else:
|
else:
|
||||||
return "нет"
|
return "нет"
|
||||||
else:
|
else:
|
||||||
return "нет"
|
return "нет"
|
||||||
|
|
||||||
def __init__(self, xml_dict):
|
def chec_explanations(self,atrebut):
|
||||||
try:
|
if 'Explanations' in atrebut:
|
||||||
for item in xml_dict['Package'][0]['CadastralErrorsParcels'][0]['CadastralErrorParcel']:
|
return atrebut['Explanations'][0]['#text']
|
||||||
|
return "нет"
|
||||||
|
|
||||||
|
def chec_object(self, atrebut):
|
||||||
|
if '@attributes' in atrebut:
|
||||||
|
if 'CadastralNumber' in atrebut['@attributes']:
|
||||||
|
return True
|
||||||
|
if 'CadastralNumber' in atrebut:
|
||||||
|
if '#text' in atrebut['CadastralNumber'][0]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __init__(self, xml):
|
||||||
|
i = 0
|
||||||
|
for section_name, section_data in xml.get('Package', [{}])[0].items():
|
||||||
|
for group in section_data:
|
||||||
|
if isinstance(group, dict):
|
||||||
|
for item_type, item_list in group.items():
|
||||||
|
for obj in item_list:
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
if self.chec_object(obj):
|
||||||
data.append(
|
data.append(
|
||||||
Data_farame(
|
Data_farame(
|
||||||
section_KPTR="Исправление ЗУ",
|
section_KPTR=self.find_best_match(section_name),
|
||||||
cadastral_number=item['CadastralErrorExistParcel'][0]['@attributes']["CadastralNumber"],
|
cadastral_number=self.chec_kad_number(obj),
|
||||||
cadastral_quarter=item['CadastralErrorExistParcel'][0]['CadastralBlock'][0]['#text'],
|
cadastral_quarter=self.chec_cad_block(obj),
|
||||||
object_type="",
|
object_type=self.chec_object_type(obj),
|
||||||
land_plot_area=item['CadastralErrorExistParcel'][0]['Area'][0]['Area'][0]['#text'],
|
land_plot_area=self.chec_area(obj),
|
||||||
error_in_determining_area=item['CadastralErrorExistParcel'][0]['Area'][0]['Inaccuracy'][0]['#text'],
|
error_in_determining_area=self.chec_inaccuracy(obj),
|
||||||
availability_coordinates=self.chec_koordinat(item['CadastralErrorExistParcel'][0]),
|
availability_coordinates=self.chec_koordinat(obj),
|
||||||
explanations=""
|
explanations=self.chec_explanations(obj)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except:
|
|
||||||
return
|
|
||||||
|
|
||||||
class SpecifyParcel():
|
|
||||||
|
|
||||||
def chec_koordinat(self,new_parcel):
|
|
||||||
if 'EntitySpatial' in new_parcel:
|
|
||||||
if 'SpatialElement' in new_parcel['EntitySpatial'][0]:
|
|
||||||
return "да"
|
|
||||||
|
|
||||||
return "нет"
|
|
||||||
return "нет"
|
|
||||||
|
|
||||||
def chec_tag_ProvidingPassCadastralNumbers(self,PPCN):
|
|
||||||
if 'ProvidingPassCadastralNumbers' in PPCN['ExistParcel'][0]:
|
|
||||||
return PPCN['ExistParcel'][0]['ProvidingPassCadastralNumbers'][0]['Other'][0]['#text']
|
|
||||||
else:
|
else:
|
||||||
return ""
|
for inner_key, inner_items in obj.items():
|
||||||
|
for real_obj in inner_items:
|
||||||
def chec_tag_Explanation(self,Explanation):
|
if isinstance(real_obj, dict):
|
||||||
if 'Explanation' in Explanation['ExistParcel'][0]:
|
|
||||||
return Explanation['ExistParcel'][0]['Explanation'][0]['#text']
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def __init__(self, xml_dict):
|
|
||||||
try:
|
|
||||||
for i,item in enumerate(xml_dict['Package'][0]['SpecifyParcels'][0]['SpecifyParcel']):
|
|
||||||
data.append(
|
data.append(
|
||||||
Data_farame(
|
Data_farame(
|
||||||
section_KPTR="Уточнение ЗУ",
|
section_KPTR=self.find_best_match(section_name),
|
||||||
cadastral_number=item['ExistParcel'][0]['@attributes']["CadastralNumber"],
|
cadastral_number=self.chec_kad_number(real_obj),
|
||||||
cadastral_quarter=item['ExistParcel'][0]['CadastralBlock'][0]['#text'],
|
cadastral_quarter=self.chec_cad_block(real_obj),
|
||||||
object_type=self.chec_tag_ProvidingPassCadastralNumbers(PPCN=item),
|
object_type=self.chec_object_type(real_obj),
|
||||||
land_plot_area=item['ExistParcel'][0]['Area'][0]['Area'][0]['#text'],
|
land_plot_area=self.chec_area(real_obj),
|
||||||
error_in_determining_area=item['ExistParcel'][0]['Area'][0]['Inaccuracy'][0]['#text'],
|
error_in_determining_area=self.chec_inaccuracy(real_obj),
|
||||||
availability_coordinates=self.chec_koordinat(item['ExistParcel'][0]),
|
availability_coordinates=self.chec_koordinat(real_obj),
|
||||||
explanations=self.chec_tag_Explanation(Explanation=item)
|
explanations=self.chec_explanations(real_obj)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except:
|
|
||||||
return
|
|
||||||
|
|
||||||
class NewParcel:
|
pass
|
||||||
|
|
||||||
def add_new_data(self,doc_category):
|
|
||||||
data=""
|
|
||||||
for item in doc_category:
|
|
||||||
data += f"{item}: {doc_category[item][0]['#text']}, "
|
|
||||||
return data
|
|
||||||
|
|
||||||
def chec_koordinat(self,new_parcel):
|
|
||||||
if 'EntitySpatial' in new_parcel:
|
|
||||||
if 'SpatialElement' in new_parcel['EntitySpatial'][0]:
|
|
||||||
return "да"
|
|
||||||
else:
|
|
||||||
return "нет"
|
|
||||||
else:
|
|
||||||
return "нет"
|
|
||||||
|
|
||||||
def get_cad_number(self,object_realty):
|
|
||||||
cad_nimbers = ""
|
|
||||||
for item in object_realty:
|
|
||||||
cad_nimbers+=f"{item['InnerCadastralNumbers'][0]['CadastralNumber'][0]['#text']}, "
|
|
||||||
return cad_nimbers
|
|
||||||
|
|
||||||
def __init__(self,xml_dict):
|
|
||||||
try:
|
|
||||||
for new_parcel in xml_dict['Package'][0]['FormParcels'][0]['NewParcel']:
|
|
||||||
data.append(
|
|
||||||
Data_farame(
|
|
||||||
section_KPTR="Образование ЗУ",
|
|
||||||
cadastral_number=self.get_cad_number(new_parcel['ObjectsRealty'][0]['ObjectRealty']),
|
|
||||||
cadastral_quarter=new_parcel['CadastralBlock'][0]['#text'],
|
|
||||||
object_type="",
|
|
||||||
land_plot_area=new_parcel['Area'][0]['Area'][0]['#text'],
|
|
||||||
error_in_determining_area=new_parcel['Area'][0]['Inaccuracy'][0]['#text'],
|
|
||||||
availability_coordinates=self.chec_koordinat(new_parcel),
|
|
||||||
explanations=self.add_new_data(new_parcel['Category'][0]['DocCategory'][0])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except:
|
|
||||||
return
|
|
||||||
|
|
||||||
def lxml_to_dict(element):
|
def lxml_to_dict(element):
|
||||||
result = {}
|
result = {}
|
||||||
@@ -148,40 +169,13 @@ def lxml_to_dict(element):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#tree = etree.parse('C:/Users/USER/Downloads/12. ХМЛ КПТР в ексель/Исходные данные/Карта-план в хмл прмиер Копейск на кк 74 30 0104002/MapPlanTerritory_54F3719F-2ED8-48FF-8442-9813191EBA51.xml')
|
#tree = etree.parse('C:/Users/jze9/Downloads/12. ХМЛ КПТР в ексель/Исходные данные/Карта-план в хмл прмиер Копейск на кк 74 30 0104002/MapPlanTerritory_EA8F3032-3AF5-4FE2-9A0D-72BCCF94DF06.xml')
|
||||||
tree = etree.parse('C:/Users/USER/Downloads/12. ХМЛ КПТР в ексель/Исходные данные/Карта-план в хмл прмиер Копейск на кк 74 30 0104002/MapPlanTerritory_E2DF5B75-E136-48DA-BB4C-8887BA4ABF46.xml')
|
#tree = etree.parse('C:/Users/jze9/Downloads/12. ХМЛ КПТР в ексель/Исходные данные/Карта-план в хмл прмиер Копейск на кк 74 30 0104002/MapPlanTerritory_54F3719F-2ED8-48FF-8442-9813191EBA51.xml')
|
||||||
|
tree = etree.parse('C:/Users/jze9/Downloads/12. ХМЛ КПТР в ексель/Исходные данные/Карта-план в хмл прмиер Копейск на кк 74 30 0104002/MapPlanTerritory_E2DF5B75-E136-48DA-BB4C-8887BA4ABF46.xml')
|
||||||
xml_dict = lxml_to_dict(tree.getroot())
|
xml_dict = lxml_to_dict(tree.getroot())
|
||||||
temp = NewParcel(xml_dict)
|
|
||||||
temp = SpecifyParcel(xml_dict)
|
|
||||||
temp = CadastralErrorsParcels(xml_dict)
|
|
||||||
|
|
||||||
def get_cad_block(cad_block):
|
temp = super_visor(xml_dict)
|
||||||
temp = ""
|
|
||||||
for item in cad_block:
|
|
||||||
temp += f"{item['#text']}, "
|
|
||||||
return temp
|
|
||||||
|
|
||||||
def get_object_type(type:str):
|
|
||||||
if type == "002001002000":
|
|
||||||
return "Здание"
|
|
||||||
if type == "002001004000":
|
|
||||||
return "Сооружение"
|
|
||||||
if type == "002001005000":
|
|
||||||
return "Объект"
|
|
||||||
|
|
||||||
for item in xml_dict['Package'][0]['ExistNewObjectsRealty'][0]['ExistNewObjectRealty']:
|
|
||||||
data.append(
|
|
||||||
Data_farame(
|
|
||||||
section_KPTR="Уточнение ОКС",
|
|
||||||
cadastral_number=item['CadastralNumber'][0]['#text'],
|
|
||||||
cadastral_quarter=get_cad_block(item['CadastralBlocks'][0]['CadastralBlock']),
|
|
||||||
object_type=get_object_type(item['ObjectType'][0]['#text']),
|
|
||||||
land_plot_area="нет",
|
|
||||||
error_in_determining_area="нет",
|
|
||||||
availability_coordinates=self.chec_koordinat(new_parcel),
|
|
||||||
explanations=self.add_new_data(new_parcel['Category'][0]['DocCategory'][0])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user