Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Nov 11, 2024
1 parent 05e6c67 commit 0ab42d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.IntStream;
import org.apache.commons.text.similarity.LevenshteinDistance;
import org.slf4j.Logger;
Expand Down Expand Up @@ -171,35 +172,39 @@ private List<User> getTop3SlackReviewers() {

return top3
.stream()
.map(entry -> {
var exactUser = allSlackUsers
.stream()
.filter(
user ->
user.getName().equals(entry.user().name()) ||
(user.getProfile().getEmail() != null &&
user.getProfile().getEmail().equals(entry.user().email()))
)
.findFirst();
if (exactUser.isPresent()) {
return exactUser.get();
}

// find through String edit distance
return allSlackUsers
.stream()
.min((a, b) ->
Integer.compare(
LevenshteinDistance.getDefaultInstance().apply(entry.user().name(), a.getName()),
LevenshteinDistance.getDefaultInstance().apply(entry.user().name(), b.getName())
)
)
.orElse(null);
})
.map(mapToSlackUser(allSlackUsers))
.filter(user -> user != null)
.toList();
}

private Function<LeaderboardEntryDTO, User> mapToSlackUser(List<User> allSlackUsers) {
return entry -> {
var exactUser = allSlackUsers
.stream()
.filter(
user ->
user.getName().equals(entry.user().name()) ||
(user.getProfile().getEmail() != null &&
user.getProfile().getEmail().equals(entry.user().email()))
)
.findFirst();
if (exactUser.isPresent()) {
return exactUser.get();
}

// find through String edit distance
return allSlackUsers
.stream()
.min((a, b) ->
Integer.compare(
LevenshteinDistance.getDefaultInstance().apply(entry.user().name(), a.getName()),
LevenshteinDistance.getDefaultInstance().apply(entry.user().name(), b.getName())
)
)
.orElse(null);
};
}

@Override
public void run() {
// get date in unix format
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class HomeComponent {

private readonly route = inject(ActivatedRoute);
private queryParams = toSignal(this.route.queryParamMap, { requireSync: true });

protected leaderboardSchedule = computed(() => {
const timeParts = this.metaQuery.data()?.scheduledTime?.split(':') ?? ['09', '00'];
return {
Expand All @@ -41,6 +42,7 @@ export class HomeComponent {
minute: Number.parseInt(timeParts[1] ?? '0')
};
});

protected after = computed(() => {
const afterParam = this.queryParams().get('after');
if (afterParam) return afterParam;
Expand Down

0 comments on commit 0ab42d4

Please sign in to comment.