|
9 | 9 | from ..dependencies.auth import verify_token |
10 | 10 |
|
11 | 11 | from ....services.analyzer import centroid_analysis |
12 | | -from ..models.request import IdeaRequest |
| 12 | +from ..models.request import IdeaInput, IdeaRequest |
13 | 13 | from ..models.response import AnalysisResponse, RelationshipGraph |
14 | 14 | from app.services.types import PlotData, Results, RankedIdea |
15 | 15 |
|
@@ -79,10 +79,11 @@ async def rank_ideas( |
79 | 79 | ) |
80 | 80 |
|
81 | 81 | # Perform core analysis |
| 82 | + print('Starting analysis for ideas: \n', ideaRequest) |
82 | 83 | results, plot_data = centroid_analysis(ideas) |
83 | 84 | await CreditService.deduct_credits(user_id, "basic_analysis", num_ideas, total_bytes) |
84 | 85 |
|
85 | | - response = await build_base_response(ideas, results, plot_data) |
| 86 | + response = await build_base_response(ideas, results, plot_data, ideaRequest.ideas) |
86 | 87 |
|
87 | 88 | if ideaRequest.advanced_features: |
88 | 89 | response = await process_advanced_features( |
@@ -123,11 +124,14 @@ def _generate_edges(ranked_ideas: List[RankedIdea], similarity_matrix: List[List |
123 | 124 |
|
124 | 125 | return edges |
125 | 126 |
|
126 | | -async def build_base_response(ideas: List[str], results: Results, plot_data: PlotData) -> dict: |
| 127 | +async def build_base_response(ideas: List[str], results: Results, plot_data: PlotData, idea_inputs: List[IdeaInput]) -> dict: |
127 | 128 | """Build base response with ranked ideas and similarity scores""" |
| 129 | + # Create lookup dict from idea string to original input |
| 130 | + idea_to_input = {input.idea: input for input in idea_inputs} |
| 131 | + |
128 | 132 | ranked_ideas = [ |
129 | 133 | RankedIdea( |
130 | | - id=str(idx), |
| 134 | + id=str(idea_to_input[idea].id) if idea_to_input[idea].id is not None else str(idx), |
131 | 135 | idea=idea, |
132 | 136 | similarity_score=results["similarity"][idx], |
133 | 137 | cluster_id=plot_data["kmeans_data"]["cluster"][idx], |
|
0 commit comments