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

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