riku
2024-08-29 6b6eff08baa3d052b66fd2e68f1ac0d8495f6f8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
  <el-row justify="end">
    <el-col span="4">
      <CardButton
        name="数据统计"
        direction="left"
        @click="() => (show = !show)"
      ></CardButton>
    </el-col>
    <el-col span="20">
      <BaseCard v-show="show" direction="rigtht" borderless="r">
        <template #content>
          <!-- <el-row>
            <el-text style="color: white">数据统计</el-text>
          </el-row> -->
          <el-table
            :data="showSummary"
            v-loading="loading"
            table-layout="auto"
            size="small"
            :show-overflow-tooltip="true"
            border
            row-class-name="t-row"
            cell-class-name="t-cell"
            header-row-class-name="t-header-row"
            header-cell-class-name="t-header-cell"
          >
            <el-table-column prop="factor" label="因子" width="66" />
            <el-table-column prop="avg" label="均值" width="66" />
            <el-table-column prop="min" label="最小值" width="66" />
            <el-table-column prop="max" label="最大值" width="66" />
          </el-table>
        </template>
      </BaseCard>
    </el-col>
  </el-row>
</template>
<script>
import { FactorDatas } from '@/model/FactorDatas';
import { factorName } from '@/constant/factor-name';
 
export default {
  props: {
    loading: Boolean,
    factorDatas: FactorDatas,
    selectFactorType: Array
  },
  data() {
    return {
      show: true
    };
  },
  computed: {
    summary() {
      const list = [];
      for (const key in this.factorDatas.factor) {
        if (Object.hasOwnProperty.call(this.factorDatas.factor, key)) {
          const f = this.factorDatas.factor[key];
          let min,
            max,
            total = 0,
            count = 0;
          f.datas.forEach((v) => {
            if (!min || v.factorData < min) {
              min = v.factorData;
            }
            if (!max || v.factorData > max) {
              max = v.factorData;
            }
            total += v.factorData;
            count++;
          });
          let _avg = count == 0 ? 0 : Math.round((total / count) * 100) / 100;
          if (isNaN(_avg)) _avg = '-';
          list.push({
            factorId: f.factorId,
            factor: factorName[f.factorName],
            min,
            max,
            avg: _avg
          });
        }
      }
      return list;
    },
    showSummary() {
      return this.summary.filter((v) => {
        return this.selectFactorType.includes(v.factorId);
      });
    }
  }
};
</script>