Support top-level manager ranking fields
This commit is contained in:
@@ -16,6 +16,7 @@ from tools.generate_popular_node_signatures import (
|
|||||||
main,
|
main,
|
||||||
normalise_input_spec,
|
normalise_input_spec,
|
||||||
normalise_manager_entries,
|
normalise_manager_entries,
|
||||||
|
rank_entries,
|
||||||
rank_packs,
|
rank_packs,
|
||||||
repo_cache_path,
|
repo_cache_path,
|
||||||
write_artifact,
|
write_artifact,
|
||||||
@@ -5650,6 +5651,39 @@ class ManagerIngestionTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(["many-downloads", "many-stars"], [pack["id"] for pack in ranked])
|
self.assertEqual(["many-downloads", "many-stars"], [pack["id"] for pack in ranked])
|
||||||
|
|
||||||
|
def test_rank_entries_reads_top_level_popularity_fields(self):
|
||||||
|
entries = [
|
||||||
|
{
|
||||||
|
"id": "third",
|
||||||
|
"title": "Third",
|
||||||
|
"repository": "https://github.com/example/third",
|
||||||
|
"downloads": 1,
|
||||||
|
"github_stars": 10,
|
||||||
|
"manager_order": 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "first",
|
||||||
|
"title": "First",
|
||||||
|
"repository": "https://github.com/example/first",
|
||||||
|
"downloads": 100,
|
||||||
|
"github_stars": 0,
|
||||||
|
"manager_order": 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "second",
|
||||||
|
"title": "Second",
|
||||||
|
"repository": "https://github.com/example/second",
|
||||||
|
"downloads": 100,
|
||||||
|
"github_stars": 50,
|
||||||
|
"manager_order": 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
ranked = rank_entries(entries)
|
||||||
|
|
||||||
|
self.assertEqual(["second", "first", "third"], [entry["id"] for entry in ranked])
|
||||||
|
self.assertEqual([1, 2, 3], [entry["rank"] for entry in ranked])
|
||||||
|
|
||||||
|
|
||||||
class RepoCacheTests(unittest.TestCase):
|
class RepoCacheTests(unittest.TestCase):
|
||||||
def test_default_cache_dir_is_under_system_temp_dir(self):
|
def test_default_cache_dir_is_under_system_temp_dir(self):
|
||||||
|
|||||||
@@ -260,6 +260,15 @@ def _metric_min_float(metrics, names):
|
|||||||
return min(values) if values else None
|
return min(values) if values else None
|
||||||
|
|
||||||
|
|
||||||
|
def _metric_min_float_from_sources(sources, names):
|
||||||
|
values = []
|
||||||
|
for source in sources:
|
||||||
|
value = _metric_min_float(source, names)
|
||||||
|
if value is not None:
|
||||||
|
values.append(value)
|
||||||
|
return min(values) if values else None
|
||||||
|
|
||||||
|
|
||||||
def _pack_id_from_repository(repository):
|
def _pack_id_from_repository(repository):
|
||||||
parsed = urlparse(repository)
|
parsed = urlparse(repository)
|
||||||
if parsed.netloc:
|
if parsed.netloc:
|
||||||
@@ -300,10 +309,13 @@ def normalise_manager_entries(raw):
|
|||||||
|
|
||||||
|
|
||||||
def _rank_sort_key(pack):
|
def _rank_sort_key(pack):
|
||||||
metrics = pack.get("metrics", {})
|
metric_sources = (pack.get("metrics", {}), pack)
|
||||||
downloads = _metric_max(metrics, ("downloads", "download_count"))
|
downloads = max(_metric_max(source, ("downloads", "download_count")) for source in metric_sources)
|
||||||
stars = _metric_max(metrics, ("stars", "github_stars", "stargazers_count"))
|
stars = max(_metric_max(source, ("stars", "github_stars", "stargazers_count")) for source in metric_sources)
|
||||||
search_ranking = _metric_min_float(metrics, ("search_ranking", "search_rank", "search_order"))
|
search_ranking = _metric_min_float_from_sources(
|
||||||
|
metric_sources,
|
||||||
|
("search_ranking", "search_rank", "search_order"),
|
||||||
|
)
|
||||||
manager_order = int(pack.get("manager_order", 0))
|
manager_order = int(pack.get("manager_order", 0))
|
||||||
return (
|
return (
|
||||||
-downloads,
|
-downloads,
|
||||||
|
|||||||
Reference in New Issue
Block a user