diff --git a/app/report/services/report_service.go b/app/report/services/report_service.go index aafcbce..85ef7dd 100644 --- a/app/report/services/report_service.go +++ b/app/report/services/report_service.go @@ -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 { @@ -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", diff --git a/app/report/services/report_service_test.go b/app/report/services/report_service_test.go index a6583f6..65abc4f 100644 --- a/app/report/services/report_service_test.go +++ b/app/report/services/report_service_test.go @@ -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}