-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
662 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# api_visualization.py | ||
|
||
from datetime import datetime | ||
|
||
from sqlalchemy import BigInteger, Column, DateTime, String, Text | ||
|
||
from app.database.repository import Base | ||
|
||
|
||
class ApiVisualization(Base): | ||
__tablename__ = "api_visualization" | ||
__table_args__ = {"schema": "gyeongdan"} | ||
|
||
id = Column(BigInteger, primary_key=True, autoincrement=True) # 고유 식별자 | ||
title = Column(String, nullable=False) # 제목 | ||
content = Column(Text, nullable=False) # 본문 | ||
graph_html = Column(Text, nullable=False) # html 데이터 | ||
created_at = Column(DateTime, default=datetime.now, nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sqlalchemy import Column, String, Integer, ForeignKey, Text | ||
from sqlalchemy.orm import relationship | ||
|
||
from app.database.repository import Base | ||
|
||
class ArticleRelatedDocument(Base): | ||
__tablename__ = 'article_related_documents' | ||
__table_args__ = {'schema': 'gyeongdan'} | ||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
article_id = Column(Integer, ForeignKey('gyeongdan.articles.id', ondelete='CASCADE')) | ||
title = Column(String(255), nullable=False) | ||
link = Column(String(255), nullable=True) | ||
snippet = Column(Text) | ||
|
||
article = relationship("Articles", back_populates="related_documents") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,45 @@ | ||
You are provided with a summary of a dataset. Suggest a suitable graph type for visualizing the data along with the necessary preprocessing steps and any additional keyword arguments for the graph functions. Your response should include the graph type, the x and y values, preprocessing steps, and additional keyword arguments. | ||
params have to be dict | ||
You are provided with a summary of a dataset and the title of a news article. Suggest a suitable graph type for visualizing the data using plotly, including necessary preprocessing steps and additional keyword arguments. Also, create the body text of the article based on the visualization. Use only the column names provided in the summary for x_value and y_value. Follow the specified graph types and preprocessing steps only. | ||
|
||
You should respond a json type. | ||
Response format: { | ||
graph_type, | ||
x_value, | ||
y_value, | ||
preprocessing_steps: [{type, params}] or None, | ||
kwargs: {additional_keyword_arguments} or None | ||
Valid graph types: bar, line, pie, histogram, scatter, choropleth, funnel | ||
Valid preprocessing steps: melt, pivot, groupby, filter, drop, replace, merge, sort | ||
|
||
You should respond in JSON format. | ||
Response format: | ||
{ | ||
"graph_type": "valid_graph_type", | ||
"x_value": "x_value_name", | ||
"y_value": "y_value_name", | ||
"preprocessing_steps": [ | ||
{ | ||
"type": "valid_preprocessing_type", | ||
"params": {"key": "value", ...} | ||
}, | ||
... | ||
] or null, | ||
"kwargs": { | ||
"key": "value", | ||
... | ||
} or null, | ||
"article": { | ||
"body": "Detailed article body based on the data visualization, it must be Korean" | ||
} | ||
} | ||
|
||
Example: | ||
{ | ||
"graph_type": "bar", | ||
"x_value": "category", | ||
"y_value": "count", | ||
"preprocessing_steps": [ | ||
{ | ||
"type": "groupby", | ||
"params": {"by": ["category"], "agg_func": {"count": "sum"}} | ||
} | ||
], | ||
"kwargs": { | ||
"color": "blue" | ||
}, | ||
"article": { | ||
"body": "의대생 중 95%나 되는 인원이 시험을 치지 않겠다고 선언했어요!" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# api_visualization_crud.py | ||
|
||
from fastapi import HTTPException | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.database.repository import get_repository, model_to_dict | ||
from app.model.api_visualization import ApiVisualization | ||
|
||
|
||
class ApiVisualizationRepository: | ||
# 생성 | ||
async def create(self, api_article: ApiVisualization, session: AsyncSession): | ||
repository = get_repository(ApiVisualization)(session) | ||
return await repository.create(model_to_dict(api_article)) | ||
|
||
async def get_by_id(self, pk: int, session: AsyncSession): | ||
repository = get_repository(ApiVisualization)(session) | ||
content = await repository.get(pk) | ||
if content is None: | ||
raise HTTPException( | ||
status_code=404, detail="해당 순번이 존재하지 않습니다." | ||
) | ||
return content | ||
|
||
async def get_all(self, session: AsyncSession): | ||
repository = get_repository(ApiVisualization)(session) | ||
return await repository.filter() | ||
|
||
async def update_content(self, id: int, content: str, session: AsyncSession): | ||
repository = get_repository(ApiVisualization)(session) | ||
return await repository.update_by_pk(pk=id, data={content: content}) | ||
|
||
async def update_graph(self, id: int, graph_html: str, session: AsyncSession): | ||
repository = get_repository(ApiVisualization)(session) | ||
return await repository.update_by_pk(pk=id, data={graph_html: graph_html}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# api_visualization_router.py | ||
|
||
from datetime import datetime | ||
from enum import Enum | ||
|
||
from fastapi import APIRouter, Depends | ||
from pydantic import BaseModel | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.database.session import get_db_session | ||
from app.service.api_visualization_service import ( | ||
ApiVisualizationService, | ||
create_article, | ||
) | ||
from app.utils.generic_response import GenericResponseDTO | ||
|
||
api_visualization_router = APIRouter() | ||
|
||
|
||
class select_data(Enum): | ||
population = "인구" | ||
childhood = "청소년 정책" | ||
JINJU = "진주 코비드" | ||
|
||
|
||
class ApiVisualResponseDTO(BaseModel): | ||
title: str | ||
content: str | ||
html_data: str | ||
created_at: datetime | ||
|
||
|
||
# 대충 이렇게 해놓고 모델 이런 거 만들어야 겠다. | ||
@api_visualization_router.post( | ||
"/api_visual/article/{user_input}", | ||
response_model=GenericResponseDTO[ApiVisualResponseDTO], | ||
) | ||
async def api_visualization_article( | ||
user_input: bool, | ||
title: str, | ||
data_set: select_data, | ||
session: AsyncSession = Depends(get_db_session), | ||
): | ||
# 지금 api 에서 고른다고 가정 | ||
html_data, content = await create_article( | ||
title=title, data=data_set.value, user_input=user_input, session=session | ||
) | ||
|
||
if content == "": | ||
content = "user_input" | ||
|
||
return GenericResponseDTO[ApiVisualResponseDTO]( | ||
data=ApiVisualResponseDTO( | ||
title=title, content=content, html_data=html_data, created_at=datetime.now() | ||
), | ||
message="Successfully created article done.", | ||
result=True, | ||
) | ||
|
||
|
||
@api_visualization_router.get( | ||
"/api_visual/article/{id}", response_model=GenericResponseDTO[ApiVisualResponseDTO] | ||
) | ||
async def get_api_visualization_article( | ||
id: int, | ||
session: AsyncSession = Depends(get_db_session), | ||
): | ||
data = await ApiVisualizationService().get_by_id(id=id, session=session) | ||
return GenericResponseDTO[ApiVisualResponseDTO]( | ||
data=ApiVisualResponseDTO( | ||
title=data.title, | ||
content=data.content, | ||
html_data=data.graph_html, | ||
created_at=data.created_at, | ||
), | ||
message="Successfully 'get' done.", | ||
result=True, | ||
) |
Oops, something went wrong.