Spaces:
Sleeping
Sleeping
fix normalizing windows
Browse files249 unmodified lines25025125225325425525625725825926026126226326426526626726826923 unmodified lines29329429529629728329829930028630130230330436 unmodified lines341342343329344345346347348349335336350351352353354355356357358359360361362339340341363364365366367368369345346347348349350351352353354355356357358359360370371372373374375376249 unmodified lines existing = load_dataset(hf_repo_id, token=hf_token) all_splits = list(existing.keys()) print(f"๐ ๊ธฐ์กด splits: {all_splits}") # ๊ธฐ์กด ๋ฐ์ดํฐ๋ฅผ ์์ ํ ์๋ก ์์ฑ (์คํค๋ง ํต์ผ) new_existing = DatasetDict() for user_id in existing.keys(): df = existing[user_id].to_pandas() # windows ํ๋๋ฅผ ๋ฌธ์์ด ๋ฆฌ์คํธ๋ก ๊ฐ์ ๋ณํ df["windows"] = df["windows"].apply( lambda w: [str(v) for v in w] if isinstance(w, list) and len(w) > 0 else [] ) # ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ์๋ก ์์ฑํ์ฌ ์คํค๋ง ํต์ผ new_existing[user_id] = df_to_dataset(df) print(f"๐ง {user_id}: ๊ธฐ์กด ๋ฐ์ดํฐ ์ฌ์์ฑ ์๋ฃ") existing = new_existing except Exception: existing = DatasetDict() print("๐ ๊ธฐ์กด repo ์์ โ ์๋ก ์์ฑ")23 unmodified lines if user_id in existing: # ๊ธฐ์กด ๋ฐ์ดํฐ ์ ๊ทํ ๋ฐ ๋ณํฉ old_df = existing[user_id].to_pandas() # ๊ธฐ์กด windows ๋ฐ์ดํฐ๋ฅผ ๋ฌธ์์ด ๋ฆฌ์คํธ๋ก ์ ๊ทํ old_df["windows"] = old_df["windows"].apply( lambda w: [str(v) for v in w] if isinstance(w, list) else [] lambda w: [str(v) for v in w] if isinstance(w, list) and len(w) > 0 else [] ) merged_df = pd.concat([old_df, new_df], ignore_index=True) existing[user_id] = Dataset.from_pandas(merged_df) existing[user_id] = df_to_dataset(merged_df) print(f"๐ {user_id}: ๊ธฐ์กด ๋ฐ์ดํฐ์ ๋ณํฉ ({len(old_df)} + {len(new_df)} = {len(merged_df)}๊ฐ ๋ ์ฝ๋)") else: existing[user_id] = new_dataset36 unmodified lines raise HTTPException(status_code=500, detail=f"๋ฐฐ์น ํธ์ ์คํจ: {str(e)}")
def normalize_windows(record): w = record.get("windows") w = record.get("windows", []) result = []
if isinstance(w, list): for item in w: if isinstance(item, dict): result.extend([str(v) for v in item.values() if v is not None]) elif item is not None: # ๋์
๋๋ฆฌ์ ๋ชจ๋ ๊ฐ๋ค์ ๋ฌธ์์ด๋ก ๋ณํ for v in item.values(): if v is not None and str(v).strip(): result.append(str(v)) elif item is not None and str(item).strip(): result.append(str(item)) elif isinstance(w, dict): # ๋์
๋๋ฆฌ์ ๋ชจ๋ ๊ฐ๋ค์ ๋ฌธ์์ด๋ก ๋ณํ for v in w.values(): if v is not None and str(v).strip(): result.append(str(v)) else: # windows๊ฐ ์๊ฑฐ๋ ๋ค๋ฅธ ํ์
์ธ ๊ฒฝ์ฐ ๋น ๋ฆฌ์คํธ result = [str(v) for v in w.values() if v is not None]
record["windows"] = [x for x in result if x not in ("", "None")] result = []
record["windows"] = result print(f"๐ Windows ์ ๊ทํ: {w} โ {result}") return record
def df_to_dataset(df): import pyarrow as pa schema = pa.schema([ ("session_id", pa.string()), ("measure_date", pa.string()), ("rms", pa.float64()), ("freq", pa.float64()), ("fatigue", pa.float64()), ("mode", pa.string()), ("window_count", pa.int64()), ("windows", pa.list_(pa.string())), ("measurement_count", pa.int64()), ("batch_date", pa.string()), ("batch_size", pa.int64()), ("timestamp", pa.string()) ]) return Dataset.from_pandas(df, schema=schema) """DataFrame์ Dataset์ผ๋ก ๋ณํ (windows ํ๋ ์ ๊ทํ)""" # windows ํ๋๊ฐ ๋ฆฌ์คํธ์ธ์ง ํ์ธํ๊ณ ์ ๊ทํ if 'windows' in df.columns: df['windows'] = df['windows'].apply( lambda x: x if isinstance(x, list) else [] ) return Dataset.from_pandas(df)app.py+40-24