所以我正在尝试一下D3's geo stream API,事情感觉有点模糊.我一直在阅读这里的文档:
https://github.com/mbostock/d3/wiki/Geo-Streams
我遇到的一个困惑是流转换的正确实现.假设我创建了一个:
//a stream transform that applies a simple translate [20,5]:
var transform = d3.geo.transform({
point:function(){this.stream.point(x+20,y+5)}
})
Run Code Online (Sandbox Code Playgroud)
根据文档,this.stream引用"包装流".但是什么是流,真的吗?从我可以收集到的,它更多的是一个过程而不是显式数据结构 - 一系列数据和函数调用来转换数据.上面的语法似乎表明包装流只是包含" 流监听器 " 的对象
继续,我可以使用投影方法应用流变换:
//a path generator with the transform applied using the projection() method
var path = d3.geo.path().projection(transform);
Run Code Online (Sandbox Code Playgroud)
虽然我不太了解底层的机制,但效果似乎相对简单:路径生成器的底层转换函数使用转换后的x,y参数调用.
对于我的用例,我发现这没有用,特别是因为我的输入数据尚未投影.我想首先使用投影来转换数据,然后转换那些输出的坐标.为此,是否存在分层变换的一般模式?
我看到它D3确实提供了projection.stream(listener)模式,它在应用监听器之前首先应用了投影变换,但我不确定如何实现它.听众的论点应该是什么?这是一个例子:http://jsfiddle.net/kv7yn8rw/2/.
任何指导将不胜感激!
我正在处理 Chrome 扩展程序的帐户删除,我有以下按钮:
<button @click="remove" id="button_remove" class="btn btn-default" style="float: right;">Remove Account</button>
Run Code Online (Sandbox Code Playgroud)
JS
methods:{
remove(event){
app.removeAccountData(url,apikey);
}
},
Run Code Online (Sandbox Code Playgroud)
我也有这个router-link:
methods:{
remove(event){
app.removeAccountData(url,apikey);
}
},
Run Code Online (Sandbox Code Playgroud)
有没有办法使用router-linkwithJS函数?
我有以下表格:
<%= form_with(model: user, local: true) do |form| %>
<% if user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.file_field :avatar %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
它在我的edit页面上被调用:
<h1>Upload Avatar</h1>
<%= image_tag(@user.avatar) %>
<%= render 'form', user: @user %>
<hr>
Run Code Online (Sandbox Code Playgroud)
我在标题中得到了错误,但是我不确定为什么头像没有被附加到user模型上。我已经完成了所有的要求active_storage。
has_one_attached :avatar …
我查看了有关此错误的所有可能解决方案,但没有任何解决方案。
每次我尝试上传图像时,都会收到该错误。
在config/application.rb我已require 'active_storage/engine'取消注释。
在config/environments/development.rb我已经config.active_storage.service = :local设置。
我跑rails active_storage:install和rails db:migrate。
模型的名字是 user_test
class UserTest < ApplicationRecord
has_one_attached :image
end
Run Code Online (Sandbox Code Playgroud)
我在 app/controllers/user_tests_controller.rb 中有这个
def user_test_params
params.require(:user_test).permit(:title, :caption, :image)
end
Run Code Online (Sandbox Code Playgroud)
**配置/存储.yml*
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
Run Code Online (Sandbox Code Playgroud)
我真的不知道为什么它不起作用。
编辑:
Completed 500 Internal Server Error in 111ms (ActiveRecord: 43.1ms)
OpenSSL::Cipher::CipherError - :
(erb):12:in `<main>'
app/controllers/user_tests_controller.rb:27:in `create'
Started POST "/__better_errors/52f33e5e173d5e27/variables" for 127.0.0.1 at 2019-01-10 …Run Code Online (Sandbox Code Playgroud) 我想用它weka来预测未来的实例.我有一个csv文件,其中一小部分如下:

我曾经r读过这个文件,但我不知道如何用"无错误"替换零,除了"错误"之外还有零.我会这样离开但遗憾的weka是无法预测以数字为状态的实例.
编辑2:我尝试了你的解决方案,即使它改变了numbbers为错误/没有错误,它删除了其他列.我做错什么了吗?我还将它写入文件,因此更容易看到.

