Skip to content

Commit 07216fc

Browse files
committed
export 까지 구현
1 parent 986033e commit 07216fc

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

data_manager.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,22 @@ def change_value(self, row, col, value):
176176
self.cond_data.iloc[row] = target_df
177177

178178
self.edited_list.append(
179-
[DataEditType.EDIT_VALUE, [col, value]])
179+
[DataEditType.EDIT_VALUE, [row, col, value]])
180180

181181
def change_hv(self, edit_type: DataEditType, args):
182-
df = self.cond_data
182+
self.cond_data = self._change_hv_func(self.cond_data, edit_type, args)
183183

184+
self.edited_list.append([edit_type, args])
185+
186+
# it's static
187+
# 변경 사항이 있으면 달라진 df를 return한다. 그 이외의 경우, 그대로 return 한다.
188+
def _change_hv_func(__self, df, edit_type, args):
184189
if edit_type == DataEditType.ADD_COLUMN:
185190
df.insert(args[0], args[1], "")
186191
elif edit_type == DataEditType.ADD_ROW:
187192
new_row = pd.Series([""] * df.shape[1], index=df.columns)
188193
insert_index = args[0]
189-
self.cond_data = pd.concat([df.iloc[:insert_index], pd.DataFrame(
194+
df = pd.concat([df.iloc[:insert_index], pd.DataFrame(
190195
[new_row]), df.iloc[insert_index:]]).reset_index(drop=True)
191196
elif edit_type == DataEditType.DUPLICATE_COLUMN:
192197
col_name = df.columns[args[0]]
@@ -197,7 +202,7 @@ def change_hv(self, edit_type: DataEditType, args):
197202
elif edit_type == DataEditType.DUPLICATE_ROW:
198203
duplicated_row = df.iloc[args[0]].copy() # 지정한 행을 복제
199204
insert_index = args[0]
200-
self.cond_data = pd.concat([df.iloc[:insert_index], pd.DataFrame(
205+
df = pd.concat([df.iloc[:insert_index], pd.DataFrame(
201206
[duplicated_row]), df.iloc[insert_index:]]).reset_index(drop=True)
202207
elif edit_type == DataEditType.REMOVE_COLUMN:
203208
col_name = df.columns[args[0]]
@@ -224,7 +229,7 @@ def change_hv(self, edit_type: DataEditType, args):
224229
for i in range(len(value_list), len(df.columns)):
225230
df.at[target_index, i] = ""
226231

227-
self.edited_list.append([edit_type, args])
232+
return df
228233

229234
def change_condition(self, conditions):
230235
sel, is_success = self._create_series_by_condition(conditions)
@@ -280,43 +285,50 @@ def _create_series_by_condition(self, conditions):
280285
# now_conditions을 기반으로 select를 붙이고 dst를 내보냄
281286
# 체크모드가 아니라면 cond_data를 직접 내보내지 마시오. sort에 영향을 받음.
282287
def export(self, dst, sep_mode, list_target_column, select_mode, list_checked):
288+
result = self.data.copy(deep=True)
289+
290+
# change value
291+
for value_list in self.edited_list:
292+
detype = value_list[0]
293+
args = value_list[1]
294+
295+
if detype == DataEditType.EDIT_VALUE:
296+
row = args[0]
297+
col = args[1]
298+
value = args[2]
299+
300+
target_df = result.iloc[row].copy()
301+
target_df[col] = value
302+
result.iloc[row] = target_df
303+
else:
304+
result = self._change_hv_func(result, detype, args)
305+
283306
# option 1. 분리자 설정
284307
sep = "," if sep_mode == ENUM_SEPERATOR.COMMA else "|"
285308

286309
# option 2. 행 거르기 or select 추가하기
287310
if select_mode == ENUM_SAVE_ROW.ALL:
288-
result = self.data.copy(deep=True)
311+
pass
289312
elif select_mode == ENUM_SAVE_ROW.FILTERED:
290-
result = self.data.copy(deep=True)
291313
sel, _ = self._create_series_by_condition(self.now_conditions)
292314
result = result[sel]
293315
elif select_mode == ENUM_SAVE_ROW.FILTERED_SELECT:
294-
result = self.data.copy(deep=True)
295316
sel, _ = self._create_series_by_condition(self.now_conditions)
296317
result["select"] = pd.Series(sel).astype(int)
297318
elif select_mode == ENUM_SAVE_ROW.CHECKED:
298319
list_checked_df = []
299320
for index in list_checked:
300-
list_checked_df.append(self.cond_data.iloc[index])
321+
list_checked_df.append(result.iloc[index])
301322
result = pd.concat(list_checked_df)
302323
elif select_mode == ENUM_SAVE_ROW.CHECKED_SELECT:
303-
result = self.cond_data.copy(deep=True)
304-
sel = pd.Series([False] * len(self.cond_data))
324+
sel = pd.Series([False] * len(result))
305325
sel.iloc[list_checked] = True
306326
result["select"] = pd.Series(sel).astype(int)
307327

308328
# option 3. 열(라벨) 거르기
309329
if list_target_column:
310330
result = result[list_target_column]
311331

312-
# change value
313-
for valueset in self.edited_list:
314-
name = valueset[0]
315-
col = valueset[1]
316-
value = valueset[2]
317-
if name in result.index:
318-
result.loc[name][col] = value
319-
320332
if self.is_dbf_loaded:
321333
# TODO write dbf
322334
fd = FileIODialog(

0 commit comments

Comments
 (0)