Skip to content

Commit 22514c6

Browse files
only show charts with at least two entries
1 parent a585c75 commit 22514c6

2 files changed

Lines changed: 80 additions & 38 deletions

File tree

src/components/CalculateQuota.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ function getComputationTimes(data, calcstartTimeInput, calcEndTimeInput, quotaUn
363363
cost = cost / 3600
364364
}
365365
ungroupedDataJobs.push({ uniqueId: uniqueId[i], user: calcTimesJobs.users[i], instances: elem,
366-
pool_labels: calcTimesJobs.pool_labels[i], multipliers: calcTimesJobs.multipliers[i].toString(),
366+
pool_labels: calcTimesJobs.pool_labels[i], multipliers: calcTimesJobs.multipliers[i],
367367
times: calcTimesJobs.times[i], comments: calcTimesJobs.comments[i], fails: calcTimesJobs.fails[i],
368368
jobs: '1', is_hypercube: calcTimesJobs.is_hypercube[i], token: calcTimesJobs.token[i],
369369
cost: cost})
@@ -377,16 +377,27 @@ function getComputationTimes(data, calcstartTimeInput, calcEndTimeInput, quotaUn
377377
cost = cost / 3600
378378
}
379379
ungroupedDataPools.push({ unique_id: uniqueId[i], user: calcTimesPools.users[i], instances: elem,
380-
pool_labels: calcTimesPools.pool_labels[i], multipliers: calcTimesPools.multipliers[i].toString(),
380+
pool_labels: calcTimesPools.pool_labels[i], multipliers: calcTimesPools.multipliers[i],
381381
times: calcTimesPools.times[i], comments: calcTimesPools.comments[i], fails: calcTimesPools.fails[i],
382382
jobs: '1', is_hypercube: calcTimesPools.is_hypercube[i], token: calcTimesPools.token[i],
383383
cost: cost})
384384
});
385385

386+
let numberUsers = [...new Set(calcTimesPools.users.concat(calcTimesJobs.users))].length;
387+
let numberInstances = [...new Set(calcTimesPools.instances.concat(calcTimesJobs.instances))].length;
388+
389+
let allPools = [...new Set(calcTimesPools.pool_labels.concat(calcTimesJobs.pool_labels))]
390+
allPools = allPools.filter(elem => elem !== null)
391+
392+
let numberPools = allPools.length;
393+
386394

387395
const result = {
388396
'data_jobs': ungroupedDataJobs,
389-
'data_pools': ungroupedDataPools
397+
'data_pools': ungroupedDataPools,
398+
'num_users': numberUsers,
399+
'num_instances': numberInstances,
400+
'num_pools': numberPools
390401
}
391402

