Qt Quick based coffee brewing control chart.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.qml 3.8KB

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