diff --git a/app/report/services/report_service.go b/app/report/services/report_service.go index 1e01c5c..dd27fdd 100644 --- a/app/report/services/report_service.go +++ b/app/report/services/report_service.go @@ -165,10 +165,8 @@ func ParseAnalysis(response *types.ResponseAnalysis) ([]int, []float64, string, var distances []float64 var angles []float64 for i := range response.LandmarksInfo { - // response.LandmarksInfo[i][2] = 길이 - // response.LandmarksInfo[i][3] = 각도 - distances = append(distances, response.LandmarksInfo[i][2].(float64)) - angles = append(angles, response.LandmarksInfo[i][3].(float64)) + distances = append(distances, response.LandmarksInfo[i].VerticalDistanceCM) + 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) diff --git a/app/report/services/report_service_test.go b/app/report/services/report_service_test.go index 7c1214e..ebe5f1b 100644 --- a/app/report/services/report_service_test.go +++ b/app/report/services/report_service_test.go @@ -174,9 +174,19 @@ func TestParseAnalysis(t *testing.T) { HunchedRatio: 10.0, NormalRatio: 90.0, Scores: []float64{99.9, 92.9, 82.3, 92.4, 69.5}, - LandmarksInfo: [][]interface{}{ - {[]float64{0.1, 0.2}, []float64{0.3, 0.4}, 1.0, 45.0}, - {[]float64{0.5, 0.6}, []float64{0.7, 0.8}, 2.0, 60.0}, + LandmarksInfo: []types.LandmarkInfo{ + { + LeftShoulder: types.Landmark{X: 0.1, Y: 0.2}, + LeftEar: types.Landmark{X: 0.3, Y: 0.4}, + VerticalDistanceCM: 1.0, + Angle: 45.0, + }, + { + LeftShoulder: types.Landmark{X: 0.5, Y: 0.6}, + LeftEar: types.Landmark{X: 0.7, Y: 0.8}, + VerticalDistanceCM: 2.0, + Angle: 60.0, + }, }, StatusFrequencies: map[string]int{"Very Serious": 6}, } @@ -200,9 +210,19 @@ func TestParseAnalysis_NoStatusFrequencies(t *testing.T) { HunchedRatio: 10.0, NormalRatio: 90.0, Scores: []float64{99.9, 92.9, 82.3, 92.4, 69.5}, - LandmarksInfo: [][]interface{}{ - {[]float64{0.1, 0.2}, []float64{0.3, 0.4}, 1.0, 45.0}, - {[]float64{0.5, 0.6}, []float64{0.7, 0.8}, 2.0, 60.0}, + LandmarksInfo: []types.LandmarkInfo{ + { + LeftShoulder: types.Landmark{X: 0.1, Y: 0.2}, + LeftEar: types.Landmark{X: 0.3, Y: 0.4}, + VerticalDistanceCM: 1.0, + Angle: 45.0, + }, + { + LeftShoulder: types.Landmark{X: 0.5, Y: 0.6}, + LeftEar: types.Landmark{X: 0.7, Y: 0.8}, + VerticalDistanceCM: 2.0, + Angle: 60.0, + }, }, } @@ -225,9 +245,19 @@ func TestParseAnalysis_FullStatusFrequencies(t *testing.T) { HunchedRatio: 10.0, NormalRatio: 90.0, Scores: []float64{99.9, 92.9, 82.3, 92.4, 69.5}, - LandmarksInfo: [][]interface{}{ - {[]float64{0.1, 0.2}, []float64{0.3, 0.4}, 1.0, 45.0}, - {[]float64{0.5, 0.6}, []float64{0.7, 0.8}, 2.0, 60.0}, + LandmarksInfo: []types.LandmarkInfo{ + { + LeftShoulder: types.Landmark{X: 0.1, Y: 0.2}, + LeftEar: types.Landmark{X: 0.3, Y: 0.4}, + VerticalDistanceCM: 1.0, + Angle: 45.0, + }, + { + LeftShoulder: types.Landmark{X: 0.5, Y: 0.6}, + LeftEar: types.Landmark{X: 0.7, Y: 0.8}, + VerticalDistanceCM: 2.0, + Angle: 60.0, + }, }, StatusFrequencies: map[string]int{"Fine": 1, "Danger": 2, "Serious": 1, "Very Serious": 2}, } diff --git a/app/report/types/response_types.go b/app/report/types/response_types.go index 37aa2d2..ebbab70 100644 --- a/app/report/types/response_types.go +++ b/app/report/types/response_types.go @@ -2,18 +2,31 @@ package types import "time" +type Landmark struct { + X float64 `json:"x"` + Y float64 `json:"y"` +} + +type LandmarkInfo struct { + LeftShoulder Landmark `json:"left_shoulder"` + LeftEar Landmark `json:"left_ear"` + VerticalDistanceCM float64 `json:"vertical_distance_cm"` + Angle float64 `json:"angle"` +} + +// 전체 수정된 구조체 type ResponseReportSummary struct { ID uint `json:"id"` CreatedAt time.Time `json:"created_at"` } type ResponseAnalysis struct { - Result []int `json:"result"` - HunchedRatio float64 `json:"hunched_ratio"` - NormalRatio float64 `json:"normal_ratio"` - Scores []float64 `json:"scores"` - LandmarksInfo [][]interface{} `json:"landmarks_info"` - StatusFrequencies map[string]int `json:"status_frequencies"` + Result []int `json:"result"` + HunchedRatio float64 `json:"hunched_ratio"` + NormalRatio float64 `json:"normal_ratio"` + Scores []float64 `json:"scores"` + LandmarksInfo []LandmarkInfo `json:"landmarks_info"` + StatusFrequencies map[string]int `json:"status_frequencies"` } type ResponseReport struct {