This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch bug/e2e
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking-ui.git


The following commit(s) were added to refs/heads/bug/e2e by this push:
     new 6f4630e  Fix #138 add a new avg function to filter 0 value
6f4630e is described below

commit 6f4630e3ce3e00b1f27c80db250fe3f56da51b8f
Author: hanahmily <hanahm...@gmail.com>
AuthorDate: Thu Mar 8 15:24:39 2018 +0800

    Fix #138 add a new avg function to filter 0 value
---
 mock/server.js                    |  4 +-
 src/routes/Dashboard/Dashboard.js |  3 +-
 src/routes/Server/Server.js       | 12 +++---
 src/routes/Service/Service.js     |  9 ++---
 src/utils/utils.js                | 79 +++------------------------------------
 5 files changed, 19 insertions(+), 88 deletions(-)

diff --git a/mock/server.js b/mock/server.js
index 55a859a..7a63465 100644
--- a/mock/server.js
+++ b/mock/server.js
@@ -43,10 +43,10 @@ export default {
       {
         data: {
           getServerResponseTimeTrend: {
-            'trendList|60': ['@natural(100, 1000)'],
+            'trendList|60': ['@natural(0, 1000)'],
           },
           getServerTPSTrend: {
-            'trendList|60': ['@natural(500, 10000)'],
+            'trendList|60': ['@natural(0, 10000)'],
           },
           getCPUTrend: {
             'cost|60': ['@natural(0, 99)'],
diff --git a/src/routes/Dashboard/Dashboard.js 
b/src/routes/Dashboard/Dashboard.js
index 45be094..5470750 100644
--- a/src/routes/Dashboard/Dashboard.js
+++ b/src/routes/Dashboard/Dashboard.js
@@ -23,6 +23,7 @@ import {
   ChartCard, Pie, MiniArea, Field,
 } from '../../components/Charts';
 import { axis } from '../../utils/time';
+import { avgTimeSeries } from '../../utils/utils';
 import { Panel, Ranking } from '../../components/Page';
 
 @connect(state => ({
@@ -47,7 +48,7 @@ export default class Dashboard extends PureComponent {
     let min = 0;
     if (numOfAlarmRate && numOfAlarmRate.length > 0) {
       visitData = axis(this.props.duration, numOfAlarmRate, ({ x, y }) => ({ 
x, y: y / accuracy }));
-      avg = numOfAlarmRate.reduce((acc, curr) => acc + curr) / 
numOfAlarmRate.length / accuracy;
+      avg = avgTimeSeries(numOfAlarmRate) / accuracy;
       max = numOfAlarmRate.reduce((acc, curr) => { return acc < curr ? curr : 
acc; }) / accuracy;
       min = numOfAlarmRate.reduce((acc, curr) => { return acc > curr ? curr : 
acc; }) / accuracy;
     }
diff --git a/src/routes/Server/Server.js b/src/routes/Server/Server.js
index e6dca2b..51a7f13 100644
--- a/src/routes/Server/Server.js
+++ b/src/routes/Server/Server.js
@@ -24,6 +24,7 @@ import {
 } from '../../components/Charts';
 import DescriptionList from '../../components/DescriptionList';
 import { axis } from '../../utils/time';
+import { avgTimeSeries } from '../../utils/utils';
 import { Panel, Search } from '../../components/Page';
 
 const { Description } = DescriptionList;
@@ -65,8 +66,6 @@ export default class Server extends PureComponent {
       payload: { variables },
     });
   }
-  avg = list => (list.length > 0 ?
-    parseFloat((list.reduce((acc, curr) => acc + curr) / 
list.length).toFixed(2)) : 0)
   bytesToMB = list => list.map(_ => parseFloat((_ / (1024 ** 2)).toFixed(2)))
   render() {
     const { form, duration, server } = this.props;
@@ -108,17 +107,18 @@ export default class Server extends PureComponent {
         >
           <Card title="Info" style={{ marginTop: 24 }} bordered={false}>
             <DescriptionList>
-              <Description term="OS">{serverInfo.name}</Description>
+              <Description term="Application 
Code">{serverInfo.applicationCode}</Description>
               <Description term="Host Name">{serverInfo.host}</Description>
-              <Description term="Process Id">{serverInfo.pid}</Description>
               <Description term="IPv4">{serverInfo.ipv4 ? 
serverInfo.ipv4.join() : ''}</Description>
+              <Description term="Process Id">{serverInfo.pid}</Description>
+              <Description term="OS">{serverInfo.name}</Description>
             </DescriptionList>
           </Card>
           <Row gutter={24}>
             <Col xs={24} sm={24} md={24} lg={12} xl={12} style={{ marginTop: 
24 }}>
               <ChartCard
                 title="Avg Response Time"
-                total={`${this.avg(getServerResponseTimeTrend.trendList)} ms`}
+                total={`${avgTimeSeries(getServerResponseTimeTrend.trendList)} 
ms`}
                 contentHeight={46}
               >
                 {getServerResponseTimeTrend.trendList.length > 0 ? (
@@ -133,7 +133,7 @@ export default class Server extends PureComponent {
             <Col xs={24} sm={24} md={24} lg={12} xl={12} style={{ marginTop: 
24 }}>
               <ChartCard
                 title="Avg Calls Per Second"
-                total={`${this.avg(getServerTPSTrend.trendList)} ms`}
+                total={`${avgTimeSeries(getServerTPSTrend.trendList)} cps`}
               >
                 <MiniBar
                   animate={false}
diff --git a/src/routes/Service/Service.js b/src/routes/Service/Service.js
index 0583c5e..5bc7014 100644
--- a/src/routes/Service/Service.js
+++ b/src/routes/Service/Service.js
@@ -23,6 +23,7 @@ import {
   ChartCard, MiniArea, MiniBar, Sankey,
 } from '../../components/Charts';
 import { axis } from '../../utils/time';
+import { avgTimeSeries } from '../../utils/utils';
 import { Panel, Search } from '../../components/Page';
 
 const { Item: FormItem } = Form;
@@ -63,8 +64,6 @@ export default class Service extends PureComponent {
       payload: { variables },
     });
   }
-  avg = list => (list.length > 0 ?
-    (list.reduce((acc, curr) => acc + curr) / list.length).toFixed(2) : 0)
   renderSankey = (data) => {
     if (data.nodes.length < 2) {
       return <span style={{ display: 'none' }} />;
@@ -135,7 +134,7 @@ export default class Service extends PureComponent {
             <Col xs={24} sm={24} md={24} lg={8} xl={8} style={{ marginTop: 24 
}}>
               <ChartCard
                 title="Avg Throughout"
-                total={`${this.avg(getServiceTPSTrend.trendList)}`}
+                total={`${avgTimeSeries(getServiceTPSTrend.trendList)}`}
                 contentHeight={46}
               >
                 <MiniArea
@@ -147,7 +146,7 @@ export default class Service extends PureComponent {
             <Col xs={24} sm={24} md={24} lg={8} xl={8} style={{ marginTop: 24 
}}>
               <ChartCard
                 title="Avg Response Time"
-                total={`${this.avg(getServiceResponseTimeTrend.trendList)} ms`}
+                
total={`${avgTimeSeries(getServiceResponseTimeTrend.trendList)} ms`}
                 contentHeight={46}
               >
                 <MiniArea
@@ -158,7 +157,7 @@ export default class Service extends PureComponent {
             <Col xs={24} sm={24} md={24} lg={8} xl={8} style={{ marginTop: 24 
}}>
               <ChartCard
                 title="Avg SLA"
-                total={`${this.avg(getServiceSLATrend.trendList) / 100} %`}
+                total={`${(avgTimeSeries(getServiceSLATrend.trendList) / 
100).toFixed(2)} %`}
               >
                 <MiniBar
                   animate={false}
diff --git a/src/utils/utils.js b/src/utils/utils.js
index fbacd0c..402a618 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -16,55 +16,15 @@
  */
 
 
-import moment from 'moment';
-
 export function fixedZero(val) {
   return val * 1 < 10 ? `0${val}` : val;
 }
 
-export function getTimeDistance(type) {
-  const now = new Date();
-  const oneDay = 1000 * 60 * 60 * 24;
-
-  if (type === 'today') {
-    now.setHours(0);
-    now.setMinutes(0);
-    now.setSeconds(0);
-    return [moment(now), moment(now.getTime() + (oneDay - 1000))];
-  }
-
-  if (type === 'week') {
-    let day = now.getDay();
-    now.setHours(0);
-    now.setMinutes(0);
-    now.setSeconds(0);
-
-    if (day === 0) {
-      day = 6;
-    } else {
-      day -= 1;
-    }
-
-    const beginTime = now.getTime() - (day * oneDay);
-
-    return [moment(beginTime), moment(beginTime + ((7 * oneDay) - 1000))];
-  }
-
-  if (type === 'month') {
-    const year = now.getFullYear();
-    const month = now.getMonth();
-    const nextDate = moment(now).add(1, 'months');
-    const nextYear = nextDate.year();
-    const nextMonth = nextDate.month();
-
-    return [moment(`${year}-${fixedZero(month + 1)}-01 00:00:00`), 
moment(moment(`${nextYear}-${fixedZero(nextMonth + 1)}-01 00:00:00`).valueOf() 
- 1000)];
-  }
-
-  if (type === 'year') {
-    const year = now.getFullYear();
-
-    return [moment(`${year}-01-01 00:00:00`), moment(`${year}-12-31 
23:59:59`)];
-  }
+export function avgTimeSeries(list) {
+  const filteredList = list.filter(_ => _ > 0);
+  return filteredList.length > 0 ?
+    parseFloat((filteredList.reduce(
+      (acc, curr) => acc + curr) / filteredList.length).toFixed(2)) : 0;
 }
 
 export function getPlainNode(nodeList, parentPath = '') {
@@ -85,33 +45,6 @@ export function getPlainNode(nodeList, parentPath = '') {
   return arr;
 }
 
-export function digitUppercase(n) {
-  const fraction = ['角', '分'];
-  const digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
-  const unit = [
-    ['元', '万', '亿'],
-    ['', '拾', '佰', '仟'],
-  ];
-  let num = Math.abs(n);
-  let s = '';
-  fraction.forEach((item, index) => {
-    s += (digit[Math.floor(num * 10 * (10 ** index)) % 10] + 
item).replace(/零./, '');
-  });
-  s = s || '整';
-  num = Math.floor(num);
-  for (let i = 0; i < unit[0].length && num > 0; i += 1) {
-    let p = '';
-    for (let j = 0; j < unit[1].length && num > 0; j += 1) {
-      p = digit[num % 10] + unit[1][j] + p;
-      num = Math.floor(num / 10);
-    }
-    s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
-  }
-
-  return s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, 
'零元整');
-}
-
-
 function getRelation(str1, str2) {
   if (str1 === str2) {
     console.warn('Two path are equal!');  // eslint-disable-line
@@ -131,9 +64,7 @@ function getRenderArr(routes) {
   renderArr.push(routes[0]);
   for (let i = 1; i < routes.length; i += 1) {
     let isAdd = false;
-    // 是否包含
     isAdd = renderArr.every(item => getRelation(item, routes[i]) === 3);
-    // 去重
     renderArr = renderArr.filter(item => getRelation(item, routes[i]) !== 1);
     if (isAdd) {
       renderArr.push(routes[i]);

-- 
To stop receiving notification emails like this one, please contact
hanahm...@apache.org.

Reply via email to