Qt Quick based coffee brewing control chart.
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.

main.qml 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import CustomComponents 1.0
  2. import QtQuick 1.0
  3. Rectangle {
  4. id: root
  5. property real sumy : 0
  6. property real sumxsq : 0
  7. property real sumx : 0
  8. property real sumxy : 0
  9. property int n : 0
  10. width: 720; height: 680
  11. BrewingControlChart {
  12. id: graph
  13. width: 450; height: 600
  14. anchors {right: parent.right; rightMargin: 20; top: parent.top; topMargin: 20}
  15. }
  16. Item {
  17. anchors {left: parent.left; leftMargin: 10; top: parent.top; topMargin: 10}
  18. Column {
  19. spacing: 8
  20. ListView {
  21. spacing: 3
  22. height: 600; width: 100
  23. contentHeight: dataViewModel.count * 35
  24. model: ListModel {
  25. id: dataViewModel
  26. }
  27. delegate: Row {
  28. spacing: 3
  29. Rectangle {
  30. width: 30; height: 30
  31. color: dataViewModel.get(index).color
  32. }
  33. Column {
  34. Text {
  35. text: "Strength: " + dataViewModel.get(index).ptds + "% TDS"
  36. }
  37. Text {
  38. text: "Extraction: " + Number(dataViewModel.get(index).extraction * 100).toFixed(2) + "%"
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. Component.onCompleted: {
  46. var quitItem = window.addMenuItem("File", "Quit");
  47. quitItem.shortcut = "Ctrl+Q";
  48. quitItem.triggered.connect(function() {
  49. Qt.quit();
  50. });
  51. var clearItem = window.addMenuItem("Plotting", "Clear Data");
  52. clearItem.triggered.connect(function() {
  53. graph.clear();
  54. dataViewModel.clear();
  55. root.sumy = 0;
  56. root.sumxsq = 0;
  57. root.sumx = 0;
  58. root.sumxy = 0;
  59. root.n = 0;
  60. graph.setFit(0, 0, 0, 0);
  61. });
  62. var showLeastSquares = window.addMenuItem("Plotting", "Least Squares Fit");
  63. showLeastSquares.checkable = true;
  64. showLeastSquares.triggered.connect(function() {
  65. graph.setFitVisible(showLeastSquares.checked);
  66. });
  67. window.newPoint.connect(function(pointDescription) {
  68. graph.plotPoint(pointDescription.extraction,
  69. pointDescription.ptds / 100,
  70. pointDescription.color)
  71. dataViewModel.append(pointDescription)
  72. root.n += 1
  73. root.sumy += pointDescription.ptds / 100
  74. root.sumx += pointDescription.extraction
  75. root.sumxy += ((pointDescription.ptds / 100) * pointDescription.extraction)
  76. root.sumxsq += Math.pow(pointDescription.extraction, 2)
  77. if(root.n > 1) {
  78. var a = ((root.sumy * root.sumxsq)-(root.sumx * root.sumxy))/((root.n * root.sumxsq)-Math.pow(root.sumx, 2))
  79. var b = ((root.n * root.sumxy)-(root.sumx * root.sumy))/((root.n * root.sumxsq) - Math.pow(root.sumx, 2))
  80. var x1 = 0.14
  81. var x2 = 0.26
  82. var y1 = a + (b * x1)
  83. var y2 = a + (b * x2)
  84. if(y1 < 0.008) {
  85. x1 = (0.008 - a) / b
  86. y1 = 0.008
  87. }
  88. if(y2 < 0.008) {
  89. x2 = (0.008 - a) / b
  90. y2 = 0.008
  91. }
  92. if(y1 > 0.016) {
  93. x1 = (0.016 - a) / b
  94. y2 = 0.016
  95. }
  96. if(y2 > 0.016) {
  97. x2 = (0.016 - a) / b
  98. y2 = 0.016
  99. }
  100. graph.setFit(x1, y1, x2, y2)
  101. }
  102. });
  103. }
  104. }