@things-factory/spc 7.0.0-alpha.6 → 7.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/client/pages/spc-chart-page.ts +251 -47
  2. package/dist-client/pages/spc-chart-page.d.ts +21 -3
  3. package/dist-client/pages/spc-chart-page.js +234 -46
  4. package/dist-client/pages/spc-chart-page.js.map +1 -1
  5. package/dist-client/tsconfig.tsbuildinfo +1 -1
  6. package/dist-server/controllers/rules/cp-cpk.js +21 -0
  7. package/dist-server/controllers/rules/cp-cpk.js.map +1 -0
  8. package/dist-server/controllers/spc-chart/c.js +26 -0
  9. package/dist-server/controllers/spc-chart/c.js.map +1 -0
  10. package/dist-server/controllers/{spc-/bchart → spc-chart}/histogram.js +1 -2
  11. package/dist-server/controllers/spc-chart/histogram.js.map +1 -0
  12. package/dist-server/controllers/spc-chart/i.js +26 -0
  13. package/dist-server/controllers/spc-chart/i.js.map +1 -0
  14. package/dist-server/controllers/{spc-/bchart → spc-chart}/index.js +17 -17
  15. package/dist-server/controllers/spc-chart/index.js.map +1 -0
  16. package/dist-server/controllers/{spc-/bchart → spc-chart}/mr.js +12 -11
  17. package/dist-server/controllers/spc-chart/mr.js.map +1 -0
  18. package/dist-server/controllers/spc-chart/np.js +26 -0
  19. package/dist-server/controllers/spc-chart/np.js.map +1 -0
  20. package/dist-server/controllers/spc-chart/p.js +25 -0
  21. package/dist-server/controllers/spc-chart/p.js.map +1 -0
  22. package/dist-server/controllers/{spc-/bchart → spc-chart}/pareto.js +1 -2
  23. package/dist-server/controllers/spc-chart/pareto.js.map +1 -0
  24. package/dist-server/controllers/{spc-/bchart → spc-chart}/r.js +15 -11
  25. package/dist-server/controllers/spc-chart/r.js.map +1 -0
  26. package/dist-server/controllers/{spc-/bchart → spc-chart}/u.js +14 -11
  27. package/dist-server/controllers/spc-chart/u.js.map +1 -0
  28. package/dist-server/controllers/spc-chart/x-bar-r.js +45 -0
  29. package/dist-server/controllers/spc-chart/x-bar-r.js.map +1 -0
  30. package/dist-server/controllers/spc-chart/x-bar.js +45 -0
  31. package/dist-server/controllers/spc-chart/x-bar.js.map +1 -0
  32. package/dist-server/service/spc-chart/spc-chart-query.js +76 -175
  33. package/dist-server/service/spc-chart/spc-chart-query.js.map +1 -1
  34. package/dist-server/service/spc-chart/spc-chart-type.js +71 -85
  35. package/dist-server/service/spc-chart/spc-chart-type.js.map +1 -1
  36. package/dist-server/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +5 -4
  38. package/server/controllers/rules/cp-cpk.ts +29 -0
  39. package/server/controllers/spc-chart/c.ts +31 -0
  40. package/server/controllers/{spc-/bchart → spc-chart}/histogram.ts +1 -3
  41. package/server/controllers/spc-chart/i.ts +31 -0
  42. package/server/controllers/{spc-/bchart → spc-chart}/index.ts +17 -17
  43. package/server/controllers/spc-chart/mr.ts +30 -0
  44. package/server/controllers/spc-chart/np.ts +30 -0
  45. package/server/controllers/spc-chart/p.ts +29 -0
  46. package/server/controllers/{spc-/bchart → spc-chart}/pareto.ts +1 -3
  47. package/server/controllers/spc-chart/r.ts +34 -0
  48. package/server/controllers/spc-chart/u.ts +31 -0
  49. package/server/controllers/spc-chart/x-bar-r.ts +53 -0
  50. package/server/controllers/spc-chart/x-bar.ts +53 -0
  51. package/server/service/spc-chart/spc-chart-query.ts +87 -177
  52. package/server/service/spc-chart/spc-chart-type.ts +57 -55
  53. package/translations/en.json +3 -1
  54. package/translations/ja.json +3 -1
  55. package/translations/ko.json +3 -1
  56. package/translations/ms.json +3 -1
  57. package/translations/zh.json +3 -1
  58. package/dist-server/controllers/spc-/bchart/c.js +0 -21
  59. package/dist-server/controllers/spc-/bchart/c.js.map +0 -1
  60. package/dist-server/controllers/spc-/bchart/histogram.js.map +0 -1
  61. package/dist-server/controllers/spc-/bchart/i.js +0 -23
  62. package/dist-server/controllers/spc-/bchart/i.js.map +0 -1
  63. package/dist-server/controllers/spc-/bchart/index.js.map +0 -1
  64. package/dist-server/controllers/spc-/bchart/mr.js.map +0 -1
  65. package/dist-server/controllers/spc-/bchart/np.js +0 -23
  66. package/dist-server/controllers/spc-/bchart/np.js.map +0 -1
  67. package/dist-server/controllers/spc-/bchart/p.js +0 -22
  68. package/dist-server/controllers/spc-/bchart/p.js.map +0 -1
  69. package/dist-server/controllers/spc-/bchart/pareto.js.map +0 -1
  70. package/dist-server/controllers/spc-/bchart/r.js.map +0 -1
  71. package/dist-server/controllers/spc-/bchart/u.js.map +0 -1
  72. package/dist-server/controllers/spc-/bchart/x-bar.js +0 -50
  73. package/dist-server/controllers/spc-/bchart/x-bar.js.map +0 -1
  74. package/server/controllers/spc-/bchart/c.ts +0 -31
  75. package/server/controllers/spc-/bchart/i.ts +0 -35
  76. package/server/controllers/spc-/bchart/mr.ts +0 -37
  77. package/server/controllers/spc-/bchart/np.ts +0 -35
  78. package/server/controllers/spc-/bchart/p.ts +0 -34
  79. package/server/controllers/spc-/bchart/r.ts +0 -40
  80. package/server/controllers/spc-/bchart/u.ts +0 -36
  81. package/server/controllers/spc-/bchart/x-bar.ts +0 -70
