Please, don't ask why and how - it's painful as hell :(
tried if/elif
This one should search for keywords of class and return class value to append cycle.
!No need to read it full!
def func_class(segment, _classes, text, _classA, _classB, _classC, _classTRC, _classTRCP, _classRTC, _classRTCP, _classSR, _classOSN):
if text and segment:
if "Office" or "WH" in segment:
if True in list(map(lambda x: x in text, _classes[_classA][0])):
return "Class A"
elif "Office" in segment:
if True in list(map(lambda x: x in text, _classes[_classB][0])):
return "Class B"
elif "WH" in segment:
if True in list(map(lambda x: x in text, _classes[_classB][0])) or \
True in list(map(lambda x: x in text and True in [w not in text for w in _classes[_classA][0]],
_classes[_classB][1])):
return "Class B"
elif "Office" or "WH" in segment:
if True in list(map(lambda x: x in text, _classes[_classC][0])):
return "Class C"
elif "Shop" in segment:
if True in list(map(lambda x: x in text and True in (lambda y: True if [landsize > 9000] else False),
_classes[_classTRC][0])):
return "TRC"
elif "Shop" in segment:
if True in list(map(lambda x: x in text and True in (lambda y: True if [9000 > landsize > 3000] else False),
_classes[_classTRCP][0])):
return "TRCP"
elif "Shop" in segment:
if True in list(map(lambda x: x in text and True in (lambda y: True if [9000 >= landsize] else False),
_classes[_classRTC][0])):
return "RTC"
elif "Shop" in segment:
if True in list(map(lambda x: x in text and True in (lambda y: True if [1000 >= landsize] else False),
_classes[_classRTCP][0])):
return "RTCP"
elif "Shop" in segment:
if True in list(map(lambda x: x in text, _classes[_classSR][0])):
return "Street retail"
elif "ОСН" in segment:
if True in list(map(lambda x: x in text, _classes[_classOSN][0])):
return "OSN"
return ""
return ""
Sorry again, please. Not me started that hell. I just can't stop because deadline is in 6h and i'll become junior DS after it. And it's bedtime :(
Now append cycle:
for i in range(1, m_row + 1):
current_row = [sheet_obj.cell(row=i, column=x).value for x in range(1, sheet_obj.max_column + 1)]
cell_obj = sheet_obj.cell(row = i, column = 3)
check_word = qualifier(cell_obj.value, Rtype)
if check_word:
current_row.append(check_word)
current_row.append(func_class(check_word, classes, cell_obj.value, "Class A", "Class B", "Class C","TRC",
"TRCP", "RTC", "RTCP", "Street retail", "OSN"))
else:
if i == 1:
current_row.append("SEGMENT")
current_row.append("CLASS")
else:
current_row.append("")
current_row.append(func_class(check_word, classes, cell_obj.value, "Class A", "Class B", "Class C","TRC",
"TRCP", "RTC", "RTCP", "Street retail", "OSN"))
table.append(current_row)
I guess the trouble is fancy, but I still can't understand how to make it writing other classes. And I dunno is trouble in search function or in append part.
Big thanks my clever bro's :)
Aucun commentaire:
Enregistrer un commentaire