Skip to content

Commit

Permalink
1. 직접 입력 기능 작성
Browse files Browse the repository at this point in the history
2. 입력된 식단 리스트에 출력 기능
3.
  • Loading branch information
mksoo committed Feb 22, 2024
1 parent 65ec84f commit 66f1b57
Show file tree
Hide file tree
Showing 24 changed files with 856 additions and 212 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ fabric.properties
.erd

# mksoo images
/static/asset/food_images/
/static/asset/food_images/*
foods.csv
/static/asset/user_food/
/static/media/user_food/*
/static/media/user_food_detail/*
32 changes: 32 additions & 0 deletions clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import requests

url = "http://192.168.45.102:2375/process_image"
# url = 'tcp://localhost:2375/process_image'

files = {
"file": (
"velog.jpg",
open("static/asset/food_images/가래떡.jpg", "rb"),
"image/jpeg",
)
}
data = {"title": "Your Title", "content": "Your Content"}

# API 호출
response = requests.post(url, files=files, data=data)

# 결과 수신 및 처리
result = response.json()
print(result)
# processed_image_data = result['processed_image']
# processed_image_bytes = bytes.fromhex(processed_image_data)

# # 처리된 이미지를 파일로 저장
# with open('processed_image.jpg', 'wb') as file:
# file.write(processed_image_bytes)

# # 결과에서 단어 리스트 추출
# food_classes = result.get('food_classes', [])

# # 여러 개의 단어를 가진 리스트 출력
# print("food_classes:", food_classes)
4 changes: 4 additions & 0 deletions diet/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from django.contrib import admin

# Register your models here.
from .models import UserDiet, DetailOfDiet

admin.site.register(UserDiet)
admin.site.register(DetailOfDiet)
37 changes: 37 additions & 0 deletions diet/migrations/0005_remove_detailofdiet_image_x_end_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.0.1 on 2024-02-20 12:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("diet", "0004_remove_food_created_at_remove_food_deleted_and_more"),
]

operations = [
migrations.RemoveField(
model_name="detailofdiet",
name="image_x_end",
),
migrations.RemoveField(
model_name="detailofdiet",
name="image_x_start",
),
migrations.RemoveField(
model_name="detailofdiet",
name="image_y_end",
),
migrations.RemoveField(
model_name="detailofdiet",
name="image_y_start",
),
migrations.AddField(
model_name="detailofdiet",
name="image_path",
field=models.CharField(
db_comment="음식 이미지 경로", default=1, max_length=200
),
preserve_default=False,
),
]
18 changes: 18 additions & 0 deletions diet/migrations/0006_rename_take_at_userdiet_take_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.1 on 2024-02-21 02:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("diet", "0005_remove_detailofdiet_image_x_end_and_more"),
]

operations = [
migrations.RenameField(
model_name="userdiet",
old_name="take_at",
new_name="take_date",
),
]
22 changes: 22 additions & 0 deletions diet/migrations/0007_userdiet_take_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.1 on 2024-02-21 02:22

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("diet", "0006_rename_take_at_userdiet_take_date"),
]

operations = [
migrations.AddField(
model_name="userdiet",
name="take_at",
field=models.DateTimeField(
db_comment="식단을 섭취한 날짜 및 시간",
default=datetime.datetime(2024, 2, 21, 11, 22, 18, 283415),
),
),
]
22 changes: 22 additions & 0 deletions diet/migrations/0008_alter_userdiet_take_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.1 on 2024-02-21 06:31

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("diet", "0007_userdiet_take_at"),
]

operations = [
migrations.AlterField(
model_name="userdiet",
name="take_at",
field=models.DateTimeField(
db_comment="식단을 섭취한 날짜 및 시간",
default=datetime.datetime(2024, 2, 21, 15, 31, 7, 184460),
),
),
]
49 changes: 28 additions & 21 deletions diet/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from django.contrib.auth.models import User

from datetime import datetime


class UserDiet(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
Expand All @@ -10,7 +12,8 @@ class UserDiet(models.Model):
blank=True,
db_comment="식단 이미지 경로, 사용자가 직접 추가한 식단이면 null",
)
take_at = models.DateField(db_comment="식단을 섭취한 날짜")
take_date = models.DateField(db_comment="식단을 섭취한 날짜")

meal = models.IntegerField(
default=1, db_comment="1은 아침, 2는 점심, 3은 저녁, 4는 간식, 5는 야식"
)
Expand All @@ -19,30 +22,34 @@ class UserDiet(models.Model):
updated_at = models.DateTimeField(auto_now=True)
deleted = models.BooleanField(default=False)
deleted_at = models.DateTimeField(null=True, blank=True)
take_at = models.DateTimeField(
db_comment="식단을 섭취한 날짜 및 시간", default=datetime.now()
)


class DetailOfDiet(models.Model):
diet = models.ForeignKey(UserDiet, on_delete=models.CASCADE)
image_x_start = models.IntegerField(
null=True,
blank=True,
db_comment="이미지의 x 시작좌표, 사용자가 직접 추가한 식단이면 null",
)
image_x_end = models.IntegerField(
null=True,
blank=True,
db_comment="이미지의 x 끝좌표, 사용자가 직접 추가한 식단이면 null",
)
image_y_start = models.IntegerField(
null=True,
blank=True,
db_comment="이미지의 y 시작좌표, 사용자가 직접 추가한 식단이면 null",
)
image_y_end = models.IntegerField(
null=True,
blank=True,
db_comment="이미지의 y 끝좌표, 사용자가 직접 추가한 식단이면 null",
)
# image_x_start = models.IntegerField(
# null=True,
# blank=True,
# db_comment="이미지의 x 시작좌표, 사용자가 직접 추가한 식단이면 null",
# )
# image_x_end = models.IntegerField(
# null=True,
# blank=True,
# db_comment="이미지의 x 끝좌표, 사용자가 직접 추가한 식단이면 null",
# )
# image_y_start = models.IntegerField(
# null=True,
# blank=True,
# db_comment="이미지의 y 시작좌표, 사용자가 직접 추가한 식단이면 null",
# )
# image_y_end = models.IntegerField(
# null=True,
# blank=True,
# db_comment="이미지의 y 끝좌표, 사용자가 직접 추가한 식단이면 null",
# )
image_path = models.CharField(max_length=200, db_comment="음식 이미지 경로")
name = models.CharField(max_length=100, db_comment="음식 이름")
carbohydrate = models.FloatField(db_comment="1인분당 탄수화물")
protein = models.FloatField(db_comment="1인분당 단백질")
Expand Down
Loading

0 comments on commit 66f1b57

Please sign in to comment.