From 3176ba8ef81fef16a79db4f3d7a9c030d346ce88 Mon Sep 17 00:00:00 2001 From: jung Date: Thu, 26 Jan 2023 07:17:24 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20data.json=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/endpoints/data.json | 68 --------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 backend/api/endpoints/data.json diff --git a/backend/api/endpoints/data.json b/backend/api/endpoints/data.json deleted file mode 100644 index 0a18192..0000000 --- a/backend/api/endpoints/data.json +++ /dev/null @@ -1,68 +0,0 @@ -[ - { - "model": "teami.fish", - "pk": 1, - "fields": { - "fish_type" : "고등어", - "toxicity" : "없지렁", - "open_season": "몰랑", - "closed_season": "몰랑", - "description": "고등어조림맛있는데 군침이싹도넹" - } - }, - { - "model": "teamj.fish", - "pk": 2, - "fields": { - "fish_type" : "띠볼락", - "toxicity" : "있지렁", - "open_season": "몰랑", - "closed_season": "몰랑", - "description": "띠볼락은 띠가볼락볼락" - } - }, - { - "model": "teamj.fish", - "pk": 3, - "fields": { - "fish_type" : "노랑 가오리", - "toxicity" : "있지렁", - "open_season": "몰랑", - "closed_season": "몰랑", - "description": "노랑 가오리는 노가리지롱 노가리" - } - }, - { - "model": "teamj.fish", - "pk": 4, - "fields": { - "fish_type" : "적색퉁돔", - "toxicity" : "없지렁", - "open_season": "몰랑", - "closed_season": "몰랑", - "description": "적생퉁돔돔돔이야 못생겼다" - } - }, - { - "model": "teamj.fish", - "pk": 5, - "fields": { - "fish_type" : "넙치", - "toxicity" : "없지렁", - "open_season": "몰랑", - "prohibit_area": "몰랑", - "description": "넙치 맛있나?" - } - }, - { - "model": "teamj.fish", - "pk": 6, - "fields": { - "fish_type" : "이상한 사진 넣지마라", - "toxicity" : "또잉", - "prohibit_period": "또잉", - "prohibit_area": "또잉", - "description": "다른 사진 넣어주라" - } - } -] \ No newline at end of file From c31a950ce3bdd0a5801c7ec206d21bf1d70b2de9 Mon Sep 17 00:00:00 2001 From: jung Date: Thu, 26 Jan 2023 07:18:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=ED=95=9C=EA=B5=AD=EC=96=B4=EA=B0=92?= =?UTF-8?q?=EC=9D=B4=20=EC=9D=B8=EC=BD=94=EB=94=A9=20=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EA=B5=AC=EB=AC=B8=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B0=92?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../versions/3928deaba815_populate_data.py | 106 +++++++++--------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/backend/alembic/versions/3928deaba815_populate_data.py b/backend/alembic/versions/3928deaba815_populate_data.py index 98c6d67..6bee9f1 100644 --- a/backend/alembic/versions/3928deaba815_populate_data.py +++ b/backend/alembic/versions/3928deaba815_populate_data.py @@ -21,7 +21,6 @@ def upgrade() -> None: sa.Column('fish_id', mysql.INTEGER(), autoincrement=True, nullable=False), sa.Column('fish_type', mysql.VARCHAR(length=64), nullable=False), sa.Column('toxicity', mysql.VARCHAR(length=16), nullable=False), - sa.Column('open_season', mysql.VARCHAR(length=64), nullable=False), sa.Column('closed_season', mysql.VARCHAR(length=64), nullable=False), sa.Column('description', mysql.VARCHAR(length=512), nullable=False), sa.Column('classification', mysql.VARCHAR(length=64), nullable=False), @@ -37,65 +36,60 @@ def upgrade() -> None: mysql_default_charset='utf8mb4', mysql_engine='InnoDB' ) - # populate some fish data + + op.execute('SET NAMES utf8') op.bulk_insert(fish_table,[ - {'fish_type': 'mackerel', - 'toxicity': 'No', - 'classification': 'Pisces', - 'scientific_name': 'Scomber japonicus', - 'open_season': 'january~december', 'closed_season': 'jan~dec', - 'description': """It is one of the representative blue-backed fish in the family such as mackerel and tuna and tuna. -It is a migratory fish species that likes the warm sea with a body length of more than 40cm and a temperature of 10-22℃. -It is widely distributed worldwide, eating plankton when fried, and adult fish mainly feed on anchovies or small fish.""", - 'fish_url': 'https://www.google.com', - 'habitat': 'Pacific Ocean', + + {'fish_type': '고등어', + 'toxicity': 'X', + 'classification': '조기어류', + 'scientific_name': 'Scomber', + 'closed_season': '4월 ~ 6월', + 'description': """삼치, 참치 등과 같은 과에 속하는 대표적인 등푸른 생선 중 하나이다. 몸길이는 40cm가 넘으며, 10∼22℃인 따뜻한 바다를 좋아하는 회유성 어종이다. 몸길이는 40cm가 넘으며, 10∼22℃인 따뜻한 바다를 좋아하는 회유성 어종이다. 세계적으로 널리 분포하며 치어 때는 플랑크톤을 먹고, 성어는 멸치 또는 작은 물고기를 주 먹이로 삼는다.""", + 'fish_url': '', + 'habitat': '태평양,인도양', + 'is_active': 1}, + + {'fish_type': '볼락', + 'classification': '조기어류', + 'scientific_name': 'Sebastes inermis', + 'toxicity': 'X', + 'closed_season': '12월 ~ 2월', + 'description': """우리나라의 전 연안, 일본의 북해도 이남 및 중국의 북부 연안에 분포하며, 특히 황해 및 발해만에 많이 서식한다. 4-6개월이 되면 2-6cm의 치어들이 해조가 많이 난 곳에 나타나서 여름부터 가을에 걸쳐 바다밑 생활을 한다. 작은 고기라고 함부로 잡았다가 뾰족한 등 지느러미와 아가미 뚜껑에 손이 베일 수 있다.""", + 'fish_url': '', + 'habitat': '한반도,일본,중국 연안 앝은곳 암초지대', 'is_active': 1}, - {'fish_type': 'red stingray', - 'classification': 'Chondrichthyes', - 'scientific_name': 'Dasyatis akajei', - 'toxicity': 'Yes', - 'open_season': 'May', 'closed_season': 'August', - 'description': """ The yellow stingray is a species of fish in the family Colomidae. -There is a long poisonous thorn on the tail, which is about 15cm long, so not only is it very long, but it also has teeth on both sides. if it pokes a human body, -not only does it hurt terribly, but it also has poison at the end of the venomous thorn, which can lead to fainting and even death. """, - 'fish_url': 'https://www.google.com', - 'habitat': 'Pacific Ocean', - 'is_active': 1}, - {'fish_type': 'red snapper', - 'classification': 'Actinopterygii', - 'scientific_name': 'Lutjanus campechanus', - 'toxicity': 'Yes', - 'open_season': 'June', 'closed_season': 'October', - 'description': """Red tung sea bream is a coastal fish species that lives well in brackish waters where fresh water and seawater are mixed, especially in the mangrove area of the estuary of the river. -It is found mainly in the sea, but some species live in the mouth of the river or feed in fresh water. -Red tung sea bream caught in the tropics is said to require attention because cases of cigar terra poisoning have been found in the past.""", - 'fish_url': 'https://www.google.com', - 'habitat': 'Indian Ocean', - 'is_active': 1}, - {'fish_type': 'flat fish', - 'classification': 'Actinopterygii', - 'scientific_name': 'Paralichthys olivaceus', - 'toxicity': 'Yes', - 'open_season': 'January', 'closed_season': 'December', - 'description': """It is a species of sea fish belonging to the flounder family of flounder order It is a flat fish that is also well known as flatfish in Korea. - Sand floors located between 10 and 200 meters deep are mainly preferred. It is not good at swimming long distances. - Some flatfish live in parts of the Korean Peninsula's freshwater depending on the season.You should be careful not to get bitten when you catch a halibut caught by fishing because it has sharp teeth in your mouth.""", - 'fish_url': 'https://www.google.com', - 'habitat': 'The western part of Pacific Ocean', - 'is_active': 1}, - {'fish_type': 'dark-banded rockfish', - 'classification': 'Actinopterygii', - 'scientific_name': 'Sebastes inermis', - 'toxicity': 'No', - 'open_season': 'December', 'closed_season': 'February', - 'description': """It is distributed in all coasts of Korea, southern North Sea of Japan, and northern coast of China, especially in the Yellow Sea and Balhae Bay. -At the age of 4-6 months, 2-6 centimeters of fry appear in a seaweed-rich place and live under the sea from summer to autumn. -Small fish can be caught recklessly and your hands can be cut by pointed dorsal fins and gill caps. """ - , 'fish_url': 'https://www.google.com', - 'habitat': 'a reef of Korean Peninsula', - 'is_active': 1}, + {'fish_type': '노랑 가오리', + 'classification': '연골어류', + 'scientific_name': 'Dasyatis akajei', + 'toxicity': 'O', + 'closed_season': '5월 ~ 8월', + 'description': """ 노랑가오리는 색가오리과에 속하는 물고기로 꼬리에 긴 독가시가 하나 있는데 길이가 약 15cm 이기 때문에 매우 기다란 것 뿐만아니라 양쪽에 톱니가 있어 인간의 몸을 찌르면 몹시 아플 뿐만 아니라 독가시 끝에 맹독이 있어 기절하고 심지어 사망하는 수도 있다.""", + 'fish_url': '', + 'habitat': '서태평양 지역의 얕은 바다와 강 하구', + 'is_active': 1}, + + {'fish_type': '적색퉁돔', + 'classification': '조기어류', + 'scientific_name': 'Lutjanus campechanus', + 'toxicity': 'O', + 'closed_season': '6월 ~ 10월', + 'description': """붉은퉁돔은 담수와 해수가 섞이는 기수역에서도 잘 생활하는 연안성의 어종으로, 특히 강 하구 맹그로브 지대에서 많이 발견된다. 주로 바다에서 발견되지만 일부 종은 강 어귀에서 서식하거나 민물에서 먹이를 구한다. 열대지방에서 잡힌 붉은퉁돔은 과거 시가테라 중독사례가 발견되기도 해서 주의를 요한다고도 한다.""", + 'fish_url': '', + 'habitat': '인도양, 서부태평양 열대 해역', + 'is_active': 1}, + + {'fish_type': '넙치', + 'classification': '조기어류', + 'scientific_name': 'Paralichthys olivaceus', + 'toxicity': 'X', + 'closed_season': '3월 ~ 8월', + 'description': """가자미목 넙치과에 속하는 바다 어류의 일종. 한국에서 광어라는 이름으로도 잘 알려져 있는 납작한 물고기다. 수심 10~200m 사이에 위치한 모래 바닥을 주로 선호한다. 장거리를 이동하기에는 수영 실력이 뛰어나지 않으며 한반도 일부 지역에서는 계절에 따라 민물에 살기도 한다.입 안에 날카로운 이빨이 나있어서 낚시로 잡은 넙치를 손으로 잡을 때는 물리지 않도록 주의해야 한다.""", + 'fish_url': '', + 'habitat': '태평양 서부지역', + 'is_active': 1}, ] ) From b5c2ea407c6531e100b296e06f026925b83a7a79 Mon Sep 17 00:00:00 2001 From: jung Date: Thu, 26 Jan 2023 07:19:00 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20mysql=EC=97=90=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EC=9E=88=EB=8A=94=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20api=20=EB=A6=AC=ED=8E=99=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/endpoints/ai.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/api/endpoints/ai.py b/backend/api/endpoints/ai.py index 5faa1db..8244a7f 100644 --- a/backend/api/endpoints/ai.py +++ b/backend/api/endpoints/ai.py @@ -2,7 +2,7 @@ from fastapi import File, UploadFile from fastapi import APIRouter, Depends from .aws.bucket import * -import json +import pymysql router = APIRouter() @@ -15,10 +15,22 @@ async def infer(file: UploadFile = File()): fp.write(content) post_bucket(content,filename) + url = "https://svj-deepblue.s3.ap-northeast-2.amazonaws.com/" + filename result = fish_detect(filename) - with open("api/endpoints/data.json", 'r') as file: - fish_data = json.load(file) - for data in fish_data: - if data["pk"] == result: - data["url"] = "https://svj-deepblue.s3.ap-northeast-2.amazonaws.com/" + filename - return data + conn = pymysql.connect(host='mysql', port=3306, user='taegong', password='taegong', db='taegong', charset='utf8') + cursor = conn.cursor() + sql = "SELECT * FROM fish where fish_id = {}".format(result) + cursor.execute(sql) + res = cursor.fetchone() + result = {"model": res[0], + "type": res[1], + "toxicity": res[2], + "classification": res[3], + "scientific_name": res[4], + "close_season": res[5], + "description": res[6], + "habitat": res[7], + "image_url": url} + conn.commit() + conn.close() + return result