35 lines
1.3 KiB
Java
35 lines
1.3 KiB
Java
package de.ph87.data.series.graph;
|
|
|
|
import de.ph87.data.series.*;
|
|
import jakarta.servlet.http.*;
|
|
import lombok.*;
|
|
import lombok.extern.slf4j.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.imageio.*;
|
|
import java.awt.image.*;
|
|
import java.io.*;
|
|
import java.time.*;
|
|
|
|
@Slf4j
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("Series/Graph")
|
|
public class GraphController {
|
|
|
|
private final GraphService graphService;
|
|
|
|
@GetMapping(path = "{seriesId}/{width}/{height}/{alignmentName}/{offset}/{duration}", produces = "image/png")
|
|
public void graph(@PathVariable final long seriesId, final HttpServletResponse response, @PathVariable final int width, @PathVariable final int height, @PathVariable final String alignmentName, @PathVariable final long offset, @PathVariable final long duration) throws IOException {
|
|
final Alignment alignment = Alignment.valueOf(alignmentName);
|
|
final Aligned end = alignment.align(ZonedDateTime.now()).minus(offset);
|
|
final Aligned begin = end.minus(duration - 1);
|
|
final Graph graph = graphService.getGraph(seriesId, begin, end, width, height, 10);
|
|
final BufferedImage image = graph.draw();
|
|
response.setContentType("image/png");
|
|
ImageIO.write(image, "PNG", response.getOutputStream());
|
|
response.getOutputStream().flush();
|
|
}
|
|
|
|
}
|