From b3f25c176b1bdb487d1a7bf111d7f170fe008842 Mon Sep 17 00:00:00 2001 From: Lorenzo Alberto Maria Ambrosi Date: Thu, 9 Apr 2020 16:21:07 +0200 Subject: [PATCH] Add average speed in flash results Changelog-entry: Add average speed in flash results Change-type: patch --- .../flash-results/flash-results.tsx | 23 +++++++++++++++++-- lib/gui/app/models/flash-state.ts | 1 - lib/gui/app/models/store.ts | 18 ++++++++++++++- lib/gui/app/pages/main/styles/_main.scss | 1 - lib/gui/css/main.css | 3 +-- npm-shrinkwrap.json | 6 ++--- package.json | 2 +- tests/gui/models/flash-state.spec.ts | 21 +++++++++++++++++ 8 files changed, 64 insertions(+), 11 deletions(-) diff --git a/lib/gui/app/components/flash-results/flash-results.tsx b/lib/gui/app/components/flash-results/flash-results.tsx index f4954b0e..a3d9f925 100644 --- a/lib/gui/app/components/flash-results/flash-results.tsx +++ b/lib/gui/app/components/flash-results/flash-results.tsx @@ -16,10 +16,12 @@ import * as _ from 'lodash'; import * as React from 'react'; +import { Txt } from 'rendition'; import styled from 'styled-components'; import { left, position, space, top } from 'styled-system'; import { progress } from '../../../../shared/messages'; +import { bytesToMegabytes } from '../../../../shared/units'; import { Underline } from '../../styled-components'; const Div = styled.div` @@ -34,15 +36,22 @@ export function FlashResults({ results, }: { errors: string; - results: { devices: { failed: number; successful: number } }; + results: { + averageFlashingSpeed: number; + devices: { failed: number; successful: number }; + }; }) { + const averageSpeed = _.round( + bytesToMegabytes(results.averageFlashingSpeed), + 1, + ); return (

Flash Complete!

-
+
{_.map(results.devices, (quantity, type) => { return quantity ? ( ) : null; })} + + Writing speed: {averageSpeed} MB/s +
); diff --git a/lib/gui/app/models/flash-state.ts b/lib/gui/app/models/flash-state.ts index 524eaaab..4c2c1d56 100644 --- a/lib/gui/app/models/flash-state.ts +++ b/lib/gui/app/models/flash-state.ts @@ -87,7 +87,6 @@ export function setProgressState( return null; }), - totalSpeed: _.attempt(() => { if (_.isFinite(state.totalSpeed)) { return _.round(bytesToMegabytes(state.totalSpeed), PRECISION); diff --git a/lib/gui/app/models/store.ts b/lib/gui/app/models/store.ts index e05552da..412e5ba8 100644 --- a/lib/gui/app/models/store.ts +++ b/lib/gui/app/models/store.ts @@ -71,8 +71,10 @@ const DEFAULT_STATE = Immutable.fromJS({ failed: 0, percentage: 0, speed: null, + averageSpeed: null, totalSpeed: null, }, + lastAverageFlashingSpeed: null, }); /** @@ -263,7 +265,11 @@ function storeReducer( }); } - return state.set('flashState', Immutable.fromJS(action.data)); + let ret = state.set('flashState', Immutable.fromJS(action.data)); + if (action.data.flashing) { + ret = ret.set('lastAverageFlashingSpeed', action.data.averageSpeed); + } + return ret; } case Actions.RESET_FLASH_STATE: { @@ -326,9 +332,19 @@ function storeReducer( }); } + if (action.data.results) { + action.data.results.averageFlashingSpeed = state.get( + 'lastAverageFlashingSpeed', + ); + } + return state .set('isFlashing', false) .set('flashResults', Immutable.fromJS(action.data)) + .set( + 'lastAverageFlashingSpeed', + DEFAULT_STATE.get('lastAverageFlashingSpeed'), + ) .set('flashState', DEFAULT_STATE.get('flashState')); } diff --git a/lib/gui/app/pages/main/styles/_main.scss b/lib/gui/app/pages/main/styles/_main.scss index 3da1468b..66570361 100644 --- a/lib/gui/app/pages/main/styles/_main.scss +++ b/lib/gui/app/pages/main/styles/_main.scss @@ -165,7 +165,6 @@ img[disabled] { .target-status-line { display: flex; align-items: baseline; - margin-bottom: 9px; > .target-status-dot { width: 12px; diff --git a/lib/gui/css/main.css b/lib/gui/css/main.css index f59bef03..542c5c30 100644 --- a/lib/gui/css/main.css +++ b/lib/gui/css/main.css @@ -6347,8 +6347,7 @@ img[disabled] { .target-status-line { display: flex; - align-items: baseline; - margin-bottom: 9px; } + align-items: baseline; } .target-status-line > .target-status-dot { width: 12px; height: 12px; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 47683aed..a9465d01 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -5426,9 +5426,9 @@ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, "etcher-sdk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-3.0.0.tgz", - "integrity": "sha512-VYr7YUaGwhP53ylzXOWIIbg8TS3v0LMAJB9yRfvLdGvrtBce8cQ7JkNcLZf3e+X4YgsrgoGOqWU5nahQSpOcqQ==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/etcher-sdk/-/etcher-sdk-3.0.1.tgz", + "integrity": "sha512-Jd30W0OfKNwbQZ4NdsNLCItyPYNP3hIugJrG/V5uzBtpL4R+gldMrUopkJ1L0x59d9NwWavQ/CqM6gxrv3tVlw==", "requires": { "@ronomon/direct-io": "^3.0.1", "axios": "^0.18.0", diff --git a/package.json b/package.json index 16069d72..f95c955d 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "d3": "^4.13.0", "debug": "^3.1.0", "electron-updater": "4.0.6", - "etcher-sdk": "^3.0.0", + "etcher-sdk": "^3.0.1", "flexboxgrid": "^6.3.0", "immutable": "^3.8.1", "inactivity-timer": "^1.0.0", diff --git a/tests/gui/models/flash-state.spec.ts b/tests/gui/models/flash-state.spec.ts index c9323f71..c1af703c 100644 --- a/tests/gui/models/flash-state.spec.ts +++ b/tests/gui/models/flash-state.spec.ts @@ -36,6 +36,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -51,6 +52,7 @@ describe('Model: flashState', function() { failed: 0, percentage: 0, speed: null, + averageSpeed: null, totalSpeed: null, }); }); @@ -106,6 +108,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -126,6 +129,7 @@ describe('Model: flashState', function() { percentage: 0, eta: 15, speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -146,6 +150,7 @@ describe('Model: flashState', function() { percentage: 101, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 1, bytes: 0, position: 0, @@ -166,6 +171,7 @@ describe('Model: flashState', function() { percentage: -1, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 1, bytes: 0, position: 0, @@ -186,6 +192,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 0, speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -207,6 +214,7 @@ describe('Model: flashState', function() { // @ts-ignore eta: '15', speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -227,6 +235,7 @@ describe('Model: flashState', function() { type: 'flashing', percentage: 50, eta: 15, + averageSpeed: 0, totalSpeed: 1, bytes: 0, position: 0, @@ -247,6 +256,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 1, bytes: 0, position: 0, @@ -268,6 +278,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 1, + averageSpeed: 1, bytes: 0, position: 0, active: 0, @@ -287,6 +298,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 0, bytes: 0, position: 0, @@ -306,6 +318,7 @@ describe('Model: flashState', function() { percentage: 50.253559459485, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 1, bytes: 0, position: 0, @@ -330,6 +343,7 @@ describe('Model: flashState', function() { percentage: 0, eta: 0, speed: 0, + averageSpeed: 0, totalSpeed: 0, bytes: 0, position: 0, @@ -350,6 +364,7 @@ describe('Model: flashState', function() { percentage: 0, eta: 0, speed: 0, + averageSpeed: 0, totalSpeed: 0, bytes: 0, position: 0, @@ -386,6 +401,7 @@ describe('Model: flashState', function() { failed: 0, percentage: 0, speed: null, + averageSpeed: null, totalSpeed: null, }); }); @@ -399,6 +415,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 0, bytes: 0, position: 0, @@ -417,6 +434,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 0, + averageSpeed: 0, totalSpeed: 0, bytes: 0, position: 0, @@ -522,6 +540,7 @@ describe('Model: flashState', function() { percentage: 50, eta: 15, speed: 100000000000, + averageSpeed: 100000000000, totalSpeed: 200000000000, bytes: 0, position: 0, @@ -535,6 +554,7 @@ describe('Model: flashState', function() { failed: 0, percentage: 0, speed: 0, + averageSpeed: 0, totalSpeed: 0, }); @@ -550,6 +570,7 @@ describe('Model: flashState', function() { failed: 0, percentage: 0, speed: null, + averageSpeed: null, totalSpeed: null, }); });