@@ -1,40 +1,131 @@
1
- import '@operato/spc/ox-chart-xbar.js'
2
- import '@operato/spc/ox-chart-r.js'
1
+ import '@operato/app/filters-form.js'
2
+ import '@operato/spc/ox-chart-xbar-r.js'
3
+ import '@operato/spc/ox-chart-i-mr.js'
4
+ import '@operato/spc/ox-chart-u.js'
5
+ import '@operato/spc/ox-chart-c.js'
6
+ import '@operato/spc/ox-chart-p.js'
7
+ import '@operato/spc/ox-chart-np.js'
3
8
 
4
- import { ScrollbarStyles } from '@operato/styles'
9
+ import { ScrollbarStyles, CommonHeaderStyles } from '@operato/styles'
5
10
  import { PageView, store } from '@operato/shell'
6
- import { css, html, PropertyValues } from 'lit'
11
+ import { css, html, PropertyValues, nothing } from 'lit'
7
12
  import { customElement, property, query, state } from 'lit/decorators.js'
8
13
  import { client } from '@operato/graphql'
9
14
  import { i18next, localize } from '@operato/i18n'
10
15
  import { isMobileDevice } from '@operato/utils'
16
+ import { FilterConfig, FilterValue, OxFiltersFormBase } from '@operato/form'
11
17
 
12
18
  import { connect } from 'pwa-helpers/connect-mixin'
13
19
  import gql from 'graphql-tag'
14
20
 
21
+ function formatDate(timestamp: number) {
22
+ const date = new Date(timestamp)
23
+ const year = date.getFullYear()
24
+ const month = String(date.getMonth() + 1).padStart(2, '0') // 월은 0부터 시작하므로 1을 더함
25
+ const day = String(date.getDate()).padStart(2, '0')
26
+ const hours = String(date.getHours()).padStart(2, '0')
27
+ const minutes = String(date.getMinutes()).padStart(2, '0')
28
+ const seconds = String(date.getSeconds()).padStart(2, '0')
29
+
30
+ return `${month}-${day} ${hours}:${minutes}`
31
+ }
32
+
15
33
  @customElement('spc-chart-page')
