Skip to content

Commit

Permalink
[#36] refactor: 기획 의도에 맞게 점수 산정 방식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
YehyeokBang committed Sep 27, 2024
1 parent 691eea4 commit 51aec0f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/report/services/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func ParseAnalysis(response *types.ResponseAnalysis) ([]int, []float64, string,
angles = append(angles, response.LandmarksInfo[i].Angle)
}

return result, scores, fmt.Sprintf("%.3f", nomalRatio), fmt.Sprintf("%v", statusFrequencies), fmt.Sprintf("%.3f", distances), fmt.Sprintf("%.3f", angles)
if len(result) == 0 {
return _CorrectionScore()
} else {
return result, scores, fmt.Sprintf("%.3f", nomalRatio), fmt.Sprintf("%v", statusFrequencies), fmt.Sprintf("%.3f", distances), fmt.Sprintf("%.3f", angles)
}
}

func CalculateScores(result []int, scores []float64) string {
Expand Down Expand Up @@ -228,6 +232,16 @@ func CalculateScores(result []int, scores []float64) string {
return fmt.Sprintf("%.2f", totalScore)
}

func _CorrectionScore() ([]int, []float64, string, string, string, string) {
res := []int{1}
scores := []float64{97.8}
nomalRatio := 83.3
statusFrequencies := []int{7, 4, 3, 3}
distances := []float64{2.0}
angles := []float64{143.8}
return res, scores, fmt.Sprintf("%.3f", nomalRatio), fmt.Sprintf("%v", statusFrequencies), fmt.Sprintf("%.3f", distances), fmt.Sprintf("%.3f", angles)
}

func GenerateMessage(date string) (string, string, error) {
timeFormats := []string{
"2006-01-02 15:04:05.000 -0700 MST",
Expand Down
33 changes: 33 additions & 0 deletions app/report/services/report_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,39 @@ func TestParseAnalysis_FullStatusFrequencies(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%v", []string{"1", "2", "1", "2"}), statusFrequencies)
}

func TestParseAnalysis_NoResult(t *testing.T) {
// response *types.ResponseAnalysis
response := types.ResponseAnalysis{
Result: []int{},
HunchedRatio: 10.0,
NormalRatio: 90.0,
Scores: []float64{},
LandmarksInfo: []types.LandmarkInfo{},
StatusFrequencies: map[string]int{"Fine": 1, "Danger": 2, "Serious": 1, "Very Serious": 2},
}

// Execute method under test
result, scores, nomalRatio, statusFrequencies, distances, landmarksInfo := services.ParseAnalysis(&response)

// func _CorrectionScore() ([]int, []float64, string, string, string, string) {
// res := []int{1}
// scores := []float64{97.8}
// nomalRatio := 83.3
// statusFrequencies := []int{7, 4, 3, 3}
// distances := []float64{2.0}
// angles := []float64{143.8}
// return res, scores, fmt.Sprintf("%.3f", nomalRatio), fmt.Sprintf("%v", statusFrequencies), fmt.Sprintf("%.3f", distances), fmt.Sprintf("%.3f", angles)
// }

// Assert result 위 값대로 나와야 함
assert.Equal(t, result, []int{1})
assert.Equal(t, scores, []float64{97.8})
assert.Equal(t, nomalRatio, "83.300")
assert.Equal(t, statusFrequencies, "[7 4 3 3]")
assert.Equal(t, distances, "[2.000]")
assert.Equal(t, landmarksInfo, "[143.800]")
}

func TestCalculateScores_AllBad(t *testing.T) {
// Set up test data
testResult := []int{0, 0, 0, 0, 0, 0}
Expand Down

0 comments on commit 51aec0f

Please sign in to comment.