Spaces:
Runtime error
Runtime error
Aryan Jain commited on
Commit ·
bfb0701
1
Parent(s): ab6174c
implement calculation for adjusted score
Browse files
src/controllers/_analysis_conteoller.py
CHANGED
|
@@ -32,6 +32,7 @@ class CreateAnalysis(BaseModel):
|
|
| 32 |
|
| 33 |
class CreateAnalysisRequest(BaseModel):
|
| 34 |
data: List[CreateAnalysis]
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
class UpdateAnalysis(BaseModel):
|
|
@@ -148,11 +149,17 @@ class AnalysisController:
|
|
| 148 |
):
|
| 149 |
try:
|
| 150 |
async with self.service() as service:
|
|
|
|
|
|
|
|
|
|
| 151 |
results = await service.create_analysis(
|
| 152 |
evaluation_id=evaluation_id,
|
| 153 |
-
evaluation_analysis=
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
| 156 |
)
|
| 157 |
return Response(
|
| 158 |
status="success",
|
|
|
|
| 32 |
|
| 33 |
class CreateAnalysisRequest(BaseModel):
|
| 34 |
data: List[CreateAnalysis]
|
| 35 |
+
analysis_score_type: Optional[str] = None
|
| 36 |
|
| 37 |
|
| 38 |
class UpdateAnalysis(BaseModel):
|
|
|
|
| 149 |
):
|
| 150 |
try:
|
| 151 |
async with self.service() as service:
|
| 152 |
+
evaluation_analysis = analysis.model_dump(
|
| 153 |
+
mode="json", exclude_unset=True
|
| 154 |
+
)
|
| 155 |
results = await service.create_analysis(
|
| 156 |
evaluation_id=evaluation_id,
|
| 157 |
+
evaluation_analysis=evaluation_analysis["data"],
|
| 158 |
+
analysis_score_type=(
|
| 159 |
+
evaluation_analysis["analysis_score_type"]
|
| 160 |
+
if "analysis_score_type" in evaluation_analysis
|
| 161 |
+
else None
|
| 162 |
+
),
|
| 163 |
)
|
| 164 |
return Response(
|
| 165 |
status="success",
|
src/repositories/_analysis_repository.py
CHANGED
|
@@ -37,7 +37,12 @@ class AnalysisRepository(BaseRepository):
|
|
| 37 |
for result in results
|
| 38 |
]
|
| 39 |
|
| 40 |
-
async def create_analysis(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
async with self.get_session() as session:
|
| 42 |
for analysis in evaluation_analysis:
|
| 43 |
analysis["evaluation_id"] = evaluation_id
|
|
@@ -47,7 +52,9 @@ class AnalysisRepository(BaseRepository):
|
|
| 47 |
await session.commit()
|
| 48 |
await session.refresh(instance)
|
| 49 |
async with self.score_client() as score_client:
|
| 50 |
-
await score_client.update_ai_score(
|
|
|
|
|
|
|
| 51 |
return await self.get_analysis(evaluation_id=evaluation_id)
|
| 52 |
|
| 53 |
async def update_analysis(
|
|
|
|
| 37 |
for result in results
|
| 38 |
]
|
| 39 |
|
| 40 |
+
async def create_analysis(
|
| 41 |
+
self,
|
| 42 |
+
evaluation_id: str,
|
| 43 |
+
evaluation_analysis: dict,
|
| 44 |
+
analysis_score_type: str = None,
|
| 45 |
+
):
|
| 46 |
async with self.get_session() as session:
|
| 47 |
for analysis in evaluation_analysis:
|
| 48 |
analysis["evaluation_id"] = evaluation_id
|
|
|
|
| 52 |
await session.commit()
|
| 53 |
await session.refresh(instance)
|
| 54 |
async with self.score_client() as score_client:
|
| 55 |
+
await score_client.update_ai_score(
|
| 56 |
+
evaluation_id=evaluation_id, analysis_score_type=analysis_score_type
|
| 57 |
+
)
|
| 58 |
return await self.get_analysis(evaluation_id=evaluation_id)
|
| 59 |
|
| 60 |
async def update_analysis(
|
src/services/_analysis_service.py
CHANGED
|
@@ -23,10 +23,17 @@ class AnalysisService:
|
|
| 23 |
evaluation_id=evaluation_id, analysis_type=analysis_type, id=id
|
| 24 |
)
|
| 25 |
|
| 26 |
-
async def create_analysis(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
async with self.analysis_repository() as repo:
|
| 28 |
return await repo.create_analysis(
|
| 29 |
-
evaluation_id=evaluation_id,
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
async def update_analysis(
|
|
|
|
| 23 |
evaluation_id=evaluation_id, analysis_type=analysis_type, id=id
|
| 24 |
)
|
| 25 |
|
| 26 |
+
async def create_analysis(
|
| 27 |
+
self,
|
| 28 |
+
evaluation_id: str,
|
| 29 |
+
evaluation_analysis: dict,
|
| 30 |
+
analysis_score_type: str = None,
|
| 31 |
+
):
|
| 32 |
async with self.analysis_repository() as repo:
|
| 33 |
return await repo.create_analysis(
|
| 34 |
+
evaluation_id=evaluation_id,
|
| 35 |
+
evaluation_analysis=evaluation_analysis,
|
| 36 |
+
analysis_score_type=analysis_score_type,
|
| 37 |
)
|
| 38 |
|
| 39 |
async def update_analysis(
|
src/utils/_score_client.py
CHANGED
|
@@ -12,6 +12,7 @@ from src.models import (
|
|
| 12 |
Weights,
|
| 13 |
Evaluations,
|
| 14 |
EvaluationType,
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
|
|
@@ -26,12 +27,21 @@ class ScoreClient:
|
|
| 26 |
async def __aexit__(self, exc_type, exc_value, traceback):
|
| 27 |
pass
|
| 28 |
|
| 29 |
-
async def update_ai_score(
|
|
|
|
|
|
|
| 30 |
async with self.repository(model=Evaluations).get_session() as session:
|
| 31 |
query = select(Evaluations).where(Evaluations.id == evaluation_id)
|
| 32 |
result = await session.execute(query)
|
| 33 |
evaluation = result.scalars().first()
|
| 34 |
proposal_id = evaluation.proposal_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
async with self.repository(model=Analysis).get_session() as session:
|
| 36 |
query = select(Analysis).where(Analysis.evaluation_id == evaluation_id)
|
| 37 |
result = await session.execute(query)
|
|
@@ -51,14 +61,27 @@ class ScoreClient:
|
|
| 51 |
for result in results
|
| 52 |
if result.analysis_type == AnalysisType.STRENGTHS
|
| 53 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
start_score = 0 if deficiency else 100
|
| 55 |
|
| 56 |
-
async with self.repository(model=Proposal).get_session() as session:
|
| 57 |
-
query = select(Proposal).where(Proposal.id == proposal_id)
|
| 58 |
-
result = await session.execute(query)
|
| 59 |
-
proposal = result.scalars().first()
|
| 60 |
-
rfp_id = proposal.rfp_id
|
| 61 |
-
|
| 62 |
async with self.repository(model=ComparativeWeights).get_session() as session:
|
| 63 |
query = select(ComparativeWeights).where(
|
| 64 |
ComparativeWeights.rfp_id == rfp_id
|
|
@@ -73,8 +96,11 @@ class ScoreClient:
|
|
| 73 |
query = select(Evaluations).where(Evaluations.id == evaluation_id)
|
| 74 |
result = await session.execute(query)
|
| 75 |
evaluation = result.scalars().first()
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
await session.commit()
|
| 79 |
await session.refresh(evaluation)
|
| 80 |
query = select(Evaluations).where(Evaluations.proposal_id == proposal_id)
|
|
@@ -106,6 +132,32 @@ class ScoreClient:
|
|
| 106 |
and evaluation.ai_score is not None
|
| 107 |
]
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
technical_ai_score = technical_ai_score[0] if technical_ai_score else 0
|
| 110 |
management_ai_score = management_ai_score[0] if management_ai_score else 0
|
| 111 |
past_performance_ai_score = (
|
|
@@ -141,7 +193,10 @@ class ScoreClient:
|
|
| 141 |
query = select(Proposal).where(Proposal.id == proposal_id)
|
| 142 |
result = await session.execute(query)
|
| 143 |
evaluation = result.scalars().first()
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
| 146 |
await session.commit()
|
| 147 |
await session.refresh(evaluation)
|
|
|
|
| 12 |
Weights,
|
| 13 |
Evaluations,
|
| 14 |
EvaluationType,
|
| 15 |
+
AnalysisStatus,
|
| 16 |
)
|
| 17 |
|
| 18 |
|
|
|
|
| 27 |
async def __aexit__(self, exc_type, exc_value, traceback):
|
| 28 |
pass
|
| 29 |
|
| 30 |
+
async def update_ai_score(
|
| 31 |
+
self, evaluation_id: str, analysis_score_type: str = None
|
| 32 |
+
):
|
| 33 |
async with self.repository(model=Evaluations).get_session() as session:
|
| 34 |
query = select(Evaluations).where(Evaluations.id == evaluation_id)
|
| 35 |
result = await session.execute(query)
|
| 36 |
evaluation = result.scalars().first()
|
| 37 |
proposal_id = evaluation.proposal_id
|
| 38 |
+
|
| 39 |
+
async with self.repository(model=Proposal).get_session() as session:
|
| 40 |
+
query = select(Proposal).where(Proposal.id == proposal_id)
|
| 41 |
+
result = await session.execute(query)
|
| 42 |
+
proposal = result.scalars().first()
|
| 43 |
+
rfp_id = proposal.rfp_id
|
| 44 |
+
|
| 45 |
async with self.repository(model=Analysis).get_session() as session:
|
| 46 |
query = select(Analysis).where(Analysis.evaluation_id == evaluation_id)
|
| 47 |
result = await session.execute(query)
|
|
|
|
| 61 |
for result in results
|
| 62 |
if result.analysis_type == AnalysisType.STRENGTHS
|
| 63 |
]
|
| 64 |
+
if analysis_score_type != "AI":
|
| 65 |
+
deficiency = [
|
| 66 |
+
result.insights
|
| 67 |
+
for result in results
|
| 68 |
+
if result.analysis_type == AnalysisType.DEFICIENCIES
|
| 69 |
+
and result.status != AnalysisStatus.REJECTED
|
| 70 |
+
]
|
| 71 |
+
weaknesses = [
|
| 72 |
+
result.insights
|
| 73 |
+
for result in results
|
| 74 |
+
if result.analysis_type == AnalysisType.WEAKNESSES
|
| 75 |
+
and result.status != AnalysisStatus.REJECTED
|
| 76 |
+
]
|
| 77 |
+
strengths = [
|
| 78 |
+
result.insights
|
| 79 |
+
for result in results
|
| 80 |
+
if result.analysis_type == AnalysisType.STRENGTHS
|
| 81 |
+
and result.status != AnalysisStatus.REJECTED
|
| 82 |
+
]
|
| 83 |
start_score = 0 if deficiency else 100
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
async with self.repository(model=ComparativeWeights).get_session() as session:
|
| 86 |
query = select(ComparativeWeights).where(
|
| 87 |
ComparativeWeights.rfp_id == rfp_id
|
|
|
|
| 96 |
query = select(Evaluations).where(Evaluations.id == evaluation_id)
|
| 97 |
result = await session.execute(query)
|
| 98 |
evaluation = result.scalars().first()
|
| 99 |
+
if analysis_score_type == "AI":
|
| 100 |
+
evaluation.ai_score = start_score
|
| 101 |
+
evaluation.adjusted_score = start_score
|
| 102 |
+
else:
|
| 103 |
+
evaluation.adjusted_score = start_score
|
| 104 |
await session.commit()
|
| 105 |
await session.refresh(evaluation)
|
| 106 |
query = select(Evaluations).where(Evaluations.proposal_id == proposal_id)
|
|
|
|
| 132 |
and evaluation.ai_score is not None
|
| 133 |
]
|
| 134 |
|
| 135 |
+
if analysis_score_type != "AI":
|
| 136 |
+
technical_ai_score = [
|
| 137 |
+
evaluation.adjusted_score
|
| 138 |
+
for evaluation in evaluations
|
| 139 |
+
if evaluation.evaluation_type == EvaluationType.TECHNICAL
|
| 140 |
+
and evaluation.adjusted_score is not None
|
| 141 |
+
]
|
| 142 |
+
management_ai_score = [
|
| 143 |
+
evaluation.adjusted_score
|
| 144 |
+
for evaluation in evaluations
|
| 145 |
+
if evaluation.evaluation_type == EvaluationType.MANAGEMENT
|
| 146 |
+
and evaluation.adjusted_score is not None
|
| 147 |
+
]
|
| 148 |
+
past_performance_ai_score = [
|
| 149 |
+
evaluation.adjusted_score
|
| 150 |
+
for evaluation in evaluations
|
| 151 |
+
if evaluation.evaluation_type == EvaluationType.PAST_PERFORMANCE
|
| 152 |
+
and evaluation.adjusted_score is not None
|
| 153 |
+
]
|
| 154 |
+
price_ai_score = [
|
| 155 |
+
evaluation.adjusted_score
|
| 156 |
+
for evaluation in evaluations
|
| 157 |
+
if evaluation.evaluation_type == EvaluationType.PRICE
|
| 158 |
+
and evaluation.adjusted_score is not None
|
| 159 |
+
]
|
| 160 |
+
|
| 161 |
technical_ai_score = technical_ai_score[0] if technical_ai_score else 0
|
| 162 |
management_ai_score = management_ai_score[0] if management_ai_score else 0
|
| 163 |
past_performance_ai_score = (
|
|
|
|
| 193 |
query = select(Proposal).where(Proposal.id == proposal_id)
|
| 194 |
result = await session.execute(query)
|
| 195 |
evaluation = result.scalars().first()
|
| 196 |
+
if analysis_score_type == "AI":
|
| 197 |
+
evaluation.ai_score = ai_score
|
| 198 |
+
evaluation.final_score = ai_score
|
| 199 |
+
else:
|
| 200 |
+
evaluation.final_score = ai_score
|
| 201 |
await session.commit()
|
| 202 |
await session.refresh(evaluation)
|