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

Calculate less weight for templates and static files #168

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

thepetk
Copy link
Collaborator

@thepetk thepetk commented Apr 1, 2023

What does this PR do?

Updates the logic of the weight calculation for each Language that is of kind=="programming". More detailed:

  • It replaces the extension count by extensionPoints. This way we are able to give different amount of points to each language extension.
  • Inside func extractExtensions(paths []string) map[string]int it checks if a given path is part of [2]string{"static/", "templates/"}. If this is the case, it gives 10 points where a normal file gets 100 points (the template file is 10% of the normal one).

The main part of the updated code:

func isStaticFileExtension(path string) bool {
	staticDirs := [2]string{"static/", "templates/"}
	for _, dir := range staticDirs {
		if strings.Contains(path, dir) {
			return true
		}
	}
	return false
}

func extractExtensions(paths []string) map[string]int {
	extensions := make(map[string]int)
	for _, path := range paths {
		extension := filepath.Ext(path)
		if len(extension) == 0 {
			continue
		}
		extensionPoints := extensions[extension]
		if !isStaticFileExtension(path) {
			extensionPoints = extensionPoints + 100
		} else {
			extensionPoints = extensionPoints + 10
		}
		extensions[extension] = extensionPoints
	}
	return extensions
}

Which issue(s) this PR fixes:

fixes #147

Test outputs

Here is the output of the test for the repo mentioned in the issue:

[
	{
		"Name": "Python",
		"Aliases": [
			"python3",
			"rusthon"
		],
		"Weight": 83,
		"Frameworks": [
			"Flask"
		],
		"Tools": [],
		"CanBeComponent": true
	},
	{
		"Name": "JavaScript",
		"Aliases": [
			"js",
			"node",
			"nodejs",
			"TypeScript"
		],
		"Weight": 16,
		"Frameworks": [],
		"Tools": [],
		"CanBeComponent": true
	}
]

Signed-off-by: thepetk <thepetk@gmail.com>
@thepetk thepetk requested review from kadel and mike-hoang April 1, 2023 17:22
@thepetk thepetk self-assigned this Apr 1, 2023
@thepetk thepetk changed the title Calculate less weight for templates and static files WIP: Calculate less weight for templates and static files Apr 5, 2023
@thepetk thepetk changed the title WIP: Calculate less weight for templates and static files Calculate less weight for templates and static files Apr 5, 2023
Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

@thepetk thepetk merged commit 98a0064 into redhat-developer:main Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong detection: Python project detected as NodeJS
2 participants