I'm new to testing world and I'd like your help with that. I have two different functions.
The first one has to do with a bits-per-second converter to a more human readable size
const formatBitrate = bitrate => {
if (bitrate === 0) {
return '0 Bytes';
}
const k = 1024;
const sizes = ['Bytes', 'kbps', 'mbps', 'gbps', 'tbps', 'pbps', 'ebps', 'zbps', 'ybps'];
const i = Math.floor(Math.log(bitrate) / Math.log(k));
return `${parseFloat((bitrate / k ** i).toFixed(0))}\u00A0${sizes[i]}`;
};
And the second one is in mapStateToProps function where I build and new array of objects with the help of map function and using some Math pre-built functions.
const mapStateToProps = state => {
let plotData = state.qualityResults.plotData;
const lastTimestamp = Number(Object.keys(plotData)[0]);
plotData = Object.keys(plotData).map(key => ({
timestamp: Number(key),
bytesReceived: plotData[key].bytesReceived,
seconds: `${Math.ceil(Math.abs(Number(key) - lastTimestamp) / 1000)}s`
}));
return {
plotData,
mos: Number(state.qualityResults.video.mos).toFixed(1),
packetLossRatio: Number(state.qualityResults.video.packetLossRatio).toFixed(0),
bitrate: formatBitrate(state.qualityResults.video.bitrate)
};
};
Aucun commentaire:
Enregistrer un commentaire