vibration.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. {% extends "index.html" %}
  2. {% block title %}振動監控{% endblock %}
  3. {% block head %}
  4. {{ super() }}
  5. {% endblock %}
  6. {% block body %}
  7. <div id="headlth_indicator">
  8. <div id="curr_health" style="width: 300px;height:300px;float:right"></div>
  9. <div id="pred_health" style="width: 300px;height:300px;float:right"></div>
  10. </div>
  11. <div id="history_record" style="width: 600px;height:600px;float:right"></div>
  12. <script>
  13. var curr_health = echarts.init(document.getElementById("curr_health"));
  14. var pred_health = echarts.init(document.getElementById("pred_health"));
  15. var history_record = echarts.init(document.getElementById("history_record"));
  16. let date = transform_time_to_string(new Date());
  17. fetch(`/health?date=${date}`)
  18. .then(function(response) {
  19. return response.json();
  20. })
  21. .then(function(myJson) {
  22. console.log(myJson);
  23. option = {
  24. series: [{
  25. type: 'gauge',
  26. startAngle: 180,
  27. endAngle: 0,
  28. min: 0,
  29. max: 1,
  30. splitNumber: 8,
  31. axisLine: {
  32. lineStyle: {
  33. width: 6,
  34. color: [
  35. [0.25, '#FF6E76'],
  36. [0.5, '#FDDD60'],
  37. // [0.75, '#58D9F9'],
  38. [1, '#7CFFB2']
  39. ]
  40. }
  41. },
  42. pointer: {
  43. icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
  44. length: '70%',
  45. width: 5,
  46. offsetCenter: [0, '-60%'],
  47. itemStyle: {
  48. color: 'auto'
  49. }
  50. },
  51. axisTick: {
  52. length: 12,
  53. lineStyle: {
  54. color: 'auto',
  55. width: 2
  56. }
  57. },
  58. splitLine: {
  59. length: 20,
  60. lineStyle: {
  61. color: 'auto',
  62. width: 5
  63. }
  64. },
  65. axisLabel: {
  66. color: '#464646',
  67. fontSize: 20,
  68. distance: -60,
  69. formatter: function (value) {
  70. if (value === 1) {
  71. return '100';
  72. }
  73. // else if (value === 0.625) {
  74. // return '中';
  75. // }
  76. else if (value === 0.5) {
  77. return '50';
  78. }
  79. else if (value === 0.3) {
  80. return '30';
  81. }
  82. }
  83. },
  84. title: {
  85. offsetCenter: [0, '-20%'],
  86. fontSize: 30
  87. },
  88. detail: {
  89. fontSize: 15,
  90. offsetCenter: [0, '+20%'],
  91. valueAnimation: true,
  92. formatter: function (value) {
  93. return '目前健康指標: ' + Math.round(value * 100) + '分';
  94. // return '目前健康指標'
  95. },
  96. color: 'auto'
  97. },
  98. data: [{
  99. value: myJson['curr_health'],
  100. name: ''
  101. }]
  102. }]
  103. };
  104. pred_health.setOption(option);
  105. option = {
  106. series: [{
  107. type: 'gauge',
  108. startAngle: 180,
  109. endAngle: 0,
  110. min: 0,
  111. max: 1,
  112. splitNumber: 8,
  113. axisLine: {
  114. lineStyle: {
  115. width: 6,
  116. color: [
  117. [0.25, '#FF6E76'],
  118. [0.5, '#FDDD60'],
  119. // [0.75, '#58D9F9'],
  120. [1, '#7CFFB2']
  121. ]
  122. }
  123. },
  124. pointer: {
  125. icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
  126. length: '70%',
  127. width: 5,
  128. offsetCenter: [0, '-60%'],
  129. itemStyle: {
  130. color: 'auto'
  131. }
  132. },
  133. axisTick: {
  134. length: 12,
  135. lineStyle: {
  136. color: 'auto',
  137. width: 2
  138. }
  139. },
  140. splitLine: {
  141. length: 20,
  142. lineStyle: {
  143. color: 'auto',
  144. width: 5
  145. }
  146. },
  147. axisLabel: {
  148. color: '#464646',
  149. fontSize: 20,
  150. distance: -60,
  151. formatter: function (value) {
  152. if (value === 1) {
  153. return '100';
  154. }
  155. // else if (value === 0.625) {
  156. // return '中';
  157. // }
  158. else if (value === 0.5) {
  159. return '50';
  160. }
  161. else if (value === 0.3) {
  162. return '30';
  163. }
  164. }
  165. },
  166. title: {
  167. offsetCenter: [0, '-20%'],
  168. fontSize: 30
  169. },
  170. detail: {
  171. fontSize: 15,
  172. offsetCenter: [0, '20%'],
  173. valueAnimation: true,
  174. formatter: function (value) {
  175. return '預測健康指標: ' + Math.round(value * 100) + '分';
  176. // return '目前健康指標'
  177. },
  178. color: 'auto'
  179. },
  180. data: [{
  181. value: myJson['pred_health'],
  182. name: ''
  183. }]
  184. }]
  185. };
  186. curr_health.setOption(option);
  187. });
  188. fetch(`/history_data?time_end=${date}`)
  189. .then(function(response) {
  190. return response.json();
  191. })
  192. .then(function(myJson) {
  193. console.log(myJson);
  194. option = {
  195. // color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
  196. title: {
  197. text: '歷史紀錄圖表'
  198. },
  199. tooltip: {
  200. trigger: 'axis',
  201. axisPointer: {
  202. type: 'cross',
  203. label: {
  204. backgroundColor: '#6a7985'
  205. }
  206. }
  207. },
  208. legend: {
  209. data: ['RPM_1X', 'RPM_2X', 'RPM_3X', 'RPM_4X', 'RPM_5X', 'RPM_6X', 'RPM_7X', 'RPM_8X', 'Gear_1X', 'Gear_2X', 'Gear_3X','Gear_4X']
  210. },
  211. toolbox: {
  212. feature: {
  213. saveAsImage: {}
  214. }
  215. },
  216. grid: {
  217. left: '3%',
  218. right: '4%',
  219. bottom: '3%',
  220. containLabel: true
  221. },
  222. xAxis: [
  223. {
  224. type: 'category',
  225. boundaryGap: false,
  226. data: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00']
  227. }
  228. ],
  229. yAxis: [
  230. {
  231. type: 'value'
  232. }
  233. ],
  234. series: [
  235. {
  236. name: 'RPM_1X',
  237. type: 'line',
  238. stack: '总量',
  239. smooth: true,
  240. lineStyle: {
  241. width: 0
  242. },
  243. showSymbol: false,
  244. areaStyle: {
  245. opacity: 0.8,
  246. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  247. // offset: 0,
  248. // color: 'rgba(128, 255, 165)'
  249. // }, {
  250. // offset: 1,
  251. // color: 'rgba(1, 191, 236)'
  252. // }])
  253. },
  254. emphasis: {
  255. focus: 'series'
  256. },
  257. data: myJson['curr_history']['RPM_1X']
  258. },
  259. {
  260. name: 'RPM_2X',
  261. type: 'line',
  262. stack: '总量',
  263. smooth: true,
  264. lineStyle: {
  265. width: 0
  266. },
  267. showSymbol: false,
  268. areaStyle: {
  269. opacity: 0.8,
  270. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  271. // offset: 0,
  272. // color: 'rgba(128, 255, 165)'
  273. // }, {
  274. // offset: 1,
  275. // color: 'rgba(1, 191, 236)'
  276. // }])
  277. },
  278. emphasis: {
  279. focus: 'series'
  280. },
  281. data: myJson['curr_history']['RPM_2X']
  282. },
  283. {
  284. name: 'RPM_3X',
  285. type: 'line',
  286. stack: '总量',
  287. smooth: true,
  288. lineStyle: {
  289. width: 0
  290. },
  291. showSymbol: false,
  292. areaStyle: {
  293. opacity: 0.8,
  294. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  295. // offset: 0,
  296. // color: 'rgba(128, 255, 165)'
  297. // }, {
  298. // offset: 1,
  299. // color: 'rgba(1, 191, 236)'
  300. // }])
  301. },
  302. emphasis: {
  303. focus: 'series'
  304. },
  305. data: myJson['curr_history']['RPM_3X']
  306. },
  307. {
  308. name: 'RPM_4X',
  309. type: 'line',
  310. stack: '总量',
  311. smooth: true,
  312. lineStyle: {
  313. width: 0
  314. },
  315. showSymbol: false,
  316. areaStyle: {
  317. opacity: 0.8,
  318. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  319. // offset: 0,
  320. // color: 'rgba(128, 255, 165)'
  321. // }, {
  322. // offset: 1,
  323. // color: 'rgba(1, 191, 236)'
  324. // }])
  325. },
  326. emphasis: {
  327. focus: 'series'
  328. },
  329. data: myJson['curr_history']['RPM_4X']
  330. },
  331. {
  332. name: 'RPM_5X',
  333. type: 'line',
  334. stack: '总量',
  335. smooth: true,
  336. lineStyle: {
  337. width: 0
  338. },
  339. showSymbol: false,
  340. areaStyle: {
  341. opacity: 0.8,
  342. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  343. // offset: 0,
  344. // color: 'rgba(128, 255, 165)'
  345. // }, {
  346. // offset: 1,
  347. // color: 'rgba(1, 191, 236)'
  348. // }])
  349. },
  350. emphasis: {
  351. focus: 'series'
  352. },
  353. data: myJson['curr_history']['RPM_5X']
  354. },
  355. {
  356. name: 'RPM_6X',
  357. type: 'line',
  358. stack: '总量',
  359. smooth: true,
  360. lineStyle: {
  361. width: 0
  362. },
  363. showSymbol: false,
  364. areaStyle: {
  365. opacity: 0.8,
  366. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  367. // offset: 0,
  368. // color: 'rgba(128, 255, 165)'
  369. // }, {
  370. // offset: 1,
  371. // color: 'rgba(1, 191, 236)'
  372. // }])
  373. },
  374. emphasis: {
  375. focus: 'series'
  376. },
  377. data: myJson['curr_history']['RPM_6X']
  378. },
  379. {
  380. name: 'RPM_7X',
  381. type: 'line',
  382. stack: '总量',
  383. smooth: true,
  384. lineStyle: {
  385. width: 0
  386. },
  387. showSymbol: false,
  388. areaStyle: {
  389. opacity: 0.8,
  390. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  391. // offset: 0,
  392. // color: 'rgba(128, 255, 165)'
  393. // }, {
  394. // offset: 1,
  395. // color: 'rgba(1, 191, 236)'
  396. // }])
  397. },
  398. emphasis: {
  399. focus: 'series'
  400. },
  401. data: myJson['curr_history']['RPM_7X']
  402. },
  403. {
  404. name: 'RPM_8X',
  405. type: 'line',
  406. stack: '总量',
  407. smooth: true,
  408. lineStyle: {
  409. width: 0
  410. },
  411. showSymbol: false,
  412. areaStyle: {
  413. opacity: 0.8,
  414. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  415. // offset: 0,
  416. // color: 'rgba(128, 255, 165)'
  417. // }, {
  418. // offset: 1,
  419. // color: 'rgba(1, 191, 236)'
  420. // }])
  421. },
  422. emphasis: {
  423. focus: 'series'
  424. },
  425. data: myJson['curr_history']['RPM_1X']
  426. },
  427. {
  428. name: 'Gear_1X',
  429. type: 'line',
  430. stack: '总量',
  431. smooth: true,
  432. lineStyle: {
  433. width: 0
  434. },
  435. showSymbol: false,
  436. areaStyle: {
  437. opacity: 0.8,
  438. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  439. // offset: 0,
  440. // color: 'rgba(128, 255, 165)'
  441. // }, {
  442. // offset: 1,
  443. // color: 'rgba(1, 191, 236)'
  444. // }])
  445. },
  446. emphasis: {
  447. focus: 'series'
  448. },
  449. data: myJson['curr_history']['Gear_1X']
  450. },
  451. {
  452. name: 'Gear_2X',
  453. type: 'line',
  454. stack: '总量',
  455. smooth: true,
  456. lineStyle: {
  457. width: 0
  458. },
  459. showSymbol: false,
  460. areaStyle: {
  461. opacity: 0.8,
  462. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  463. // offset: 0,
  464. // color: 'rgba(128, 255, 165)'
  465. // }, {
  466. // offset: 1,
  467. // color: 'rgba(1, 191, 236)'
  468. // }])
  469. },
  470. emphasis: {
  471. focus: 'series'
  472. },
  473. data: myJson['curr_history']['Gear_2X']
  474. },
  475. {
  476. name: 'Gear_3X',
  477. type: 'line',
  478. stack: '总量',
  479. smooth: true,
  480. lineStyle: {
  481. width: 0
  482. },
  483. showSymbol: false,
  484. areaStyle: {
  485. opacity: 0.8,
  486. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  487. // offset: 0,
  488. // color: 'rgba(128, 255, 165)'
  489. // }, {
  490. // offset: 1,
  491. // color: 'rgba(1, 191, 236)'
  492. // }])
  493. },
  494. emphasis: {
  495. focus: 'series'
  496. },
  497. data: myJson['curr_history']['Gear_3X']
  498. },
  499. {
  500. name: 'Gear_4X',
  501. type: 'line',
  502. stack: '总量',
  503. smooth: true,
  504. lineStyle: {
  505. width: 0
  506. },
  507. showSymbol: false,
  508. areaStyle: {
  509. opacity: 0.8,
  510. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  511. // offset: 0,
  512. // color: 'rgba(128, 255, 165)'
  513. // }, {
  514. // offset: 1,
  515. // color: 'rgba(1, 191, 236)'
  516. // }])
  517. },
  518. emphasis: {
  519. focus: 'series'
  520. },
  521. data: myJson['curr_history']['Gear_4X']
  522. }
  523. ]
  524. };
  525. history_record.setOption(option);
  526. });
  527. </script>
  528. {% endblock %}