Skip to content

Commit

Permalink
[fix] 다양성 지수 계산 함수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
pingpingy1 committed Nov 27, 2023
1 parent 69bae9a commit e329e87
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions analysis/diversity_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ def calculate_rank_local(factor: str) -> None:


def calculate_age_diversity_rank_history_local() -> None:
for councilor_type in ["elected", "candidate"]:
for is_elected in [True, False]:
for localId in range(1, 227):
docs = client["stats"]["age_hist"].find(
{
"councilorType": councilor_type,
"councilorType": "local_councilor",
"is_elected": is_elected,
"method": "equal",
"level": 2,
"localId": localId,
Expand All @@ -115,7 +116,8 @@ def calculate_age_diversity_rank_history_local() -> None:
)
client["stats"]["age_hist"].find_one_and_update(
{
"councilorType": councilor_type,
"councilorType": "local_councilor",
"is_elected": is_elected,
"method": "equal",
"level": 2,
"localId": localId,
Expand All @@ -131,7 +133,8 @@ def calculate_age_diversity_rank_history_local() -> None:
[
{
"$match": {
"councilorType": councilor_type,
"councilorType": "local_councilor",
"is_elected": is_elected,
"method": "equal",
"level": 2,
"year": year,
Expand All @@ -147,7 +150,8 @@ def calculate_age_diversity_rank_history_local() -> None:
for doc in result:
client["stats"]["age_hist"].find_one_and_update(
{
"councilorType": councilor_type,
"councilorType": "local_councilor",
"is_elected": is_elected,
"method": "equal",
"level": 2,
"localId": doc["localId"],
Expand Down Expand Up @@ -196,13 +200,14 @@ def calculate_rank_metro(factor: str) -> None:


def calculate_age_diversity_rank_history_metro() -> None:
for councilor_type in ["elected", "candidate"]:
for is_elected in [True, False]:
for metroId in range(1, 18):
docs = client["stats"]["age_hist"].find(
{
"councilorType": councilor_type,
"councilorType": "metro_councilor",
"method": "equal",
"level": 1,
"is_elected": is_elected,
"metroId": metroId,
}
)
Expand All @@ -217,9 +222,10 @@ def calculate_age_diversity_rank_history_metro() -> None:
)
client["stats"]["age_hist"].find_one_and_update(
{
"councilorType": councilor_type,
"councilorType": "metro_councilor",
"method": "equal",
"level": 1,
"is_elected": is_elected,
"metroId": metroId,
"year": doc["year"],
},
Expand All @@ -233,9 +239,10 @@ def calculate_age_diversity_rank_history_metro() -> None:
[
{
"$match": {
"councilorType": councilor_type,
"councilorType": "metro_councilor",
"method": "equal",
"level": 1,
"is_elected": is_elected,
"year": year,
}
},
Expand All @@ -249,9 +256,10 @@ def calculate_age_diversity_rank_history_metro() -> None:
for doc in result:
client["stats"]["age_hist"].find_one_and_update(
{
"councilorType": councilor_type,
"councilorType": "metro_councilor",
"method": "equal",
"level": 1,
"is_elected": is_elected,
"metroId": doc["metroId"],
"year": year,
},
Expand All @@ -267,7 +275,7 @@ def calculate_age_diversity_rank_history_metro() -> None:
# calculate_rank_local("age")
# calculate_rank_local("gender")
# calculate_rank_local("party")
calculate_age_diversity_rank_history_local()
# calculate_age_diversity_rank_history_local()

# for metroId in range(1, 18):
# if metroId in [8, 17]:
Expand All @@ -278,4 +286,4 @@ def calculate_age_diversity_rank_history_metro() -> None:
# calculate_rank_metro("age")
# calculate_rank_metro("gender")
# calculate_rank_metro("party")
# calculate_age_diversity_rank_history_metro()
calculate_age_diversity_rank_history_metro()

0 comments on commit e329e87

Please sign in to comment.