Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions diets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def food_to_dict(food):
"trans_fatty_acids": safe_float(getattr(food, "trans_fatty_acids", 0)),
"serving_size": safe_float(getattr(food, "serving_size", 0)),
"weight": safe_float(getattr(food, "weight", 0)),
"company_name": safe_str(getattr(food, "mallName", "") or getattr(food, "company_name", "") or ""),
"company_name": safe_str(getattr(food, "company_name", "") or ""),
"score": safe_float(getattr(food, "nutrition_score", 0)),
"letter_grade": safe_str(getattr(food, "nutri_score_grade", "") or letterGrade(food) or ""),
"nutri_score_grade": safe_str(getattr(food, "nutri_score_grade", "") or letterGrade(food) or "")
Expand Down Expand Up @@ -181,7 +181,7 @@ def diet_list(request):
recent_foods.append({
"food_id": str(cur_food.food_id),
"food_name" : cur_food.food_name,
"company_name": cur_food.mallName or cur_food.company_name,
"company_name": cur_food.company_name,
"food_img": cur_food.image_url or cur_food.food_img
})
cnt += 1 #식품 카운팅
Expand Down Expand Up @@ -212,7 +212,7 @@ def diet_search(request):
food_data = dict() #food의 정보를 담을 dict
food_data['food_id'] = str(food.food_id)
food_data['food_name'] = food.food_name
food_data['company_name'] = food.mallName or food.company_name
food_data['company_name'] = food.company_name
food_data['food_img'] = food.image_url or food.food_img
ret['foods'].append(food_data) #food_data 에 정보를 모두 담았으니 ret['foods']에 추가

Expand Down
6 changes: 3 additions & 3 deletions foods/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

@admin.register(Food)
class FoodAdmin(admin.ModelAdmin):
list_display = ['food_id', 'food_name', 'company_name', 'food_category', 'mallName', 'lprice']
list_filter = ['food_category', 'company_name', 'mallName']
list_display = ['food_id', 'food_name', 'company_name', 'food_category', 'lprice']
list_filter = ['food_category', 'company_name']
search_fields = ['food_name', 'company_name', 'representative_food']
readonly_fields = ['food_id']

Expand All @@ -29,7 +29,7 @@ class FoodAdmin(admin.ModelAdmin):
'classes': ('collapse',)
}),
('가격 정보', {
'fields': ('mallName', 'lprice', 'discount_price', 'shop_url', 'image_url'),
'fields': ('lprice', 'discount_price', 'shop_url', 'image_url'),
'classes': ('collapse',)
}),
('기타 정보', {
Expand Down
17 changes: 17 additions & 0 deletions foods/migrations/0011_remove_food_mallname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.2.4 on 2025-08-18 10:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('foods', '0010_remove_food_shop_name'),
]

operations = [
migrations.RemoveField(
model_name='food',
name='mallName',
),
]
1 change: 0 additions & 1 deletion foods/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Food(models.Model):
# 가격 정보 (CSV 칼럼에 맞춰 추가)
lprice = models.BigIntegerField(null=True, blank=True) # 네이버 쇼핑 최저가
discount_price = models.BigIntegerField(null=True, blank=True)
mallName = models.CharField(max_length=100, null=True, blank=True) # 쇼핑몰 이름
shop_url = models.URLField(null=True, blank=True)
image_url = models.URLField(null=True, blank=True)

Expand Down
2 changes: 1 addition & 1 deletion mypage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def favorite_food_list(request):
"food_id": str(food.food_id),
"food_name": food.food_name,
"food_img": getattr(food, 'image_url', '') or getattr(food, 'food_img', '') or "http://example.com/default_food.png",
"company_name": getattr(food, 'mallName', '') or getattr(food, 'company_name', '') or "Unknown",
"company_name": getattr(food, 'company_name', '') or "Unknown",
"calorie": int(food.calorie) if getattr(food, 'calorie', None) else 0,
"created_at": getattr(f, 'created_at', None),
})
Expand Down
3 changes: 1 addition & 2 deletions products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ def _product_dict(food, is_favorite: bool):
"trans_fatty_acids": safe_float(food.trans_fatty_acids),
"nutritional_value_standard_amount": safe_int(food.nutritional_value_standard_amount),
"weight": safe_float(food.weight),
"company_name": safe_str(food.mallName) or safe_str(food.company_name),
"company_name": safe_str(food.company_name),
"nutrition_score": safe_float(food.nutrition_score),
"nutri_score_grade": safe_str(food.nutri_score_grade),
"lprice": safe_int(food.lprice),
"shop_name": safe_str(food.mallName),
"shop_url": safe_str(food.shop_url),
"sugar_level": None,
"saturated_fatty_acids_level": None,
Expand Down
74 changes: 74 additions & 0 deletions scripts/extract_manufacturer_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3
"""
20250327_가공식품DB_147999건.xlsx에서 제조사 정보를 추출하여
food_clean_data.csv의 company_name을 업데이트하는 스크립트
"""

