Skip to content

Commit

Permalink
Drops: (#835)
Browse files Browse the repository at this point in the history
- Watch highest priority drops enabled streamer via M3U8
- Watch two highest-priority, ignoring Drops, streamer via Spade
  • Loading branch information
jabbink authored Jul 21, 2024
1 parent e03fe40 commit c92a3bf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ protected boolean send(@NotNull Streamer streamer){
protected boolean shouldUpdateWatchedMinutes(){
return false;
}

@Override
protected boolean shouldWatchDropsOnly(){
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ public abstract class SendMinutesWatched implements Runnable{

protected abstract boolean shouldUpdateWatchedMinutes();

protected abstract boolean shouldWatchDropsOnly();

@Override
public void run(){
log.debug("Starting sending {} minutes watched", getType());

try(var ignored = LogContext.with(miner)){
var dropsOnly = shouldWatchDropsOnly();
var toSendMinutesWatched = miner.getStreamers().stream()
.filter(Streamer::isStreaming)
.filter(streamer -> !streamer.isChatBanned())
.filter(this::checkStreamer)
.map(streamer -> Map.entry(streamer, streamer.getScore(miner)))
.map(streamer -> Map.entry(streamer, streamer.getScore(miner, !dropsOnly)))
.sorted(this::compare)
.limit(2)
.limit(dropsOnly ? 1 : 2)
.map(Map.Entry::getKey)
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ protected boolean send(@NotNull Streamer streamer){
protected boolean shouldUpdateWatchedMinutes(){
return true;
}

@Override
protected boolean shouldWatchDropsOnly(){
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import fr.rakambda.channelpointsminer.miner.factory.TimeFactory;
import fr.rakambda.channelpointsminer.miner.log.LogContext;
import fr.rakambda.channelpointsminer.miner.miner.IMiner;
import fr.rakambda.channelpointsminer.miner.priority.DropsPriority;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -109,9 +110,10 @@ public boolean needUpdate(){
return TimeFactory.now().isAfter(lastUpdated.plus(5, MINUTES));
}

public int getScore(@NotNull IMiner miner){
public int getScore(@NotNull IMiner miner, boolean ignoreDropsPriority){
try(var ignored = LogContext.with(miner).withStreamer(this)){
var score = settings.getPriorities().stream()
.filter(priority -> ignoreDropsPriority != (priority instanceof DropsPriority))
.mapToInt(p -> {
var s = p.getScore(miner, this);
if(s != 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.time.Instant;
import java.util.LinkedList;
Expand Down Expand Up @@ -208,25 +207,23 @@ void sendingMinutesWatchedBestScores() throws MalformedURLException{

var s1 = mock(Streamer.class);
when(s1.isStreaming()).thenReturn(true);
when(s1.getScore(miner)).thenReturn(10);
when(s1.getScore(miner, true)).thenReturn(10);

var spade2 = new URL("https://spade2");
var s2 = mock(Streamer.class);
when(s2.getId()).thenReturn("s2");
when(s2.getUsername()).thenReturn("sn2");
when(s2.isStreaming()).thenReturn(true);
when(s2.getScore(miner)).thenReturn(100);
when(s2.getScore(miner, true)).thenReturn(100);

var s3 = mock(Streamer.class);
when(s3.isStreaming()).thenReturn(true);
when(s3.getScore(miner)).thenReturn(20);
when(s3.getScore(miner, true)).thenReturn(20);

var spade4 = new URL("https://spade4");
var s4 = mock(Streamer.class);
when(s4.getId()).thenReturn("s4");
when(s4.getUsername()).thenReturn("sn4");
when(s4.isStreaming()).thenReturn(true);
when(s4.getScore(miner)).thenReturn(50);
when(s4.getScore(miner, true)).thenReturn(50);

when(miner.getStreamers()).thenReturn(List.of(s1, s2, s3, s4));

Expand All @@ -240,29 +237,27 @@ void sendingMinutesWatchedBestScoresEqualsPicksIndex() throws MalformedURLExcept

var s1 = mock(Streamer.class);
when(s1.isStreaming()).thenReturn(true);
when(s1.getScore(miner)).thenReturn(10);
when(s1.getScore(miner, true)).thenReturn(10);
when(s1.getIndex()).thenReturn(1);

var spade2 = new URL("https://spade2");
var s2 = mock(Streamer.class);
when(s2.getId()).thenReturn("s2");
when(s2.getUsername()).thenReturn("sn2");
when(s2.isStreaming()).thenReturn(true);
when(s2.getIndex()).thenReturn(0);
when(s2.getScore(miner)).thenReturn(10);
when(s2.getScore(miner, true)).thenReturn(10);

var s3 = mock(Streamer.class);
when(s3.isStreaming()).thenReturn(true);
when(s3.getScore(miner)).thenReturn(10);
when(s3.getScore(miner, true)).thenReturn(10);
when(s3.getIndex()).thenReturn(25);

var spade4 = new URL("https://spade4");
var s4 = mock(Streamer.class);
when(s4.getId()).thenReturn("s4");
when(s4.getUsername()).thenReturn("sn4");
when(s4.isStreaming()).thenReturn(true);
when(s4.getIndex()).thenReturn(-5);
when(s4.getScore(miner)).thenReturn(10);
when(s4.getScore(miner, true)).thenReturn(10);

when(miner.getStreamers()).thenReturn(List.of(s1, s2, s3, s4));

Expand Down Expand Up @@ -310,5 +305,10 @@ protected boolean send(Streamer streamer){
protected boolean shouldUpdateWatchedMinutes(){
return true;
}

@Override
protected boolean shouldWatchDropsOnly(){
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void doesNotFollowRaid(){
@Test
void getScoreNoPriorities(){
when(settings.getPriorities()).thenReturn(List.of());
assertThat(tested.getScore(miner)).isEqualTo(0);
assertThat(tested.getScore(miner, true)).isEqualTo(0);
}

@Test
Expand All @@ -431,7 +431,7 @@ void getScoreSumsScores(){
when(p2.getScore(miner, tested)).thenReturn(s2);

when(settings.getPriorities()).thenReturn(List.of(p1, p2));
assertThat(tested.getScore(miner)).isEqualTo(s1 + s2);
assertThat(tested.getScore(miner, true)).isEqualTo(s1 + s2);
}

@ParameterizedTest
Expand Down

0 comments on commit c92a3bf

Please sign in to comment.