-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow selecting multiple metrics on compare page #133
Draft
dbutenhof
wants to merge
10
commits into
cloud-bulldozer:main
Choose a base branch
from
dbutenhof:compare
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6717f4d
Add new Crucible backend service
dbutenhof 55f9c2b
Add an `ilab` API module for InstructLab
dbutenhof 176ddee
Add an ilab UI tab
MVarshini 7215bb2
Support graphing multiple run comparisons
dbutenhof 1fb02a0
Multi-run comparison UI
MVarshini bea1372
Crucible statistics comparison
dbutenhof 1245407
Display statistical summaries
dbutenhof f2c28fd
Add metadata flyover on comparison page
dbutenhof ea19d5a
Support selection of multiple metrics
dbutenhof ac58188
Add metrics pulldown to compare view
dbutenhof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,18 +78,22 @@ export const setIlabDateFilter = | |
appendQueryString({ ...appliedFilters, start_date, end_date }, navigate); | ||
}; | ||
|
||
export const fetchMetricsInfo = (uid) => async (dispatch) => { | ||
export const fetchMetricsInfo = (uid) => async (dispatch, getState) => { | ||
try { | ||
if (getState().ilab.metrics?.find((i) => i.uid == uid)) { | ||
return; | ||
} | ||
dispatch({ type: TYPES.LOADING }); | ||
const response = await API.get(`/api/v1/ilab/runs/${uid}/metrics`); | ||
if (response.status === 200) { | ||
if ( | ||
response.data.constructor === Object && | ||
Object.keys(response.data).length > 0 | ||
) { | ||
const metrics = Object.keys(response.data).sort(); | ||
dispatch({ | ||
type: TYPES.SET_ILAB_METRICS, | ||
payload: { uid, metrics: Object.keys(response.data).sort() }, | ||
payload: { uid, metrics }, | ||
}); | ||
} | ||
} | ||
|
@@ -100,8 +104,11 @@ export const fetchMetricsInfo = (uid) => async (dispatch) => { | |
dispatch({ type: TYPES.COMPLETED }); | ||
}; | ||
|
||
export const fetchPeriods = (uid) => async (dispatch) => { | ||
export const fetchPeriods = (uid) => async (dispatch, getState) => { | ||
try { | ||
if (getState().ilab.periods?.find((i) => i.uid == uid)) { | ||
return; | ||
} | ||
dispatch({ type: TYPES.LOADING }); | ||
const response = await API.get(`/api/v1/ilab/runs/${uid}/periods`); | ||
if (response.status === 200) { | ||
|
@@ -121,146 +128,147 @@ export const fetchPeriods = (uid) => async (dispatch) => { | |
dispatch({ type: TYPES.COMPLETED }); | ||
}; | ||
|
||
export const fetchSummaryData = | ||
(uid, metric = null) => | ||
async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods.find((i) => i.uid == uid); | ||
const metrics = getState().ilab.metrics_selected[uid]; | ||
dispatch({ type: TYPES.SET_ILAB_SUMMARY_LOADING }); | ||
let summaries = []; | ||
periods?.periods?.forEach((p) => { | ||
if (p.is_primary) { | ||
summaries.push({ | ||
run: uid, | ||
metric: p.primary_metric, | ||
periods: [p.id], | ||
}); | ||
} | ||
if (metrics) { | ||
metrics.forEach((metric) => | ||
export const fetchSummaryData = (uid) => async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods.find((i) => i.uid == uid); | ||
const metrics = getState().ilab.metrics_selected; | ||
const avail_metrics = getState().ilab.metrics; | ||
dispatch({ type: TYPES.SET_ILAB_SUMMARY_LOADING }); | ||
let summaries = []; | ||
periods?.periods?.forEach((p) => { | ||
if (p.is_primary) { | ||
summaries.push({ | ||
run: uid, | ||
metric: p.primary_metric, | ||
periods: [p.id], | ||
}); | ||
} | ||
if (metrics) { | ||
metrics.forEach((metric) => { | ||
if ( | ||
avail_metrics.find((m) => m.uid == uid)?.metrics?.includes(metric) | ||
) { | ||
summaries.push({ | ||
run: uid, | ||
metric, | ||
aggregate: true, | ||
periods: [p.id], | ||
}) | ||
); | ||
} | ||
}); | ||
const response = await API.post( | ||
`/api/v1/ilab/runs/multisummary`, | ||
summaries | ||
); | ||
if (response.status === 200) { | ||
dispatch({ | ||
type: TYPES.SET_ILAB_SUMMARY_DATA, | ||
payload: { uid, data: response.data }, | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can some basic comments be included to differentiate these two? Looking closely I can see that the bottom one is aggregate. |
||
}); | ||
} | ||
} catch (error) { | ||
console.error( | ||
`ERROR (${error?.response?.status}): ${JSON.stringify( | ||
error?.response?.data | ||
)}` | ||
); | ||
dispatch(showFailureToast()); | ||
} | ||
dispatch({ type: TYPES.SET_ILAB_SUMMARY_COMPLETE }); | ||
}; | ||
|
||
export const handleSummaryData = | ||
(uids, metric = null) => | ||
async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods; | ||
const pUids = periods.map((i) => i.uid); | ||
const missingPeriods = uids.filter(function (x) { | ||
return pUids.indexOf(x) < 0; | ||
}); | ||
const response = await API.post( | ||
`/api/v1/ilab/runs/multisummary`, | ||
summaries | ||
); | ||
if (response.status === 200) { | ||
dispatch({ | ||
type: TYPES.SET_ILAB_SUMMARY_DATA, | ||
payload: { uid, data: response.data }, | ||
}); | ||
console.log(`Missing periods for ${missingPeriods}`); | ||
await Promise.all( | ||
missingPeriods.map(async (uid) => { | ||
console.log(`Fetching periods for ${uid}`); | ||
await dispatch(fetchPeriods(uid)); // Dispatch each item | ||
}) | ||
); | ||
await Promise.all( | ||
uids.map(async (uid) => { | ||
console.log(`Fetching summary data for ${uid}`); | ||
await dispatch(fetchSummaryData(uid, metric)); | ||
}) | ||
); | ||
} catch (error) { | ||
console.error(`ERROR: ${JSON.stringify(error)}`); | ||
dispatch(showFailureToast()); | ||
} | ||
}; | ||
} catch (error) { | ||
console.error( | ||
`ERROR (${error?.response?.status}): ${JSON.stringify( | ||
error?.response?.data | ||
)}` | ||
); | ||
dispatch(showFailureToast()); | ||
} | ||
dispatch({ type: TYPES.SET_ILAB_SUMMARY_COMPLETE }); | ||
}; | ||
|
||
export const fetchGraphData = | ||
(uid, metric = null) => | ||
async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods.find((i) => i.uid == uid); | ||
const graphData = cloneDeep(getState().ilab.graphData); | ||
const filterData = graphData.filter((i) => i.uid !== uid); | ||
const metrics = getState().ilab.metrics_selected[uid]; | ||
dispatch({ | ||
type: TYPES.SET_ILAB_GRAPH_DATA, | ||
payload: filterData, | ||
}); | ||
const copyData = cloneDeep(filterData); | ||
dispatch({ type: TYPES.GRAPH_LOADING }); | ||
let graphs = []; | ||
periods?.periods?.forEach((p) => { | ||
if (p.is_primary) { | ||
graphs.push({ run: uid, metric: p.primary_metric, periods: [p.id] }); | ||
} | ||
if (metrics) { | ||
metrics.forEach((metric) => | ||
export const handleSummaryData = (uids) => async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods; | ||
const pUids = periods.map((i) => i.uid); | ||
const missingPeriods = uids.filter(function (x) { | ||
return pUids.indexOf(x) < 0; | ||
}); | ||
await Promise.all( | ||
missingPeriods.map(async (uid) => { | ||
await dispatch(fetchPeriods(uid)); // Dispatch each item | ||
}) | ||
); | ||
await Promise.all( | ||
uids.map(async (uid) => { | ||
await dispatch(fetchSummaryData(uid)); | ||
}) | ||
); | ||
} catch (error) { | ||
console.error(`ERROR: ${JSON.stringify(error)}`); | ||
dispatch(showFailureToast()); | ||
} | ||
}; | ||
|
||
export const fetchGraphData = (uid) => async (dispatch, getState) => { | ||
try { | ||
const periods = getState().ilab.periods.find((i) => i.uid == uid); | ||
const graphData = cloneDeep(getState().ilab.graphData); | ||
const filterData = graphData.filter((i) => i.uid !== uid); | ||
const metrics = getState().ilab.metrics_selected; | ||
const avail_metrics = getState().ilab.metrics; | ||
dispatch({ | ||
type: TYPES.SET_ILAB_GRAPH_DATA, | ||
payload: filterData, | ||
}); | ||
const copyData = cloneDeep(filterData); | ||
dispatch({ type: TYPES.GRAPH_LOADING }); | ||
let graphs = []; | ||
periods?.periods?.forEach((p) => { | ||
if (p.is_primary) { | ||
graphs.push({ run: uid, metric: p.primary_metric, periods: [p.id] }); | ||
} | ||
if (metrics) { | ||
metrics.forEach((metric) => { | ||
if ( | ||
avail_metrics.find((m) => m.uid == uid)?.metrics?.includes(metric) | ||
) { | ||
graphs.push({ | ||
run: uid, | ||
metric, | ||
aggregate: true, | ||
periods: [p.id], | ||
}) | ||
); | ||
} | ||
}); | ||
const response = await API.post(`/api/v1/ilab/runs/multigraph`, { | ||
name: `graph ${uid}`, | ||
graphs, | ||
}); | ||
if (response.status === 200) { | ||
response.data.layout["showlegend"] = true; | ||
response.data.layout["responsive"] = "true"; | ||
response.data.layout["autosize"] = "true"; | ||
response.data.layout["legend"] = { | ||
orientation: "h", | ||
xanchor: "left", | ||
yanchor: "top", | ||
y: -0.1, | ||
}; | ||
copyData.push({ | ||
uid, | ||
data: response.data.data, | ||
layout: response.data.layout, | ||
}); | ||
dispatch({ | ||
type: TYPES.SET_ILAB_GRAPH_DATA, | ||
payload: copyData, | ||
}); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
console.error( | ||
`ERROR (${error?.response?.status}): ${JSON.stringify( | ||
error?.response?.data | ||
)}` | ||
); | ||
dispatch(showFailureToast()); | ||
}); | ||
const response = await API.post(`/api/v1/ilab/runs/multigraph`, { | ||
name: `graph ${uid}`, | ||
graphs, | ||
}); | ||
if (response.status === 200) { | ||
response.data.layout["showlegend"] = true; | ||
response.data.layout["responsive"] = "true"; | ||
response.data.layout["autosize"] = "true"; | ||
response.data.layout["legend"] = { | ||
orientation: "h", | ||
xanchor: "left", | ||
yanchor: "top", | ||
y: -0.1, | ||
}; | ||
copyData.push({ | ||
uid, | ||
data: response.data.data, | ||
layout: response.data.layout, | ||
}); | ||
dispatch({ | ||
type: TYPES.SET_ILAB_GRAPH_DATA, | ||
payload: copyData, | ||
}); | ||
} | ||
dispatch({ type: TYPES.GRAPH_COMPLETED }); | ||
}; | ||
} catch (error) { | ||
console.error( | ||
`ERROR (${error?.response?.status}): ${JSON.stringify( | ||
error?.response?.data | ||
)}` | ||
); | ||
dispatch(showFailureToast()); | ||
} | ||
dispatch({ type: TYPES.GRAPH_COMPLETED }); | ||
}; | ||
|
||
export const handleMultiGraph = (uids) => async (dispatch, getState) => { | ||
try { | ||
|
@@ -292,6 +300,8 @@ export const fetchMultiGraphData = (uids) => async (dispatch, getState) => { | |
dispatch({ type: TYPES.LOADING }); | ||
const periods = getState().ilab.periods; | ||
const filterPeriods = periods.filter((item) => uids.includes(item.uid)); | ||
const get_metrics = getState().ilab.metrics_selected; | ||
const avail_metrics = getState().ilab.metrics; | ||
|
||
let graphs = []; | ||
uids.forEach(async (uid) => { | ||
|
@@ -304,12 +314,20 @@ export const fetchMultiGraphData = (uids) => async (dispatch, getState) => { | |
periods: [p.id], | ||
}); | ||
} | ||
// graphs.push({ | ||
// run: uid, | ||
// metric, | ||
// aggregate: true, | ||
// periods: [p.id], | ||
// }); | ||
if (get_metrics) { | ||
get_metrics.forEach((metric) => { | ||
if ( | ||
avail_metrics.find((m) => m.uid == uid)?.metrics?.includes(metric) | ||
) { | ||
graphs.push({ | ||
run: uid, | ||
metric, | ||
aggregate: true, | ||
periods: [p.id], | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
console.log(graphs); | ||
|
@@ -374,15 +392,13 @@ export const checkIlabJobs = (newPage) => (dispatch, getState) => { | |
} | ||
}; | ||
|
||
export const toggleSelectedMetric = (id, metric) => (dispatch, getState) => { | ||
const metrics_selected = cloneDeep(getState().ilab.metrics_selected); | ||
var new_selected = metrics_selected[id] ? metrics_selected[id] : []; | ||
if (new_selected.includes(metric)) { | ||
new_selected = new_selected.filter((m) => m !== metric); | ||
export const toggleSelectedMetric = (metric) => (dispatch, getState) => { | ||
let metrics_selected = getState().ilab.metrics_selected; | ||
if (metrics_selected.includes(metric)) { | ||
metrics_selected = metrics_selected.filter((m) => m !== metric); | ||
} else { | ||
new_selected = [...new_selected, metric]; | ||
metrics_selected = [...metrics_selected, metric]; | ||
} | ||
metrics_selected[id] = new_selected; | ||
dispatch({ | ||
type: TYPES.SET_ILAB_SELECTED_METRICS, | ||
payload: metrics_selected, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the case for when it already has the data synced? If so I would just add a simple comment like this:
This also applies to the other instances of this.