Skip to content

Commit

Permalink
Issue #91: Provide rating from block of related numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
haumacher committed Dec 2, 2024
1 parent b91467a commit 513591e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,23 @@ private static SearchResult analyze(String query, boolean isBot, boolean isSeach
if (comments.isEmpty()) {
comments = reports.getAllComments(aggregation100.getPrefix());
}

if (info.getRating() == Rating.B_MISSED) {
DBNumberInfo aggregateInfo = reports.getPhoneInfoAggregate(aggregation100.getPrefix());
info.setRating(DB.rating(aggregateInfo));
}
} else {
if (aggregation10.getCnt() >= DB.MIN_AGGREGATE_10) {
relatedNumbers = reports.getRelatedNumbers(aggregation10.getPrefix());

if (comments.isEmpty()) {
comments = reports.getAllComments(aggregation10.getPrefix());
}

if (info.getRating() == Rating.B_MISSED) {
DBNumberInfo aggregateInfo = reports.getPhoneInfoAggregate(aggregation10.getPrefix());
info.setRating(DB.rating(aggregateInfo));
}
} else {
relatedNumbers = Collections.emptyList();
}
Expand Down
5 changes: 3 additions & 2 deletions phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ private static BlockListEntry toBlocklistEntry(DBNumberInfo n) {
.setRating(rating(n));
}

private static Rating rating(NumberInfo n) {
public static Rating rating(NumberInfo n) {
if (n.getVotes() <= 0) {
return Rating.A_LEGITIMATE;
}
Expand Down Expand Up @@ -1020,6 +1020,7 @@ public PhoneInfo getPhoneInfo(NumberInfo info, AggregationInfo aggregation10, Ag
.setDateAdded(info.getAdded())
.setLastUpdate(info.getUpdated());

Rating rating = rating(info);
int votes;
if (aggregation100.getVotes() >= MIN_AGGREGATE_100) {
votes = aggregation100.getVotes();
Expand All @@ -1044,7 +1045,7 @@ public PhoneInfo getPhoneInfo(NumberInfo info, AggregationInfo aggregation10, Ag
}

result.setVotes(votes);
result.setRating(rating(info));
result.setRating(rating);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ SELECT COUNT(1) FROM NUMBERS s
""")
DBNumberInfo getPhoneInfo(String phone);

@Select("""
select #{prefix}, max(s.ADDED), max(s.UPDATED), max(s.LASTSEARCH), true, sum(s.CALLS), sum(s.VOTES), sum(s.LEGITIMATE), sum(s.PING), sum(s.POLL), sum(s.ADVERTISING), sum(s.GAMBLE), sum(s.FRAUD), sum(s.SEARCHES)
from NUMBERS s
where
s.PHONE > #{prefix} and
s.PHONE < concat(#{prefix}, 'Z')
""")
DBNumberInfo getPhoneInfoAggregate(String prefix);

@Select("""
select s.PHONE from NUMBERS s
WHERE s.PHONE > #{phone}
Expand Down

0 comments on commit 513591e

Please sign in to comment.