{"action":"created","comment":{"url":"https://api.github.com/repos/cyclus/cyclus/pulls/comments/28791691","id":28791691,"diff_hunk":"@@ -0,0 +1,114 @@\n+#include \"buy_policy.h\"\n+\n+#include \"error.h\"\n+\n+#define LG(X) LOG(LEV_##X, \"buypol\")\n+#define LGH(X)                                               \\\n+  LOG(LEV_##X, \"buypol\") << \"policy \" << name_ << \" (agent \" \\\n+                         << manager()->id() << \"): \"\n+\n+namespace cyclus {\n+namespace toolkit {\n+\n+BuyPolicy::BuyPolicy() : Trader(NULL) {\n+  Warn<EXPERIMENTAL_WARNING>(\n+      \"BuyPolicy is experimental and its API may be subject to change\");\n+}\n+\n+BuyPolicy::~BuyPolicy() { manager()->context()->UnregisterTrader(this); }\n+\n+BuyPolicy& BuyPolicy::Init(Agent* manager, ResourceBuff* buf, std::string name,\n+                           double quantize) {\n+  manager_ = manager;\n+  buf_ = buf;\n+  quantize_ = quantize;\n+  name_ = name;\n+  return *this;\n+}\n+\n+BuyPolicy& BuyPolicy::Set(std::string commod, Composition::Ptr c, double pref) {\n+  CommodDetail d;\n+  d.comp = c;\n+  d.pref = pref;\n+  commods_[commod] = d;\n+  return *this;\n+}\n+\n+void BuyPolicy::Start() { manager()->context()->RegisterTrader(this); }\n+\n+void BuyPolicy::Stop() { manager()->context()->UnregisterTrader(this); }\n+\n+std::map<Material::Ptr, std::string> BuyPolicy::Commods() {\n+  return rsrc_commod_;\n+};\n+\n+std::set<RequestPortfolio<Material>::Ptr> BuyPolicy::GetMatlRequests() {\n+  rsrc_commod_.clear();\n+  std::set<RequestPortfolio<Material>::Ptr> ports;\n+  double amt = buf_->space();\n+  if (amt < eps()) {\n+    return ports;\n+  }\n+\n+  double quanta = quantize_;\n+  bool exclusive = true;\n+  if (quantize_ < 0) {\n+    exclusive = false;\n+    quanta = amt;\n+  }\n+\n+  LGH(INFO3) << \"requesting \" << amt << \" kg\";\n+\n+  RequestPortfolio<Material>::Ptr port(new RequestPortfolio<Material>());","path":"src/toolkit/buy_policy.cc","position":62,"original_position":62,"commit_id":"983626945c722b39c3bf85d5d58d3b968a938c5e","original_commit_id":"983626945c722b39c3bf85d5d58d3b968a938c5e","user":{"login":"mbmcgarry","id":8630709,"avatar_url":"https://avatars.githubusercontent.com/u/8630709?v=3","gravatar_id":"","url":"https://api.github.com/users/mbmcgarry","html_url":"https://github.com/mbmcgarry","followers_url":"https://api.github.com/users/mbmcgarry/followers","following_url":"https://api.github.com/users/mbmcgarry/following{/other_user}","gists_url":"https://api.github.com/users/mbmcgarry/gists{/gist_id}","starred_url":"https://api.github.com/users/mbmcgarry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbmcgarry/subscriptions","organizations_url":"https://api.github.com/users/mbmcgarry/orgs","repos_url":"https://api.github.com/users/mbmcgarry/repos","events_url":"https://api.github.com/users/mbmcgarry/events{/privacy}","received_events_url":"https://api.github.com/users/mbmcgarry/received_events","type":"User","site_admin":false},"body":"Indent?","created_at":"2015-04-21T15:48:43Z","updated_at":"2015-04-21T15:48:43Z","html_url":"https://github.com/cyclus/cyclus/pull/1047#discussion_r28791691","pull_request_url":"https://api.github.com/repos/cyclus/cyclus/pulls/1047","_links":{"self":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/comments/28791691"},"html":{"href":"https://github.com/cyclus/cyclus/pull/1047#discussion_r28791691"},"pull_request":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/1047"}}},"pull_request":{"url":"https://api.github.com/repos/cyclus/cyclus/pulls/1047","id":24622198,"html_url":"https://github.com/cyclus/cyclus/pull/1047","diff_url":"https://github.com/cyclus/cyclus/pull/1047.diff","patch_url":"https://github.com/cyclus/cyclus/pull/1047.patch","issue_url":"https://api.github.com/repos/cyclus/cyclus/issues/1047","number":1047,"state":"open","locked":false,"title":"implement basic buy and sell policies","user":{"login":"rwcarlsen","id":1351242,"avatar_url":"https://avatars.githubusercontent.com/u/1351242?v=3","gravatar_id":"","url":"https://api.github.com/users/rwcarlsen","html_url":"https://github.com/rwcarlsen","followers_url":"https://api.github.com/users/rwcarlsen/followers","following_url":"https://api.github.com/users/rwcarlsen/following{/other_user}","gists_url":"https://api.github.com/users/rwcarlsen/gists{/gist_id}","starred_url":"https://api.github.com/users/rwcarlsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwcarlsen/subscriptions","organizations_url":"https://api.github.com/users/rwcarlsen/orgs","repos_url":"https://api.github.com/users/rwcarlsen/repos","events_url":"https://api.github.com/users/rwcarlsen/events{/privacy}","received_events_url":"https://api.github.com/users/rwcarlsen/received_events","type":"User","site_admin":false},"body":"The only thing really missing here is tests.  I'm not sure of a *good* way to effectively test this API other than creating a full fake mock resource exchange that calls these functions and carefully checks through returned portfolios, etc.  I would be happy to have help writing the tests.  I won't have much time soon ;-)","created_at":"2014-11-18T16:07:35Z","updated_at":"2015-04-21T15:48:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d8648d4e169cd368c48893ca7e472a79583e120","assignee":null,"milestone":{"url":"https://api.github.com/repos/cyclus/cyclus/milestones/31","html_url":"https://github.com/cyclus/cyclus/milestones/v1.3","labels_url":"https://api.github.com/repos/cyclus/cyclus/milestones/31/labels","id":879142,"number":31,"title":"v1.3","description":"","creator":{"login":"scopatz","id":320553,"avatar_url":"https://avatars.githubusercontent.com/u/320553?v=3","gravatar_id":"","url":"https://api.github.com/users/scopatz","html_url":"https://github.com/scopatz","followers_url":"https://api.github.com/users/scopatz/followers","following_url":"https://api.github.com/users/scopatz/following{/other_user}","gists_url":"https://api.github.com/users/scopatz/gists{/gist_id}","starred_url":"https://api.github.com/users/scopatz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scopatz/subscriptions","organizations_url":"https://api.github.com/users/scopatz/orgs","repos_url":"https://api.github.com/users/scopatz/repos","events_url":"https://api.github.com/users/scopatz/events{/privacy}","received_events_url":"https://api.github.com/users/scopatz/received_events","type":"User","site_admin":false},"open_issues":43,"closed_issues":42,"state":"open","created_at":"2014-11-24T23:27:16Z","updated_at":"2015-04-15T19:29:11Z","due_on":"2015-03-01T06:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/cyclus/cyclus/pulls/1047/commits","review_comments_url":"https://api.github.com/repos/cyclus/cyclus/pulls/1047/comments","review_comment_url":"https://api.github.com/repos/cyclus/cyclus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cyclus/cyclus/issues/1047/comments","statuses_url":"https://api.github.com/repos/cyclus/cyclus/statuses/983626945c722b39c3bf85d5d58d3b968a938c5e","head":{"label":"rwcarlsen:policy","ref":"policy","sha":"983626945c722b39c3bf85d5d58d3b968a938c5e","user":{"login":"rwcarlsen","id":1351242,"avatar_url":"https://avatars.githubusercontent.com/u/1351242?v=3","gravatar_id":"","url":"https://api.github.com/users/rwcarlsen","html_url":"https://github.com/rwcarlsen","followers_url":"https://api.github.com/users/rwcarlsen/followers","following_url":"https://api.github.com/users/rwcarlsen/following{/other_user}","gists_url":"https://api.github.com/users/rwcarlsen/gists{/gist_id}","starred_url":"https://api.github.com/users/rwcarlsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwcarlsen/subscriptions","organizations_url":"https://api.github.com/users/rwcarlsen/orgs","repos_url":"https://api.github.com/users/rwcarlsen/repos","events_url":"https://api.github.com/users/rwcarlsen/events{/privacy}","received_events_url":"https://api.github.com/users/rwcarlsen/received_events","type":"User","site_admin":false},"repo":{"id":3349921,"name":"cyclus","full_name":"rwcarlsen/cyclus","owner":{"login":"rwcarlsen","id":1351242,"avatar_url":"https://avatars.githubusercontent.com/u/1351242?v=3","gravatar_id":"","url":"https://api.github.com/users/rwcarlsen","html_url":"https://github.com/rwcarlsen","followers_url":"https://api.github.com/users/rwcarlsen/followers","following_url":"https://api.github.com/users/rwcarlsen/following{/other_user}","gists_url":"https://api.github.com/users/rwcarlsen/gists{/gist_id}","starred_url":"https://api.github.com/users/rwcarlsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwcarlsen/subscriptions","organizations_url":"https://api.github.com/users/rwcarlsen/orgs","repos_url":"https://api.github.com/users/rwcarlsen/repos","events_url":"https://api.github.com/users/rwcarlsen/events{/privacy}","received_events_url":"https://api.github.com/users/rwcarlsen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rwcarlsen/cyclus","description":"the meat","fork":true,"url":"https://api.github.com/repos/rwcarlsen/cyclus","forks_url":"https://api.github.com/repos/rwcarlsen/cyclus/forks","keys_url":"https://api.github.com/repos/rwcarlsen/cyclus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rwcarlsen/cyclus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rwcarlsen/cyclus/teams","hooks_url":"https://api.github.com/repos/rwcarlsen/cyclus/hooks","issue_events_url":"https://api.github.com/repos/rwcarlsen/cyclus/issues/events{/number}","events_url":"https://api.github.com/repos/rwcarlsen/cyclus/events","assignees_url":"https://api.github.com/repos/rwcarlsen/cyclus/assignees{/user}","branches_url":"https://api.github.com/repos/rwcarlsen/cyclus/branches{/branch}","tags_url":"https://api.github.com/repos/rwcarlsen/cyclus/tags","blobs_url":"https://api.github.com/repos/rwcarlsen/cyclus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rwcarlsen/cyclus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rwcarlsen/cyclus/git/refs{/sha}","trees_url":"https://api.github.com/repos/rwcarlsen/cyclus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rwcarlsen/cyclus/statuses/{sha}","languages_url":"https://api.github.com/repos/rwcarlsen/cyclus/languages","stargazers_url":"https://api.github.com/repos/rwcarlsen/cyclus/stargazers","contributors_url":"https://api.github.com/repos/rwcarlsen/cyclus/contributors","subscribers_url":"https://api.github.com/repos/rwcarlsen/cyclus/subscribers","subscription_url":"https://api.github.com/repos/rwcarlsen/cyclus/subscription","commits_url":"https://api.github.com/repos/rwcarlsen/cyclus/commits{/sha}","git_commits_url":"https://api.github.com/repos/rwcarlsen/cyclus/git/commits{/sha}","comments_url":"https://api.github.com/repos/rwcarlsen/cyclus/comments{/number}","issue_comment_url":"https://api.github.com/repos/rwcarlsen/cyclus/issues/comments{/number}","contents_url":"https://api.github.com/repos/rwcarlsen/cyclus/contents/{+path}","compare_url":"https://api.github.com/repos/rwcarlsen/cyclus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rwcarlsen/cyclus/merges","archive_url":"https://api.github.com/repos/rwcarlsen/cyclus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rwcarlsen/cyclus/downloads","issues_url":"https://api.github.com/repos/rwcarlsen/cyclus/issues{/number}","pulls_url":"https://api.github.com/repos/rwcarlsen/cyclus/pulls{/number}","milestones_url":"https://api.github.com/repos/rwcarlsen/cyclus/milestones{/number}","notifications_url":"https://api.github.com/repos/rwcarlsen/cyclus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rwcarlsen/cyclus/labels{/name}","releases_url":"https://api.github.com/repos/rwcarlsen/cyclus/releases{/id}","created_at":"2012-02-04T01:10:37Z","updated_at":"2015-04-20T17:21:38Z","pushed_at":"2015-04-20T17:21:48Z","git_url":"git://github.com/rwcarlsen/cyclus.git","ssh_url":"git@github.com:rwcarlsen/cyclus.git","clone_url":"https://github.com/rwcarlsen/cyclus.git","svn_url":"https://github.com/rwcarlsen/cyclus","homepage":"cyclus.github.com","size":16805,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"develop"}},"base":{"label":"cyclus:develop","ref":"develop","sha":"4e001a966ddb92079dff00d8173baea29b9b729a","user":{"login":"cyclus","id":1355686,"avatar_url":"https://avatars.githubusercontent.com/u/1355686?v=3","gravatar_id":"","url":"https://api.github.com/users/cyclus","html_url":"https://github.com/cyclus","followers_url":"https://api.github.com/users/cyclus/followers","following_url":"https://api.github.com/users/cyclus/following{/other_user}","gists_url":"https://api.github.com/users/cyclus/gists{/gist_id}","starred_url":"https://api.github.com/users/cyclus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyclus/subscriptions","organizations_url":"https://api.github.com/users/cyclus/orgs","repos_url":"https://api.github.com/users/cyclus/repos","events_url":"https://api.github.com/users/cyclus/events{/privacy}","received_events_url":"https://api.github.com/users/cyclus/received_events","type":"Organization","site_admin":false},"repo":{"id":3308958,"name":"cyclus","full_name":"cyclus/cyclus","owner":{"login":"cyclus","id":1355686,"avatar_url":"https://avatars.githubusercontent.com/u/1355686?v=3","gravatar_id":"","url":"https://api.github.com/users/cyclus","html_url":"https://github.com/cyclus","followers_url":"https://api.github.com/users/cyclus/followers","following_url":"https://api.github.com/users/cyclus/following{/other_user}","gists_url":"https://api.github.com/users/cyclus/gists{/gist_id}","starred_url":"https://api.github.com/users/cyclus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyclus/subscriptions","organizations_url":"https://api.github.com/users/cyclus/orgs","repos_url":"https://api.github.com/users/cyclus/repos","events_url":"https://api.github.com/users/cyclus/events{/privacy}","received_events_url":"https://api.github.com/users/cyclus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cyclus/cyclus","description":"The Cyclus Nuclear Fuel Cycle Simulator","fork":false,"url":"https://api.github.com/repos/cyclus/cyclus","forks_url":"https://api.github.com/repos/cyclus/cyclus/forks","keys_url":"https://api.github.com/repos/cyclus/cyclus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cyclus/cyclus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cyclus/cyclus/teams","hooks_url":"https://api.github.com/repos/cyclus/cyclus/hooks","issue_events_url":"https://api.github.com/repos/cyclus/cyclus/issues/events{/number}","events_url":"https://api.github.com/repos/cyclus/cyclus/events","assignees_url":"https://api.github.com/repos/cyclus/cyclus/assignees{/user}","branches_url":"https://api.github.com/repos/cyclus/cyclus/branches{/branch}","tags_url":"https://api.github.com/repos/cyclus/cyclus/tags","blobs_url":"https://api.github.com/repos/cyclus/cyclus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cyclus/cyclus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cyclus/cyclus/git/refs{/sha}","trees_url":"https://api.github.com/repos/cyclus/cyclus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cyclus/cyclus/statuses/{sha}","languages_url":"https://api.github.com/repos/cyclus/cyclus/languages","stargazers_url":"https://api.github.com/repos/cyclus/cyclus/stargazers","contributors_url":"https://api.github.com/repos/cyclus/cyclus/contributors","subscribers_url":"https://api.github.com/repos/cyclus/cyclus/subscribers","subscription_url":"https://api.github.com/repos/cyclus/cyclus/subscription","commits_url":"https://api.github.com/repos/cyclus/cyclus/commits{/sha}","git_commits_url":"https://api.github.com/repos/cyclus/cyclus/git/commits{/sha}","comments_url":"https://api.github.com/repos/cyclus/cyclus/comments{/number}","issue_comment_url":"https://api.github.com/repos/cyclus/cyclus/issues/comments{/number}","contents_url":"https://api.github.com/repos/cyclus/cyclus/contents/{+path}","compare_url":"https://api.github.com/repos/cyclus/cyclus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cyclus/cyclus/merges","archive_url":"https://api.github.com/repos/cyclus/cyclus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cyclus/cyclus/downloads","issues_url":"https://api.github.com/repos/cyclus/cyclus/issues{/number}","pulls_url":"https://api.github.com/repos/cyclus/cyclus/pulls{/number}","milestones_url":"https://api.github.com/repos/cyclus/cyclus/milestones{/number}","notifications_url":"https://api.github.com/repos/cyclus/cyclus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cyclus/cyclus/labels{/name}","releases_url":"https://api.github.com/repos/cyclus/cyclus/releases{/id}","created_at":"2012-01-30T21:16:54Z","updated_at":"2015-04-21T15:31:10Z","pushed_at":"2015-04-21T15:31:10Z","git_url":"git://github.com/cyclus/cyclus.git","ssh_url":"git@github.com:cyclus/cyclus.git","clone_url":"https://github.com/cyclus/cyclus.git","svn_url":"https://github.com/cyclus/cyclus","homepage":"http://fuelcycle.org/","size":28421,"stargazers_count":21,"watchers_count":21,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":29,"mirror_url":null,"open_issues_count":58,"forks":29,"open_issues":58,"watchers":21,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/1047"},"html":{"href":"https://github.com/cyclus/cyclus/pull/1047"},"issue":{"href":"https://api.github.com/repos/cyclus/cyclus/issues/1047"},"comments":{"href":"https://api.github.com/repos/cyclus/cyclus/issues/1047/comments"},"review_comments":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/1047/comments"},"review_comment":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cyclus/cyclus/pulls/1047/commits"},"statuses":{"href":"https://api.github.com/repos/cyclus/cyclus/statuses/983626945c722b39c3bf85d5d58d3b968a938c5e"}}}}