Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

Commit

Permalink
Change rating system to use letters instead of %
Browse files Browse the repository at this point in the history
  • Loading branch information
Ullaakut committed Jul 13, 2019
1 parent 842a402 commit 5e27cad
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/signature/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func sendReport(report SignedReport) error {
return fmt.Errorf("unable to send signed report to astronomer server: %v", err)
}

if response.StatusCode != 200 {
if response.StatusCode != 201 {
return fmt.Errorf("astronomer server did not trust this report: %v", response.Status)
}

Expand Down
44 changes: 22 additions & 22 deletions pkg/trust/factors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ var (
factorReferences = map[FactorName]float64{
PrivateContributionFactor: 300,
ContributionScoreFactor: 18000,
IssueContributionFactor: 20,
IssueContributionFactor: 18,
CommitContributionFactor: 370,
RepoContributionFactor: 30,
RepoContributionFactor: 25,
PRContributionFactor: 20,
PRReviewContributionFactor: 8,
PRReviewContributionFactor: 7,
AccountAgeFactor: 1600,
}

percentileReferences = map[Percentile]float64{
"5": 7,
"10": 22,
"15": 42,
"20": 98,
"25": 167,
"30": 286,
"35": 435,
"40": 515,
"45": 875,
"50": 1230,
"55": 1860,
"60": 2830,
"65": 4270,
"70": 5990,
"75": 8420,
"80": 10140,
"85": 19900,
"90": 33470,
"95": 59320,
"5": 6,
"10": 18,
"15": 34,
"20": 76,
"25": 142,
"30": 232,
"35": 396,
"40": 435,
"45": 625,
"50": 1005,
"55": 1490,
"60": 2230,
"65": 3680,
"70": 5100,
"75": 7850,
"80": 9230,
"85": 17800,
"90": 28495,
"95": 51230,
}

// factorWeights represents the importance of each factor in
Expand Down
43 changes: 31 additions & 12 deletions pkg/trust/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ func printHeader(info bool) {
// FactorName: Score Trust%
func printFactor(info bool, factorName string, factor Factor) {
format := tabulateFormat(factorsFormat, factorName, firstColumnLength)
format = tabulateFormat(format, fmt.Sprintf("%1.f", factor.Value), secondColumnLength)
format = tabulateFormat(format, fmt.Sprintf("%1.f", factor.Value), secondColumnLength+2)

if factor.TrustPercent < 0.5 {
printf(info, format, factorName, style.Failure(fmt.Sprintf("%1.f", factor.Value)), style.Failure(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
} else if factor.TrustPercent < 0.75 {
printf(info, format, factorName, style.Important(fmt.Sprintf("%1.f", factor.Value)), style.Important(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
grade := percentToLetterGrade(factor.TrustPercent)

if factor.TrustPercent < 0.4 {
printf(info, format, factorName, style.Failure(fmt.Sprintf("%1.f", factor.Value)), style.Failure(grade))
} else if factor.TrustPercent < 0.6 {
printf(info, format, factorName, style.Important(fmt.Sprintf("%1.f", factor.Value)), style.Important(grade))
} else {
printf(info, format, factorName, style.Success(fmt.Sprintf("%1.f", factor.Value)), style.Success(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
printf(info, format, factorName, style.Success(fmt.Sprintf("%1.f", factor.Value)), style.Success(grade))
}
}

Expand All @@ -111,15 +113,17 @@ func printPercentile(info bool, percentile Percentile, factor Factor) {
// printResult prints the overall result in the following format:
// FactorName: Trust%
func printResult(info bool, factorName string, factor Factor) {
format := tabulateFormat(OverallTrustFormat, factorName, firstColumnLength+secondColumnLength+1)
format := tabulateFormat(OverallTrustFormat, factorName, firstColumnLength+secondColumnLength+3)
underline := generateUnderline(firstColumnLength + secondColumnLength + 8)

if factor.TrustPercent < 0.5 {
printf(info, format, underline, factorName, style.Failure(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
} else if factor.TrustPercent < 0.75 {
printf(info, format, underline, factorName, style.Important(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
grade := percentToLetterGrade(factor.TrustPercent)

if factor.TrustPercent < 0.4 {
printf(info, format, underline, factorName, style.Failure(grade))
} else if factor.TrustPercent < 0.6 {
printf(info, format, underline, factorName, style.Important(grade))
} else {
printf(info, format, underline, factorName, style.Success(fmt.Sprintf("%4.f%%", factor.TrustPercent*100)))
printf(info, format, underline, factorName, style.Success(grade))
}
}

Expand Down Expand Up @@ -148,3 +152,18 @@ func generateUnderline(length int) string {

return string(underline)
}

func percentToLetterGrade(percent float64) string {
switch {
case percent > 0.8:
return "A"
case percent > 0.6:
return "B"
case percent > 0.4:
return "C"
case percent > 0.2:
return "D"
default:
return "E"
}
}
6 changes: 3 additions & 3 deletions pkg/trust/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestPrintTrustFactor(t *testing.T) {
TrustPercent: 0.99,
})

assert.Contains(t, logger.String(), "test_name: 42 99%")
assert.Contains(t, logger.String(), "test_name: 42 A")
}

func TestPrintPercentile(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestPrintPercentile(t *testing.T) {
TrustPercent: 0.99,
})

assert.Contains(t, logger.String(), "5th percentile: 8484 99%")
assert.Contains(t, logger.String(), "5th percentile: 8484 A")
}

func TestPrintResult(t *testing.T) {
Expand All @@ -41,7 +41,7 @@ func TestPrintResult(t *testing.T) {
})

assert.Contains(t, logger.String(), "----------------------------------------------------------")
assert.Contains(t, logger.String(), "test_name: 87%")
assert.Contains(t, logger.String(), "test_name: A")
}

func TestPrintHeader(t *testing.T) {
Expand Down

0 comments on commit 5e27cad

Please sign in to comment.