Skip to content

Commit

Permalink
[fix] 연령 클러스터링 결과 저장 함수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pingpingy1 committed Nov 23, 2023
1 parent 680c85f commit 5138e27
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
60 changes: 51 additions & 9 deletions analysis/age/hist_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,61 @@ def insert_data_to_mongo(
):
if localId is None:
dic["data"] = histdata
histcoll.insert_one(dic)
histcoll.find_one_and_update(
{
"councilorType": dic["councilorType"],
"year": dic["year"],
"level": dic["level"],
"method": dic["method"],
"metroId": dic["metroId"],
},
{"$set": dic},
upsert=True,
)
if statdata is not None:
print(statdata)
dic["data"] = statdata
statcoll.insert_one(dic)
statcoll.find_one_and_update(
{
"councilorType": dic["councilorType"],
"year": dic["year"],
"level": dic["level"],
"method": dic["method"],
"metroId": dic["metroId"],
},
{"$set": dic},
upsert=True,
)
else:
dic["localId"] = localId
dic["data"] = histdata
histcoll.insert_one(dic)
histcoll.find_one_and_update(
{
"councilorType": dic["councilorType"],
"year": dic["year"],
"level": dic["level"],
"method": dic["method"],
"metroId": dic["metroId"],
"localId": dic["localId"],
},
{"$set": dic},
upsert=True,
)
if statdata is not None:
print(statdata)
dic["data"] = statdata
statcoll.insert_one(dic)
statcoll.find_one_and_update(
{
"councilorType": dic["councilorType"],
"year": dic["year"],
"level": dic["level"],
"method": dic["method"],
"metroId": dic["metroId"],
"localId": dic["localId"],
},
{"$set": dic},
upsert=True,
)


def cluster(df, year, n_clst, method, cluster_by, outdir, font_name, folder_name):
Expand Down Expand Up @@ -172,9 +214,9 @@ def cluster(df, year, n_clst, method, cluster_by, outdir, font_name, folder_name
"method": method,
}
# 기존 histogram 정보는 삭제 (나이별로 넣는 것이기 때문에 찌꺼기값 존재가능)
histcoll.delete_many(basedic)
if method == "equal":
statcoll.delete_many(basedic)
# histcoll.delete_many(basedic)
# if method == "equal":
# statcoll.delete_many(basedic)
youngest_age = ("", 100)
oldest_age = ("", 0)
print(f"({year}), {n_clst} clusters")
Expand Down Expand Up @@ -272,14 +314,14 @@ def cluster(df, year, n_clst, method, cluster_by, outdir, font_name, folder_name
dic = basedic.copy()
dic["level"] = 1
dic["metroId"] = metroId
histcoll.delete_many(dic) # 기존 정보를 삭제
# histcoll.delete_many(dic) # 기존 정보를 삭제
if method == "kmeans":
insert_data_to_mongo(dic, histdata, histcoll)
else:
# l1statcoll = statcollection[
# folder_name + "_" + year + "_1level_" + method
# ]
statcoll.delete_many(dic)
# statcoll.delete_many(dic)
insert_data_to_mongo(
dic,
histdata,
Expand Down
2 changes: 1 addition & 1 deletion analysis/age/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main(N=5):
# 필요한 열만 추출합니다.
df = df[["sdName", "wiwName", "name", "age", "gender"]]
df = df.sort_values(by="age")
year = d[7:11]
year = int(d[7:11])
# most_common_age_group(df, year)
cluster(
df, year, N, "kmeans", cluster_by, outdir, font_name, folder_name
Expand Down

0 comments on commit 5138e27

Please sign in to comment.