@things-factory/spc 8.0.0-beta.9 → 8.0.0

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.
@@ -0,0 +1 @@
1
+ export default function bootstrap() {}
File without changes
@@ -0,0 +1,336 @@
1
+ import '@material/web/icon/icon.js'
2
+
3
+ import '@operato/app/filters-form.js'
4
+ import '@operato/spc/ox-chart-xbar-r.js'
5
+ import '@operato/spc/ox-chart-i-mr.js'
6
+ import '@operato/spc/ox-chart-u.js'
7
+ import '@operato/spc/ox-chart-c.js'
8
+ import '@operato/spc/ox-chart-p.js'
9
+ import '@operato/spc/ox-chart-np.js'
10
+
11
+ import { ScrollbarStyles, CommonHeaderStyles } from '@operato/styles'
12
+ import { PageView, store } from '@operato/shell'
13
+ import { css, html, PropertyValues, nothing } from 'lit'
14
+ import { customElement, property, query, state } from 'lit/decorators.js'
15
+ import { client } from '@operato/graphql'
16
+ import { i18next, localize } from '@operato/i18n'
17
+ import { isMobileDevice } from '@operato/utils'
18
+ import { FilterConfig, FilterValue, OxFiltersFormBase } from '@operato/form'
19
+
20
+ import { connect } from 'pwa-helpers/connect-mixin'
21
+ import gql from 'graphql-tag'
22
+
23
+ function formatDate(timestamp: number) {
24
+ const date = new Date(timestamp)
25
+ const year = date.getFullYear()
26
+ const month = String(date.getMonth() + 1).padStart(2, '0') // 월은 0부터 시작하므로 1을 더함
27
+ const day = String(date.getDate()).padStart(2, '0')
28
+ const hours = String(date.getHours()).padStart(2, '0')
29
+ const minutes = String(date.getMinutes()).padStart(2, '0')
30
+ const seconds = String(date.getSeconds()).padStart(2, '0')
31
+
32
+ return `${month}-${day} ${hours}:${minutes}`
33
+ }
34
+
35
+ @customElement('spc-chart-page')
36
+ export class SpcChartPage extends connect(store)(localize(i18next)(PageView)) {
37
+ static styles = [
38
+ ScrollbarStyles,
39
+ CommonHeaderStyles,
40
+ css`
41
+ :host {
42
+ display: flex;
43
+ flex-direction: column;
44
+
45
+ width: 100%;
46
+ }
47
+
48
+ .chart {
49
+ flex: 1;
50
+ padding: var(--spacing-medium);
51
+ }
52
+ `
53
+ ]
54
+
55
+ @state() dataSetId?: string = ''
56
+ @state() variable?: string = ''
57
+ @state() chartType?: string = ''
58
+ @state() spcChart: any
59
+ @state() filtersValue?: FilterValue[]
60
+ @state() variables: { display: string; value: string }[] = []
61
+
62
+ @query('ox-filters-form-base') formBase!: OxFiltersFormBase
63
+
64
+ private get filtersConfig(): FilterConfig[] {
65
+ return [
66
+ {
67
+ name: 'dataSetId',
68
+ type: 'resource-id',
69
+ label: 'dataset',
70
+ operator: 'eq',
71
+ options: {
72
+ queryName: 'dataSets'
73
+ },
74
+ onchange: (value, formBase) => {
75
+ requestAnimationFrame(async () => {
76
+ const variableFilter = formBase.getFieldByName('variable') as HTMLInputElement
77
+ variableFilter.value = ''
78
+
79
+ this.variables = [
80
+ {
81
+ display: '',
82
+ value: ''
83
+ },
84
+ ...(await this.fetchVariables(value as string))
85
+ ]
86
+ })
87
+
88
+ this.dataSetId = value
89
+
90
+ return false /* whether filters-change event triggered or not */
91
+ }
92
+ },
93
+ {
94
+ name: 'variable',
95
+ type: 'select',
96
+ label: 'variable',
97
+ operator: 'eq',
98
+ options: () => this.variables,
99
+ onchange: value => (this.variable = value)
100
+ },
101
+ {
102
+ name: 'chartType',
103
+ type: 'select',
104
+ label: 'chart',
105
+ operator: 'eq',
106
+ options: ['Xbar-R', 'I-MR', 'C', 'U', 'P', 'NP'],
107
+ onchange: value => (this.chartType = value)
108
+ },
109
+ {
110
+ name: 'dateRange',
111
+ type: 'date',
112
+ label: 'date',
113
+ operator: 'between',
114
+ value: [
115
+ {
116
+ name: 'today',
117
+ params: {
118
+ relativeDays: -30
119
+ }
120
+ },
121
+ {
122
+ name: 'today',
123
+ params: {
124
+ relativeDays: -1
125
+ }
126
+ }
127
+ ]
128
+ }
129
+ ]
130
+ }
131
+
132
+ get context() {
133
+ return {
134
+ title: i18next.t('title.spc-chart'),
135
+ help: 'spc/spc-chart'
136
+ }
137
+ }
138
+
139
+ render() {
140
+ const { dataSet = {}, variable, charts = [] } = this.spcChart || {}
141
+
142
+ var plotters: { chart: string; data: any[] }[] = []
143
+
144
+ switch (this.chartType) {
145
+ case 'Xbar-R':
146
+ const xbar = charts.find(r => r.chartType == 'Xbar')
147
+ const r = charts.find(r => r.chartType == 'R')
148
+
149
+ plotters.push({ chart: 'xbar-r', data: xbar?.plots ?? [] })
150
+ break
151
+
152
+ case 'I-MR':
153
+ const i = charts.find(r => r.chartType == 'I')
154
+ const mr = charts.find(r => r.chartType == 'MR')
155
+
156
+ plotters.push({ chart: 'i-mr', data: i?.plots ?? [] })
157
+ break
158
+
159
+ case 'P':
160
+ const p = charts.find(r => r.chartType == 'P')
161
+ plotters.push({ chart: 'p', data: p?.plots ?? [] })
162
+ break
163
+
164
+ case 'NP':
165
+ const np = charts.find(r => r.chartType == 'NP')
166
+ plotters.push({ chart: 'np', data: np?.plots ?? [] })
167
+ break
168
+
169
+ case 'C':
170
+ const c = charts.find(r => r.chartType == 'C')
171
+ plotters.push({ chart: 'c', data: c?.plots ?? [] })
172
+ break
173
+
174
+ case 'U':
175
+ const u = charts.find(r => r.chartType == 'U')
176
+ plotters.push({ chart: 'u', data: u?.plots ?? [] })
177
+
178
+ default:
179
+ }
180
+
181
+ plotters = plotters.map(plotter => {
182
+ return {
183
+ ...plotter,
184
+ data: plotter.data.map(plot => {
185
+ return {
186
+ ...plot,
187
+ x: formatDate(Number(plot.x))
188
+ }
189
+ })
190
+ }
191
+ })
192
+
193
+ return html`
194
+ <div class="header">
195
+ <div class="title"><md-icon>apps</md-icon>${i18next.t('title.spc-chart')}</div>
196
+ <ox-filters-form-base
197
+ class="filters"
198
+ .value=${this.filtersValue}
199
+ .filters=${this.filtersConfig}
200
+ ?url-params-sensitive=${false}
201
+ @filters-change=${(e: CustomEvent) => {
202
+ this.fetchSpcChart()
203
+ }}
204
+ >
205
+ </ox-filters-form-base>
206
+ </div>
207
+
208
+ ${plotters.map(({ chart, data }) =>
209
+ chart == 'xbar-r'
210
+ ? html` <ox-chart-xbar-r class="chart" .plots=${data}></ox-chart-xbar-r> `
211
+ : chart == 'i-mr'
212
+ ? html` <ox-chart-i-mr class="chart" .plots=${data}></ox-chart-i-mr> `
213
+ : chart == 'u'
214
+ ? html` <ox-chart-u class="chart" .plots=${data}></ox-chart-u> `
215
+ : chart == 'c'
216
+ ? html` <ox-chart-c class="chart" .plots=${data}></ox-chart-c> `
217
+ : chart == 'p'
218
+ ? html` <ox-chart-p class="chart" .plots=${data}></ox-chart-p> `
219
+ : chart == 'np'
220
+ ? html` <ox-chart-np class="chart" .plots=${data}></ox-chart-np> `
221
+ : nothing
222
+ )}
223
+ `
224
+ }
225
+
226
+ updated(changes: PropertyValues<this>) {
227
+ if (!changes.has('spcChart')) {
228
+ this.fetchSpcChart()
229
+ }
230
+ }
231
+
232
+ async pageUpdated(changes: any, lifecycle: any) {
233
+ if (this.active) {
234
+ this.dataSetId = lifecycle.resourceId
235
+ }
236
+ }
237
+
238
+ async fetchSpcChart() {
239
+ const {
240
+ dataSetId,
241
+ dateRange: [fromDate, toDate],
242
+ variable,
243
+ chartType
244
+ } = (await this.formBase.getQueryFilters()).reduce((sum, field) => {
245
+ sum[field.name] = field.value
246
+ return sum
247
+ }, {} as any)
248
+
249
+ if (!(dataSetId && fromDate && toDate && variable && chartType)) {
250
+ return
251
+ }
252
+
253
+ const response = await client.query({
254
+ query: gql`
255
+ query spcChart(
256
+ $dataSetId: String!
257
+ $variable: String!
258
+ $chartType: String!
259
+ $fromDate: String!
260
+ $toDate: String!
261
+ ) {
262
+ spcChart(
263
+ dataSetId: $dataSetId
264
+ variable: $variable
265
+ chartType: $chartType
266
+ fromDate: $fromDate
267
+ toDate: $toDate
268
+ ) {
269
+ dataSet {
270
+ id
271
+ name
272
+ }
273
+ variable
274
+ charts {
275
+ chartType
276
+ controlLimits {
277
+ ucl
278
+ lcl
279
+ cl
280
+ }
281
+ specLimits {
282
+ usl
283
+ lsl
284
+ target
285
+ }
286
+ plots {
287
+ x
288
+ values
289
+ xbar
290
+ r
291
+ i
292
+ mr
293
+ n
294
+ defects
295
+ }
296
+ }
297
+ }
298
+ }
299
+ `,
300
+ variables: {
301
+ dataSetId,
302
+ variable,
303
+ chartType,
304
+ fromDate,
305
+ toDate
306
+ }
307
+ })
308
+
309
+ this.spcChart = response.data.spcChart
310
+ }
311
+
312
+ async fetchVariables(id: string): Promise<{ display: string; value: string }[]> {
313
+ const response = await client.query({
314
+ query: gql`
315
+ query dataSet($id: String!) {
316
+ dataSet(id: $id) {
317
+ dataItems {
318
+ name
319
+ tag
320
+ }
321
+ }
322
+ }
323
+ `,
324
+ variables: {
325
+ id
326
+ }
327
+ })
328
+
329
+ return response.data.dataSet.dataItems.map(dataItem => {
330
+ return {
331
+ display: dataItem.name,
332
+ value: dataItem.name
333
+ }
334
+ })
335
+ }
336
+ }
@@ -0,0 +1,7 @@
1
+ export default function route(page) {
2
+ switch (page) {
3
+ case 'spc-chart':
4
+ import('./pages/spc-chart-page')
5
+ return page
6
+ }
7
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "experimentalDecorators": true,
5
+ "skipLibCheck": true,
6
+ "strict": true,
7
+ "declaration": true,
8
+ "module": "esnext",
9
+ "outDir": "../dist-client",
10
+ "baseUrl": "./"
11
+ },
12
+ "include": ["./**/*"]
13
+ }