Skip to content

Commit

Permalink
改了bug,界面也改了点
Browse files Browse the repository at this point in the history
1、不知道怎么把 从服务端返回的两个准确率值 传到js里面去 再异步刷新显示到界面上 
2、还要把测试的详细信息给做出来
  • Loading branch information
999Yy999 committed May 10, 2020
1 parent febf947 commit b407aad
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public String testpage(){
public String test(String time, int fre, int sample, Model model){
//完成搜索功能
//List<HashMap<String, Object>> audios=audioService.search(filename);
double[] zql=audioService.test(time, fre, sample);
//model.addAttribute("audios", audios);
//double[] zql=audioService.test(time, fre, sample);
HashMap<String,Object> zql=audioService.test(time, fre, sample);
model.addAttribute("zqls", zql);
System.out.println("time:"+time+",fre:"+fre+",sample:"+sample);

return "result";
//return "result";
return "redirect:test";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface AudioService {

public void startrecord();

public double[] test(String time, int fre, int sample);
public HashMap<String, Object> test(String time, int fre, int sample);

//List<HashMap<String, Object>> search(String filename, float[] data1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ public List<HashMap<String,Object>> search(String filename, float[] data1) {
e.printStackTrace();
}
int[] id = search(linkTime, linkHash, minHit);
/*if (id[i]<0){
System.out.println("--------------------------error!--id="+id);
if (id==null){
System.out.println("--------------------------时间太短 或噪声太大,未提取出指纹!--");
return null;
}
else{*/
for (int i=0; i<3; i++){
System.out.println("----------------------------id="+id[i]+",");
}
Expand Down Expand Up @@ -134,10 +133,15 @@ public List<HashMap<String,Object>> search(String filename, float[] data1) {

public int[] search(int[] linkTime, int[] linkHash, int minHit){
HashMap<Integer,Integer> linkHashMap = new HashMap<>(linkHash.length);
System.out.println("---------fingerprint parameter length:"+linkHash.length);
for(int i = 0; i < linkHash.length; i ++){ //client端 hash,time
//System.out.println("-------linkHash["+i+"]"+"="+linkHash[i]);
linkHashMap.put(linkHash[i],linkTime[i]);
}
hashMap = new HashMap<>(400000);
if (linkHash.length==0){
return null;
}
List<HashTable> audios= audioMapper.searchAllAudios(linkHash);
for (int i=0; i<audios.size(); i++){
int hash = audios.get(i).getHash();
Expand Down Expand Up @@ -184,6 +188,7 @@ public int compare(HashMap.Entry<Long, Integer> o1, HashMap.Entry<Long, Integer>

public void setHashTime(Fingerprint fp){
ArrayList<Fingerprint.Link> linkList = fp.getLinkList();
//System.out.println("---------fingerprint length:"+linkList.size());
linkHash = new int[linkList.size()]; //159
linkTime = new int[linkList.size()];
for(int i = 0; i < linkHash.length; i ++){
Expand Down Expand Up @@ -264,7 +269,7 @@ public void startrecord(){
}*/

@Override
public double[] test(String time, int fre, int sample) {
public HashMap<String, Object> test(String time, int fre, int sample) {
int maxmusicdata=239; //音乐库最大歌曲数
int success1=0, success2=0, failure1=0, failure2=0; //记录器
String path="D:\\Z_毕设\\音频素材\\wav";
Expand Down Expand Up @@ -308,6 +313,7 @@ public double[] test(String time, int fre, int sample) {
List<HashMap<String, Object>> audios=search(filename,data);
// 测试结果与源文件(名称+歌手+专辑)对比
int flag=0; //判断是否在top3
if (audios==null) {continue;}
System.out.println("-------------audios.size()="+audios.size());
if (audios.size()==1){
String title=(String) audios.get(0).get("title");
Expand Down Expand Up @@ -336,9 +342,10 @@ public double[] test(String time, int fre, int sample) {

Map<String, Object> map = audios.get(k);
Iterator iterator = map.keySet().iterator();
title=(String) map.get("title");
while (iterator.hasNext()) {
String string = (String) iterator.next();
System.out.println("string:"+string);
//System.out.println("string:"+string);
if (j==1){
artist=map.get(string).toString();
}
Expand All @@ -356,8 +363,11 @@ public double[] test(String time, int fre, int sample) {
if (samerate>maxrate){
maxrate=samerate;
maxartist=artist;
//System.out.println("-------------maxartist赋值成功:"+maxartist);
maxalbum=album;
maxtitle=title;
//System.out.println("-------------maxartist赋值成功:"+maxalbum);
maxtitle=title; //上面为它赋值了,这段代码改下,不需要用迭代器,直接用属性当键取值
//System.out.println("-------------maxartist赋值成功:"+maxtitle);
}
}
j++;
Expand Down Expand Up @@ -388,8 +398,11 @@ public double[] test(String time, int fre, int sample) {
zql[1]=success2*1.0/sample;
System.out.println("----------zql1="+zql[0]+" = "+success1+"/"+sample);
System.out.println("----------zql2="+zql[1]+" = "+success2+"/"+sample);
HashMap<String, Object> zqlmap = new HashMap<>();
zqlmap.put("zql1", zql[0]);
zqlmap.put("zql2", zql[1]);

return zql;
return zqlmap;
}

// 2.模拟生成fre频率的白噪声
Expand Down
1 change: 1 addition & 0 deletions NewAudioR/src/main/webapp/WEB-INF/jsp/searchpage.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<tbody id="tbody">

</tbody>

</table>
</div>
</fieldset>
Expand Down
18 changes: 11 additions & 7 deletions NewAudioR/src/main/webapp/WEB-INF/jsp/test.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<link rel="stylesheet" href="${css }/filter.css">
<script defer src="${fonts }/js/fontawesome-all.js"></script>
<script src="${js }/jquery.js"></script>
<!-- inserting these scripts at the end to be able to use all the elements in the DOM -->
<script src="https://cdn.rawgit.com/mattdiamond/Recorderjs/08e7abd9/dist/recorder.js"></script>
<script src="${js }/testresult.js"></script>
<script type="text/javascript" src="${js }/jquery-1.8.2.js"></script>
<!--
<script>
Expand All @@ -42,7 +39,7 @@
<div id="content">
<h1><span class="icon"><i class="fa fa-filter"></i></span> Test</h1>
<p>
<form action="test" method="POST">
<!-- form action="test" method="POST"> -->
<fieldset>
<fieldset id="filter" class="ft">
<legend>Search word</legend>
Expand Down Expand Up @@ -73,10 +70,10 @@
<div class="filter" id="testing">
<i class="fa fa-search"></i>
</div>
<input class="filter" id="formsubmit" type="submit" value="Test" style="width: 1028px;" />
<!-- input class="filter" id="formsubmit" type="submit" value="Test" style="width: 1028px;" /> -->
</p>
</fieldset>
</form>
<!-- </form> -->
</p>

<h1><span class="icon"><i class="fa fa-filter"></i></span> Results </h1>
Expand All @@ -86,15 +83,22 @@
<tr>
<th>编号</th>
<th>时长</th>
<th width="40%">噪音频率</th>
<th>噪音频率</th>
<th>测试样例数</th>
<th>操作</th>
<th>测试准确率1</th>
<th>测试准确率2</th>
<th>详细</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>

<a>
${zqls.zql1 } ${zqls.zql2 }
</a>
</div>
</div>
<script src="${js }/testresult.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions NewAudioR/src/main/webapp/resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function createDownloadLink(blob) {
//name of .wav file to use during upload and download (without extendion)
var filename = new Date().toISOString();

//add controls to the <audio> element
//add controls to the <audio> element这些都可以删掉
au.controls = true;
au.src = url;

Expand Down Expand Up @@ -175,7 +175,7 @@ function createDownloadLink(blob) {
xhr.open("POST","record2local",true);
xhr.send(fd);
})*/
var upload = document.createElement('button');
/*var upload = document.createElement('button');
//upload.href="#";
upload.innerHTML = "Upload";
upload.addEventListener("click", function(event){
Expand All @@ -198,7 +198,7 @@ function createDownloadLink(blob) {
li.appendChild(upload)//add the upload link to li
//add the li element to the ol
recordingsList.appendChild(li);
recordingsList.appendChild(li);*/
}

var num=0;
Expand Down
57 changes: 39 additions & 18 deletions NewAudioR/src/main/webapp/resources/js/testresult.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,81 @@

var testing = document.getElementById("testing");
var stopButton = document.getElementById("stopButton");
var pauseButton = document.getElementById("pauseButton");

//add events to those 2 buttons
testing.addEventListener("click", testing);
testing.addEventListener("click", formsubmit);

function formsubmit() {
console.log("formsubmit clicked");

//新建一行
add();
}


var num=0;
function add(blob){
var req;
function add(){
num++;
var tr=document.createElement("tr");
// 新建一项
// 1.新建一项
var id=document.createElement("td");
var dur=document.createElement("td");
var noise=document.createElement("td");
var sample=document.createElement("td");
var zql1=document.createElement("td");
var zql2=document.createElement("td");
var exec=document.createElement("td");

id.innerHTML=num;
dur.innerHTML=document.getElementByName("time");
noise.innerHTML=document.getElementByName("fre");
sample.innerHTML=document.getElementByName("sample");

var time = $('input[name=time]:checked').val();
var fre = $('input[name=fre]:checked').val();
var samplenum = $('input[name=sample]:checked').val();

// 2.填内容
dur.innerHTML=time;
noise.innerHTML=fre;
sample.innerHTML=samplenum;

var tab=document.getElementById("table");
var tbody=document.getElementById("tbody");
tbody.appendChild(tr);
//id加到表里
// 3.id加到表里
tr.appendChild(id);
tr.appendChild(dur);
tr.appendChild(noise);
tr.appendChild(sample);

var test = getElementById("testing");
//var upload = document.createElement('a');

req="test?time="+time+"&fre="+fre+"&sample="+samplenum;
alert(req);
var exectest = document.createElement('a');
//upload.href="#";
//upload.innerHTML = "Search";
test.addEventListener("click", function(event){
exectest.innerHTML = "开始测试";
exectest.addEventListener("click", function(event){
var xhr=new XMLHttpRequest();
alert("1:"+xhr.status);
//设置响应返回的数据格式
//xhr.responseType = "document";
//注册相关事件回调处理函数,onload当请求成功完成时触发,此时xhr.readystate=4
xhr.onload=function(e) {
alert("2:"+xhr.status);
if(this.readyState === 4) {
alert("3:"+xhr.status);
console.log("Server returned: ",e.target.responseText);
//document.getElementById("results").innerHTML=e.target.responseText;
console.log("allheaders: ",xhr.getAllResponseHeaders());

$.get("test", function(data) {
alert("zql1:" + data.zql + "\nzql2:" + data.zql);
});
}
};
xhr.open("POST","test",true); //异步
})
alert("4:"+xhr.status);
//打开连接
xhr.open("POST",req,true); //异步
//发送请求 必须有send
xhr.send();
});
tr.appendChild(exec);
exec.appendChild(exectest);

}
Binary file modified NewAudioR/target/classes/com/audio/controller/AudioController.class
Binary file not shown.
Binary file modified NewAudioR/target/classes/com/audio/service/AudioService.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed May 06 08:50:06 CST 2020
#Sat May 09 22:05:52 CST 2020
version=0.0.1-SNAPSHOT
groupId=com.audio
m2e.projectName=NewAudioR
Expand Down

0 comments on commit b407aad

Please sign in to comment.