Skip to content

Commit fa3df38

Browse files
committed
[wip] Refactor data payload
1 parent ee23cf3 commit fa3df38

File tree

1 file changed

+103
-23
lines changed

1 file changed

+103
-23
lines changed

src/shared/hooks/useGetChartData.ts

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,129 @@ export const useGetChartData = async ({
3131
dimensions = [],
3232
from,
3333
to,
34+
...rest
3435
}: UseGetChartDataType) => {
35-
let aggregations = [];
36+
console.log({
37+
baseUrl,
38+
roomId,
39+
nodes,
40+
spaceId,
41+
contextId,
42+
filterBy,
43+
filterValue,
44+
groupBy,
45+
method,
46+
group,
47+
dimensions,
48+
from,
49+
to,
50+
...rest,
51+
});
52+
let metrics = [];
3653

3754
switch (groupBy) {
3855
case 'node':
39-
aggregations = [
40-
{ method: 'sum', groupBy: ['chart', 'node'] },
41-
{ method, groupBy: ['node'] },
56+
metrics = [
57+
{
58+
group_by: ['chart', 'node'],
59+
group_by_label: [],
60+
aggregation: 'sum',
61+
},
62+
{
63+
group_by: ['node'],
64+
group_by_label: [],
65+
aggregation: method,
66+
},
4267
];
68+
// metrics = [
69+
// { method: 'sum', groupBy: ['chart', 'node'] },
70+
// { method, groupBy: ['node'] },
71+
// ];
4372
break;
4473
case 'dimension':
45-
aggregations = [{ method, groupBy: ['dimension'] }];
74+
metrics = [
75+
{
76+
group_by: ['dimension'],
77+
group_by_label: [],
78+
aggregation: method,
79+
},
80+
];
81+
// metrics = [{ method, groupBy: ['dimension'] }];
4682
break;
4783
case 'instance':
48-
aggregations = [{ method: 'sum', groupBy: ['chart', 'node'] }];
84+
metrics = [
85+
{
86+
group_by: ['chart', 'node'],
87+
group_by_label: [],
88+
aggregation: 'sum',
89+
},
90+
];
91+
// metrics = [{ method: 'sum', groupBy: ['chart', 'node'] }];
4992
break;
5093
default:
51-
aggregations = [
52-
{ method: 'sum', groupBy: ['chart', `label=${groupBy}`] },
53-
{ method: 'avg', groupBy: [`label=${groupBy}`] },
94+
metrics = [
95+
{
96+
group_by: ['chart'],
97+
group_by_label: groupBy,
98+
aggregation: 'sum',
99+
},
100+
{
101+
group_by: [],
102+
group_by_label: groupBy,
103+
aggregation: 'avg',
104+
},
54105
];
106+
// metrics = [
107+
// { method: 'sum', groupBy: ['chart', `label=${groupBy}`] },
108+
// { method: 'avg', groupBy: [`label=${groupBy}`] },
109+
// ];
55110
break;
56111
}
57112

58113
return await Post({
59114
path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`,
60115
baseUrl,
61116
data: {
62-
filter: {
63-
nodeIDs: nodes,
64-
context: contextId,
65-
dimensions,
66-
...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}),
117+
format: 'json2',
118+
options: ['jsonwrap', 'flip', 'ms'],
119+
scope: {
120+
contexts: [contextId],
121+
nodes,
67122
},
68-
aggregations,
69-
agent_options: ['jsonwrap', 'flip', 'ms'],
70-
points: 335,
71-
format: 'json',
72-
group,
73-
gtime: 0,
74-
after: from,
75-
before: to,
76-
with_metadata: true,
123+
selectors: {
124+
contexts: ['*'],
125+
nodes: ['*'],
126+
instances: ['*'],
127+
dimensions: ['*'],
128+
labels: ['*'],
129+
},
130+
aggregations: {
131+
metrics,
132+
time: { time_group: group, time_resampling: 0 },
133+
},
134+
window: { after: from, before: to, points: 269 },
77135
},
78136
});
137+
138+
// return await Post({
139+
// path: `/v3/spaces/${spaceId}/rooms/${roomId}/data`,
140+
// baseUrl,
141+
// data: {
142+
// filter: {
143+
// nodeIDs: nodes,
144+
// context: contextId,
145+
// dimensions,
146+
// ...(filterBy && filterValue ? { labels: { [filterBy]: [filterValue] } } : {}),
147+
// },
148+
// aggregations,
149+
// agent_options: ['jsonwrap', 'flip', 'ms'],
150+
// points: 335,
151+
// format: 'json',
152+
// group,
153+
// gtime: 0,
154+
// after: from,
155+
// before: to,
156+
// with_metadata: true,
157+
// },
158+
// });
79159
};

0 commit comments

Comments
 (0)