Skip to content

Commit

Permalink
chore: Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaancayli committed Dec 1, 2024
1 parent 8054be4 commit 526d2bc
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public interface SubmissionRepository extends ArtemisJpaRepository<Submission, L
List<Submission> findAllWithResultsAndAssessorByParticipationId(Long participationId);

/**
* Get all submissions of a participation and eagerly load results and assessor ordered by submission date in ascending order
* Get all submissions of a participation and eagerly load results ordered by submission date in ascending order
*
* @param participationId the id of the participation
* @return a list of the participation's submissions
*/
@EntityGraph(type = LOAD, attributePaths = { "results", "results.assessor" })
List<Submission> findAllWithResultsAndAssessorByParticipationIdOrderBySubmissionDateAsc(Long participationId);
@EntityGraph(type = LOAD, attributePaths = { "results" })
List<Submission> findAllWithResultsByParticipationIdOrderBySubmissionDateAsc(Long participationId);

/**
* Get all submissions with their results by the submission ids
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.cit.aet.artemis.iris.service.pyris;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_IRIS;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
Expand All @@ -17,7 +19,7 @@
* Service to handle Pyris events.
*/
@Service
@Profile("iris")
@Profile(PROFILE_IRIS)
public class PyrisEventService {

private static final Logger log = LoggerFactory.getLogger(PyrisEventService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ private <T, U> void executeCourseChatPipeline(String variant, IrisCourseChatSess
executionDto.initialStages()
);
},
stages -> irisChatWebsocketService.sendStatusUpdate(session, stages));
stages -> irisChatWebsocketService.sendStatusUpdate(session, stages)
);
// @formatter:on
}

