일단 커밋. 오랫동안 커밋을 안해서 꼬였다.
리팩토리 중.
This commit is contained in:
130
UtilPack2.py
130
UtilPack2.py
@@ -14,11 +14,27 @@ from pathlib import Path
|
||||
m_dbgLevel = 0
|
||||
listDbgStr: list[str] = []
|
||||
|
||||
#for debug
|
||||
def DbgOut(strInput:str, bPrint:bool = False):
|
||||
strMsg = (f"{GetCurrentTime()} : {strInput}")
|
||||
listDbgStr.append(strMsg)
|
||||
|
||||
if True == bPrint:
|
||||
print(strMsg)
|
||||
|
||||
#
|
||||
def IsEmptyStr(string: str) -> bool:
|
||||
temp = f"{string}"
|
||||
return 0 == len(temp.strip())
|
||||
def printDbgMessages():
|
||||
for line in listDbgStr:
|
||||
print(line)
|
||||
|
||||
#
|
||||
def SaveDbgMessages(Path: str):
|
||||
try:
|
||||
with open(Path, 'w') as file:
|
||||
for line in listDbgStr:
|
||||
file.write(line + "\n")
|
||||
except IOError:
|
||||
DbgOut(f"Error: Could not write to the file at {Path}.", True)
|
||||
|
||||
|
||||
#
|
||||
@@ -39,30 +55,10 @@ def GetCurrentTime() -> str:
|
||||
return strRet
|
||||
|
||||
|
||||
#for debug
|
||||
def DbgOut(strInput:str, bPrint:bool = False):
|
||||
strMsg = (f"{GetCurrentTime()} : {strInput}")
|
||||
listDbgStr.append(strMsg)
|
||||
|
||||
if True == bPrint:
|
||||
print(strMsg)
|
||||
|
||||
|
||||
#
|
||||
def printDbgMessages():
|
||||
for line in listDbgStr:
|
||||
print(line)
|
||||
|
||||
|
||||
#
|
||||
def SaveDbgMessages(Path: str):
|
||||
try:
|
||||
with open(Path, 'w') as file:
|
||||
for line in listDbgStr:
|
||||
file.write(line + "\n")
|
||||
except IOError:
|
||||
DbgOut(f"Error: Could not write to the file at {Path}.", True)
|
||||
|
||||
def IsEmptyStr(string: str) -> bool:
|
||||
temp = f"{string}"
|
||||
return 0 == len(temp.strip())
|
||||
|
||||
# 입력된 경로의 자식 폴더를 찾아 반환한다.
|
||||
# 반환하는 리스트는 리커시브 - 손자, 증손자 폴더까지 전부 포함한다
|
||||
@@ -148,6 +144,7 @@ def IsFinalFolder(path : str) -> bool:
|
||||
|
||||
return bRet;
|
||||
|
||||
|
||||
# 어떤 경로 안에서 특정 확장자의 파일을 뽑아내어 그 리스트를 반환한다.
|
||||
def FindFileFromExt(path: str, ext: str)-> list[str]:
|
||||
bDot = False
|
||||
@@ -281,11 +278,6 @@ def PrintJSONTree(data, indent: int=0 ) -> None:
|
||||
else:
|
||||
print(' ' * indent + str(data))
|
||||
|
||||
#
|
||||
def IsPathWithin(base_path: str, target_path: str) -> bool:
|
||||
base = Path(base_path).resolve()
|
||||
target = Path(target_path).resolve()
|
||||
return target.is_relative_to(base)
|
||||
|
||||
# 랜덤 UUID 생성
|
||||
def UUIDGenRandom():
|
||||
@@ -327,11 +319,6 @@ def CalculateFileHash(strFilePath: str, method: str="sha256")-> str:
|
||||
# method (str): 사용할 해시 알고리즘
|
||||
#Returns:
|
||||
# bool: 파일이 정상인지 여부
|
||||
def VerifyIsValidFile(strPath: str, strCompHash: str, strMethod: str="sha256")->bool:
|
||||
Hash_Calcd = CalculateFileHash(strPath, strMethod)
|
||||
|
||||
return strCompHash.lower() == Hash_Calcd.lower()
|
||||
|
||||
"""
|
||||
# 사용 예시
|
||||
if __name__ == "__main__":
|
||||
@@ -343,4 +330,73 @@ if __name__ == "__main__":
|
||||
print("파일이 정상입니다!")
|
||||
else:
|
||||
print("파일이 손상되었거나 다릅니다!")
|
||||
"""
|
||||
"""
|
||||
def VerifyIsValidFile(strPath: str, strCompHash: str, strMethod: str="sha256")->bool:
|
||||
Hash_Calcd = CalculateFileHash(strPath, strMethod)
|
||||
|
||||
return strCompHash.lower() == Hash_Calcd.lower()
|
||||
|
||||
|
||||
# 세로 크기를 가로 비율대로 줄여서 반환 (가로를 기준으로 세로 길이)
|
||||
def GetRSzHeight(nWidth, nHeight, nTrgW):
|
||||
if nWidth <= 0 or nTrgW <= 0:
|
||||
return 0;
|
||||
|
||||
fRatio = nTrgW / nWidth
|
||||
nTrgH = round(nHeight * fRatio)
|
||||
|
||||
return nTrgH
|
||||
|
||||
# 가로 크기를 세로 비율대로 줄여서 반환 (세로를 기준으로 가로 길이)
|
||||
def GetRSzWidth(nWidth, nHeight, nTrgH):
|
||||
if nHeight <= 0 or nTrgH <= 0:
|
||||
return 0;
|
||||
|
||||
fRatio = nTrgH / nHeight
|
||||
nTrgW = round(nWidth * fRatio)
|
||||
|
||||
return nTrgW
|
||||
|
||||
# 엑셀 열 너비는 약 7.5픽셀 단위
|
||||
# 엑셀 행 높이는 약 25픽셀 단위
|
||||
# 이대로는 사이즈가 안 맞아서 적당히 곱해줌
|
||||
def GetCellSize(nImgW, nImgH, DPI = 96):
|
||||
column_width = (nImgW / DPI) * 7.5 * 2
|
||||
row_height = (nImgH / DPI) * 25 * 3
|
||||
|
||||
return column_width, row_height
|
||||
|
||||
def GetSheetInfoValue(text):
|
||||
if text is None:
|
||||
return "", ""
|
||||
|
||||
pattern = r'<(.*?)>'
|
||||
matches = re.findall(pattern, text)
|
||||
cleaned = re.sub(pattern, '', text)
|
||||
|
||||
return cleaned, matches
|
||||
|
||||
# 두 GPS 좌표 간 거리 구하기 (미터)
|
||||
def GetDistanceGPS(lat1, lon1, lat2, lon2):
|
||||
# 지구의 반지름 (단위: 미터)
|
||||
R = 6371008.8
|
||||
|
||||
# 위도와 경도를 라디안으로 변환
|
||||
lat1 = math.radians(lat1)
|
||||
lon1 = math.radians(lon1)
|
||||
lat2 = math.radians(lat2)
|
||||
lon2 = math.radians(lon2)
|
||||
|
||||
# 차이 계산
|
||||
dlat = lat2 - lat1
|
||||
dlon = lon2 - lon1
|
||||
|
||||
# Haversine 공식 적용
|
||||
a = math.sin(dlat / 2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2)**2
|
||||
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
|
||||
|
||||
# 거리 계산
|
||||
distance = R * c
|
||||
|
||||
return distance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user