@things-factory/dataset 6.0.85 → 6.0.87

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/dataset",
3
- "version": "6.0.85",
3
+ "version": "6.0.87",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -50,5 +50,5 @@
50
50
  "simple-statistics": "^7.8.3",
51
51
  "statistics": "^3.3.0"
52
52
  },
53
- "gitHead": "98d3d1b2cde1c9d6cb717b5c8cdb6d585a2a744a"
53
+ "gitHead": "a6999758a676c8f50526e75638f95e10f2e69d72"
54
54
  }
@@ -91,12 +91,17 @@ export async function queryDataSummaryByPeriod(
91
91
 
92
92
  const { from, to } = await getTimesForPeriod(period, context)
93
93
 
94
- const selectPeriod =
95
- period == 'today'
96
- ? ['summary.date', 'summary.period']
97
- : ['this year', '12 months'].includes(period)
98
- ? ['SUBSTRING(summary.date, 1, 7) AS month']
99
- : ['summary.date']
94
+ const selectPeriod = queryBuilder => {
95
+ if (period == 'today') {
96
+ queryBuilder.addSelect('summary.date', 'date').addSelect('summary.period', 'period')
97
+ } else if (['this year', '12 months'].includes(period)) {
98
+ queryBuilder.addSelect('SUBSTRING(summary.date, 1, 7) AS month')
99
+ } else {
100
+ queryBuilder.addSelect('summary.date', 'date')
101
+ }
102
+
103
+ return queryBuilder
104
+ }
100
105
  const selectKeys = dataKeyItems.map((item, index) => {
101
106
  const aliasName = `key0${index + 1}`
102
107
  const columnName = `summary.${aliasName}`
@@ -172,20 +177,22 @@ export async function queryDataSummaryByPeriod(
172
177
  .select('summary.dataSet')
173
178
  .addSelect('ds.name', 'name')
174
179
  .addSelect('ds.description', 'description')
175
- .addSelect('summary.date', 'date')
176
- .addSelect('summary.period', 'period')
177
- .addSelect(selectPeriod)
178
180
  .addSelect(selectKeys)
179
181
  .addSelect(selectData)
180
182
  .addSelect('SUM(summary.count)', 'count')
181
183
  .addSelect('SUM(summary.countOoc)', 'countOoc')
182
184
  .addSelect('SUM(summary.countOos)', 'countOos')
185
+
186
+ selectPeriod(queryBuilder)
183
187
  .innerJoin('summary.dataSet', 'ds', 'ds.id = :dataSetName', {
184
188
  dataSetName: dataSet.id
185
189
  })
186
190
  .andWhere('summary.domain = :domain', { domain: domain.id })
187
191
  .andWhere('summary.date >= :from', { from })
188
192
  .andWhere('summary.date < :to', { to })
193
+ .addGroupBy('summary.dataSet')
194
+ .addGroupBy('ds.name')
195
+ .addGroupBy('ds.description')
189
196
  .addGroupBy(groupByPeriod)
190
197
  .addGroupBy(groupByKeys)
191
198