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 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. Row {
  22. spacing: 5
  23. Text {
  24. text: "Mass of ground coffee: "
  25. }
  26. TextInput {
  27. id: groundMass
  28. width: 30
  29. validator: DoubleValidator {
  30. bottom: 0
  31. decimals: 2
  32. notation: DoubleValidator.StandardNotation
  33. }
  34. KeyNavigation.tab: brewedMass
  35. Line {
  36. x1: -3; y1: groundMass.height
  37. x2: 33; y2: y1
  38. penWidth: 1
  39. color: "black"
  40. }
  41. }
  42. }
  43. Row {
  44. spacing: 5
  45. Text {
  46. text: "Mass of brewed coffee:"
  47. }
  48. TextInput {
  49. id: brewedMass
  50. width: 30
  51. validator: DoubleValidator {
  52. bottom: 0
  53. decimals: 2
  54. notation: DoubleValidator.StandardNotation
  55. }
  56. KeyNavigation.backtab: groundMass
  57. KeyNavigation.tab: ptds
  58. Line {
  59. x1: -3; y1: brewedMass.height
  60. x2: 33; y2: y1
  61. penWidth: 1
  62. color: "black"
  63. }
  64. }
  65. }
  66. Row {
  67. spacing: 56
  68. Text {
  69. text: "Percent TDS:"
  70. }
  71. TextInput {
  72. id: ptds
  73. width: 30
  74. validator: DoubleValidator {
  75. bottom: 0
  76. top: 100
  77. decimals: 2
  78. notation: DoubleValidator.StandardNotation
  79. }
  80. KeyNavigation.backtab: brewedMass
  81. Line {
  82. x1: -3; y1: ptds.height
  83. x2: 33; y2: y1
  84. penWidth: 1
  85. color: "black"
  86. }
  87. }
  88. }
  89. Row {
  90. spacing: 87
  91. Text {
  92. id: colorlabel
  93. text: "Color:"
  94. }
  95. ColorPicker {
  96. id: colorpicker
  97. width: 37; height: colorlabel.height
  98. }
  99. }
  100. Row {
  101. id: lsfrow
  102. visible: false
  103. spacing: 1
  104. Text {
  105. id: fitcolorlabel
  106. text: "Least Squares Fit Color:"
  107. }
  108. ColorPicker {
  109. id: fitcolorpicker
  110. width: 37; height: colorlabel.height
  111. onColorChanged: {
  112. graph.setFitColor(color)
  113. }
  114. }
  115. }
  116. Rectangle {
  117. z: 0
  118. anchors.horizontalCenter: parent.horizontalCenter
  119. height: buttonText.height + 20; width: buttonText.width + 40
  120. border.color: "black"
  121. radius: 10
  122. Text {
  123. id: buttonText
  124. text: "Plot This Brew"
  125. anchors {horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter}
  126. }
  127. MouseArea {
  128. anchors.fill: parent
  129. onClicked: {
  130. var extraction = (brewedMass.text * (ptds.text / 100)) / groundMass.text
  131. graph.plotPoint(extraction, (ptds.text / 100), colorpicker.color)
  132. dataViewModel.append({"color": colorpicker.color, "ptds": ptds.text, "extraction": extraction})
  133. root.n += 1
  134. root.sumy += (ptds.text / 100)
  135. root.sumx += extraction
  136. root.sumxy += ((ptds.text / 100) * extraction)
  137. root.sumxsq += Math.pow(extraction, 2)
  138. if(root.n > 1) {
  139. var a = ((root.sumy * root.sumxsq)-(root.sumx * root.sumxy))/((root.n * root.sumxsq)-Math.pow(root.sumx, 2))
  140. var b = ((root.n * root.sumxy)-(root.sumx * root.sumy))/((root.n * root.sumxsq) - Math.pow(root.sumx, 2))
  141. var x1 = 0.14
  142. var x2 = 0.26
  143. var y1 = a + (b * x1)
  144. var y2 = a + (b * x2)
  145. if(y1 < 0.008) {
  146. x1 = (0.008 - a) / b
  147. y1 = 0.008
  148. }
  149. if(y2 < 0.008) {
  150. x2 = (0.008 - a) / b
  151. y2 = 0.008
  152. }
  153. if(y1 > 0.016) {
  154. x1 = (0.016 - a) / b
  155. y1 = 0.016
  156. }
  157. if(y2 > 0.016) {
  158. x2 = (0.016 - a) / b
  159. y2 = 0.016
  160. }
  161. graph.setFit(x1, y1, x2, y2);
  162. }
  163. }
  164. }
  165. }
  166. Repeater {
  167. id: dataView
  168. model: ListModel {
  169. id: dataViewModel
  170. }
  171. delegate: Row {
  172. spacing: 3
  173. Rectangle {
  174. width: 30; height: 30
  175. color: dataViewModel.get(index).color
  176. }
  177. Column {
  178. Text {
  179. text: "Strength: "+dataViewModel.get(index).ptds+"% TDS"
  180. }
  181. Text {
  182. text: "Extraction: "+Number(dataViewModel.get(index).extraction*100).toFixed(2)+"%"
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. Component.onCompleted: {
  190. var quitItem = window.addMenuItem("File", "Quit");
  191. quitItem.shortcut = "Ctrl+Q";
  192. quitItem.triggered.connect(function() {
  193. Qt.quit();
  194. });
  195. var clearItem = window.addMenuItem("Plotting", "Clear Data");
  196. clearItem.triggered.connect(function() {
  197. graph.clear();
  198. dataViewModel.clear();
  199. root.sumy = 0;
  200. root.sumxsq = 0;
  201. root.sumx = 0;
  202. root.sumxy = 0;
  203. root.n = 0;
  204. graph.setFit(0, 0, 0, 0);
  205. });
  206. var showLeastSquares = window.addMenuItem("Plotting", "Least Squares Fit");
  207. showLeastSquares.checkable = true;
  208. showLeastSquares.triggered.connect(function() {
  209. graph.setFitVisible(showLeastSquares.checked);
  210. lsfrow.visible = showLeastSquares.checked;
  211. });
  212. }
  213. }