Skip to content

Commit

Permalink
Merge d4a9e9d into 3378a11
Browse files Browse the repository at this point in the history
  • Loading branch information
Raditya Kertiyasa committed Sep 16, 2018
2 parents 3378a11 + d4a9e9d commit 955510d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
34 changes: 32 additions & 2 deletions model/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,39 @@ type Survey struct {
Cases []*Case
}

func (s *Survey) GetScore(answer string) int {
switch answer {
case "Low":
return 1
case "Medium":
return 2
case "High":
return 3
default:
return 0
}
}

func (s *Survey) CalculateScore() {
// TODO: do this
s.SubjectiveScore = 0
score := 0
score += s.GetScore(s.S1Q1)
score += s.GetScore(s.S1Q2)
score += s.GetScore(s.S1Q3)
score += s.GetScore(s.S1Q4)
score += s.GetScore(s.S1Q5)
score += s.GetScore(s.S1Q6)
score += s.GetScore(s.S1Q7)
score += s.GetScore(s.S2Q1)
score += s.GetScore(s.S2Q2)
score += s.GetScore(s.S2Q3)
score += s.GetScore(s.S2Q4)
score += s.GetScore(s.S2Q5)
score += s.GetScore(s.S2Q6)
score += s.GetScore(s.S2Q7)
score += s.GetScore(s.S2Q8)
score += s.GetScore(s.S2Q9)
normalizedScore := (score - 16) * 100 / (37 - 16)
s.SubjectiveScore = int32(normalizedScore)
}

// SurveyInput is the input for section entity
Expand Down
20 changes: 10 additions & 10 deletions model/survey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ var (
surveyorID = "fake_surveyor_id"
date = "2018-01-01"
s1q1 = "Low"
s1q2 = "Medium"
s1q3 = "High"
s1q2 = "Low"
s1q3 = "Low"
s1q4 = "Low"
s1q5 = "Medium"
s1q6 = "High"
s1q5 = "Low"
s1q6 = "Low"
s1q7 = "Low"
s2q1 = "Medium"
s2q2 = "High"
s2q1 = "Low"
s2q2 = "Low"
s2q3 = "Low"
s2q4 = "Medium"
s2q5 = "High"
s2q4 = "Low"
s2q5 = "Low"
s2q6 = "Low"
s2q7 = "Medium"
s2q8 = "High"
s2q7 = "Low"
s2q8 = "Low"
s2q9 = "Low"
lowerD = int32(1)
lowerE = int32(2)
Expand Down
1 change: 1 addition & 0 deletions service/survey_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (s *SurveyService) FindByID(id string) (*model.Survey, error) {
}

func (s *SurveyService) TransactionalCreateSurvey(survey *model.Survey) (*model.Survey, error) {
survey.CalculateScore()
surveySQL := `
INSERT INTO surveys
(
Expand Down

0 comments on commit 955510d

Please sign in to comment.