这里我附加了我的代码,我传递完成回调并使用supertest请求.因为我在request.end块中的testcase中使用assert/expect,为什么我需要担心超时?我在这里犯的是什么错误.
it('should get battle results ', function(done) {
request(url)
.post('/compare?vf_id='+vf_id)
.set('access_token',access_token)
.send(battleInstance)
.end(function(err, res){ // why need timeout
if (err) return done(err);
console.log(JSON.stringify(res.body));
expect(res.body.status).to.deep.equal('SUCCESS');
done();
});
});
Run Code Online (Sandbox Code Playgroud)
响应后的测试用例结果:错误:超出2000ms的超时.确保在此测试中调用done()回调.
如果我使用mocha命令运行我的测试用例,那么它显示此错误,而如果我正在运行测试, mocha --timeout 15000 则testcase正确传递.但我想避免超时,我该怎么做?
我有以下场景:我在Rails应用程序中导入了一些CSV,并且数据集的大小可能超过10万行,这意味着使用了大量内存 - 我在服务器上没有这些内存.
每个CSV代表一个表转储.
现在,我的问题是我需要在几个表中导入数据,通过外键维护关系.
到目前为止我所做的大致是这样的:
find_or_initialize,尽可能使用属性,或执行model.where({complicated conditions}) || model.create({complicated conditions})保存创建的对象之类的操作CSV id=>DB id在complicated conditions语句中可以放置保存在以前的表中并缓存的一些ID.
看看在这里的代码,了解更多详情.
注意:我需要的upsert不仅仅是一个平原insert.
我已经尝试过的一些优化:
crewaitgem =>比普通AR快,但比事务慢model.skip_callbacks(:create) =>加速或内存改进不明显user在所有其他表中广泛使用的模型=>高内存使用和慢速(?!)id要使用较少内存的属性=>速度/内存不会有很大差异我看过的其他东西却无法弄清楚如何使用:
crewait但就我尝试而言它并不能很好地工作activerecord-import:导入速度更快,但我会失去所有关系或CSV到数据库ID映射upsert:我已经看过了,但我想用它作为最后的手段(这有点棘手恕我直言).任何建议,关于如何改进的建议都是非常受欢迎的:谈论工具,图书馆,战略等等.
更新这是我所拥有的CSV的简化示例:
lings.csv
------------------------
| id | name | depth |
------------------------
| 0 | English | …Run Code Online (Sandbox Code Playgroud) 我正在使用 NetworkX 制作图表以导出以使用 Gephi 进行可视化。我一直在向图中的节点添加各种属性,没有问题,直到我尝试添加颜色。有谁知道如何使用 networkx 导出带有“彩色”节点的图形?(我一直在写一个 gexf 文件,但只要它与 Gephi 兼容,我不在乎它是否是另一种格式。)
这是我制作图表的代码:
def construct_weighted_graph(nodes, distance_dict, weighting_function, color = True):
G = nx.Graph()
#nodes automatically added when edges added.
for sequence in nodes: #loop through and add size attribute for num of sequences
G.add_node(sequence)
G.node[sequence]['size'] = distance_dict[sequence][1] #size represented by the node
if color:
G.node[sequence]['color'] = (0,1,0)
for i_node1 in range(len(nodes)):
dist_list = distance_dict[nodes[i_node1]][-2] #list of distances
for i_node2 in range(i_node1+1, len(nodes)):
G.add_edge(nodes[i_node1], nodes[i_node2],
weight = weighting_function(dist_list[i_node2]))
return G
Run Code Online (Sandbox Code Playgroud)
这不是我对颜色的确切要求,因为不同的节点被分配了不同的颜色,但这是基本思想。