392403
return (

src/components/Quotas.jsx

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { Link } from "react-router-dom";
1515
ChartJS.register(ArcElement, Tooltip, Legend);
1616

1717

18-
19-
const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
18+
const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit}) => {
2019
/*
2120
const data = test_data['test_hypercube_with_pool_and_job'];
2221
const calcStartDate = "2021-08-03T17:10:15.000000+00:00";
@@ -33,11 +32,25 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
3332
const dataTmp = computeTimes(testData, calcStartDate, calcEndTime, quotaUnit)
3433
const [ungroupedDataJobs, setUngroupedDataJobs] = useState(dataTmp.data_jobs);
3534
const [ungroupedDataPools, setUngroupedDataPools] = useState(dataTmp.data_pools);
35+
const [numUser, setNumUser] = useState(dataTmp.num_users);
36+
const [numInstances, setNumInstances] = useState(dataTmp.num_instances);
37+
const [numPools, setNumPools] = useState(dataTmp.num_pools);
38+
const [numCharts, setNumCharts] = useState(dataTmp.num_pools);
3639

3740
useEffect(() => {
3841
const dataTmp = computeTimes(testData, calcStartDate, calcEndTime, quotaUnit)
3942
setUngroupedDataJobs(dataTmp.data_jobs)
4043
setUngroupedDataPools(dataTmp.data_pools)
44+
setNumUser(dataTmp.num_users)
45+
setNumInstances(dataTmp.num_instances)
46+
setNumPools(dataTmp.num_pools)
47+
48+
let tmp = 0;
49+
tmp = (dataTmp.num_users > 1) ? tmp +=1: tmp;
50+
tmp = (dataTmp.num_instances > 1) ? tmp +=1: tmp;
51+
tmp = (dataTmp.num_pools > 1) ? tmp +=1: tmp;
52+
53+
setNumCharts(tmp)
4154
}, [testData, calcStartDate, calcEndTime, quotaUnit])
4255

4356

@@ -59,17 +72,18 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
5972
cost = groupedData.map(elem => elem.cost);
6073
}
6174

75+
const labelTimePairs = labels.map((label, index) => ({ label, cost: cost[index] }));
76+
77+
// Sort the array of objects based on decreasing time
78+
labelTimePairs.sort((a, b) => b.cost - a.cost);
79+
80+
// Extract the sorted labels and times separately
81+
labels = labelTimePairs.map(pair => pair.label);
82+
cost = labelTimePairs.map(pair => pair.cost);
83+
6284
const cutOff = 20;
6385
if (labels.length > cutOff) {
6486
setTruncateWarning(current => `${current} Only the ${cutOff} most used ${label} displayed. `)
65-
const labelTimePairs = labels.map((label, index) => ({ label, cost: cost[index] }));
66-
67-
// Sort the array of objects based on decreasing time
68-
labelTimePairs.sort((a, b) => b.cost - a.cost);
69-
70-
// Extract the sorted labels and times separately
71-
labels = labelTimePairs.map(pair => pair.label);
72-
cost = labelTimePairs.map(pair => pair.cost);
7387
labels = labels.slice(0,cutOff);
7488
cost = cost.slice(0,cutOff)
7589
}
@@ -152,14 +166,14 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
152166
{
153167
field: "multipliers",
154168
column: "Multiplier",
155-
sorter: "alphabetical",
156-
displayer: String
169+
sorter: "numerical",
170+
displayer: (mult) => Intl.NumberFormat('en-US', { style: 'decimal' }).format(mult)
157171
},
158172
{
159173
field: "cost",
160174
column: quotaUnit,
161175
sorter: "numerical",
162-
displayer: (cost) => Intl.NumberFormat('en-US', { style: 'decimal' }).format(cost)//(cost) => cost.toFixed(2)
176+
displayer: (cost) => Intl.NumberFormat('en-US', { style: 'decimal' }).format(cost)
163177
}
164178
])
165179

@@ -242,24 +256,25 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
242256

243257
useEffect(() => {
244258
setTruncateWarning('')
245-
let chartDataTmp = getChartData('usernames', ungroupedDataJobs)
246-
if (chartDataTmp.labels.length === 0) {
247-
chartDataTmp = { labels: ['-'], datasets: [{label: '# of Votes', data: [1], backgroundColor: ["rgba(31,120,180,0.2)"]}]}
248-
}
249-
setUserChartData(chartDataTmp)
250-
chartDataTmp = getChartData('instances', ungroupedDataJobs)
251-
if (chartDataTmp.labels.length === 0) {
252-
chartDataTmp = { labels: ['-'], datasets: [{label: '# of Votes', data: [1], backgroundColor: ["rgba(31,120,180,0.2)"]}]}
259+
let chartDataTmp = {};
260+
if (numUser > 1) {
261+
chartDataTmp = getChartData('usernames', ungroupedDataJobs.concat(ungroupedDataPools))
262+
setUserChartData(chartDataTmp)
253263
}
254-
setInstanceChartData(chartDataTmp)
255-
chartDataTmp = getChartData('pool_labels', ungroupedDataJobs.concat(ungroupedDataPools))
256-
if (chartDataTmp.labels.length === 0) {
257-
chartDataTmp = { labels: ['-'], datasets: [{label: '# of Votes', data: [1], backgroundColor: ["rgba(31,120,180,0.2)"]}]}
264+
265+
if (numInstances > 1) {
266+
chartDataTmp = getChartData('instances', ungroupedDataJobs.concat(ungroupedDataPools))
267+
setInstanceChartData(chartDataTmp)
258268
}
259-
setPoolLabelChartData(chartDataTmp)
260269

261-
}, [ungroupedDataJobs, ungroupedDataPools])
270+
if (numPools > 1) {
271+
chartDataTmp = getChartData('pool_labels', ungroupedDataJobs.concat(ungroupedDataPools))
272+
setPoolLabelChartData(chartDataTmp)
273+
}
274+
275+
}, [ungroupedDataJobs, ungroupedDataPools, numUser, numInstances, numPools])
262276

277+
console.log(numCharts)
263278
return (
264279
<div className="App">
265280
<div className="form-group mt-3 mb-3">
@@ -280,23 +295,35 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
280295
{truncateWarning}
281296
</div>}
282297
<div className='row'>
283-
<div className='col-xl-6 col-12'>
284-
<div className='row'>
285-
<div className='col-md-4 col-sm-6 col-12'>
298+
{(numCharts > 0) ? (
299+
<div className={'col-xl-'+ ((numCharts === 3)? '12':'3') + ' col-lg-3 col-md-12 col-12'}>
300+
<div className='row'>
301+
{(numUser > 1) ? (
302+
<div className={'col-xl-' + ((numCharts === 3)? '4':'12') +
303+
' col-lg-12 col-md-6 col-sm-' + (12 / numCharts).toString() + ' col-12'}>
286304
<h3>Users</h3>
287305
<Pie data={userChartData} />
288306
</div>
289-
<div className='col-md-4 col-sm-6 col-12'>
307+
) :null}
308+
{(numInstances > 1) ? (
309+
<div className={'col-xl-' + ((numCharts === 3)? '4':'12') +
310+
' col-lg-12 col-md-6 col-sm-' + (12 / numCharts).toString() + ' col-12'}>
290311
<h3>Instances</h3>
291312
<Pie data={instanceChartData} />
292313
</div>
293-
<div className='col-md-4 col-sm-6 col-12'>
294-
<h3>Pools (With Idle)</h3>
314+
) :null}
315+
{(numPools > 1) ? (
316+
<div className={'col-xl-' + ((numCharts === 3)? '4':'12') +
317+
' col-lg-12 col-md-6 col-sm-' + (12 / numCharts).toString() + ' col-12'}>
318+
<h3>Pool *</h3>
295319
<Pie data={poolLabelChartData} />
296320
</div>
297-
</div>
321+
) :null}
298322
</div>
299-
<div className='col-xl-6 col-12'>
323+
</div>
324+
): null}
325+
<div className={'col-xl-'+ ((numCharts === 3)? '12': ((numCharts > 0)?'9': '12')) +
326+
' col-lg-' + (((numCharts > 0)?'9': '12')) + ' col-md-12 col-12'}>
300327
<h3>Jobs</h3>
301328
<Table data={tableDataJobs}
302329
noDataMsg="No Usage data found"
@@ -311,6 +338,10 @@ const Quotas = ({ testData, calcStartDate, calcEndTime, quotaUnit }) => {
311338
idFieldName={'unique_id'} />
312339
</div>
313340
</div>
341+
{(numPools > 1) ? (
342+
<div>* includes Idle Times</div>
343+
) :null}
344+
314345
</div>
315346
);
316347
}

0 commit comments

Comments
 (0)