Skip to content

Commit

Permalink
relocate package trait details and update css to be more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin committed Oct 31, 2023
1 parent 8082a27 commit bfb0643
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 75 deletions.
4 changes: 2 additions & 2 deletions FrontEnd/styles/maintainer_info.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
border: 1px solid var(--score-category-background);
}

.container {
.package-score-breakdown {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;

.category {
.score-trait {
display: grid;
grid-template-rows: 2fr 3fr;
border: 1px solid var(--score-category-background);
Expand Down
40 changes: 0 additions & 40 deletions Sources/App/Core/Score.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,6 @@ enum Score {
case readme
case contributors
case tests

var title: String {
switch self {
case .archive: return "Archived"
case .license: return "License"
case .releases: return "Releases"
case .stars: return "Stars"
case .dependencies: return "Dependencies"
case .maintenance: return "Last Activity"
case .documentation: return "Documentation"
case .readme: return "README"
case .contributors: return "Contributors"
case .tests: return "Tests"
}
}

func description(candidate: Input) -> String {
switch self {
case .archive:
"Repository is \(candidate.isArchived ? "" : "not") archived."
case .license:
"OSI-compatible license \(candidate.licenseKind == .compatibleWithAppStore ? "" : "not") which is compatible with the App Store."
case .releases:
"Has \(pluralizedCount: candidate.releaseCount, singular: "release")."
case .stars:
"Has \(pluralizedCount: candidate.likeCount, singular: "star")."
case .dependencies:
"\(candidate.numberOfDependencies ?? 0 < 1 ? "Has no dependencies." : "Depends on \(pluralizedCount: candidate.numberOfDependencies ?? 0, singular: "package", plural: "packages").")"
case .maintenance:
"The last maintenance activity was \(candidate.lastActivityAt?.relative)."
case .documentation:
"\(candidate.hasDocumentation ? "Includes " : "Has no") documentation."
case .readme:
"\(candidate.hasReadme ? "Has a" : "Does not have a") README file."
case .contributors:
"Has \(pluralizedCount: candidate.numberOfContributors, singular: "contributor")."
case .tests:
"Has \(candidate.hasTestTargets ? "" : "no") test targets."
}
}
}

var candidate: Input?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension MaintainerInfoIndex {
func packageScoreCategories() -> Node<HTML.BodyContext> {
.forEach(0..<scoreCategories.count, { index in
.div(
.class("category"),
.class("score-trait"),
.p("\(scoreCategories[index].title)"),
.p("\(scoreCategories[index].score) points"),
.p("\(scoreCategories[index].description)")
Expand All @@ -78,3 +78,45 @@ extension MaintainerInfoIndex {
}
}
}

extension Score.ScoreDetails.ScoreCategory {
var title: String {
switch self {
case .archive: return "Archived"
case .license: return "License"
case .releases: return "Releases"
case .stars: return "Stars"
case .dependencies: return "Dependencies"
case .maintenance: return "Last Activity"
case .documentation: return "Documentation"
case .readme: return "README"
case .contributors: return "Contributors"
case .tests: return "Tests"
}
}

func description(candidate: Score.Input) -> String {
switch self {
case .archive:
"Repository is \(candidate.isArchived ? "" : "not") archived."
case .license:
"\(candidate.licenseKind == .compatibleWithAppStore ? "" : "No ")OSI-compatible license which is compatible with the App Store."
case .releases:
"Has \(pluralizedCount: candidate.releaseCount, singular: "release")."
case .stars:
"Has \(pluralizedCount: candidate.likeCount, singular: "star")."
case .dependencies:
"\(candidate.numberOfDependencies ?? 0 < 1 ? "Has no dependencies." : "Depends on \(pluralizedCount: candidate.numberOfDependencies ?? 0, singular: "package", plural: "packages").")"
case .maintenance:
if candidate.lastActivityAt != nil { "The last maintenance activity was \(candidate.lastActivityAt?.relative)." } else { "No data available."}
case .documentation:
"\(candidate.hasDocumentation ? "Includes " : "Has no") documentation."
case .readme:
"\(candidate.hasReadme ? "Has a" : "Does not have a") README file."
case .contributors:
"Has \(pluralizedCount: candidate.numberOfContributors, singular: "contributor")."
case .tests:
"Has \(candidate.hasTestTargets ? "" : "no") test targets."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ enum MaintainerInfoIndex {
.text("Total – \(model.score) points")
),
.div(
.class("container"),
.class("package-score-breakdown"),
model.packageScoreCategories()
),
.p("If you are interested in providing feedback for the package score, please submit ideas in the ",
Expand Down
20 changes: 11 additions & 9 deletions Tests/AppTests/Mocks/MaintainerInfoIndex+mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ extension MaintainerInfoIndex.Model {
candidate: Score.Input(
licenseKind: .compatibleWithAppStore,
releaseCount: 10,
likeCount: 30,
likeCount: 300,
isArchived: false,
numberOfDependencies: 3,
lastActivityAt: Date(),
hasDocumentation: true,
hasReadme: true,
numberOfContributors: 20,
hasTestTargets: false
),
scoreBreakdown: [
.archive: 20,
.license: 20,
.releases: 20,
.license: 10,
.releases: 10,
.stars: 20,
.dependencies: 20,
.maintenance: 20,
.documentation: 20,
.readme: 20,
.contributors: 20,
.tests: 20
.dependencies: 2,
.maintenance: 15,
.documentation: 15,
.readme: 15,
.contributors: 10,
.tests: 0
]
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,55 +150,55 @@ <h3>Package Score</h3>
<p>Based on our analysis, this package has the total score of 10. In combination with the relevancy of a search query, we use the package score to partially influence the ordering of search results on the Swift Package Index.</p>
<p>The score is currently evaluated based on 10 traits and the breakdown of each trait is shown below.</p>
<div class="package-score">Total – 10 points</div>
<div class="container">
<div class="category">
<div class="package-score-breakdown">
<div class="score-trait">
<p>Archived</p>
<p>20 points</p>
<p>Repository is not archived.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Contributors</p>
<p>20 points</p>
<p>10 points</p>
<p>Has 20 contributors.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Dependencies</p>
<p>20 points</p>
<p>Has no dependencies.</p>
<p>2 points</p>
<p>Depends on 3 packages.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Documentation</p>
<p>20 points</p>
<p>15 points</p>
<p>Includes documentation.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Last Activity</p>
<p>20 points</p>
<p>The last maintenance activity was nil.</p>
<p>15 points</p>
<p>The last maintenance activity was in 53 years.</p>
</div>
<div class="category">
<div class="score-trait">
<p>License</p>
<p>20 points</p>
<p>10 points</p>
<p>OSI-compatible license which is compatible with the App Store.</p>
</div>
<div class="category">
<div class="score-trait">
<p>README</p>
<p>20 points</p>
<p>15 points</p>
<p>Has a README file.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Releases</p>
<p>20 points</p>
<p>10 points</p>
<p>Has 10 releases.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Stars</p>
<p>20 points</p>
<p>Has 30 stars.</p>
<p>Has 300 stars.</p>
</div>
<div class="category">
<div class="score-trait">
<p>Tests</p>
<p>20 points</p>
<p>0 points</p>
<p>Has no test targets.</p>
</div>
</div>
Expand Down

0 comments on commit bfb0643

Please sign in to comment.