Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决matplot绘制过慢 #14

Open
laiqun opened this issue Jul 10, 2019 · 8 comments
Open

解决matplot绘制过慢 #14

laiqun opened this issue Jul 10, 2019 · 8 comments

Comments

@laiqun
Copy link
Owner

laiqun commented Jul 10, 2019

之前的代码

x=np.asarray(label_value)
				y=np.arange(len(label_value))
				fig=plt.figure()
				plt.plot(x,y)
				plt.show()

是这样的

xit=iter(label_value)
				yit=iter(np.arange(len(label_value)))
				#x=np.asarray(label_value)
				x=np.fromiter(xit,dtype=int)
				y=np.fromiter(yit,dtype=int)
				
				fig=plt.figure()
				plt.plot(x,y)
				plt.savefig("D:/temp.png")
				plt.show()

改了之后是这样的

图形秒出

我明白了

类似于range 和xrange

@laiqun
Copy link
Owner Author

laiqun commented Oct 9, 2019

首先要理解promise:
https://www.liaoxuefeng.com/wiki/1022910821149312/1023024413276544
promise表示函数立即执行,然后用then和catch传入成功和错误处理的函数。
然后理解generate:
fun*(){
while(true){
yield;
}
}
g = fun(); //g是一个generate对象,然后每次调用g.next都会执行到yield返回。
3. async 和await
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
await会把后面的东西强制转换为Promise,当其变为fulfullied的时候,函数向下执行。调用resolve或reject是必须的。此时resove代表这个函数的next执行。await的返回值,就是resolve中传入的参数。

async function aa()
{
	console.log("aa");
	await new Promise(resolve=>{  setTimeout(  ()=>{console.log("xx");resolve("ok");},10   )});
	console.log("bb");
}

@laiqun
Copy link
Owner Author

laiqun commented Oct 30, 2019

"google.com, pub-8319785630586631, DIRECT, f08c47fec0942fa0"

@laiqun
Copy link
Owner Author

laiqun commented Jan 20, 2020

@laiqun
Copy link
Owner Author

laiqun commented Feb 27, 2020

(async() => {
await setLocalStorage({ aaa: 1, bbb: 2 });

let aaa = await getLocalStorage("aaa");
let bbb = await getLocalStorage("bbb");
let all = await getLocalStorage();

console.log(aaa);// 1
console.log(bbb);// 2
console.log(all);// {aaa: 1, bbb: 2}

})();

function setLocalStorage(obj) {
return new Promise( (resolve) => {
chrome.storage.local.set( obj, () => resolve() );
});
}

function getLocalStorage(key = null) {
return new Promise( (resolve) => {
chrome.storage.local.get(key, (item) => {
key ? resolve(item[key]) : resolve(item);
});
});
}

@laiqun
Copy link
Owner Author

laiqun commented Feb 27, 2020

for (let i =0;i<8;i++)
chrome.tabs.create({"active":false,'url':"http://127.0.0.1/"+i});
let newTabsId=[];
let tabsState ={};//ready ; wait两种选项
chrome.tabs.onCreated.addListener(function(tab) {
newTabsId.push(tab.id);
newTabsId["tab.id"] = "ready";
if(newTabsId.length == 8)//8个tab已经创建完成,开始浏览页面
{
for (const iterator of newTabsId) {
chrome.tabs.update(iterator,{url:"http://127.0.0.1/"+iterator});
//只要打开url即可,content script 会自动把数据抓好,给background
//content script怎么知道数据可以抛了呢?
//发信息确认一下后台的stage
}
}
});
//爬完后关闭所有的tab
for (const iterator of newTabsId) {
chrome.tabs.remove(iterator);
}

// 监听来自content-script的消息
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
console.log('收到来自content-script的消息:');
console.log(request, sender, sendResponse);
sendResponse('我是后台,我已收到你的消息:' + JSON.stringify(request));
//可以得知哪个url已经完成,如果完成,那就把该标签卡的状态,设置为ready,表示可以接下一次任务了

});

@laiqun
Copy link
Owner Author

laiqun commented Feb 27, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant