我正在开发一个需要不断匹配用户的rails应用程序.基本上我需要一种算法,它将用户列表作为输入,并返回最匹配的对列表.根据标准,用户被认为是良好的匹配,这些标准具有更多共同利益或它们之间的距 一般来说,我需要能够调整被认为是"良好匹配"的东西,但我只需要一个方向来寻找将需要一组用户并返回一组对的算法.
如果它有帮助,我在用户模型中有一个方法,作为另一个用户的参数,并返回sa得分有多好.我需要帮助把它用于大规模匹配.
我计划让用户进入一个表,然后经常在列表中运行一个cron作业,以找到每个人之间的最佳配对.有人有主意吗?
非常感谢!
我正在尝试生成一个网址,但即使它有效,我仍然会收到一个奇怪的警告.我正在制作一个api xml页面,我在控制器中使用以下调用:
public function executeList(sfWebRequest $request)
{
$this->users = array();
foreach($this->getRoute()->getObjects() as $user)
{
$this->users[$this->generateUrl('user_show', $user, true)] = $user->asArray($request->getHost());
}
}
Run Code Online (Sandbox Code Playgroud)
user_show路由如下:
# api urls
user_show:
url: /user/:nickname
param: { module: user, action: show }
Run Code Online (Sandbox Code Playgroud)
并且xml输出如下:
<br />
<b>Warning</b>: array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 is not an array in <b>/opt/local/lib/php/symfony/routing/sfRoute.class.php</b> on line <b>253</b><br />
<br />
<b>Warning</b>: array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 is not an array in <b>/opt/local/lib/php/symfony/routing/sfRoute.class.php</b> on line <b>253</b><br />
<br />
<b>Warning</b>: array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的api,用json响应.当我尝试从浏览器调用它时,我得到了相应的json响应,但是当我尝试从actionscript远程调用它时,似乎它试图调用json就好像它是一个方法.这是控制器动作:
def matcher
@conn = Connection.first
if(@conn)
respond_with({:conn => @conn, :status => :ok}.to_json)
else
respond_with({:status => :no_content}.to_json)
end
end
Run Code Online (Sandbox Code Playgroud)
这是接到电话时的服务器响应
Started POST "/connection/matcher/1.json" for 127.0.0.1 at 2010-11-11 22:57:24 -0800
Processing by ConnectionsController#matcher as JSON
Parameters: {"stratus_string"=>"bad1de003755eaa01a2920f0091d0dd66beaf2d34f651b09a578afb1b54e5686", "user_id"=>"1", "id"=>"1"}
Connection Load (0.5ms) SELECT "connections".* FROM "connections" LIMIT 1
Completed in 24ms
NoMethodError (undefined method `{"conn":{"created_at":"2010-11-12T06:55:13Z","id":6,"stratus_string":"474735730abe81d7622d377bd0bf816c3f94721ece3eddf670bf3a74b1c2356c","updated_at":"2010-11-12T06:55:13Z","user_id":1},"status":"ok"}_url' for #<ConnectionsController:0x000001030e4350>):
app/controllers/connections_controller.rb:7:in `matcher'
Run Code Online (Sandbox Code Playgroud)
为什么rails试图执行json响应?我不明白.
更新:
这是进行调用的actionscript代码,虽然我不明白为什么它会产生影响.
this.restService = new HTTPService();
this.restService.url = "http://localhost:3000/connection/matcher/1.json";
this.restService.method = "POST";
this.restService.addEventListener("result", onRestResult);
this.restService.addEventListener("fault", onRestFault);
var request:Object = new Object(); …Run Code Online (Sandbox Code Playgroud) 我对涉及影响DB的控制器方法的rpsec测试的行为有点困惑.我见过很多涉及POST和DELETE的rspec测试示例,人们检查是否创建或删除了对象.在大多数这些测试中,人们只需通过以下测试检查数据库中模型的计数是增加还是减少:
delete :clear_photos, :id => @album.id
@album.photos.size.should == 0
Run Code Online (Sandbox Code Playgroud)
或与lambdas:
lambda {delete :destroy, :id => @photo.id}.should change(@album.photos, :size).by(-1)
Run Code Online (Sandbox Code Playgroud)
在最后一个例子中语法并不完美,但我的观点是,根据我的经验,我需要在对象上调用reload才能通过任何这些测试,但出于某种原因,其他人能够使它们工作没有显式调用重载.每次我测试db create/destroy动作时调用重载的东西对我来说都很可疑.
谁能帮我理解发生了什么?谢谢!
实际代码更新
it "should clear all photos for an album" do
@album = Factory(:album, :photos => [Factory(:photo), Factory(:photo)])
delete :clear, :album_id => @album.id
@album.photo_count.should == 0
end
Run Code Online (Sandbox Code Playgroud)
我收到了这个回复:
'PhotosController#clear should clear all photos for an album' FAILED
expected: 0,
got: 2 (using ==)
./spec/controllers/photos_controller_spec.rb:17:
Run Code Online (Sandbox Code Playgroud)
如果我在调用photo_count之前重新加载@album,它会起作用.
我发布了类似的问题,但无法解决.我创建了一个用户和组的关系数据库,但由于某种原因,我无法正确插入测试数据.以下是架构的示例:
User:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
email: { type: string(255), notnull: true, unique: true }
nickname: { type: string(255), unique: true }
password: { type: string(300), notnull: true }
image: { type: string(255) }
Group:
actAs: { Timestampable: ~ }
columns:
name: { type: string(500), notnull: true }
image: { type: string(255) }
type: { type: string(255), notnull: true }
created_by_id: { type: integer }
relations:
User: { onDelete: SET NULL, …Run Code Online (Sandbox Code Playgroud) 我正在创建一个具有几个has_many关联的对象.关于tob构建对象的所有内容都可以正常工作,但是当我尝试测试其中一个子节点或父节点的删除时,它并没有反映在测试中.
例如:
base_article = Factory(:base_article, :articles => [Factory(:article)])
p base_article.articles.size
base_article.articles.first.destroy
p base_article.articles.size
base_article.destroyed?.should == true
Run Code Online (Sandbox Code Playgroud)
打印出:
1
1
在没有更多子项时删除基础的文章中,我正在测试回调.为什么文章关联的大小没有减少一个?
谢谢!