Skip to content

Commit

Permalink
[#28] refactor: 자세 분석 보고서 응답 구조체 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
YehyeokBang committed Sep 26, 2024
1 parent 1504172 commit 03114e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 19 deletions.
6 changes: 2 additions & 4 deletions app/report/services/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 39 additions & 9 deletions app/report/services/report_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand All @@ -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,
},
},
}

Expand All @@ -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},
}
Expand Down
25 changes: 19 additions & 6 deletions app/report/types/response_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 03114e3

Please sign in to comment.