-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e290ab
commit 46ec58d
Showing
5 changed files
with
147 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<template> | ||
<el-button :disabled="id==0" @click="clickExportJSON"> | ||
{{ $t('profile.exportJSON') }} | ||
<el-tooltip :content="$t('profile.exportJSONTooltip')" raw-content> | ||
<el-icon v-if="local.tooltip_show"> | ||
<QuestionFilled /> | ||
</el-icon> | ||
</el-tooltip> | ||
</el-button> | ||
<el-button @click="clickExportCSV" :disabled="id==0"> | ||
{{ $t('profile.exportArbiterCSV') }} | ||
<el-tooltip :content="$t('profile.exportArbiterCSVTooltip')" raw-content> | ||
<el-icon v-if="local.tooltip_show"> | ||
<QuestionFilled /> | ||
</el-icon> | ||
</el-tooltip> | ||
</el-button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { local } from '@/store'; | ||
import useCurrentInstance from '@/utils/common/useCurrentInstance'; | ||
import { ref, watch } from 'vue'; | ||
import { httpErrorNotification } from '../Notifications'; | ||
const { proxy } = useCurrentInstance(); | ||
const data = ref([] as any[]); | ||
const progress = ref(0); | ||
const status = ref(""); | ||
const text = ref("") | ||
const prop = defineProps({ | ||
id: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
}) | ||
watch(prop, ()=>{data.value=[]}); | ||
async function fetchData(id: number) { | ||
await proxy.$axios.get('video/query_by_id', | ||
{ | ||
params: { | ||
id: id, | ||
} | ||
} | ||
).then(function(response){ | ||
data.value = response.data | ||
}).catch(httpErrorNotification) | ||
} | ||
function generateArbiterCSV(data: any) { | ||
if (!data) return ""; | ||
let csvdata = ['Day,Month,Year,Hour,Min,Sec,mode,Time,BBBV,BBBVs,style,cell0,cell1,cell2,cell3,cell4,cell5,cell6,cell7,cell8,Lcl,Rcl,Dcl,Leff,Reff,Deff,Openings,Islands,Path,GZiNi,HZiNi'] | ||
for (let v of data) { | ||
if (v.mode != 'std' && v.mode != 'nf') continue; | ||
let date = new Date(v.upload_time); | ||
let row: any[] = [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()]; | ||
switch (v.level) { | ||
case 'e': row.push(3); break; | ||
case 'i': row.push(2); break; | ||
case 'b': row.push(1); break; | ||
default: console.error('未知级别'); | ||
} | ||
row.push((v.timems / 1000).toFixed(2)); | ||
row.push(v.bv); | ||
row.push(v.bvs.toFixed(2)); | ||
if (v.video__flag == 0) row.push('NF'); | ||
else row.push('Flag'); | ||
row.push(v.video__cell0, v.video__cell1, v.video__cell2, v.video__cell3, v.video__cell4, v.video__cell5, v.video__cell6, v.video__cell7, v.video__cell8) | ||
row.push(v.video__left, v.video__right, v.video__double, 0, 0, 0) | ||
row.push(v.video__op, v.video__isl) | ||
row.push(Math.round(v.video__path)) | ||
row.push(0, 0) | ||
csvdata.push(row.join()) | ||
} | ||
return csvdata.join('\n'); | ||
} | ||
// Credit: ChatGPT | ||
function downloadCSV(csv: string) { | ||
if (csv==="") return; | ||
// Create a Blob from the CSV data | ||
const blob = new Blob([csv], { type: 'text/csv' }); | ||
const url = URL.createObjectURL(blob); | ||
// Create a temporary anchor element | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = 'stats_csv.csv'; // Set the file name | ||
// Append the anchor to the body | ||
document.body.appendChild(a); | ||
a.click(); // Trigger the download | ||
document.body.removeChild(a); // Remove the anchor after download | ||
// Release the object URL | ||
URL.revokeObjectURL(url); | ||
} | ||
function downloadJSON(json: string) { | ||
if (json==="") return; | ||
// Create a Blob from the CSV data | ||
const blob = new Blob([json], { type: 'text/json' }); | ||
const url = URL.createObjectURL(blob); | ||
// Create a temporary anchor element | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = 'stats_json.json'; // Set the file name | ||
// Append the anchor to the body | ||
document.body.appendChild(a); | ||
a.click(); // Trigger the download | ||
document.body.removeChild(a); // Remove the anchor after download | ||
// Release the object URL | ||
URL.revokeObjectURL(url); | ||
} | ||
async function clickExportCSV() { | ||
if (data.value.length===0) await fetchData(prop.id); | ||
if (data.value.length===0) return; | ||
downloadCSV(generateArbiterCSV(data.value)); | ||
} | ||
async function clickExportJSON() { | ||
if (data.value.length===0) await fetchData(prop.id); | ||
if (data.value.length===0) return; | ||
downloadJSON(JSON.stringify(data.value)) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters