diff --git a/dashboard/src/hooks/use-fetch-data.js b/dashboard/src/hooks/use-fetch-data.js new file mode 100644 index 00000000..231eec6b --- /dev/null +++ b/dashboard/src/hooks/use-fetch-data.js @@ -0,0 +1,29 @@ +import { useState, useEffect } from 'react'; + +function useFetchData(url) { + const [data, setData] = useState(null); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + fetch(url) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(json => { + setData(json); + setIsLoading(false); + }) + .catch(err => { + setError(err); + setIsLoading(false); + }); + }, [url]); // Dependency array includes url to re-run the effect if the url changes + + return { data, isLoading, error }; +} + +export default useFetchData; diff --git a/dashboard/src/pages/throughput.jsx b/dashboard/src/pages/throughput.jsx index 354c2754..12754aff 100644 --- a/dashboard/src/pages/throughput.jsx +++ b/dashboard/src/pages/throughput.jsx @@ -1,42 +1,37 @@ import { Helmet } from 'react-helmet-async'; -import { useState, useEffect } from 'react'; import Grid from '@mui/material/Unstable_Grid2'; import Container from '@mui/material/Container'; import Typography from '@mui/material/Typography'; +import useFetchData from 'src/hooks/use-fetch-data'; + import { GraphView } from 'src/sections/overview/graphing'; +import { + parseLinuxDownloadQuic, + parseLinuxDownloadTcp, + parseLinuxUploadQuic, + parseLinuxUploadTcp, + parseWindowsDownloadQuic, + parseWindowsDownloadTcp, + parseWindowsUploadQuic, + parseWindowsUploadTcp, + parseCommitsList, + parseRunDates, +} from './util/parser'; + + // ---------------------------------------------------------------------- export default function ThroughputPage() { - // TODO: Once you have the pipeline to auto-update based on the last ~20 commits, update this URL. - const URL = "https://microsoft.github.io/netperf/data/secnetperf/2023-12-01-20-25-09._.67ee09354f52d014ad4e9ec85fcb6b9260890134.json/test_result.json"; - - const [data, setData] = useState(null); - const [isLoading, setIsLoading] = useState(true); - const [error, setError] = useState(null); - - - useEffect(() => { - fetch(URL) - .then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }) - .then(json => { - setData(json); - setIsLoading(false); - }) - .catch(err => { - setError(err); - setIsLoading(false); - }); - }, []); + const URL = "https://microsoft.github.io/netperf/data/secnetperf/dashboard.json"; + const { data, isLoading, error } = useFetchData(URL); + + let uploadThroughput =
+ let downloadThroughput = if (isLoading) { console.log("Loading..."); @@ -48,6 +43,78 @@ export default function ThroughputPage() { if (data) { console.log(data); + const commits = parseCommitsList(data); + const runDates = parseRunDates(data); + const windowsTcpUpload = parseWindowsUploadTcp(data); + const windowsTcpDownload = parseWindowsDownloadTcp(data); + const windowsQuicUpload = parseWindowsUploadQuic(data); + const windowsQuicDownload = parseWindowsDownloadQuic(data); + const linuxTcpUpload = parseLinuxUploadTcp(data); + const linuxTcpDownload = parseLinuxDownloadTcp(data); + const linuxQuicUpload = parseLinuxUploadQuic(data); + const linuxQuicDownload = parseLinuxDownloadQuic(data); + + uploadThroughput =