编辑3:
dput(data)
structure(list(BoxType = structure(c(3L, 3L, 6L, 6L, 3L, 8L,
3L, 3L, 6L, 4L, 4L, 3L, 3L, 4L, 6L, 6L, 3L, 6L, 2L, 4L, 3L, 3L,
8L, 3L, 6L, 8L, 2L, 3L, 8L, 8L, 3L, 8L, 2L, 2L, 8L, 8L, 2L, 3L,
8L, 3L, 4L, 3L, 3L, 3L, 2L, 2L, 6L, 4L, 3L, 4L, 4L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, …Run Code Online (Sandbox Code Playgroud) 我在这方面还很陌生。我有以下内容iframe
<iframe width="560" height="315" src="<%=video1[1]%>" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
我想做的是让它播放video1[1],但显示其中的图像video1[2]。
我尝试做的是:
<iframe width="560" height="315" href="<%=video1[2]%>" src="<%=video1[1]%>" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
但这行不通。
有简单的方法吗?
我正在运行迁移以重命名表,但我得到一个奇怪的错误.
public function up()
{
Schema::rename($accounts, $feeds);
}
public function down()
{
Schema::rename($feeds, $accounts);
}
Run Code Online (Sandbox Code Playgroud)
错误:
Undefined variable: accounts
表绝对存在.知道可能是什么问题吗?
我使用r对我的数据进行了pca,我试图用大于1的特征值来保存组件.
> summary(pca1)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
Standard deviation 1.2851803 1.1245020 1.0737268 1.0011978 0.9841687 0.88758402 0.84798807 0.67308490
Proportion of Variance 0.2064611 0.1580631 0.1441112 0.1252996 0.1210735 0.09847567 0.08988547 0.05663041
Cumulative Proportion 0.2064611 0.3645241 0.5086353 0.6339349 0.7550084 0.85348412 0.94336959 1.00000000
> loadings(pca1)
Loadings:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
AspectRatio 0.604 0.325 0.230 0.194 0.652
CPUSpeed 0.241 0.278 0.890 -0.242
IsDvrEnabled 0.428 -0.329 -0.109 -0.290 -0.724 -0.281
ZoomMode 0.123 0.837 -0.133 -0.232 -0.124 …Run Code Online (Sandbox Code Playgroud) 我正在使用具有多个NA值的数据帧,因此我考虑根据其NA值对属性进行排序.我试图使用for循环,这是我到目前为止:
> data <- read.csv("C:/Users/Nikita/Desktop/first1k.csv")
> for (i in 1:length(data) ) {
+ temp <- c(sum(is.na(data[i])))}
> temp
[1] 0
Run Code Online (Sandbox Code Playgroud)
这是我第一次在r中使用for循环,所以我确信它只是一个愚蠢的语法问题,但我无法理解究竟是哪一个.
最终,我需要一个列表,显示属性的名称及其NA计数.这样我就可以对列表进行排序并获得所需的信息.这是一些模拟数据,使其更容易.
data <- data.frame(A = c(500, 600, 700, 1000),
B = c(500, 600, 700, NA),
C = c(NA, NA, 500, 700),
D = c(800, NA, 933, NA),
E = c(NA, NA, NA, NA))
Run Code Online (Sandbox Code Playgroud)
编辑:谢谢大家的帮助.这三种解决方案都适合我.我确实想知道是否有一行代码在将它们导出到文件之前对这些属性进行排序.就像我之前提到的,我很新,r所以我不确定它是否可行.
编辑2:当我运行sort时,会给出下一个错误:
temp <- sort(temp)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
我试图限制每个失败的登录尝试ip。
我有以下内容:
def validate(email, context)
attempt = insert_into_attempts(email, context)
return nil unless allow_login_by_ip(context.ip_address)
flag_successful_attempt(attempt, context.ip_address)
load_data
end
def allow_login_by_ip(ip_address)
limit = LoginLimits.new(ip_address).limit
last_5_attempts = AuthenticationAttempt.select("id","successful").where(ip: ip_address).last(5)
last_5_attempts.include?("true")
end
def insert_into_attempts(email, context)
attempt = AuthenticationAttempt.new(
:email => email,
:ip => context.ip_address)
attempt.save
end
def flag_successful_attempt(attempt, ip_address)
AuthenticationAttempt.where(ip: ip_address).last.update(successful: '1')
end
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是它总是返回fasle。我一定是搜索array错误,但我不知道为什么。last_5_attempts是:
#<AuthenticationAttempt id: 1, successful: false>,
#<AuthenticationAttempt id: 2, successful: false>,
#<AuthenticationAttempt id: 3, successful: true>,
#<AuthenticationAttempt id: 4, successful: false>,
#<AuthenticationAttempt id: …Run Code Online (Sandbox Code Playgroud) 我查看了有关此错误的所有可能解决方案,但没有解决方案。
每次尝试上传图像时,都会收到此错误:
Unable to autoload constant ActiveStorage::Blob::Analyzable, expected /usr/local/lib/ruby/gems/2.5.0/gems/activestorage-5.2.2/app/models/active_storage/blob/analyzable.rb to define it。
宝石文件
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
gem 'rails', '~> 5.2.0'
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0' …Run Code Online (Sandbox Code Playgroud)