-
Notifications
You must be signed in to change notification settings - Fork 108
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
Generate Comparison Charts #3500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,28 +37,29 @@ export const getQuisbyData = (dataset) => async (dispatch, getState) => { | |
dispatch(parseChartData()); | ||
} | ||
} catch (error) { | ||
if (error?.response && error.response?.data) { | ||
const errorMsg = error.response.data?.message; | ||
const isUnsupportedType = errorMsg | ||
if ( | ||
error?.response?.data && | ||
error.response.data?.message | ||
?.toLowerCase() | ||
.includes("unsupported benchmark"); | ||
if (isUnsupportedType) { | ||
dispatch({ | ||
type: TYPES.IS_UNSUPPORTED_TYPE, | ||
payload: errorMsg, | ||
}); | ||
} | ||
.includes("unsupported benchmark") | ||
) { | ||
dispatch({ | ||
type: TYPES.IS_UNSUPPORTED_TYPE, | ||
payload: error.response.data.message, | ||
}); | ||
Comment on lines
+40
to
+49
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. So if we get back a server error that's not "unsupported benchmark", we fall through to the |
||
} else { | ||
dispatch(showToast(DANGER, ERROR_MSG)); | ||
} | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
dispatch({ type: TYPES.COMPLETED }); | ||
}; | ||
|
||
const COLORS = ["#8BC1F7", "#0066CC", "#519DE9", "#004B95", "#002F5D"]; | ||
export const parseChartData = () => (dispatch, getState) => { | ||
const response = getState().comparison.data.data; | ||
const isCompareSwitchChecked = getState().comparison.isCompareSwitchChecked; | ||
const chartData = []; | ||
let i = 0; | ||
|
||
for (const run of response) { | ||
const options = { | ||
|
@@ -97,26 +98,130 @@ export const parseChartData = () => (dispatch, getState) => { | |
}, | ||
}; | ||
|
||
const datasets = [ | ||
{ | ||
label: run.instances[0].dataset_name, | ||
data: run.instances.map((i) => i.time_taken), | ||
backgroundColor: "#8BC1F7", | ||
}, | ||
]; | ||
|
||
const datasets = []; | ||
const data = { | ||
labels: run.instances.map((i) => i.name), | ||
labels: [...new Set(run.instances.map((i) => i.name))], | ||
id: `${run.test_name}_${run.metrics_unit}`, | ||
datasets, | ||
}; | ||
const result = run.instances.reduce(function (r, a) { | ||
r[a.dataset_name] = r[a.dataset_name] || []; | ||
r[a.dataset_name].push(a); | ||
return r; | ||
}, Object.create(null)); | ||
|
||
for (const [key, value] of Object.entries(result)) { | ||
console.log(key); | ||
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. Is this a debugging statement you want to keep? 😆 |
||
|
||
const map = {}; | ||
for (const element of value) { | ||
map[element.name] = element.time_taken.trim(); | ||
} | ||
const mappedData = data.labels.map((label) => { | ||
return map[label]; | ||
}); | ||
const obj = { label: key, backgroundColor: COLORS[i], data: mappedData }; | ||
i++; | ||
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. You've got 5 |
||
datasets.push(obj); | ||
} | ||
|
||
const obj = { options, data }; | ||
chartData.push(obj); | ||
i = 0; | ||
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. Is this "reset" really necessary? Isn't |
||
} | ||
const type = isCompareSwitchChecked | ||
? TYPES.SET_COMPARE_DATA | ||
: TYPES.SET_PARSED_DATA; | ||
|
||
dispatch({ | ||
type: TYPES.SET_PARSED_DATA, | ||
type, | ||
payload: chartData, | ||
}); | ||
}; | ||
|
||
export const toggleCompareSwitch = () => (dispatch, getState) => { | ||
dispatch({ | ||
type: TYPES.TOGGLE_COMPARE_SWITCH, | ||
payload: !getState().comparison.isCompareSwitchChecked, | ||
}); | ||
}; | ||
Comment on lines
+142
to
+147
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.
Actually, instead of returning a thunk, |
||
|
||
export const setSelectedId = (isChecked, rId) => (dispatch, getState) => { | ||
let selectedIds = [...getState().comparison.selectedResourceIds]; | ||
if (isChecked) { | ||
selectedIds = [...selectedIds, rId]; | ||
} else { | ||
selectedIds = selectedIds.filter((item) => item !== rId); | ||
} | ||
Comment on lines
+150
to
+155
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. Alternately, using just const prev = getState().comparison.selectedResourceIds;
const selectedIds = isChecked ? [...prev, rId] : prev.filter((id) => id !== rId); |
||
dispatch({ | ||
type: TYPES.SET_SELECTED_RESOURCE_ID, | ||
payload: selectedIds, | ||
}); | ||
}; | ||
Comment on lines
+149
to
+160
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. Why is I think the reason you're using a thunk here is to get access to So, instead of having the caller dispatch to a thunk which dispatches the action, this function can generate the action and the caller can dispatch it without needing the thunk. The same comment applies to |
||
|
||
export const compareMultipleDatasets = () => async (dispatch, getState) => { | ||
Comment on lines
+161
to
+162
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. Again, why is this function returning a thunk instead of just being the thunk, which saves a function call. |
||
try { | ||
dispatch({ type: TYPES.LOADING }); | ||
|
||
const endpoints = getState().apiEndpoint.endpoints; | ||
const selectedIds = [...getState().comparison.selectedResourceIds]; | ||
Comment on lines
+166
to
+167
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. Why is |
||
|
||
const params = new URLSearchParams(); | ||
params.append("datasets", selectedIds.toString()); | ||
const response = await API.get( | ||
uriTemplate(endpoints, "datasets_compare", {}), | ||
{ params } | ||
); | ||
if (response.status === 200 && response.data.json_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. This is fine, I guess, since we really only expect 200 on success; but I still like the idea of using |
||
dispatch({ | ||
type: TYPES.SET_QUISBY_DATA, | ||
payload: response.data.json_data, | ||
}); | ||
dispatch({ | ||
type: TYPES.UNMATCHED_BENCHMARK_TYPES, | ||
payload: "", | ||
}); | ||
dispatch(parseChartData()); | ||
} | ||
} catch (error) { | ||
if ( | ||
error?.response?.data && | ||
error.response.data?.message | ||
?.toLowerCase() | ||
.includes("benchmarks must match") | ||
) { | ||
dispatch({ | ||
type: TYPES.UNMATCHED_BENCHMARK_TYPES, | ||
payload: error.response.data.message, | ||
}); | ||
} else { | ||
dispatch(showToast(DANGER, ERROR_MSG)); | ||
} | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
dispatch({ type: TYPES.COMPLETED }); | ||
}; | ||
|
||
export const setChartModalContent = (chartId) => (dispatch, getState) => { | ||
const isCompareSwitchChecked = getState().comparison.isCompareSwitchChecked; | ||
const data = isCompareSwitchChecked | ||
? getState().comparison.compareChartData | ||
: getState().comparison.chartData; | ||
|
||
const activeChart = data.filter((item) => item.data.id === chartId)[0]; | ||
|
||
dispatch({ | ||
type: TYPES.SET_CURRENT_CHARTID, | ||
payload: activeChart, | ||
}); | ||
}; | ||
|
||
export const setChartModal = (isOpen) => ({ | ||
type: TYPES.SET_CHART_MODAL, | ||
payload: isOpen, | ||
}); | ||
|
||
export const setSearchValue = (value) => ({ | ||
type: TYPES.SET_SEARCH_VALUE, | ||
payload: value, | ||
}); |
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.
I don't think there is a need to check
error?.response?.data
before checkingerror.response.data?.message?.toLowerCase().includes(...)
-- this would be a great place to use the?.
operator throughout:That is, we'll get a
false
if any of the values are false/undefined/missing, which is what I think you want.(That said, I agree with Dave's comment below that it would be better if we got the Server's error message instead of a generic, canned one, so we might want to defer or omit the down-casing and the
includes()
, but I think you can still do it with one test.)Ditto for the code at line 187.