def extract_fixDate3(yyyymmdd, value): yyyy, mm, dd, char = extract_common_data(yyyymmdd, value) if char.isdigit(): add_count = int(char) else: add_count = 10 yyyymmdd = Date.addDayFromFixDate(yyyy, mm, dd, add_count).strftime('%Y%m%d') return yyyymmdd + Date.curDateStr('%H%M%S')
def splitCsv(self): #dtype = eval("{'FDL_9':'str'}") # 추후에 추가할것 dtype = eval("{}") # 20210601,extract_numType1:FDL_I1,extract_fixDate1 split_rule = self.table_info_doc.getroot().find('csv_split_rule').text.split(',') print(split_rule) df = pd.read_csv(self.basic_file_path + '/' + self.csv_file_nm, encoding='utf-8', header=0, sep='', dtype=dtype) # 숫자 앞에 0 짤리는걸 방지하기 위해 dtype값을 줌 # 파티션 키/데이터 값 넣기 self.insertIrisColumn(df, split_rule) #self.insertPartitionKey(df, split_rule[0]) #self.insertPartitionDate(df, split_rule[1]) #print(df) for key, group in df.groupby('partition_key'): print("key :{}".format(key)) rowSeries = group.head(1).get('partition_date') save_folder = self.basic_file_path + '/split_data/' + Date.curDateStr('%Y%m%d') print('whole file path : {}/{}_{}'.format(save_folder, key, rowSeries[rowSeries.index[0]])) createFolder(save_folder) group.to_csv(save_folder + '/{}_{}'.format(key, rowSeries[rowSeries.index[0]]), sep='', header=True, index=False)
def extract_fixDate2(yyyymmdd, value): yyyy, mm, dd, char = extract_common_data(yyyymmdd, value) if char.isdigit(): add_count = int(char) elif char.encode().isalpha(): asciiNum = ord(char) if asciiNum >= 32 or asciiNum <= 57: # A~Z add_count = asciiNum - 55 # 10~35 else: # a~z add_count = asciiNum - 61 # 36~61 else: add_count = 62 yyyymmdd = Date.addDayFromFixDate(yyyy, mm, dd, add_count).strftime('%Y%m%d') return yyyymmdd + Date.curDateStr('%H%M%S')
def insertPartitionDate(self, df, rule): rules = rule.split(':') # rule명:필드 standardYMD = rules[2] print('rules : {}'.format(rules)) if rules[2] == 'YMD': standardYMD = Date.curDateStr('%Y%m%d') df.insert(1, 'partition_date', df['partition_key'].map(lambda value: eval(rules[0] + '(\'' + standardYMD + '\', str(value))'))) # extract_fixDate1('20210528', value[-1])
def extract_fixDate1(yyyymmdd): return str(yyyymmdd) + Date.curDateStr('%H%M%S')