|
@@ -254,41 +254,54 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
//最低有效频率
|
|
//最低有效频率
|
|
|
float minValidFrequency = 20;
|
|
float minValidFrequency = 20;
|
|
|
|
|
|
|
|
- //有效音频数量
|
|
|
|
|
- float validNum = 0;
|
|
|
|
|
- //音频有效阈值
|
|
|
|
|
- float validDuty = 0.1f;
|
|
|
|
|
-
|
|
|
|
|
//音准匹配数量
|
|
//音准匹配数量
|
|
|
float intonationNum = 0;
|
|
float intonationNum = 0;
|
|
|
//音准匹配误差范围
|
|
//音准匹配误差范围
|
|
|
float intonationErrRange = 15;
|
|
float intonationErrRange = 15;
|
|
|
//音准有效阈值
|
|
//音准有效阈值
|
|
|
- float intonationValidDuty = 0.3f;
|
|
|
|
|
|
|
+ float intonationValidDuty = 0.1f;
|
|
|
|
|
|
|
|
//节奏匹配数量
|
|
//节奏匹配数量
|
|
|
float cadenceNum = 0;
|
|
float cadenceNum = 0;
|
|
|
//节奏匹配误差范围
|
|
//节奏匹配误差范围
|
|
|
float cadenceErrRange = 30;
|
|
float cadenceErrRange = 30;
|
|
|
//节奏有效阈值
|
|
//节奏有效阈值
|
|
|
- float cadenceValidDuty = 0.6f;
|
|
|
|
|
|
|
+ float cadenceValidDuty = 0.1f;
|
|
|
|
|
+
|
|
|
|
|
+ //完整性数量
|
|
|
|
|
+ float integrityNum = 0;
|
|
|
|
|
+ //完整性误差范围
|
|
|
|
|
+ float integrityRange = 30;
|
|
|
|
|
+ //完整性有效阈值
|
|
|
|
|
+ float integrityValidDuty = 0.5f;
|
|
|
|
|
|
|
|
int totalCompareNum = userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex).size();
|
|
int totalCompareNum = userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex).size();
|
|
|
|
|
|
|
|
for (MusicPitchDetailDto musicXmlInfo : userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex)) {
|
|
for (MusicPitchDetailDto musicXmlInfo : userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex)) {
|
|
|
- int ot = (int) (musicXmlInfo.getDuration()*0.1);
|
|
|
|
|
- int startTimeStamp = musicXmlInfo.getTimeStamp() - ot + userSoundInfoMap.get(phone).getOffsetTime();
|
|
|
|
|
- int endTimeStamp = musicXmlInfo.getTimeStamp() + ot + musicXmlInfo.getDuration() + userSoundInfoMap.get(phone).getOffsetTime();
|
|
|
|
|
|
|
+ int ot5 = (int) (musicXmlInfo.getDuration()*0.1);
|
|
|
|
|
+ int startTimeStamp = musicXmlInfo.getTimeStamp() - ot5 + userSoundInfoMap.get(phone).getOffsetTime();
|
|
|
|
|
+ int endTimeStamp = musicXmlInfo.getTimeStamp() + ot5 + musicXmlInfo.getDuration() + userSoundInfoMap.get(phone).getOffsetTime();
|
|
|
|
|
|
|
|
//时间范围内有效音准数量
|
|
//时间范围内有效音准数量
|
|
|
float recordValidIntonationNum = 0;
|
|
float recordValidIntonationNum = 0;
|
|
|
//时间范围内有效节奏数量
|
|
//时间范围内有效节奏数量
|
|
|
float cadenceValidNum = 0;
|
|
float cadenceValidNum = 0;
|
|
|
//时间范围内有效音频数量
|
|
//时间范围内有效音频数量
|
|
|
- float recordValidNum = 0;
|
|
|
|
|
|
|
+ float integrityValidNum = 0;
|
|
|
//时间范围内匹配次数
|
|
//时间范围内匹配次数
|
|
|
float compareNum = 0;
|
|
float compareNum = 0;
|
|
|
- for (MusicPitchDetailDto recordInfo : userSoundInfoMap.get(phone).getRecordMeasurePithInfo()) {
|
|
|
|
|
|
|
+ int faultNum = 0;
|
|
|
|
|
+ for (int i = 0; i < userSoundInfoMap.get(phone).getRecordMeasurePithInfo().size(); i++) {
|
|
|
|
|
+ MusicPitchDetailDto recordInfo = userSoundInfoMap.get(phone).getRecordMeasurePithInfo().get(i);
|
|
|
|
|
+ if(recordInfo.getTimeStamp()>(startTimeStamp-ot5)&&Math.abs((recordInfo.getFrequency()-musicXmlInfo.getFrequency()))>20){
|
|
|
|
|
+ faultNum++;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if(faultNum<6)
|
|
|
|
|
+ faultNum = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(faultNum<6){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
//如果在时间范围之外直接跳过
|
|
//如果在时间范围之外直接跳过
|
|
|
if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>endTimeStamp){
|
|
if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>endTimeStamp){
|
|
|
continue;
|
|
continue;
|
|
@@ -299,37 +312,43 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(recordInfo.getFrequency()<minValidFrequency&&musicXmlInfo.getFrequency()!=-1){
|
|
if(recordInfo.getFrequency()<minValidFrequency&&musicXmlInfo.getFrequency()!=-1){
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- recordValidNum++;
|
|
|
|
|
|
|
+ cadenceValidNum++;
|
|
|
|
|
+ if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>endTimeStamp){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
//如果频率差值在节奏误差范围内
|
|
//如果频率差值在节奏误差范围内
|
|
|
- if(Math.abs(recordInfo.getFrequency()-musicXmlInfo.getFrequency())<=cadenceErrRange){
|
|
|
|
|
- cadenceValidNum++;
|
|
|
|
|
|
|
+ if(Math.abs(recordInfo.getFrequency()-musicXmlInfo.getFrequency())<=integrityRange){
|
|
|
|
|
+ integrityValidNum++;
|
|
|
}
|
|
}
|
|
|
//如果频率差值在音准误差范围内
|
|
//如果频率差值在音准误差范围内
|
|
|
if(Math.abs(recordInfo.getFrequency()-musicXmlInfo.getFrequency())<=intonationErrRange){
|
|
if(Math.abs(recordInfo.getFrequency()-musicXmlInfo.getFrequency())<=intonationErrRange){
|
|
|
recordValidIntonationNum++;
|
|
recordValidIntonationNum++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+// for (MusicPitchDetailDto recordInfo : userSoundInfoMap.get(phone).getRecordMeasurePithInfo()) {
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
//有效音频占比
|
|
//有效音频占比
|
|
|
- float recordValidDuty = recordValidNum/compareNum;
|
|
|
|
|
- if(recordValidDuty<validDuty){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- validNum++;
|
|
|
|
|
|
|
+ float integrityDuty = integrityValidNum/compareNum;
|
|
|
//有效音高占比
|
|
//有效音高占比
|
|
|
float intonationDuty = recordValidIntonationNum/compareNum;
|
|
float intonationDuty = recordValidIntonationNum/compareNum;
|
|
|
//有效节奏占比
|
|
//有效节奏占比
|
|
|
float cadenceDuty = cadenceValidNum/compareNum;
|
|
float cadenceDuty = cadenceValidNum/compareNum;
|
|
|
- if(intonationDuty>=intonationValidDuty){
|
|
|
|
|
- intonationNum++;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //节奏
|
|
|
if(cadenceDuty>=cadenceValidDuty){
|
|
if(cadenceDuty>=cadenceValidDuty){
|
|
|
cadenceNum++;
|
|
cadenceNum++;
|
|
|
|
|
+ if(intonationDuty>=intonationValidDuty){
|
|
|
|
|
+ intonationNum++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(integrityDuty>=integrityValidDuty){
|
|
|
|
|
+ integrityNum++;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
intonation = new BigDecimal(intonationNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
intonation = new BigDecimal(intonationNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
cadence = new BigDecimal(cadenceNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
cadence = new BigDecimal(cadenceNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
- integrity = new BigDecimal(validNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
+ integrity = new BigDecimal(integrityNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
} catch (ArithmeticException e){
|
|
} catch (ArithmeticException e){
|
|
|
LOGGER.info("无musicXml信息");
|
|
LOGGER.info("无musicXml信息");
|
|
|
}
|
|
}
|
|
@@ -379,7 +398,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(currentCompareNum>0){
|
|
if(currentCompareNum>0){
|
|
|
intonation = userSoundInfoMap.get(phone).getUserScoreMap().get("intonation").divide(new BigDecimal(currentCompareNum), 0, BigDecimal.ROUND_DOWN);
|
|
intonation = userSoundInfoMap.get(phone).getUserScoreMap().get("intonation").divide(new BigDecimal(currentCompareNum), 0, BigDecimal.ROUND_DOWN);
|
|
|
cadence = userSoundInfoMap.get(phone).getUserScoreMap().get("cadence").divide(new BigDecimal(currentCompareNum), 0, BigDecimal.ROUND_DOWN);
|
|
cadence = userSoundInfoMap.get(phone).getUserScoreMap().get("cadence").divide(new BigDecimal(currentCompareNum), 0, BigDecimal.ROUND_DOWN);
|
|
|
- integrity = new BigDecimal(currentCompareNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
|
+ integrity = userSoundInfoMap.get(phone).getUserScoreMap().get("integrity").divide(new BigDecimal(currentCompareNum), 0, BigDecimal.ROUND_DOWN);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("overall", -1, intonation, cadence, integrity))));
|
|
WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("overall", -1, intonation, cadence, integrity))));
|
|
@@ -407,7 +426,8 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
webSocketInfo.setHeader(header);
|
|
webSocketInfo.setHeader(header);
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
// BigDecimal score = intonation.multiply(new BigDecimal(0.5)).add(cadence.multiply(new BigDecimal(0.5))).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
// BigDecimal score = intonation.multiply(new BigDecimal(0.5)).add(cadence.multiply(new BigDecimal(0.5))).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
- BigDecimal score = intonation.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
|
+ BigDecimal score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+// BigDecimal score = intonation.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
result.put("score", score);
|
|
result.put("score", score);
|
|
|
result.put("intonation", intonation);
|
|
result.put("intonation", intonation);
|
|
|
result.put("cadence", cadence);
|
|
result.put("cadence", cadence);
|