-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2c6c7b0
commit ea788eb
Showing
7 changed files
with
226 additions
and
42 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/backend/Eyesee/src/main/java/com/fortune/eyesee/dto/CheatingStatistic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.fortune.eyesee.dto; | ||
|
||
import lombok.Data; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Data | ||
public class CheatingStatistic { | ||
private Integer cheatingStatisticsId; | ||
private String koreanTypeName; | ||
private Integer cheatingCount; | ||
private String detectedTime; | ||
|
||
// 생성자 | ||
public CheatingStatistic(Integer cheatingStatisticsId, String koreanTypeName, Integer cheatingCount, String detectedTime) { | ||
this.cheatingStatisticsId = cheatingStatisticsId; | ||
this.koreanTypeName = koreanTypeName; | ||
this.cheatingCount = cheatingCount; | ||
this.detectedTime = detectedTime; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/backend/Eyesee/src/main/java/com/fortune/eyesee/enums/CheatingTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fortune.eyesee.enums; | ||
|
||
public enum CheatingTypeEnum { | ||
LOOK_AROUND("look_around", "주변 응시"), | ||
REPEATED_GAZE("repeated_gaze", "반복된 응시"), | ||
OBJECT("object", "부정행위 물체 감지"), | ||
FACE_ABSENCE_LONG("face_absence_long", "장기 화면 이탈"), | ||
FACE_ABSENCE_REPEAT("face_absence_repeat", "반복 화면 이탈"), | ||
HAND_GESTURE("hand_gesture", "특정 손동작 반복"), | ||
HEAD_TURN_LONG("head_turn_long", "고개 돌림 유지"), | ||
HEAD_TURN_REPEAT("head_turn_repeat", "고개 돌림 반복"); | ||
|
||
private final String englishName; | ||
private final String koreanName; | ||
|
||
CheatingTypeEnum(String englishName, String koreanName) { | ||
this.englishName = englishName; | ||
this.koreanName = koreanName; | ||
} | ||
|
||
public String getEnglishName() { | ||
return englishName; | ||
} | ||
|
||
public String getKoreanName() { | ||
return koreanName; | ||
} | ||
|
||
public static String getKoreanNameByEnglish(String englishName) { | ||
for (CheatingTypeEnum type : values()) { | ||
if (type.getEnglishName().equalsIgnoreCase(englishName)) { // 대소문자 무시 비교 | ||
return type.getKoreanName(); | ||
} | ||
} | ||
return "알 수 없음"; | ||
} | ||
} |
26 changes: 25 additions & 1 deletion
26
...kend/Eyesee/src/main/java/com/fortune/eyesee/repository/CheatingStatisticsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,40 @@ | ||
package com.fortune.eyesee.repository; | ||
|
||
|
||
import com.fortune.eyesee.dto.CheatingStatistic; | ||
import com.fortune.eyesee.dto.UserDetailResponseDTO; | ||
import com.fortune.eyesee.entity.CheatingStatistics; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface CheatingStatisticsRepository extends JpaRepository<CheatingStatistics, Integer> { | ||
List<CheatingStatistics> findByUserId(Integer userId); | ||
int countByUserId(Integer userId); | ||
|
||
//int countByUserId(Integer userId); | ||
// 특정 userId와 cheatingTypeId에 대한 통계 정보를 조회 | ||
CheatingStatistics findByUserIdAndCheatingTypeId(Integer userId, Integer cheatingTypeId); | ||
|
||
@Query(""" | ||
SELECT new com.fortune.eyesee.dto.CheatingStatistic( | ||
cs.cheatingStatisticsId, | ||
ct.koreanTypeName, | ||
cs.cheatingCount, | ||
CAST(dc.detectedTime AS string) | ||
) | ||
FROM CheatingStatistics cs | ||
JOIN CheatingType ct ON cs.cheatingTypeId = ct.cheatingTypeId | ||
LEFT JOIN DetectedCheating dc ON cs.userId = dc.userId AND cs.cheatingTypeId = dc.cheatingTypeId | ||
WHERE cs.userId = :userId | ||
ORDER BY CAST(dc.detectedTime AS string) ASC | ||
""") | ||
List<CheatingStatistic> findStatisticsByUserId(@Param("userId") Integer userId); | ||
|
||
// 특정 사용자 ID의 부정행위 횟수를 합산 | ||
@Query("SELECT SUM(cs.cheatingCount) FROM CheatingStatistics cs WHERE cs.userId = :userId") | ||
Integer findTotalCheatingCountByUserId(@Param("userId") Integer userId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/backend/Eyesee/src/main/java/com/fortune/eyesee/utils/CheatingTypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.fortune.eyesee.utils; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
import java.util.List; | ||
|
||
@Converter | ||
public class CheatingTypeConverter implements AttributeConverter<List<String>, String> { | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(List<String> attribute) { | ||
try { | ||
return objectMapper.writeValueAsString(attribute); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Could not convert list to JSON string: " + attribute, e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> convertToEntityAttribute(String dbData) { | ||
try { | ||
return objectMapper.readValue(dbData, new TypeReference<List<String>>() {}); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not convert JSON string to list", e); | ||
} | ||
} | ||
} |