16
34
  export class SpcChartPage extends connect(store)(localize(i18next)(PageView)) {
17
35
  static styles = [
18
36
  ScrollbarStyles,
37
+ CommonHeaderStyles,
19
38
  css`
20
39
  :host {
21
40
  display: flex;
41
+ flex-direction: column;
22
42
 
23
43
  width: 100%;
24
-
25
- --grid-record-emphasized-background-color: #8b0000;
26
- --grid-record-emphasized-color: #ff6b6b;
27
44
  }
28
45
 
29
46
  .chart {
30
47
  flex: 1;
48
+ padding: var(--padding-default);
31
49
  }
32
50
  `
33
51
  ]
34
52
 
35
- @state() dataSetId?: string
36
- @state() variable?: string
53
+ @state() dataSetId?: string = ''
54
+ @state() variable?: string = ''
55
+ @state() chartType?: string = ''
37
56
  @state() spcChart: any
57
+ @state() filtersValue?: FilterValue[]
58
+ @state() variables: { display: string; value: string }[] = []
59
+
60
+ @query('ox-filters-form-base') formBase!: OxFiltersFormBase
61
+
62
+ private get filtersConfig(): FilterConfig[] {
63
+ return [
64
+ {
65
+ name: 'dataSetId',
66
+ type: 'resource-id',
67
+ label: 'dataset',
68
+ operator: 'eq',
69
+ options: {
70
+ queryName: 'dataSets'
71
+ },
72
+ onchange: (value, formBase) => {
73
+ requestAnimationFrame(async () => {
74
+ const variableFilter = formBase.getFieldByName('variable') as HTMLInputElement
75
+ variableFilter.value = ''
76
+
77
+ this.variables = [
78
+ {
79
+ display: '',
80
+ value: ''
81
+ },
82
+ ...(await this.fetchVariables(value as string))
83
+ ]
84
+ })
85
+
86
+ this.dataSetId = value
87
+
88
+ return false /* whether filters-change event triggered or not */
89
+ }
90
+ },
91
+ {
92
+ name: 'variable',
93
+ type: 'select',
94
+ label: 'variable',
95
+ operator: 'eq',
96
+ options: () => this.variables,
97
+ onchange: value => (this.variable = value)
98
+ },
99
+ {
100
+ name: 'chartType',
101
+ type: 'select',
102
+ label: 'chart',
103
+ operator: 'eq',
104
+ options: ['Xbar-R', 'I-MR', 'C', 'U', 'P', 'NP'],
105
+ onchange: value => (this.chartType = value)
106
+ },
107
+ {
108
+ name: 'dateRange',
109
+ type: 'date',
110
+ label: 'date',
111
+ operator: 'between',
112
+ value: [
113
+ {
114
+ name: 'today',
115
+ params: {
116
+ relativeDays: -30
117
+ }
118
+ },
119
+ {
120
+ name: 'today',
121
+ params: {
122
+ relativeDays: -1
123
+ }
124
+ }
125
+ ]
126
+ }
127
+ ]
128
+ }
38
129
 
39
130
  get context() {
40
131
  return {
@@ -44,15 +135,95 @@ export class SpcChartPage extends connect(store)(localize(i18next)(PageView)) {
44
135
  }
45
136
 
46
137
  render() {
138
+ const { dataSet = {}, variable, charts = [] } = this.spcChart || {}
139
+
140
+ var plotters: { chart: string; data: any[] }[] = []
141
+
142
+ switch (this.chartType) {
143
+ case 'Xbar-R':
144
+ const xbar = charts.find(r => r.chartType == 'Xbar')
145
+ const r = charts.find(r => r.chartType == 'R')
146
+
147
+ plotters.push({ chart: 'xbar-r', data: xbar?.plots ?? [] })
148
+ break
149
+
150
+ case 'I-MR':
151
+ const i = charts.find(r => r.chartType == 'I')
152
+ const mr = charts.find(r => r.chartType == 'MR')
153
+
154
+ plotters.push({ chart: 'i-mr', data: i?.plots ?? [] })
155
+ break
156
+
157
+ case 'P':
158
+ const p = charts.find(r => r.chartType == 'P')
159
+ plotters.push({ chart: 'p', data: p?.plots ?? [] })
160
+ break
161
+
162
+ case 'NP':
163
+ const np = charts.find(r => r.chartType == 'NP')
164
+ plotters.push({ chart: 'np', data: np?.plots ?? [] })
165
+ break
166
+
167
+ case 'C':
168
+ const c = charts.find(r => r.chartType == 'C')
169
+ plotters.push({ chart: 'c', data: c?.plots ?? [] })
170
+ break
171
+
172
+ case 'U':
173
+ const u = charts.find(r => r.chartType == 'U')
174
+ plotters.push({ chart: 'u', data: u?.plots ?? [] })
175
+
176
+ default:
177
+ }
178
+
179
+ plotters = plotters.map(plotter => {
180
+ return {
181
+ ...plotter,
182
+ data: plotter.data.map(plot => {
183
+ return {
184
+ ...plot,
185
+ x: formatDate(Number(plot.x))
186
+ }
187
+ })
188
+ }
189
+ })
190
+
47
191
  return html`
48
- <ox-chart-xbar class="chart"></ox-chart-xbar>
49
- <ox-chart-r class="chart"></ox-chart-r>
192
+ <div class="header">
193
+ <div class="title"><mwc-icon>summarize</mwc-icon>${i18next.t('title.spc-chart')}</div>
194
+ <ox-filters-form-base
195
+ class="filters"
196
+ .value=${this.filtersValue}
197
+ .filters=${this.filtersConfig}
198
+ ?url-params-sensitive=${false}
199
+ @filters-change=${(e: CustomEvent) => {
200
+ this.fetchSpcChart()
201
+ }}
202
+ >
203
+ </ox-filters-form-base>
204
+ </div>
205
+
206
+ ${plotters.map(({ chart, data }) =>
207
+ chart == 'xbar-r'
208
+ ? html` <ox-chart-xbar-r class="chart" .plots=${data}></ox-chart-xbar-r> `
209
+ : chart == 'i-mr'
210
+ ? html` <ox-chart-i-mr class="chart" .plots=${data}></ox-chart-i-mr> `
211
+ : chart == 'u'
212
+ ? html` <ox-chart-u class="chart" .plots=${data}></ox-chart-u> `
213
+ : chart == 'c'
214
+ ? html` <ox-chart-c class="chart" .plots=${data}></ox-chart-c> `
215
+ : chart == 'p'
216
+ ? html` <ox-chart-p class="chart" .plots=${data}></ox-chart-p> `
217
+ : chart == 'np'
218
+ ? html` <ox-chart-np class="chart" .plots=${data}></ox-chart-np> `
219
+ : nothing
220
+ )}
50
221
  `
51
222
  }
52
223
 
53
224
  updated(changes: PropertyValues<this>) {
54
- if (changes.has('dataSetId')) {
55
- this.fetchSpcChart(this.dataSetId!, this.variable!)
225
+ if (!changes.has('spcChart')) {
226
+ this.fetchSpcChart()
56
227
  }
57
228
  }
58
229
 
@@ -62,44 +233,51 @@ export class SpcChartPage extends connect(store)(localize(i18next)(PageView)) {
62
233
  }
63
234
  }
64
235
 
65
- async fetchSpcChart(dataSetId: string, variable: string, startDate?: string, endDate?: string) {
236
+ async fetchSpcChart() {
237
+ const {
238
+ dataSetId,
239
+ dateRange: [fromDate, toDate],
240
+ variable,
241
+ chartType
242
+ } = (await this.formBase.getQueryFilters()).reduce((sum, field) => {
243
+ sum[field.name] = field.value
244
+ return sum
245
+ }, {} as any)
246
+
247
+ if (!(dataSetId && fromDate && toDate && variable && chartType)) {
248
+ return
249
+ }
250
+
66
251
  const response = await client.query({
67
252
  query: gql`
68
- query spcChart($dataSetId: String!, $startDate: String, $endDate: String, $variable: String) {
69
- spcChart(dataSetId: $dataSetId, startDate: $startDate, endDate: $endDate, variable: $variable) {
253
+ query spcChart($dataSetId: String!, $variable: String!, $chartType: String!, $fromDate: String!, $toDate: String!) {
254
+ spcChart(dataSetId: $dataSetId, variable: $variable, chartType: $chartType, fromDate: $fromDate, toDate: $toDate) {
70
255
  dataSet {
71
256
  id
72
257
  name
73
258
  }
74
- analysisResults {
259
+ variable
260
+ charts {
75
261
  chartType
76
- variables {
77
- name
78
- stats {
79
- mean
80
- UCL
81
- LCL
82
- CL
83
- range
84
- proportion
85
- nonconforming
86
- count
87
- defectsPerUnit
88
- individualValue
89
- movingRange
90
- }
91
- samples {
92
- sampleId
93
- value
94
- }
95
- bins {
96
- binRange
97
- count
98
- }
99
- categories {
100
- category
101
- count
102
- }
262
+ controlLimits {
263
+ ucl
264
+ lcl
265
+ cl
266
+ }
267
+ specLimits {
268
+ usl
269
+ lsl
270
+ target
271
+ }
272
+ plots {
273
+ x
274
+ values
275
+ xbar
276
+ r
277
+ i
278
+ mr
279
+ n
280
+ defects
103
281
  }
104
282
  }
105
283
  }
@@ -107,12 +285,38 @@ export class SpcChartPage extends connect(store)(localize(i18next)(PageView)) {
107
285
  `,
108
286
  variables: {
109
287
  dataSetId,
110
- startDate,
111
- endDate,
112
- variable
288
+ variable,
289
+ chartType,
290
+ fromDate,
291
+ toDate
113
292
  }
114
293
  })
115
294
 
116
295
  this.spcChart = response.data.spcChart
117
296
  }
297
+
298
+ async fetchVariables(id: string): Promise<{ display: string; value: string }[]> {
299
+ const response = await client.query({
300
+ query: gql`
301
+ query dataSet($id: String!) {
302
+ dataSet(id: $id) {
303
+ dataItems {
304
+ name
305
+ tag
306
+ }
307
+ }
308
+ }
309
+ `,
310
+ variables: {
311
+ id
312
+ }
313
+ })
314
+
315
+ return response.data.dataSet.dataItems.map(dataItem => {
316
+ return {
317
+ display: dataItem.name,
318
+ value: dataItem.name
319
+ }
320
+ })
321
+ }
118
322
  }
@@ -1,7 +1,13 @@
1
- import '@operato/spc/ox-chart-xbar.js';
2
- import '@operato/spc/ox-chart-r.js';
1
+ import '@operato/app/filters-form.js';
2
+ import '@operato/spc/ox-chart-xbar-r.js';
3
+ import '@operato/spc/ox-chart-i-mr.js';
4
+ import '@operato/spc/ox-chart-u.js';
5
+ import '@operato/spc/ox-chart-c.js';
6
+ import '@operato/spc/ox-chart-p.js';
7
+ import '@operato/spc/ox-chart-np.js';
3
8
  import { PageView } from '@operato/shell';
4
9
  import { PropertyValues } from 'lit';
10
+ import { FilterValue, OxFiltersFormBase } from '@operato/form';
5
11
  declare const SpcChartPage_base: (new (...args: any[]) => {
6
12
  _storeUnsubscribe: import("redux").Unsubscribe;
7
13
  connectedCallback(): void;
@@ -13,7 +19,15 @@ export declare class SpcChartPage extends SpcChartPage_base {
13
19
  static styles: import("lit").CSSResult[];
14
20
  dataSetId?: string;
15
21
  variable?: string;
22
+ chartType?: string;
16
23
  spcChart: any;
24
+ filtersValue?: FilterValue[];
25
+ variables: {
26
+ display: string;
27
+ value: string;
28
+ }[];
29
+ formBase: OxFiltersFormBase;
30
+ private get filtersConfig();
17
31
  get context(): {
18
32
  title: string;
19
33
  help: string;
@@ -21,6 +35,10 @@ export declare class SpcChartPage extends SpcChartPage_base {
21
35
  render(): import("lit-html").TemplateResult<1>;
22
36
  updated(changes: PropertyValues<this>): void;
23
37
  pageUpdated(changes: any, lifecycle: any): Promise<void>;
24
- fetchSpcChart(dataSetId: string, variable: string, startDate?: string, endDate?: string): Promise<void>;
38
+ fetchSpcChart(): Promise<void>;
39
+ fetchVariables(id: string): Promise<{
40
+ display: string;
41
+ value: string;
42
+ }[]>;
25
43
  }
26
44
  export {};