Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyamsinghal committed Jan 9, 2025
1 parent de90d2c commit 988fae3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
20 changes: 10 additions & 10 deletions yb-voyager/cmd/migration_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const explainTemplateHTML = `
<p>
Level-1 Impact: Resolutions are available with minimal effort.<br/>
Level-2 Impact: Resolutions are available requiring moderate effort.<br/>
Level-3 Impact: Resolutions may not be available or are highly complex.
Level-3 Impact: Resolutions may not be available or are complex.
</p>
<p>
Expand All @@ -250,12 +250,12 @@ const explainTemplateHTML = `

const explainTemplateText = `Reasoning: {{ .ComplexityRationale }}`

type ExplanationData struct {
Summaries []CategorySummary
type MigrationComplexityExplanationData struct {
Summaries []MigrationComplexityCategorySummary
ComplexityRationale string // short reasoning or explanation text
}

type CategorySummary struct {
type MigrationComplexityCategorySummary struct {
Category string
TotalIssueCount int
ImpactCounts map[string]int // e.g. {"Level-1": 3, "Level-2": 5, "Level-3": 2}
Expand All @@ -266,7 +266,7 @@ func buildMigrationComplexityExplanation(sourceDBType string, assessmentReport A
return "", nil
}

var explanation ExplanationData
var explanation MigrationComplexityExplanationData
explanation.ComplexityRationale = migrationComplexityRationale

explanation.Summaries = buildCategorySummary(assessmentReport.Issues)
Expand Down Expand Up @@ -302,15 +302,15 @@ func buildRationale(finalComplexity string, l1Count int, l2Count int, l3Count in
return ""
}

func buildCategorySummary(issues []AssessmentIssue) []CategorySummary {
summaryMap := make(map[string]*CategorySummary)
func buildCategorySummary(issues []AssessmentIssue) []MigrationComplexityCategorySummary {
summaryMap := make(map[string]*MigrationComplexityCategorySummary)
for _, issue := range issues {
if issue.Category == "" {
continue // skipping unknown category issues
}

if _, ok := summaryMap[issue.Category]; !ok {
summaryMap[issue.Category] = &CategorySummary{
summaryMap[issue.Category] = &MigrationComplexityCategorySummary{
Category: issue.Category,
TotalIssueCount: 0,
ImpactCounts: make(map[string]int),
Expand All @@ -321,9 +321,9 @@ func buildCategorySummary(issues []AssessmentIssue) []CategorySummary {
summaryMap[issue.Category].ImpactCounts[issue.Impact]++
}

var result []CategorySummary
var result []MigrationComplexityCategorySummary
for _, summary := range summaryMap {
summary.Category = utils.ToTitleCase(summary.Category)
summary.Category = utils.SnakeCaseToTitleCase(summary.Category)
result = append(result, *summary)
}
return result
Expand Down
13 changes: 8 additions & 5 deletions yb-voyager/src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var DoNotPrompt bool
Expand Down Expand Up @@ -745,12 +747,13 @@ func BuildObjectName(schemaName, objName string) string {
return lo.Ternary(schemaName != "", schemaName+"."+objName, objName)
}

// ToTitleCase converts a snake_case string to a title case string with spaces.
func ToTitleCase(snake string) string {
// SnakeCaseToTitleCase converts a snake_case string to a title case string with spaces.
func SnakeCaseToTitleCase(snake string) string {
words := strings.Split(snake, "_")
c := cases.Title(language.English)
for i, word := range words {
words[i] = strings.Title(word)
words[i] = c.String(word)
}

return strings.Join(words, " ")
}
}

0 comments on commit 988fae3

Please sign in to comment.