You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.7KB

  1. package fr.slixe.benchmarks.http.controller;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import com.google.gson.Gson;
  5. import com.google.inject.Inject;
  6. import fr.litarvan.paladin.http.Controller;
  7. import fr.litarvan.paladin.http.routing.JsonBody
  8. import fr.litarvan.paladin.http.routing.RequestParams;
  9. import fr.slixe.benchmarks.Benchmark;
  10. import fr.slixe.benchmarks.Benchmark.Vendor
  11. import fr.slixe.benchmarks.service.BenchmarkService;
  12. public class MainController extends Controller {
  13. private static final Logger log = LoggerFactory.getLogger("DERO HTTP Controller")
  14. @Inject
  15. private BenchmarkService benchmarkService
  16. @Inject
  17. private Gson gson
  18. /**
  19. * accessible from: api/benchmarks
  20. * @return all confirmed benchmarks
  21. */
  22. def benchmarks()
  23. {
  24. log.debug("Benchmarks requested")
  25. return benchmarkService.getBenchmarks()
  26. }
  27. def unconfirmedBenchmarks()
  28. {
  29. log.debug("Unconfirmed Benchmarks requested")
  30. return benchmarkService.getUnconfirmedBenchmarks()
  31. }
  32. /** Submit a benchmark
  33. * @param Vendor vendor (AMD/INTEL/NVIDIA)
  34. * @param String model (Ryzen 5 3600X)
  35. * @param long hashrate (in h/s)
  36. * @param watts 75
  37. * @param String minerVersion (XMRig 5.9.0)
  38. * @param String owner (Slixe)
  39. */
  40. @JsonBody
  41. @RequestParams(required = ["vendor", "model", "memory", "hashrate", "watts", "minerVersion", "owner"])
  42. def submit(Vendor vendor, String model, String memory, long hashrate, int watts, String minerVersion, String owner)
  43. {
  44. log.debug("A new benchmark has been submitted!")
  45. Benchmark benchmark = new Benchmark(benchmarkService.lastUnconfirmedBenchId(), vendor, model, memory, hashrate, watts, minerVersion, owner, System.currentTimeMillis())
  46. benchmarkService.addUnconfirmedBenchmarks(benchmark)
  47. [
  48. success: true,
  49. message: "Your benchmark has been submitted! It will be reviewed soon. Thanks.",
  50. result: null
  51. ]
  52. }
  53. /** Confirm a submitted benchmark.
  54. * accessible from: api/confirm
  55. * @param int benchID
  56. */
  57. @JsonBody
  58. @RequestParams(required = ["benchID"])
  59. def confirm(int benchID)
  60. {
  61. log.debug("Confirmation of Benchmark $benchID")
  62. def result = benchmarkService.confirmBenchmark(benchID)
  63. [
  64. success: result,
  65. message: result ? "The benchmark $benchID is now confirmed!" : "The benchmark $benchID was not found!",
  66. result: null
  67. ]
  68. }
  69. /** Delete a benchmark using the unique ID.
  70. * accessible from: api/delete
  71. * @param int benchID
  72. */
  73. @JsonBody
  74. @RequestParams(required = ["benchID"])
  75. def delete(int benchID)
  76. {
  77. log.debug("Removing Benchmark $benchID")
  78. def result = benchmarkService.removeBenchmark(benchID)
  79. [
  80. success: result,
  81. message: result ? "The benchmark $benchID has been removed!" : "Benchmark $benchID not found!",
  82. result: null
  83. ]
  84. }
  85. }