Expand Down Expand Up @@ -307,9 +308,9 @@ private <T, U> PyrisEventDTO<U> generateEventPayloadFromObjectType(Class<U> dtoC
*
* @param dtoClass the class of the DTO
* @param object the object to generate the DTO from
* @param <T> the type of the object
* @param <U> the type of the DTO
* @return Method the 'of' method
* @param <T> the type of the object
* @param <U> the type of the DTO
*/
private static <T, U> Method getOfMethod(Class<U> dtoClass, T object) {
Method ofMethod = null;
Expand All @@ -318,11 +319,9 @@ private static <T, U> Method getOfMethod(Class<U> dtoClass, T object) {
// Traverse up the class hierarchy
while (currentClass != null && ofMethod == null) {
for (Method method : dtoClass.getMethods()) {
if (method.getName().equals("of") && method.getParameterCount() == 1) {
if (method.getParameters()[0].getType().isAssignableFrom(currentClass)) {
ofMethod = method;
break;
}
if (method.getName().equals("of") && method.getParameterCount() == 1 && method.getParameters()[0].getType().isAssignableFrom(currentClass)) {
ofMethod = method;
break;
}
}
currentClass = currentClass.getSuperclass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public class IrisExerciseChatSessionService extends AbstractIrisChatSessionServi

private final SubmissionRepository submissionRepository;

private final double SUCCESS_THRESHOLD = 100.0; // TODO: Retrieve configuration from Iris settings

private final int INTERVAL_SIZE = 3; // TODO: Retrieve configuration from Iris settings

public IrisExerciseChatSessionService(IrisMessageService irisMessageService, LLMTokenUsageService llmTokenUsageService, IrisSettingsService irisSettingsService,
IrisChatWebsocketService irisChatWebsocketService, AuthorizationCheckService authCheckService, IrisSessionRepository irisSessionRepository,
ProgrammingExerciseStudentParticipationRepository programmingExerciseStudentParticipationRepository, ProgrammingSubmissionRepository programmingSubmissionRepository,
Expand Down Expand Up @@ -221,16 +217,18 @@ public void onNewResult(Result result) {

irisSettingsService.isActivatedForElseThrow(IrisEventType.PROGRESS_STALLED, exercise);

var recentSubmissions = submissionRepository.findAllWithResultsAndAssessorByParticipationIdOrderBySubmissionDateAsc(studentParticipation.getId());
var recentSubmissions = submissionRepository.findAllWithResultsByParticipationIdOrderBySubmissionDateAsc(studentParticipation.getId());

double successThreshold = 100.0; // TODO: Retrieve configuration from Iris settings

// Check if the user has already successfully submitted before
var successfulSubmission = recentSubmissions.stream()
.anyMatch(submission -> submission.getLatestResult() != null && submission.getLatestResult().getScore() == SUCCESS_THRESHOLD);
.anyMatch(submission -> submission.getLatestResult() != null && submission.getLatestResult().getScore() == successThreshold);
if (!successfulSubmission && recentSubmissions.size() >= 3) {
var listOfScores = recentSubmissions.stream().map(Submission::getLatestResult).filter(Objects::nonNull).map(Result::getScore).toList();

// Check if the student needs intervention based on their recent score trajectory
var needsIntervention = needsIntervention(listOfScores, INTERVAL_SIZE);
var needsIntervention = needsIntervention(listOfScores);
if (needsIntervention) {
log.info("Scores in the last 3 submissions did not improve for user {}", studentParticipation.getParticipant().getName());
var participant = ((ProgrammingExerciseStudentParticipation) participation).getParticipant();
Expand Down Expand Up @@ -280,11 +278,11 @@ private boolean hasOverallImprovement(List<Double> scores, int i, int j) {
/**
* Checks if the student needs intervention based on their recent score trajectory.
*
* @param scores The list of all scores for the student.
* @param intervalSize The number of recent submissions to consider.
* @param scores The list of all scores for the student.
* @return true if intervention is needed, false otherwise.
*/
private boolean needsIntervention(List<Double> scores, int intervalSize) {
private boolean needsIntervention(List<Double> scores) {
int intervalSize = 3; // TODO: Retrieve configuration from Iris settings
if (scores.size() < intervalSize) {
return false; // Not enough data to make a decision
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class IrisExerciseChatbotButtonComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
// Subscribes to route params and gets the exerciseId from the router
// Subscribes to route params and gets the exerciseId from the route
this.paramsSubscription = this.route.params.subscribe((params) => {
const exerciseId = parseInt(params['exerciseId'], 10);
this.chatService.switchTo(this.mode, exerciseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ <h4 class="form-label mt-3" jhiTranslate="artemisApp.iris.settings.subSettings.e
(ngModelChange)="onEventToggleChange(event)"
/>
<label class="form-check-label" for="{{ event }}" [jhiTranslate]="eventTranslationKeys[event]"></label>
@if (
this.parentSubSettings &&
!subSettings?.disabledProactiveEvents?.includes(event) &&
(this.parentSubSettings.disabledProactiveEvents?.includes(event) || !this.parentSubSettings.enabled)
) {
@if (eventInParentDisabledStatusMap.get(event)) {
<fa-icon
class="text-warning"
[icon]="faCircleExclamation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class IrisCommonSubSettingsUpdateComponent implements OnInit, OnChanges {

inheritAllowedVariants: boolean;

eventInParentDisabledStatusMap = new Map<IrisEventType, boolean | undefined>();

availableVariants: IrisVariant[] = [];

allowedVariants: IrisVariant[] = [];
Expand Down Expand Up @@ -90,6 +92,9 @@ export class IrisCommonSubSettingsUpdateComponent implements OnInit, OnChanges {
if (changes.subSettings) {
this.enabled = this.subSettings?.enabled ?? false;
}
if (changes.parentSubSettings || changes.subSettings) {
this.updateEventDisabledStatus();
}
}

loadCategories() {
Expand Down Expand Up @@ -206,4 +211,19 @@ export class IrisCommonSubSettingsUpdateComponent implements OnInit, OnChanges {
get isSettingsSwitchDisabled() {
return this.inheritDisabled || (!this.isAdmin && this.settingsType !== this.EXERCISE);
}

/**
* Updates the event disabled status map based on the parent settings
* @private
*/
private updateEventDisabledStatus(): void {
this.exerciseChatEvents.forEach((event) => {
const isDisabled =
!this.subSettings?.enabled ||
(this.parentSubSettings &&
!this.subSettings?.disabledProactiveEvents?.includes(event) &&
(this.parentSubSettings.disabledProactiveEvents?.includes(event) || !this.parentSubSettings.enabled));
this.eventInParentDisabledStatusMap.set(event, isDisabled);
});
}
}
4 changes: 2 additions & 2 deletions src/main/webapp/i18n/de/iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
},
"proactivitySettings": {
"title": "Proaktivitätseinstellungen",
"tooltip": "Wenn eine der unten aufgeführten Optionen aktiviert ist, wird Iris basierend auf den ausgewählten Bedingungen proaktiv Hilfe-Nachrichten an Studenten senden.",
"parentDisabled": "Iris wird keine proaktiven Nachrichten für diese Option senden, da entweder dieselbe Option oder Iris in den übergeordneten Einstellungen deaktiviert ist."
"tooltip": "Aktiviere die untenstehenden Optionen, damit Iris proaktiv Studierende kontaktiert, wenn bestimmte Bedingungen erfüllt sind.",
"parentDisabled": "Iris sendet keine proaktiven Nachrichten für diese Option, da entweder die Option selbst oder Iris in den aktuellen oder übergeordneten Einstellungen deaktiviert sind."
},
"enabled-disabled": "Aktiviert/Deaktiviert",
"enabledForCategories": "Automatisch aktivieren für Kategorien",
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/i18n/en/iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
},
"proactivitySettings": {
"title": "Proactivity Settings",
"tooltip": "When any of options listed below are activated, Iris will proactively send help messages to students based on the selected conditions.",
"parentDisabled": "Iris won't send proactive messages for this option because either the same option or the Iris is disabled in the parent settings."
"tooltip": "Enable options below to allow Iris to proactively reach out to students when specific conditions are met.",
"parentDisabled": "Iris won't send proactive messages for this option because either option itself or Iris are disabled in the current or parent settings."
},
"enabled-disabled": "Enabled/Disabled",
"enabledForCategories": "Automatically enable for categories",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
import de.tum.cit.aet.artemis.programming.domain.TemplateProgrammingExerciseParticipation;
import de.tum.cit.aet.artemis.programming.util.ProgrammingExerciseUtilService;

class PyrisEventSystemTest extends AbstractIrisIntegrationTest {
class PyrisEventSystemIntegrationTest extends AbstractIrisIntegrationTest {

private static final String TEST_PREFIX = "pyriseventsystemtest";
private static final String TEST_PREFIX = "pyriseventsystemintegration";

@Autowired
protected PyrisStatusUpdateService pyrisStatusUpdateService;
Expand Down

0 comments on commit 526d2bc

Please sign in to comment.