import pandas as pd

def main():
print("제조사 정보 추출 및 매핑 시작...")

try:
# 1. 원본 Excel 파일 읽기
print("20250327_가공식품DB_147999건.xlsx 로딩 중...")
df_original = pd.read_excel('/Users/kimminji/Desktop/Healthtant/20250327_가공식품DB_147999건.xlsx')
print(f"원본 데이터: {len(df_original)}개 행")

# 2. food_clean_data.csv 읽기
print("food_clean_data.csv 로딩 중...")
df_food = pd.read_csv('/Users/kimminji/Desktop/Healthtant/food_clean_data.csv')
print(f"현재 식품 데이터: {len(df_food)}개 행")

# 3. 제조사 정보 추출 (식품코드 -> 제조사명)
manufacturer_mapping = {}
for idx, row in df_original.iterrows():
food_code = str(row['식품코드']).strip()
manufacturer = str(row['제조사명']).strip() if pd.notna(row['제조사명']) else ''

# 제조사명이 없으면 수입업체명이나 유통업체명 사용
if not manufacturer or manufacturer == 'nan':
manufacturer = str(row['수입업체명']).strip() if pd.notna(row['수입업체명']) else ''
if not manufacturer or manufacturer == 'nan':
manufacturer = str(row['유통업체명']).strip() if pd.notna(row['유통업체명']) else ''

if manufacturer and manufacturer != 'nan':
manufacturer_mapping[food_code] = manufacturer

print(f"제조사 정보를 찾은 식품: {len(manufacturer_mapping)}개")

# 4. food_clean_data.csv의 company_name 업데이트
updated_count = 0
for idx, row in df_food.iterrows():
food_id = str(row['food_id']).strip()
if food_id in manufacturer_mapping:
df_food.at[idx, 'company_name'] = manufacturer_mapping[food_id]
updated_count += 1

print(f"업데이트된 식품: {updated_count}개")

# 5. 업데이트된 CSV 저장
output_file = '/Users/kimminji/Desktop/Healthtant/food_clean_data_updated.csv'
df_food.to_csv(output_file, index=False, encoding='utf-8')
print(f"업데이트된 파일 저장: {output_file}")

# 6. 통계 출력
total_foods = len(df_food)
foods_with_manufacturer = len(df_food[df_food['company_name'].notna() & (df_food['company_name'] != '') & (df_food['company_name'] != 'UNKNOWN')])
print(f"\n=== 통계 ===")
print(f"전체 식품: {total_foods}개")
print(f"제조사 정보 있음: {foods_with_manufacturer}개 ({foods_with_manufacturer/total_foods*100:.1f}%)")

