Skip to content

Commit

Permalink
Merge pull request #108 from SVTeamJ/refactor/#106
Browse files Browse the repository at this point in the history
[Refactor/#106]
  • Loading branch information
ppinkypeach authored Jan 25, 2023
2 parents 43dbeb3 + b5c2ea4 commit 318ce5a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 131 deletions.
106 changes: 50 additions & 56 deletions backend/alembic/versions/3928deaba815_populate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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},
]
)

Expand Down
26 changes: 19 additions & 7 deletions backend/api/endpoints/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fastapi import File, UploadFile
from fastapi import APIRouter, Depends
from .aws.bucket import *
import json
import pymysql

router = APIRouter()

Expand All @@ -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
68 changes: 0 additions & 68 deletions backend/api/endpoints/data.json

This file was deleted.

0 comments on commit 318ce5a

Please sign in to comment.