riku
2024-12-23 329bc53486678ea26b1b63c69299509c01677aeb
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<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-summary"
            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="84" />
            <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';
import { windDir } from '@/constant/wind-dir';
 
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];
          if (f.factorName == 'WIND_DIRECTION') {
            const avg = this.windDirAvg(f);
            list.push({
              factorId: f.factorId,
              factor: factorName[f.factorName],
              min: '-',
              max: '-',
              avg: `${avg}(${windDir(avg)})`
            });
          } else {
            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);
      });
    }
  },
  methods: {
    windDirAvg(factor) {
      let u = 0, // 东西方向分量总和
        v = 0, // 南北方向分量总和
        c = 0; // 风向数据个数
      factor.datas.forEach((value) => {
        let r = (value.factorData / 180.0) * Math.PI;
        u += Math.sin(r);
        v += Math.cos(r);
        c++;
      });
      if (c != 0) {
        const avgU = u / c;
        const avgV = v / c;
        let a = Math.atan(avgU / avgV);
        /**
         * avgU>0;avgV>0: 真实角度处于第一象限,修正值为+0°
         * avgU>0;avgV<0: 真实角度处于第二象限,修正值为+180°
         * avgU<0;avgV<0: 真实角度处于第三象限,修正值为+180°
         * avgU<0;avgV>0: 真实角度处于第四象限,修正值为+360°
         */
        a = (a * 180.0) / Math.PI;
        if (avgV > 0) {
          a += avgU > 0 ? 0 : 360;
        } else {
          a += 180;
        }
        return parseInt(a);
      } else {
        return 0;
      }
    }
  }
};
</script>
<style>
.t-row-summary {
  cursor: auto;
  background-color: transparent !important;
}
</style>
<style scoped>
.el-table {
  --el-table-row-hover-bg-color: transparent;
  --el-table-current-row-bg-color: transparent;
}
</style>