# 7. 샘플 데이터 확인
print(f"\n=== 업데이트된 샘플 데이터 ===")
sample = df_food[df_food['company_name'].notna() & (df_food['company_name'] != '') & (df_food['company_name'] != 'UNKNOWN')].head(10)
for _, row in sample.iterrows():
print(f"ID: {row['food_id']}, 식품명: {row['food_name']}, 제조사: {row['company_name']}")

except Exception as e:
print(f"오류 발생: {e}")
import traceback
traceback.print_exc()

if __name__ == "__main__":
main()
69 changes: 0 additions & 69 deletions scripts/extract_manufacturers.py

This file was deleted.

43 changes: 0 additions & 43 deletions scripts/health_check.py

This file was deleted.

1 change: 0 additions & 1 deletion scripts/insert_food_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def main():
# 2) 매핑 - food_clean_data.csv 칼럼에 맞춰 수정
csv_to_db = {
'food_id': 'food_id',
'shop_name': 'mallName',
'price': 'lprice',
'discount_price': 'discount_price',
'shop_url': 'shop_url',
Expand Down
3 changes: 1 addition & 2 deletions scripts/rebuild_clean_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def validate_and_clean_row(args):
'food_category': (row.get('food_category', ''), 255),
'representative_food': (row.get('representative_food', ''), 255),
'company_name': (row.get('company_name', ''), 255),
'shop_name': (row.get('mallName', ''), 100),
'nutri_score_grade': (row.get('nutri_score_grade', ''), 10),
}

Expand Down Expand Up @@ -419,7 +418,7 @@ def update_progress():
'potassium','salt','"VitaminA"','"VitaminB"','"VitaminC"','"VitaminD"','"VitaminE"',
'cholesterol','saturated_fatty_acids','trans_fatty_acids','serving_size',
'weight','company_name','nutrition_score','nutri_score_grade','nrf_index',
'shop_name','lprice','discount_price','shop_url','image_url'
'lprice','discount_price','shop_url','image_url'
]

placeholders = ",".join(["%s"] * len(cols))
Expand Down
58 changes: 0 additions & 58 deletions scripts/update_mallname.py

This file was deleted.

2 changes: 1 addition & 1 deletion search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def food_to_dict(food, user=None, favorite_ids=None):
"trans_fatty_acids": safe_float(getattr(food, "trans_fatty_acids", 0)),
"serving_size": safe_float(getattr(food, "serving_size", 0)),
"weight": safe_float(getattr(food, "weight", 0)),
"company_name": safe_str(getattr(food, "mallName", "") or getattr(food, "company_name", "") or ""),
"company_name": safe_str(getattr(food, "company_name", "") or ""),
"score": safe_float(getattr(food, "nutrition_score", 0)),
"letter_grade": safe_str(getattr(food, "nutri_score_grade", "") or letterGrade(food) or ""),
"nutri_score_grade": safe_str(getattr(food, "nutri_score_grade", "") or letterGrade(food) or ""),
Expand Down
2 changes: 1 addition & 1 deletion static/diets/js/diets_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function createFoodElement(food) {
</div>
<div class="food-info">
<h3 class="food-name">${food.food_name}</h3>
<p class="food-company">판매처: ${food.company_name || '판매처 정보 없음'}</p>
<p class="food-company">제조사: ${food.company_name || '제조사 정보 없음'}</p>
</div>
<button class="register-btn btn btn-primary" onclick="registerFood('${food.food_id}')">
<span class="plus-icon">+</span>
Expand Down
2 changes: 1 addition & 1 deletion static/search/js/advanced_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class AdvancedResultPage {
</div>
<div class="food-right">
<div class="food-name clickable" onclick="advancedResult.goToProductDetail('${food.food_id}')">${food.food_name}</div>
<div class="food-company">${food.company_name || '판매처 정보 없음'}</div>
<div class="food-company">${food.company_name || '제조사 정보 없음'}</div>
</div>
</div>
<button class="favorite-button ${favoriteClass}"
Expand Down
Loading