RingData.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { CurrentDot, RealRing, RingCommon, TargetRing } from "@/components/view/Rings"
  2. import { ColorType } from "@/context/themes/color";
  3. const startArc = (time: number) => {
  4. var date = new Date(time);
  5. var hour = date.getHours();
  6. var minute = date.getMinutes();
  7. var second = date.getSeconds();
  8. return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
  9. }
  10. const durationArc = (start_time: number, end_time: number) => {
  11. var duration = (end_time - start_time) / 1000;
  12. return duration / (24 * 3600) * 2 * Math.PI;
  13. }
  14. export const haveSmallRing = (data: any) => {
  15. if (data.scenario == 'FAST_SLEEP')
  16. return true
  17. return false
  18. }
  19. export const getCommon = (data: any, isBigRing: boolean) => {
  20. const commonBig: RingCommon = {
  21. useCase: 'Record',
  22. radius: 50,
  23. lineWidth: 8,
  24. isFast: true,
  25. status: 'WAIT_FOR_START'
  26. }
  27. const commonSmall: RingCommon = {
  28. useCase: 'Record',
  29. radius: 40,
  30. lineWidth: 8,
  31. isFast: true,
  32. status: 'WAIT_FOR_START'
  33. }
  34. if (isBigRing) {
  35. return commonBig
  36. }
  37. return commonSmall
  38. }
  39. export const getBgRing = () => {
  40. return {
  41. color: ColorType.ring
  42. }
  43. }
  44. export const getDot = (data: any, isBigRing: boolean) => {
  45. const currentDotBig: CurrentDot = {
  46. color: global.fastColor ? global.fastColor : ColorType.fast,
  47. lineWidth: 8,
  48. borderColor: 'black'
  49. }
  50. const currentDotSmall: CurrentDot = {
  51. color: global.sleepColor?global.sleepColor:ColorType.sleep,
  52. lineWidth: 8,
  53. borderColor: 'black'
  54. }
  55. if (isBigRing) {
  56. if (data && data.scenario == 'SLEEP') {
  57. currentDotBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
  58. }
  59. return currentDotBig
  60. }
  61. else {
  62. return currentDotSmall
  63. }
  64. }
  65. export const getTarget = (data: any, isBigRing: boolean) => {
  66. const targetRingBig: TargetRing = {
  67. color: '#FF0000',
  68. startArc: 0,
  69. durationArc: 0
  70. }
  71. const targetRingSmall: TargetRing = {
  72. color: '#FF0000',
  73. startArc: 0,
  74. durationArc: 0
  75. }
  76. if (isBigRing) {
  77. if (data.scenario == 'SLEEP') {
  78. targetRingBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
  79. targetRingBig.startArc = startArc(data.sleep.target_start_time)
  80. targetRingBig.durationArc = durationArc(data.sleep.start_time, data.sleep.target_end_time)
  81. }
  82. else {
  83. targetRingBig.startArc = startArc(data.fast.target_start_time)
  84. targetRingBig.durationArc = durationArc(data.fast.target_start_time, data.fast.target_end_time)
  85. }
  86. return targetRingBig
  87. }
  88. else {
  89. targetRingSmall.startArc = startArc(data.sleep.target_start_time)
  90. targetRingSmall.durationArc = durationArc(data.sleep.target_start_time, data.sleep.target_end_time)
  91. return targetRingSmall
  92. }
  93. }
  94. export const getReal = (data: any, isBigRing: boolean, isRecord: boolean) => {
  95. const realRingBig: RealRing = {
  96. color: global.fastColor ? global.fastColor : ColorType.fast,
  97. startArc: 0,
  98. durationArc: 0
  99. }
  100. const realRingSmall: RealRing = {
  101. color: global.sleepColor?global.sleepColor:ColorType.sleep,
  102. startArc: 0,
  103. durationArc: 0
  104. }
  105. if (isBigRing) {
  106. if (data.scenario == 'SLEEP') {
  107. realRingBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
  108. realRingBig.startArc = startArc(data.sleep.real_start_time)
  109. realRingBig.durationArc = durationArc(data.sleep.real_start_time, isRecord ? (data.sleep.real_end_time ? data.sleep.real_end_time : new Date().getTime()) : new Date().getTime())
  110. }
  111. else {
  112. realRingBig.startArc = startArc(data.fast.real_start_time)
  113. realRingBig.durationArc = durationArc(data.fast.real_start_time, isRecord ? (data.fast.real_end_time ? data.fast.real_end_time : new Date().getTime()) : new Date().getTime())
  114. }
  115. return realRingBig
  116. }
  117. else {
  118. realRingSmall.startArc = startArc(data.sleep.real_start_time)
  119. realRingSmall.durationArc = durationArc(data.sleep.real_start_time, isRecord ? (data.sleep.real_end_time ? data.sleep.real_end_time : new Date().getTime()) : new Date().getTime())
  120. // if (isRecord && !isBigRing){
  121. // debugger
  122. // }
  123. return realRingSmall
  124. }
  125. }