|
@@ -0,0 +1,129 @@
|
|
|
|
|
+import { toCSV, downloadCSV } from '@/utils/downloadCVS'
|
|
|
|
|
+import { useSiteModeDataStore } from '@/stores/modules/data/siteModeData'
|
|
|
|
|
+import { useSitePowerFlowDataStore } from '@/stores/modules/data/sitePowerFlowData'
|
|
|
|
|
+import type { SitePowerFlow } from '@/views/sites-monitor/interface'
|
|
|
|
|
+
|
|
|
|
|
+interface CsvRow {
|
|
|
|
|
+ id: number
|
|
|
|
|
+ sn: string
|
|
|
|
|
+ rates: string
|
|
|
|
|
+ description: string
|
|
|
|
|
+ '9-5(Weekday)': string
|
|
|
|
|
+ '9-6(Weekend)': string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const siteModeDataStore = useSiteModeDataStore()
|
|
|
|
|
+const sitePowerFlowDataStore = useSitePowerFlowDataStore()
|
|
|
|
|
+
|
|
|
|
|
+const getPowerFlowData = async (site: string, date: string) => {
|
|
|
|
|
+ let powerData = sitePowerFlowDataStore.powerFlowGet(site, date)
|
|
|
|
|
+ if (powerData === undefined) {
|
|
|
|
|
+ await sitePowerFlowDataStore.queryPowerFlow(site, date)
|
|
|
|
|
+ powerData = sitePowerFlowDataStore.powerFlowGet(site, date)
|
|
|
|
|
+ }
|
|
|
|
|
+ return powerData
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const analysisPowerFlow = (data: SitePowerFlow | undefined, start: number, end: number): string => {
|
|
|
|
|
+ if (data === undefined) return '无数据'
|
|
|
|
|
+ if (data.powerFhpArray === undefined) return '无数据'
|
|
|
|
|
+ if (data.powerFhpArray === null) return '无数据'
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = start; i <= end; i++) {
|
|
|
|
|
+ if (data.powerFhpArray.length <= i) return '数据不全'
|
|
|
|
|
+
|
|
|
|
|
+ const power = data.powerFhpArray[i]
|
|
|
|
|
+ if (power < 4) {
|
|
|
|
|
+ if (i - start < 6) {
|
|
|
|
|
+ return '未放电'
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return '放电不足'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return '正常放电'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const getRatesDescriptionAndAnalysis = async (
|
|
|
|
|
+ sn: string,
|
|
|
|
|
+ rate: string | undefined,
|
|
|
|
|
+): Promise<{
|
|
|
|
|
+ description: string
|
|
|
|
|
+ analysis5: string
|
|
|
|
|
+ analysis6: string
|
|
|
|
|
+}> => {
|
|
|
|
|
+ console.log({ rate })
|
|
|
|
|
+ if (rate === 'E-ELEC (NBT 2025)') {
|
|
|
|
|
+ const p5 = await getPowerFlowData(sn, '2025-09-05')
|
|
|
|
|
+ const p6 = await getPowerFlowData(sn, '2025-09-06')
|
|
|
|
|
+ return {
|
|
|
|
|
+ description: '9月份每天放电',
|
|
|
|
|
+ analysis5: analysisPowerFlow(p5, 230, 238), // 230 - 19:10, 238 - 19: 50
|
|
|
|
|
+ analysis6: analysisPowerFlow(p6, 230, 238),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (rate === 'TOU-D-PRIME (NBT 2025)') {
|
|
|
|
|
+ return {
|
|
|
|
|
+ description: '9月不放电',
|
|
|
|
|
+ analysis5: '无需放电',
|
|
|
|
|
+ analysis6: '无需放电',
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (rate === 'EV-TOU-5 (NBT 2025)') {
|
|
|
|
|
+ const p6 = await getPowerFlowData(sn, '2025-09-06')
|
|
|
|
|
+ return {
|
|
|
|
|
+ description: '9月节假日放电',
|
|
|
|
|
+ analysis5: '无需放电',
|
|
|
|
|
+ analysis6: analysisPowerFlow(p6, 218, 238), // 218 - 18:10, 238 - 19: 50
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ description: '',
|
|
|
|
|
+ analysis5: rate ?? '',
|
|
|
|
|
+ analysis6: rate ?? '',
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const createNbtResult = async (siteList: string[]): Promise<CsvRow[]> => {
|
|
|
|
|
+ let resCsv: CsvRow[] = []
|
|
|
|
|
+ for (const [index, site] of siteList.entries()) {
|
|
|
|
|
+ // 加载站点工作模式
|
|
|
|
|
+ let modeInfo = siteModeDataStore.siteModeInfoGet(site)
|
|
|
|
|
+ let modeName: string | undefined
|
|
|
|
|
+ modeInfo ??= await siteModeDataStore.querySiteModeInfo(site)
|
|
|
|
|
+ if (modeInfo !== undefined) {
|
|
|
|
|
+ const currentId = modeInfo.currendId
|
|
|
|
|
+ modeInfo.list.forEach((item) => {
|
|
|
|
|
+ if (item.id === currentId) {
|
|
|
|
|
+ modeName = `${item.name}`
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const res = await getRatesDescriptionAndAnalysis(site, modeName)
|
|
|
|
|
+
|
|
|
|
|
+ resCsv.push({
|
|
|
|
|
+ id: index + 1,
|
|
|
|
|
+ sn: site,
|
|
|
|
|
+ rates: modeName ?? 'unknown',
|
|
|
|
|
+ description: res.description,
|
|
|
|
|
+ '9-5(Weekday)': res.analysis5,
|
|
|
|
|
+ '9-6(Weekend)': res.analysis6,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ return resCsv
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export const DownloadNbtCsv = async (siteList: string[]) => {
|
|
|
|
|
+ const data = await createNbtResult(siteList)
|
|
|
|
|
+ downloadCSV(
|
|
|
|
|
+ '9月份NBT放电结果.csv',
|
|
|
|
|
+ toCSV(data, {
|
|
|
|
|
+ headers: ['id', 'sn', 'rates', 'description', '9-5(Weekday)', '9-6(Weekend)'], // 指定列顺序(可选)
|
|
|
|
|
+ includeHeader: true,
|
|
|
|
|
+ }),
|
|
|
|
|
+ )
|
|
|
|
|
+}
|