Skip to content

Commit

Permalink
feat kookmin-sw#1 - feat query
Browse files Browse the repository at this point in the history
삽입 쿼리 생성
  • Loading branch information
cheesecrust committed May 11, 2024
1 parent add3243 commit 9dfcfb3
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ async def clustering(user_male_cards, user_female_cards, post_male_cards, post_f
convert_fit_data(female_df)
)

print("convert")
male_cluster = defaultdict(lambda: [])

find_male_user_cluster = defaultdict(lambda: {"my": None, "mate": None})
Expand Down Expand Up @@ -285,7 +284,6 @@ async def clustering(user_male_cards, user_female_cards, post_male_cards, post_f
}
)

print("here?")
female_recommendation_result = defaultdict(
lambda: {"user": {"my": [], "mate": []}, "post": {"my": [], "mate": []}}
)
Expand Down Expand Up @@ -331,7 +329,11 @@ async def clustering(user_male_cards, user_female_cards, post_male_cards, post_f

for recommendation_result in (male_recommendation_result, female_recommendation_result):
for user_id in recommendation_result:
# print(user_id, recommendation_result[user_id])

query = """
insert into recommend (user_id, card_type, recommendation_id, recommendation_card_type, score)
values (:user_id, :card_type, :id, :recommendation_card_type, :score)
"""

my_card_result = recommendation_result[user_id]["user"]["my"]
mate_card_result = recommendation_result[user_id]["user"]["mate"]
Expand All @@ -341,26 +343,31 @@ async def clustering(user_male_cards, user_female_cards, post_male_cards, post_f
score = result["score"]
card_type = result["cardType"]

# query = """
# insert into recommend (user_id, card_type, recommendation_id, recommendation_card_type, score)
# values (:user_id, 'my', :id, :card_type, :score)
# """

# # print("------------------------------- recommend_ result",user_id, id, score, card_type)
# await database.execute(query, {"user_id": user_id, "id": id, "score": score, "card_type": card_type})
# pass
await database.execute(query, {"user_id": user_id, "card_type": 'my', "id": id, "score": score, "recommendation_card_type": card_type})

for result in mate_card_result:
pass
id = result["id"]
score = result["score"]
card_type = result["cardType"]

await database.execute(query, {"user_id": user_id, "card_type": 'mate', "id": id, "score": score, "recommendation_card_type": card_type})

post_my_card_result = recommendation_result[user_id]["post"]["my"]
post_mate_card_result = recommendation_result[user_id]["post"]["mate"]

for result in post_my_card_result:
pass
id = result["id"]
score = result["score"]
card_type = result["cardType"]

await database.execute(query, {"user_id": user_id, "card_type": 'my', "id": id, "score": score, "recommendation_card_type": card_type})

for result in post_mate_card_result:
pass
id = result["id"]
score = result["score"]
card_type = result["cardType"]

await database.execute(query, {"user_id": user_id, "card_type": 'mate', "id": id, "score": score, "recommendation_card_type": card_type})


print()
Expand Down

0 comments on commit 9dfcfb3

Please sign in to comment.