Skip to content

Commit

Permalink
Merge pull request #89 from BbeumbungE/feat/BACK-341
Browse files Browse the repository at this point in the history
fix: SSE 및 그림 변환하기 로깅 처리 [BACK-341]
  • Loading branch information
Fishphobiagg authored Oct 5, 2023
2 parents 4c7b621 + 9c80a16 commit 466ee85
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.siliconvalley.domain.sse.application.CanvasSseEmitterService;
import com.siliconvalley.global.common.dto.Response;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,6 +18,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/canvases")
@Slf4j
public class CanvasController {

private final CanvasConvertService canvasConvertService;
Expand All @@ -29,6 +31,7 @@ public ResponseEntity<Response> convertSketchToCanvas(
@RequestParam Long profileId,
@RequestParam Long subjectId
) throws IOException {
log.info(profileId + "번 프로필의 " + subjectId + "번 주제에 대한 최초 변환 요청");
String sketch = s3ImageUploadService.uploadFile(sketchFile, s3PathBuildService.buildPath(profileId, "sketch"));
Response response = canvasConvertService.convertSketchToCanvas(profileId, subjectId, sketch);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
Expand All @@ -40,6 +43,7 @@ public ResponseEntity<Response> updateSketchAndCanvas(
@RequestParam Long profileId,
@PathVariable Long canvasId
) throws IOException {
log.info(profileId + "번 프로필의 " + canvasId + "번 그림에 대한 변환 요청");
String sketch = s3ImageUploadService.uploadFile(sketchFile, s3PathBuildService.buildPath(profileId, "sketch"));
Response response = canvasConvertService.updateSketchAndCanvas(profileId, canvasId, sketch);
return ResponseEntity.status(HttpStatus.OK).body(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void updateConvertedData(SketchConversionResponse response){
canvas.updateCanvas(response.getCanvasUrl());
Long profileId = canvas.getProfile().getId();
ConvertEventDto convertEventDto = new ConvertEventDto(canvas.getId(), response.getCanvasUrl());
log.info(canvas.getId() + "번 그림에 대한 변환 처리 완료 및 SSE로 메시지 전송");
convertResultSender.send(canvasSseEmitterFinder.findByProfileId(profileId), convertEventDto, profileId, "drawing");
}
public void sendConvertedDemoCanvas(DemoConversionResponse response){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public ResponseEntity<Response> scoreTest(
return ResponseEntity.ok(Response.of(CommonCode.GOOD_REQUEST, visionDetectingService.calculateCanvasScore(canvasId).getScoreValue()));
}

@GetMapping("/score")
public ResponseEntity<Response> scoreTest2(
@RequestParam String filePath,
@RequestParam String visionName
){
return ResponseEntity.ok(Response.of(CommonCode.GOOD_REQUEST, visionDetectingService.calculateCanvasScore(filePath, visionName).getScoreValue()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public Score calculateCanvasScore(Long canvasId) {
return Score.determineScore(detectionScore);
}

public Score calculateCanvasScore(String filePath, String visionName) {
Map<String, Float> detectResult = visionService.detectLabels(filePath);
log.info(detectResult.size() + "개");
if (detectResult.size() == 0 || detectResult.containsKey("Error")) {return Score.LOW;}
log.info(detectResult + "점");
Float detectionScore = detectResult.get(visionName);

return Score.determineScore(detectionScore);
}


public Response testLabelDetecting(Long canvasId){
Canvas canvas = canvasFindDao.findById(canvasId);
List<LabelResultDto> results = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.siliconvalley.domain.sse.repository.CanvasSseEmitterRepository;
import com.siliconvalley.domain.sse.repository.DemoCanvasSseEmitterRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@Service
@Slf4j
@RequiredArgsConstructor
public class CanvasSseEmitterService {

Expand All @@ -21,7 +23,7 @@ public SseEmitter connect(Long profileId) {
canvasSseEmitterRepository.delete(profileId);
}
SseEmitter sseEmitter = canvasSseEmitterCreater.createEmitter(profileId);

log.info(profileId + "번 유저 SSE 연결 완료");
return sseEmitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.siliconvalley.domain.sse.repository.CanvasSseEmitterRepository;
import com.siliconvalley.domain.sse.repository.DemoCanvasSseEmitterRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;

@Component
@RequiredArgsConstructor
@Slf4j
public class ConvertResultSender {

private final CanvasSseEmitterRepository canvasSseEmitterRepository;
Expand All @@ -21,7 +23,9 @@ public void send(SseEmitter sseEmitter, Object data, Long profileId, String even
.name(eventName)
.data(data)
.reconnectTime(0L)); // 재연결 시도
log.info(profileId + "번 프로필 SSE 전송 성공");
} catch (IOException exception) {
log.info("에러 발생, SSE 삭제");
canvasSseEmitterRepository.delete(profileId);
throw new RuntimeException("SSE Connect Fail");
}
Expand Down

0 comments on commit 466ee85

Please sign in to comment.