[ML] Formatting for additional timing and model size stats (#55062) (#55415)

* [ML] formatting for additional timing and model size stats

* [ML] roundToDecimalPlace only average search time

* [ML] adjust functional tests

* [ML] remove debug tag, fix assert value

* [ML] check for no decimal place

* [ML] fix functional tests

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Dima Arnautov 2020-01-21 19:06:30 +01:00 committed by GitHub
parent dd7a204716
commit 1fa378b31f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 21 deletions

View file

@ -20,6 +20,7 @@ describe('ML - roundToDecimalPlace formatter', () => {
expect(roundToDecimalPlace(0.0005)).toBe('5.00e-4');
expect(roundToDecimalPlace(-0.0005)).toBe('-5.00e-4');
expect(roundToDecimalPlace(-12.045)).toBe(-12.04);
expect(roundToDecimalPlace(0)).toBe(0);
});
it('returns the correct format using specified decimal place', () => {
@ -31,5 +32,6 @@ describe('ML - roundToDecimalPlace formatter', () => {
expect(roundToDecimalPlace(0.0005, 4)).toBe(0.0005);
expect(roundToDecimalPlace(0.00005, 4)).toBe('5.00e-5');
expect(roundToDecimalPlace(-0.00005, 4)).toBe('-5.00e-5');
expect(roundToDecimalPlace(0, 4)).toBe(0);
});
});

View file

@ -4,7 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
export function roundToDecimalPlace(num: number, dp: number = 2) {
export function roundToDecimalPlace(num: number, dp: number = 2): number | string {
if (num % 1 === 0) {
// no decimal place
return num;
}
if (Math.abs(num) < Math.pow(10, -dp)) {
return Number.parseFloat(String(num)).toExponential(2);
}

View file

@ -6,6 +6,7 @@
import numeral from '@elastic/numeral';
import { formatDate } from '@elastic/eui/lib/services/format';
import { roundToDecimalPlace } from '../../../../formatters/round_to_decimal_place';
import { toLocaleString } from '../../../../util/string_utils';
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
@ -35,6 +36,8 @@ export function formatValues([key, value]) {
case 'established_model_memory':
case 'input_bytes':
case 'model_bytes':
case 'model_bytes_exceeded':
case 'model_bytes_memory_limit':
value = formatData(value);
break;
@ -53,9 +56,16 @@ export function formatValues([key, value]) {
case 'total_over_field_count':
case 'total_partition_field_count':
case 'bucket_allocation_failures_count':
case 'search_count':
value = toLocaleString(value);
break;
// numbers rounded to 3 decimal places
case 'average_search_time_per_bucket_ms':
case 'exponential_average_search_time_per_hour_ms':
value = typeof value === 'number' ? roundToDecimalPlace(value, 3).toLocaleString() : value;
break;
default:
break;
}

View file

@ -194,8 +194,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '10485760',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '10.0 MB',
total_by_field_count: '37',
total_over_field_count: '92',
total_partition_field_count: '8',
@ -261,8 +261,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '104857600',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '100.0 MB',
total_by_field_count: '994',
total_over_field_count: '0',
total_partition_field_count: '2',

View file

@ -60,8 +60,8 @@ export default function({ getService }: FtrProviderContext) {
return {
job_id: expectedJobId,
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '59',
total_over_field_count: '0',
total_partition_field_count: '58',

View file

@ -74,8 +74,8 @@ export default function({ getService }: FtrProviderContext) {
return {
job_id: expectedJobId,
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '8388608',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '8.0 MB',
total_by_field_count: '25',
total_over_field_count: '92',
total_partition_field_count: '3',

View file

@ -53,8 +53,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '3',
total_over_field_count: '0',
total_partition_field_count: '2',
@ -104,8 +104,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '7',
total_over_field_count: '0',
total_partition_field_count: '6',
@ -155,8 +155,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '7',
total_over_field_count: '0',
total_partition_field_count: '6',
@ -207,8 +207,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '3',
total_over_field_count: '0',
total_partition_field_count: '2',
@ -258,8 +258,8 @@ export default function({ getService }: FtrProviderContext) {
},
modelSizeStats: {
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '20971520',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '20.0 MB',
total_by_field_count: '3',
total_over_field_count: '0',
total_partition_field_count: '2',

View file

@ -59,8 +59,8 @@ export default function({ getService }: FtrProviderContext) {
return {
job_id: expectedJobId,
result_type: 'model_size_stats',
model_bytes_exceeded: '0',
model_bytes_memory_limit: '15728640',
model_bytes_exceeded: '0.0 B',
model_bytes_memory_limit: '15.0 MB',
total_by_field_count: '3',
total_over_field_count: '0',
total_partition_field_count: '2',