Skip to content

전처리

JaeMin Kim edited this page Sep 26, 2022 · 3 revisions
const preprocessingLH = () => {
  const homesStr = readFileSync(`publichome/src/util/rawDataLH.txt`, "utf-8");
  const homesList = homesStr.split("\n");

  const homesObj = homesList.map((e) => {
    const line = e.split("\t");
    const keyAddress = getAddress(line[0]).replace(" ", "");
    // : line[0].split("(")[0]
    return {
      keyAddress,
      address: line[0],
      name: line[1],
      classes:
        line[2] +
        " " +
        (line[3] ? line[3] + "동 " : "") +
        line[4] +
        "호 " +
        Number(line[5]) +
        "㎡",
      totalPrice: addCommas(convertToNumber(line[6]) / 10000) + "만원",
      monthPay: line[7].trim() + "원",
    };
  });

  const homesAddrList = homesObj.map(({ keyAddress }) => keyAddress);

  const homesAddrSetify = Array.from(new Set(homesAddrList));

  const homesReuslt = homesAddrSetify.map((keyAddress) => {
    return { keyAddress, sells: [] };
  });

  homesObj.forEach(
    ({ keyAddress, address, classes, monthPay, name, totalPrice }) => {
      const Obj = homesReuslt.filter((e) => e.keyAddress === keyAddress)[0];
      Obj.gov = "LH 청년매입";
      Obj.name = name;
      Obj.address = address;
      Obj.sells.push({ classes, totalPrice, monthPay });
    }
  );
  return homesReuslt;
};
const convertToNumber = (string) => {
  return parseInt(string.replace(/(,|개|원)/g, ''));
};

const addCommas = (n) => {
  return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};


const homesObj = homesList.map((e)=>{
    const line = e.split('\t')
    return {
        address:line[0].split('(')[0],
        name:line[1],
        classes:line[2]+' '+(line[3]?line[3]+'동 ':'') + line[4] + '호 ' + line[5].split('.')[0]+'㎡',
        totalPrice:addCommas(convertToNumber(line[6])/10000)+'만원',
        monthPay:line[7].trim()+'원'
    }
})




const homesNameList = homesObj.map(({name})=>name)

const homesNameSetify = Array.from(new Set(homesNameList))

const homesReuslt = homesNameSetify.map(name=>{return {name,sells:[]}})

homesObj.forEach(({address,classes,monthPay,name,totalPrice})=>{
const Obj = homesReuslt.filter((e)=>e.name===name.split('-')[0])[0];
Obj.address = address;
Obj.sells.push({classes,
totalPrice,
monthPay,})
})

전처리를 직접 나름대로 해보시고 왜 이렇게 해야만 했는가 이해하셨길 바랍니다. 이렇게 해야한 것

  • 주소 기준으로 묶기
  • 공고마다 열 이름 일관성 없음
Clone this wiki locally