|
@@ -359,6 +359,8 @@ const fs = require("fs");
|
|
|
const { ipcRenderer } = require("electron");
|
|
|
const RingBuffer = require("ringbufferjs");
|
|
|
// import RingBuffer from 'ringbufferjs'
|
|
|
+var os = require("os");
|
|
|
+var userInfo = os.userInfo();
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -553,6 +555,7 @@ export default {
|
|
|
ecgAllList: [], //心电数据部分
|
|
|
ecgSectionList: [], //心电数据全部
|
|
|
//开始脑电各个部分的数据
|
|
|
+ targetList: [],
|
|
|
},
|
|
|
userTwoLink: {
|
|
|
num: "",
|
|
@@ -561,6 +564,7 @@ export default {
|
|
|
ecgAllList: [], //心电数据部分
|
|
|
ecgSectionList: [], //心电数据全部
|
|
|
//开始脑电各个部分的数据
|
|
|
+ targetList: [],
|
|
|
},
|
|
|
//用户2的脑电变量//脑电变量
|
|
|
waveDataSecond: [],
|
|
@@ -670,6 +674,7 @@ export default {
|
|
|
//心电刷新频率控制器
|
|
|
ecgTimeFlag: null,
|
|
|
visibleFlag: true,
|
|
|
+ filePath: "",
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
@@ -759,6 +764,16 @@ export default {
|
|
|
];
|
|
|
this.gameTarget = 1;
|
|
|
}
|
|
|
+ let url = userInfo.homedir;
|
|
|
+ let downloadsUrl = url.replace(/\\/g, "/");
|
|
|
+
|
|
|
+ this.filePath = downloadsUrl + "/rzgy";
|
|
|
+ fs.exists(that.filePath, function (exists) {
|
|
|
+ // var that = this;
|
|
|
+ if (!exists) {
|
|
|
+ fs.mkdirSync(that.filePath);
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
clearTimeout(this.attentionTime);
|
|
@@ -781,8 +796,6 @@ export default {
|
|
|
methods: {
|
|
|
initHRV(event, arg) {
|
|
|
let that = this;
|
|
|
- console.log("INITHRV");
|
|
|
- console.log(arg);
|
|
|
let data1 = "";
|
|
|
//判断arg是否为空
|
|
|
if (arg === "") {
|
|
@@ -803,13 +816,20 @@ export default {
|
|
|
section: "1.5~2.0",
|
|
|
},
|
|
|
];
|
|
|
+ //当选项选选择的是心电//切按钮状态不为开始时
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userLink.targetList.push(0);
|
|
|
+ }
|
|
|
} else {
|
|
|
data1 = arg.data1;
|
|
|
//判断返回值是否包含rmssd对象
|
|
|
// data1.hasOwnProperty('rmssd')
|
|
|
- console.log(data1.hasOwnProperty("rmssd"));
|
|
|
+
|
|
|
if (data1.hasOwnProperty("rmssd")) {
|
|
|
let a = data1.rmssd.toFixed(2);
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userLink.targetList.push(a);
|
|
|
+ }
|
|
|
let b = (a - 15) * 4;
|
|
|
if (b < 0) {
|
|
|
b = 0;
|
|
@@ -836,13 +856,15 @@ export default {
|
|
|
];
|
|
|
} else {
|
|
|
this.attentionAnimation = 0;
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userLink.targetList.push(0);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
initTwoHRV(event, arg) {
|
|
|
let that = this;
|
|
|
- console.log("INITHRV");
|
|
|
- console.log(arg);
|
|
|
+
|
|
|
let data1 = "";
|
|
|
//判断arg是否为空
|
|
|
if (arg === "") {
|
|
@@ -863,13 +885,18 @@ export default {
|
|
|
section: "1.5~2.0",
|
|
|
},
|
|
|
];
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userTwoLink.targetList.push(0);
|
|
|
+ }
|
|
|
} else {
|
|
|
data1 = arg.data1;
|
|
|
//判断返回值是否包含rmssd对象
|
|
|
// data1.hasOwnProperty('rmssd')
|
|
|
- console.log(data1.hasOwnProperty("rmssd"));
|
|
|
if (data1.hasOwnProperty("rmssd")) {
|
|
|
let a = data1.rmssd.toFixed(2);
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userTwoLink.targetList.push(a);
|
|
|
+ }
|
|
|
let b = (a - 15) * 4;
|
|
|
if (b < 0) {
|
|
|
b = 0;
|
|
@@ -896,6 +923,9 @@ export default {
|
|
|
];
|
|
|
} else {
|
|
|
this.attentionSecondAnimation = 0;
|
|
|
+ if (this.equipment == 2 && this.buttonFlag == "结束") {
|
|
|
+ this.userTwoLink.targetList.push(0);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -933,7 +963,7 @@ export default {
|
|
|
ipcRenderer.send("asynchronoushrv-filter_two_ecg", cc);
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
//双人向传输数据
|
|
|
sendAtten() {
|
|
|
let one =
|
|
@@ -1970,7 +2000,7 @@ export default {
|
|
|
this.pulseTimeNum = 180;
|
|
|
//3.重置开始的按钮
|
|
|
this.buttonFlag = "开始";
|
|
|
- this.sendStart('false')
|
|
|
+ this.sendStart("false");
|
|
|
this.gameTimeTimerFlag = false;
|
|
|
//4.重置数据
|
|
|
this.resetData();
|
|
@@ -1979,7 +2009,7 @@ export default {
|
|
|
resetData() {
|
|
|
// this.send(0);
|
|
|
this.buttonFlag = "开始";
|
|
|
- this.sendStart('false')
|
|
|
+ this.sendStart("false");
|
|
|
if (this.gameTime == 1) {
|
|
|
this.gameTimeReserve = 180;
|
|
|
this.timeShow = "03:00";
|
|
@@ -2110,10 +2140,10 @@ export default {
|
|
|
let gameName = "";
|
|
|
switch (val) {
|
|
|
case "1":
|
|
|
- gameName = "心灵之火";
|
|
|
+ gameName = "天平倾斜";
|
|
|
break;
|
|
|
case "2":
|
|
|
- gameName = "心之花";
|
|
|
+ gameName = "双人奔跑";
|
|
|
break;
|
|
|
case "3":
|
|
|
gameName = "急速赛车";
|
|
@@ -2217,40 +2247,17 @@ export default {
|
|
|
//按钮状态改为结束
|
|
|
this.gameTimeTimerFlag = false;
|
|
|
this.buttonFlag = "开始";
|
|
|
- this.sendStart('false')
|
|
|
+ this.sendStart("false");
|
|
|
if (this.equipment == 1) {
|
|
|
// 保存脑电数据
|
|
|
//参数进行保存
|
|
|
- let params = {
|
|
|
- type: "2", //1表示是单人模式 2代表是双人模式
|
|
|
- num: [{ num: that.userLink.num }, { num: that.userTwoLink.num }], //个人编号
|
|
|
- gameScene: that.getGameSence(that.$route.query.gameType), //游戏场景
|
|
|
- equipmentType: "脑电", //设备类型
|
|
|
- gameDifficulty: that.getGameDiff(that.gameDifficulty), //游戏难度
|
|
|
- gameTime: that.formatterGameTime(that.gameTime), //游戏时间
|
|
|
- // animationSourceList: that.animationSourceList, //原始数据
|
|
|
- // fileName: "-",
|
|
|
- // animationTarget: "", //指标数据
|
|
|
- saveTime: that.getCurrentTimeFun(), //保存数据的时间
|
|
|
- };
|
|
|
//调用保存数据的方法
|
|
|
that.saveAnimation(params);
|
|
|
}
|
|
|
if (this.equipment == 2) {
|
|
|
// 保存心电数据
|
|
|
//参数进行保存
|
|
|
- let params = {
|
|
|
- type: "2", //1表示是单人模式 2代表是双人模式
|
|
|
- num: [{ num: that.userLink.num }, { num: that.userTwoLink.num }], //个人编号
|
|
|
- gameScene: that.getGameSence(that.$route.query.gameType), //游戏场景
|
|
|
- equipmentType: "心电", //设备类型
|
|
|
- gameDifficulty: that.getGameDiff(that.gameDifficulty), //游戏难度
|
|
|
- gameTime: that.formatterGameTime(that.gameTime), //游戏时间
|
|
|
- // animationSourceList: that.animationSourceList, //原始数据
|
|
|
- // fileName: "-",
|
|
|
- // animationTarget: "", //指标数据
|
|
|
- saveTime: that.getCurrentTimeFun(), //保存数据的时间
|
|
|
- };
|
|
|
+
|
|
|
//调用保存数据的方法
|
|
|
that.saveAnimation(params);
|
|
|
}
|
|
@@ -2259,10 +2266,292 @@ export default {
|
|
|
}, 1000);
|
|
|
},
|
|
|
//保存游戏数据
|
|
|
- saveAnimation(params) {
|
|
|
+ saveAnimation() {
|
|
|
+ let that = this;
|
|
|
+ let params = {};
|
|
|
+ //判断是脑电还是心电
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ params = {
|
|
|
+ type: "1", //1表示是单人模式 2代表是双人模式
|
|
|
+ gameScene: that.getGameSence(that.$route.query.gameType), //游戏场景
|
|
|
+ equipmentType: "脑电", //设备类型
|
|
|
+ gameDifficulty: that.getGameDiff(that.gameDifficulty), //游戏难度
|
|
|
+ gameTime: that.formatterGameTime(that.gameTime), //游戏时间
|
|
|
+ targetType: that.formatterTargetType(that.gameTargetObj), //选择的指标
|
|
|
+ //个人编号
|
|
|
+ num1: that.userLink.num, //个人编号
|
|
|
+ num2: that.userTwoLink.num, //第二个人的编号
|
|
|
+ //原始数据--但是不包括 原始信号--因为原始信号比较大,导致数据库储存查询慢
|
|
|
+ //第一个人的原始数据
|
|
|
+ animationSourceList1: JSON.stringify(that.dataHistory1()),
|
|
|
+ //第二个人的原始数据
|
|
|
+ animationSourceList2: JSON.stringify(that.dataHistory2()),
|
|
|
+ //指标数据--指的是选择指标的数据
|
|
|
+ //指标数据-- //判断当前选中过的是哪个指标,并进行指标保存
|
|
|
+ //在原始数据中其实已经保存了--在这里其实没必要保存了
|
|
|
+ //指标类型
|
|
|
+ //指标显示的数据1
|
|
|
+ animationTarget1: that.dataTarget1(), //指标数据
|
|
|
+ //显示指标数据2
|
|
|
+ animationTarget2: that.dataTarget2(), //指标数据
|
|
|
+
|
|
|
+ //文件名称表示--该文件中出储存的原始脑电原始数据
|
|
|
+ fileName1: that.dataFilename1(),
|
|
|
+ fileName2: that.dataFilename2(),
|
|
|
+
|
|
|
+ saveTime: that.getCurrentTimeFun(), //保存数据的时间
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ params = {
|
|
|
+ type: "1", //1表示是单人模式 2代表是双人模式
|
|
|
+ gameScene: that.getGameSence(that.$route.query.gameType), //游戏场景
|
|
|
+ equipmentType: "心电", //设备类型
|
|
|
+ gameDifficulty: that.getGameDiff(that.gameDifficulty), //游戏难度
|
|
|
+ gameTime: that.formatterGameTime(that.gameTime), //游戏时间
|
|
|
+ //指标类型
|
|
|
+ targetType: that.formatterTargetType(that.gameTargetObj),
|
|
|
+ //个人编号
|
|
|
+ num1: that.userLink.num, //个人编号
|
|
|
+ num2: that.userTwoLink.num, //第二个人的编号
|
|
|
+ //心电的话原始数据都在文件里进行存取
|
|
|
+ animationSourceList1: "", //原始数据
|
|
|
+ animationSourceList2: "", //原始数据
|
|
|
+
|
|
|
+ //数据传空就行了,因为原始数据已经储存到文件中去了
|
|
|
+
|
|
|
+ //指标数据进行数据保存。
|
|
|
+ animationTarget1: that.dataTarget1(), //指标数据
|
|
|
+ animationTarget2: that.dataTarget2(), //指标数据
|
|
|
+
|
|
|
+ fileName1: that.dataFilename1(),
|
|
|
+
|
|
|
+ fileName2: that.dataFilename2(),
|
|
|
+
|
|
|
+ saveTime: that.getCurrentTimeFun(), //保存数据的时间
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
console.log(params);
|
|
|
console.log("游戏和数据保存");
|
|
|
},
|
|
|
+ formatterTargetType(val) {
|
|
|
+ if (val == 1) {
|
|
|
+ return "专注度";
|
|
|
+ }
|
|
|
+ if (val == 2) {
|
|
|
+ return "放松度";
|
|
|
+ }
|
|
|
+ if (val == 3) {
|
|
|
+ return "心率变异性";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ formateDate() {
|
|
|
+ let current = new Date();
|
|
|
+ let year = this.formateNewTime(current.getFullYear());
|
|
|
+ let month = this.formateNewTime(current.getMonth() + 1);
|
|
|
+ let day = this.formateNewTime(current.getDate());
|
|
|
+ let hour = this.formateNewTime(current.getHours());
|
|
|
+ let min = this.formateNewTime(current.getMinutes());
|
|
|
+ let ss = this.formateNewTime(current.getSeconds());
|
|
|
+ let mm = this.formateNewMm(current.getMilliseconds());
|
|
|
+ return (
|
|
|
+ year +
|
|
|
+ "年" +
|
|
|
+ month +
|
|
|
+ "月" +
|
|
|
+ day +
|
|
|
+ "日" +
|
|
|
+ hour +
|
|
|
+ "时" +
|
|
|
+ min +
|
|
|
+ "分" +
|
|
|
+ ss +
|
|
|
+ "秒" +
|
|
|
+ mm
|
|
|
+ );
|
|
|
+ },
|
|
|
+ formateNewTime(val) {
|
|
|
+ if (val < 10) {
|
|
|
+ return "0" + val;
|
|
|
+ } else {
|
|
|
+ return val + "";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ formateNewMm(val) {
|
|
|
+ if (val < 10) {
|
|
|
+ return "00" + val;
|
|
|
+ } else if (val < 100) {
|
|
|
+ return "0" + val;
|
|
|
+ } else {
|
|
|
+ return val + "";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //用户1的指标数据
|
|
|
+ dataTarget1() {
|
|
|
+ let para = null;
|
|
|
+ //判断当前是脑电还是心电
|
|
|
+ //是脑电的情况下
|
|
|
+
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ //需要判断是选择的注意力指标
|
|
|
+ //还是放松度指标
|
|
|
+ //gameTarget
|
|
|
+ //专注度
|
|
|
+ if (this.gameTarget == 1) {
|
|
|
+ para = this.attentionDataAll;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ if (this.gameTarget == 2) {
|
|
|
+ para = this.meditationDataAll;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ para = this.userLink.targetList;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //用户2的指标数据
|
|
|
+ dataTarget2() {
|
|
|
+ let para = null;
|
|
|
+ //判断当前是脑电还是心电
|
|
|
+ //是脑电的情况下
|
|
|
+
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ //需要判断是选择的注意力指标
|
|
|
+ //还是放松度指标
|
|
|
+ //gameTarget
|
|
|
+ //专注度
|
|
|
+ if (this.gameTarget == 1) {
|
|
|
+ para = this.attentionDataAllSecond;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ if (this.gameTarget == 2) {
|
|
|
+ para = this.meditationDataAllSecond;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ para = this.userTwoLink.targetList;
|
|
|
+ return para;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //判断当前是脑电还是心电
|
|
|
+ dataFilename1() {
|
|
|
+ let that = this;
|
|
|
+ let fileName = "";
|
|
|
+ //当时脑电的情况下
|
|
|
+ let acount = that.userLink.num;
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ let timeStamp = that.formateDate();
|
|
|
+
|
|
|
+ fileName = acount + "-" + timeStamp + "脑电";
|
|
|
+ let test_result_tmp = that.waveDataAll;
|
|
|
+ fs.writeFile(
|
|
|
+ `${that.filePath}/${fileName}.txt`,
|
|
|
+ test_result_tmp,
|
|
|
+ "binary",
|
|
|
+ function (err) {
|
|
|
+ if (err) {
|
|
|
+ that.$message.error("失败");
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return fileName;
|
|
|
+ } else {
|
|
|
+ //心电
|
|
|
+ let timeStamp = that.formateDate();
|
|
|
+
|
|
|
+ fileName = acount + "-" + timeStamp + "心电";
|
|
|
+ let test_result_tmp = that.userLink.ecgAllList;
|
|
|
+ fs.writeFile(
|
|
|
+ `${that.filePath}/${fileName}.txt`,
|
|
|
+ test_result_tmp,
|
|
|
+ "binary",
|
|
|
+ function (err) {
|
|
|
+ if (err) {
|
|
|
+ that.$message.error("失败");
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //判断当前是脑电还是心电
|
|
|
+ dataFilename2() {
|
|
|
+ let that = this;
|
|
|
+ let fileName = "";
|
|
|
+ //当时脑电的情况下
|
|
|
+ let acount = that.userTwoLink.num;
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ let timeStamp = that.formateDate();
|
|
|
+
|
|
|
+ fileName = acount + "-" + timeStamp + "脑电";
|
|
|
+ let test_result_tmp = that.waveDataAllSecond;
|
|
|
+ fs.writeFile(
|
|
|
+ `${that.filePath}/${fileName}.txt`,
|
|
|
+ test_result_tmp,
|
|
|
+ "binary",
|
|
|
+ function (err) {
|
|
|
+ if (err) {
|
|
|
+ that.$message.error("失败");
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return fileName;
|
|
|
+ } else {
|
|
|
+ //心电
|
|
|
+ let timeStamp = that.formateDate();
|
|
|
+
|
|
|
+ fileName = acount + "-" + timeStamp + "心电";
|
|
|
+ let test_result_tmp = that.userTwoLink.ecgAllList;
|
|
|
+ fs.writeFile(
|
|
|
+ `${that.filePath}/${fileName}.txt`,
|
|
|
+ test_result_tmp,
|
|
|
+ "binary",
|
|
|
+ function (err) {
|
|
|
+ if (err) {
|
|
|
+ that.$message.error("失败");
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dataHistory1() {
|
|
|
+ let pa = {
|
|
|
+ deltaDataFlagAll: this.deltaDataFlagAll,
|
|
|
+ thetaDataAll: this.thetaDataAll,
|
|
|
+ lowAlphaDataAll: this.lowAlphaDataAll,
|
|
|
+ highAlphaDataAll: this.highAlphaDataAll,
|
|
|
+ lowBetaDataAll: this.lowBetaDataAll,
|
|
|
+ highBetaDataAll: this.highBetaDataAll,
|
|
|
+ lowGammaDataAll: this.lowGammaDataAll,
|
|
|
+ midGammaDataAll: this.midGammaDataAll,
|
|
|
+ noiseDataAll: this.noiseDataAll,
|
|
|
+ attentionDataAll: this.attentionDataAll,
|
|
|
+ meditationDataAll: this.meditationDataAll,
|
|
|
+ };
|
|
|
+ return pa;
|
|
|
+ },
|
|
|
+ dataHistory2() {
|
|
|
+ let pa = {
|
|
|
+ deltaDataFlagAll: this.deltaDataFlagAllSecond,
|
|
|
+ thetaDataAll: this.thetaDataAllSecond,
|
|
|
+ lowAlphaDataAll: this.lowAlphaDataAllSecond,
|
|
|
+ highAlphaDataAll: this.highAlphaDataAllSecond,
|
|
|
+ lowBetaDataAll: this.lowBetaDataAllSecond,
|
|
|
+ highBetaDataAll: this.highBetaDataAllSecond,
|
|
|
+ lowGammaDataAll: this.lowGammaDataAllSecond,
|
|
|
+ midGammaDataAll: this.midGammaDataAllSecond,
|
|
|
+ noiseDataAll: this.noiseDataAllSecond,
|
|
|
+ attentionDataAll: this.attentionDataAllSecond,
|
|
|
+ meditationDataAll: this.meditationDataAllSecond,
|
|
|
+ };
|
|
|
+ return pa;
|
|
|
+ },
|
|
|
startTest() {
|
|
|
//首先先判断是脑电还是脉搏
|
|
|
if (this.buttonFlag == "开始") {
|
|
@@ -2270,7 +2559,7 @@ export default {
|
|
|
//如果是脑电.则需要判断脑电是否连接
|
|
|
if (this.userLink.linkStatus && this.userTwoLink.linkStatus) {
|
|
|
this.buttonFlag = "结束";
|
|
|
- this.sendStart('true')
|
|
|
+ this.sendStart("true");
|
|
|
this.clearNaoData();
|
|
|
this.timeCom();
|
|
|
} else {
|
|
@@ -2289,12 +2578,21 @@ export default {
|
|
|
this.userTwoLink.ecgAllList = [];
|
|
|
this.userTwoLink.ecgSectionList = [];
|
|
|
this.buttonFlag = "结束";
|
|
|
- this.sendStart('true')
|
|
|
+ this.sendStart("true");
|
|
|
} else {
|
|
|
this.$message.warning("请先连接心电设备");
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if (this.buttonFlag == "结束") {
|
|
|
+ if (this.equipment == 1) {
|
|
|
+ //调用保存数据的方法
|
|
|
+ that.saveAnimation();
|
|
|
+ }
|
|
|
+ if (this.equipment == 2) {
|
|
|
+ //获取心电数据
|
|
|
+ //调用保存数据的方法
|
|
|
+ that.saveAnimation();
|
|
|
+ }
|
|
|
//改变按钮状态
|
|
|
this.clearDataFun();
|
|
|
this.resetData();
|