Personal intranet/start page where I can view the weather, links, fitbit data, and the news.
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.

135 lines
4.1 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  5. <script src="lib/moment.min.js"></script>
  6. <link href="vis/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  7. <script src="vis/vis.js"></script>
  8. <!-- jQuery library -->
  9. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  10. </head>
  11. <div id="heartRateGraph"></div>
  12. <body>
  13. <div class="container">
  14. <div class="row">
  15. <div class="col-4 shadow-lg p-3 bg-white rounded">
  16. <label>Heart Rate JSON Files</label>
  17. <input type="file" id="files" name="files[]" multiple />
  18. <output id="list"></output>
  19. </div>
  20. <div class="col-4 shadow-lg p-3 bg-white rounded">
  21. <label>Activity Files</label>
  22. <input type="file" id="actFiles" name="files[]" multiple />
  23. <output id="actList"></output>
  24. </div>
  25. </div>
  26. <div class="row">
  27. </div>
  28. </div>
  29. </body>
  30. <footer>
  31. <script>
  32. function generateHeartRateGraph(jsonFiles)
  33. {
  34. var items = [];
  35. for(var i = 0; i < jsonFiles.length; i++)
  36. {
  37. console.log(jsonFiles[i].length);
  38. for(var j = 0; j < jsonFiles[i].length; j++)
  39. {
  40. var localTime = new Date(jsonFiles[i][j].dateTime);
  41. items.push({y:jsonFiles[i][j].value.bpm, x:localTime.setHours(localTime.getHours() - 4)});
  42. }
  43. }
  44. console.log("Finished Loading Heart Rate Data Into Graph");
  45. var dataset = new vis.DataSet(items);
  46. var options = {
  47. dataAxis: {
  48. showMinorLabels: true,
  49. left: {
  50. title: {
  51. text: "Heart Rate"
  52. }
  53. }
  54. }
  55. };
  56. var container = document.getElementById("heartRateGraph");
  57. var graph2d = new vis.Graph2d(container, dataset, options);
  58. }
  59. function generateTimeline(jsonFiles)
  60. {
  61. console.log(jsonFiles);
  62. }
  63. function fetchFilesAsJSONArray(evt)
  64. {
  65. return new Promise((res, rej)=>
  66. {
  67. var files = evt.target.files; // FileList object
  68. var promises = [];
  69. for (var i = 0, f; f = files[i]; i++)
  70. {
  71. promises.push(new Promise((resolve, reject)=>
  72. {
  73. var reader = new FileReader();
  74. reader.onload = function(e)
  75. {
  76. resolve(JSON.parse(reader.result));
  77. };
  78. reader.onerror= function(e)
  79. {
  80. reject(e);
  81. };
  82. reader.readAsBinaryString(files[i]);
  83. }));
  84. }
  85. Promise.all(promises).then((data)=>
  86. {
  87. res(data);
  88. }).catch((error)=>
  89. {
  90. console.log(error);
  91. console.log("Unable to Load Data");
  92. rej(error);
  93. })
  94. });
  95. }
  96. function handleFileSelect(evt)
  97. {
  98. fetchFilesAsJSONArray(evt).then((data)=>
  99. {
  100. generateHeartRateGraph(data);
  101. })
  102. }
  103. document.getElementById('files').addEventListener('change', handleFileSelect, false);
  104. function handleFileSelectEvents(evt)
  105. {
  106. fetchFilesAsJSONArray(evt).then((data)=>
  107. {
  108. generateTimeline(data);
  109. })
  110. }
  111. document.getElementById('actFiles').addEventListener('change', handleFileSelectEvents, false);
  112. </script>
  113. </footer>
  114. </html>