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

Commit

Permalink
refactor: rename UsageInPercentage to Weight (#77) (#90)
Browse files Browse the repository at this point in the history
* refactor: rename UsageInPercentage to Weight (#77)

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* update doc

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi authored Jul 14, 2022
1 parent d5c8528 commit 59b004f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ The result is an ordered list of information for each language detected in the s
- *name*: the name of the detected language
- *framework*: a list of detected frameworks (Quarkus, Flash,...) used by the application
- *tools*: a list of tools (Maven,...) used by the application
- *usageInPercentage*: a double value that represents the language weight compared to the others.
- *weight*: a double value that represents the language weight compared to the others.

NOTE: the sum of all weights can be over 100 because a file may be associated to multiple languages and Alizer may not be able to detect it precisely. E.g. a SQL script could be associated to SPLPL, TSQL, PLSQL languages so Alizer will return all 3 with the same weight.

### Devfile selection

Expand Down
4 changes: 3 additions & 1 deletion go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ The result is an ordered (sorted by usage) list of informations for each languag
- *Aliases*: other names which identify the detected language
- *Framework*: a list of detected frameworks (Quarkus, Flash,...) used by the application
- *Tools*: a list of tools (Maven,...) used by the application
- *UsageInPercentage*: a double value that represents the language weight compared to the others.
- *Weight*: a double value that represents the language weight compared to the others.

NOTE: the sum of all weights can be over 100 because a file may be associated to multiple languages and Alizer may not be able to detect it precisely. E.g. a SQL script could be associated to SPLPL, TSQL, PLSQL so Alizer will print out all 3 languages with the same weight.

To analyze your source code with Alizer, just import it and use the recognizer:

Expand Down
12 changes: 6 additions & 6 deletions go/pkg/apis/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
package model

type Language struct {
Name string
Aliases []string
UsageInPercentage float64
Frameworks []string
Tools []string
CanBeComponent bool
Name string
Aliases []string
Weight float64
Frameworks []string
Tools []string
CanBeComponent bool
}

type Component struct {
Expand Down
28 changes: 14 additions & 14 deletions go/pkg/apis/recognizer/language_recognizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

type languageItem struct {
item langfile.LanguageItem
percentage int
item langfile.LanguageItem
weight int
}

func Analyze(path string) ([]model.Language, error) {
Expand Down Expand Up @@ -58,8 +58,8 @@ func Analyze(path string) ([]model.Language, error) {
}
}
tmpLanguageItem := languageItem{languageFileItem, 0}
percentage := languagesDetected[tmpLanguageItem.item.Name].percentage + extensionsGrouped[extension]
tmpLanguageItem.percentage = percentage
weight := languagesDetected[tmpLanguageItem.item.Name].weight + extensionsGrouped[extension]
tmpLanguageItem.weight = weight
languagesDetected[tmpLanguageItem.item.Name] = tmpLanguageItem
extensionHasProgrammingLanguage = true
}
Expand All @@ -72,16 +72,16 @@ func Analyze(path string) ([]model.Language, error) {

var languagesFound []model.Language
for name, item := range languagesDetected {
tmpPercentage := float64(item.percentage) / float64(totalProgrammingOccurrences)
tmpPercentage = float64(int(tmpPercentage*10000)) / 10000
if tmpPercentage > 0.02 {
tmpWeight := float64(item.weight) / float64(totalProgrammingOccurrences)
tmpWeight = float64(int(tmpWeight*10000)) / 10000
if tmpWeight > 0.02 {
tmpLanguage := model.Language{
Name: name,
Aliases: item.item.Aliases,
UsageInPercentage: tmpPercentage * 100,
Frameworks: []string{},
Tools: []string{},
CanBeComponent: item.item.Component}
Name: name,
Aliases: item.item.Aliases,
Weight: tmpWeight * 100,
Frameworks: []string{},
Tools: []string{},
CanBeComponent: item.item.Component}
langEnricher := enricher.GetEnricherByLanguage(name)
if langEnricher != nil {
langEnricher.DoEnrichLanguage(&tmpLanguage, &paths)
Expand All @@ -91,7 +91,7 @@ func Analyze(path string) ([]model.Language, error) {
}

sort.SliceStable(languagesFound, func(i, j int) bool {
return languagesFound[i].UsageInPercentage > languagesFound[j].UsageInPercentage
return languagesFound[i].Weight > languagesFound[j].Weight
})

return languagesFound, nil
Expand Down
10 changes: 5 additions & 5 deletions go/test/apis/devfile_recognizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDetectDjangoDevfileUsingLanguages(t *testing.T) {
Aliases: []string{
"python3",
},
UsageInPercentage: 88.23,
Weight: 88.23,
Frameworks: []string{
"Django",
},
Expand All @@ -52,10 +52,10 @@ func TestDetectDjangoDevfileUsingLanguages(t *testing.T) {
Aliases: []string{
"sh",
},
UsageInPercentage: 11.77,
Frameworks: []string{},
Tools: []string{},
CanBeComponent: false,
Weight: 11.77,
Frameworks: []string{},
Tools: []string{},
CanBeComponent: false,
},
}
detectDevFileUsingLanguages(t, "", languages, "python-django")
Expand Down

0 comments on commit 59b004f

Please sign in to comment.