Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ai/feature/recommendation #161

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
93 changes: 92 additions & 1 deletion src/ai/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,101 @@
<<<<<<< HEAD
# from fastapi import FastAPI
# from pydantic import BaseModel
# import requests
# import gpxpy
# import os

# from runningmachine import print_filtered_files, load_csv

# app = FastAPI()

# toilet_csv_path = 'csv/final_toilet.csv'
# conv_csv_path = 'csv/final_conv.csv'

# toilet_data = load_csv(toilet_csv_path)
# conv_data = load_csv(conv_csv_path)

# # GPX load
# def fetch_gpx_files(base_url):
# try:
# response = requests.get(base_url) # 스프링 부트 API에서 GPX URL 리스트 전달 받음
# response.raise_for_status() # 요청이 성공적으로 완료되지 않으면 예외 발생
# gpx_urls = response.json() # GPX URL 리스트

# gpx_files = []
# for url in gpx_urls:
# try:
# file_name = os.path.basename(url) # 파일 이름 추출
# gpx_response = requests.get(url) # GPX 파일 다운로드
# gpx_response.raise_for_status() # 요청이 성공적으로 완료되지 않으면 예외 발생

# gpx_data = gpxpy.parse(gpx_response.text) # GPX 파일 파싱
# gpx_files.append((file_name, gpx_data))
# except Exception as e:
# print(f"Error processing {url}: {e}")
# return gpx_files
# except Exception as e:
# return {"error": str(e)}

# # get_gpx_url = "http://localhost:8080/course/getAllCourse"
# get_gpx_url = "http://52.78.82.12:8080/course/getAllCourse"

# # 요청 모델 정의
# class UserInfo(BaseModel):
# latitude: float
# longitude: float
# elevation_preference: str
# convenience_preference: str
# track_preference: str

# @app.post("/recommendCourse")
# def process_route(preferences: UserInfo):
# gpx_files = fetch_gpx_files(get_gpx_url) # 스프링부트 API로 부터 gpx 받아오기

# center_coords = (preferences.latitude, preferences.longitude) # 사용자 위치 위경도
# radius_threshold = 2500

# # 선호도
# elevation_preference = preferences.elevation_preference.strip()
# convenience_preference = preferences.convenience_preference.strip()
# track_preference = preferences.track_preference.strip()

# # 결과 처리 및 출력
# result = print_filtered_files(
# gpx_files, center_coords, radius_threshold, elevation_preference, convenience_preference, track_preference
# )

# return result

import sys
import os

# src 디렉터리 경로를 추가
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')))

=======
>>>>>>> 079cf380a7544c94ab661ccdbe29eb4cb0701dce
from fastapi import FastAPI, HTTPException
from lxml import etree
from pydantic import BaseModel
import requests
import os
<<<<<<< HEAD

# 이제 src 폴더가 Python 경로에 포함되어 'runningmachine' 모듈을 불러올 수 있습니다.
from runningmachine import print_filtered_files

app = FastAPI()

# GPX 파일 로드 함수 (lxml 기반)
=======
from concurrent.futures import ThreadPoolExecutor, as_completed
from runningmachine import filter_gpx_within_radius_and_preferences, load_gpx_files, print_filtered_files

app = FastAPI()

# GPX 파일 로드 함수
>>>>>>> 079cf380a7544c94ab661ccdbe29eb4cb0701dce
def fetch_gpx_files(base_url):
try:
response = requests.get(base_url) # 스프링 부트 API에서 GPX URL 리스트 가져오기
Expand Down Expand Up @@ -71,13 +158,17 @@ def recommend_course(preferences: UserInfo):
gpx_files, center_coords, radius_threshold,
elevation_preference, convenience_preference, track_preference
)

if not result:
raise HTTPException(status_code=404, detail="조건에 맞는 경로를 찾을 수 없습니다.")
<<<<<<< HEAD
return {"recommended_courses": result}
=======

return result

>>>>>>> 079cf380a7544c94ab661ccdbe29eb4cb0701dce
except HTTPException as e:
raise e # FastAPI 에러로 전달
except Exception as e:
raise HTTPException(status_code=500, detail=f"서버 오류: {str(e)}")

Loading