在我的rails 4应用程序中,客户端(客户端表)可以有许多项目(项目表).我name在每个表中都有一个列.我正在尝试编写一个join然后select使用项目作为基表和客户端作为查找表.client_id是foreign_key项目表中的:
我写的查询如下:
Project.joins(:client).select('projects.id,projects.name,clients.name')
Run Code Online (Sandbox Code Playgroud)
我收到以下回复:
Project Load (0.6ms) SELECT projects.id,projects.name,clients.name FROM "projects" INNER JOIN "clients" ON "clients"."id" = "projects"."client_id"
=> #<ActiveRecord::Relation [#<Project id: 1, name: "Fantastico Client">]>
Run Code Online (Sandbox Code Playgroud)
如果我试着像这样别名:
Project.joins(:client).select('projects.id,projects.name,clients.name as client_name')
Run Code Online (Sandbox Code Playgroud)
然后我得到以下回复:
Project Load (0.8ms) SELECT projects.id,projects.name,clients.name as client_name FROM "projects" INNER JOIN "clients" ON "clients"."id" = "projects"."client_id"
=> #<ActiveRecord::Relation [#<Project id: 1, name: "The Dream Project">]>
Run Code Online (Sandbox Code Playgroud)
在任何一种情况下,ActiveRecord都会丢失其中一个名称,您可以从上面的响应中看到.我该怎么写这个查询?
这是父模型:
class TypeWell < ActiveRecord::Base
...
has_many :type_well_phases, :dependent => :destroy
accepts_nested_attributes_for :type_well_phases, :reject_if => lambda { |a| a[:phase_id].blank? }, :allow_destroy => true
...
end
Run Code Online (Sandbox Code Playgroud)
这是嵌套模型:
class TypeWellPhase < ActiveRecord::Base
belongs_to :type_well
belongs_to :phase
end
Run Code Online (Sandbox Code Playgroud)
这是阶段模型:
class Phase < ActiveRecord::Base
...
has_many :type_well_phases
...
end
Run Code Online (Sandbox Code Playgroud)
我通过在父模型的控制器中复制我的阶段(阶段模型)表中的所有记录来在子表(TypeWellPhases)中添加嵌套记录,如下所示:
class TypeWellsController < ResourceController
...
def new
@new_heading = "New Type Well - Computed"
@type_well = TypeWell.new
initialize_phase_fields
end
private
def initialize_phase_fields
Phase.order("id").all.each do |p|
type_well_phase = @type_well.type_well_phases.build
type_well_phase.phase_id = p.id
type_well_phase.gw_heat_value = p.gw_heat_value …Run Code Online (Sandbox Code Playgroud) 下图显示了 2 X 2 网格布局中的标准 Seaborn/Matplotlib 箱线图:
这几乎是我想要的,只是我想在图的第一行和第二行之间留出更多空间。第一行图的 X 轴标签与第二行图的标题之间的距离几乎不存在。我一直在玩这个线程中解释的参数:
这是我的相关代码:
import math
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from PyPDF2 import PdfFileMerger
import seaborn as sns
num_cols = 2
num_rows = int(math.ceil(tot_plots / float(num_cols)))
fig, axes = plt.subplots(nrows=num_rows, ncols=num_cols, figsize=(16, 16))
x_var = df_orig['hra']
for idx, ax in enumerate(axes.flat):
data_var = current_cols[idx]
y_var = df_orig[data_var]
title_str = ''
sns.boxplot(x=x_var, y=y_var, ax=ax,
order=order, palette=color, showfliers=False)
ax.set_title(data_var + title_str) …Run Code Online (Sandbox Code Playgroud) 我的构建在 Windows 10 上一直失败,无法在 anaconda 中安装 fbprophet,并显示以下消息:
ERROR conda.core.link:_execute(502): An error occurred while installing package 'conda-forge::automat-0.7.0-py_1'.
CondaError: Cannot link a source that does not exist. C:\Users\bharat.c.ruparel\AppData\Local\Continuum\anaconda3\Scripts\conda.exe
Run Code Online (Sandbox Code Playgroud)
给出的命令是:
conda install -c conda-forge fbprophet
有没有人在 Windows 10 上成功安装过 fbprophet?如果是,请给出步骤。
谢谢。我也试过 pip install 但没有运气。我有一台 Mac 并设法在其上安装了 fbprophet,没有任何问题。
我有一个rails应用程序,我使用Bootstrap进行样式设置.我使用bootstrap 3在bootstrap 3进度条中显示完成百分比以及任务状态.如果进度条填满了条的大部分宽度,则条形图中的文本显示正常.但是,对于较低的百分比,文本会被删除.请参阅随附的屏幕截图. 
Rails代码渲染进度条非常简单.这是为了完整性:
def progress_bar(todate_units, total_units, completion_date, checkpoint_status)
if (total_units.nil? || (total_units == 0) || completion_date.blank?)
return ""
end
# compute percent complete
todate_units = (todate_units.nil? ? 0 : todate_units)
if (checkpoint_status.present? && (checkpoint_status == 'QC Complete'))
percent_complete = 100
else
percent_complete = ((todate_units / total_units.to_f) * 0.8).round(2) * 100
end
# determine status
if (checkpoint_status.present? && (checkpoint_status == 'QC Complete'))
status = 'QC Complete'
elsif (todate_units == 0)
status = "Pending"
elsif ((todate_units > 0) and (todate_units < …Run Code Online (Sandbox Code Playgroud) 在我的HighChart折线图中,系列数据是从我的Ruby on Rails应用程序动态提供的.有时系列值为零或更小,这是HighCharts的一个问题,它会抛出以下异常:
Highcharts Error #10
Can't plot zero or subzero values on a logarithmic axis
Run Code Online (Sandbox Code Playgroud)
因此,作为一种解决方法,我处理我的ruby数组以有条件地将一个较小值的零替换为无效的正数,.eg 0.00001,如下所示:
oil_vol_array = d_array[1].map { |e| (e < 0.0001) ? 0.0001 : e.round(3) }
Run Code Online (Sandbox Code Playgroud)
这可以防止抛出异常,但是如果起始值为零,显示屏将显示从0.0001开始的图形(可以理解的是,因为我要求它).更理想的显示是将图形设置为零,但HighChart不喜欢它:(
有没有办法实现这一目标?
以下代码段适用于大于10 K的CSV文件.
lines = CSV.read(open(resource.csv(:original)))
Run Code Online (Sandbox Code Playgroud)
这是使用Paperclip gem读取存储在Amazon S3中的CSV文件.
如果文件大小小于10 K,我会收到以下错误:
ActionView :: Template :: Error(无法将StringIO转换为String):
我用Google搜索并找到以下帖子:
http://adayinthepit.com/?p=269
所以我尝试使用fastercsv gem,当我再次运行我的程序时,这是我得到的错误:
ActionView :: Template :: Error(请切换到Ruby 1.9的标准CSV库.它是FasterCSV加上对Ruby 1.9的m17n编码引擎的支持.):
看起来它是一个Catch-22.如何在ruby 1.9.2 p290中处理小于10 K的文件?
请指教.
谢谢.
巴拉特
我正在 Mac 上开发一个 Go 程序,该 Mac 上安装了与 Windows 一起安装的 Parallels,以便我可以在两个平台上进行测试。我的程序运行良好。我可以在 Mac 上编译 Windows“.exe”文件并从 Windows 运行它,除了日志文件之外,它运行良好。
我已将记录器设置为将其输出写入文件,如下所示:
log.SetOutput(projectsLog)
Run Code Online (Sandbox Code Playgroud)
其中,projectsLog 在其上方声明,如下所示:
projectsLog *os.File
Run Code Online (Sandbox Code Playgroud)
我正在使用 log.Printf 语句,因为我想要格式化输出。一个例子如下所示:
log.Printf("Error: wrong Hra Class value %s in row %v for project/path %s", hraClass, (rowNum + 1), testDir)
Run Code Online (Sandbox Code Playgroud)
这在 Mac 上运行得很好。使用 log.Printf 的每一行都记录在单独的行上,但在 Windows 上,换行符不显示,并且我得到一行没有换行符。我很清楚unix和windows之间的“\r”和“\r\n”区别。但我认为 log.Printf 会根据其运行的平台而适当地表现?
如果我的假设是错误的,那么我必须采取哪些选项来确保日志文件在 Windows 上可读?如果可以的话,我不想传递标志,例如 -platform windows 或类似的东西。这件事能以透明的方式处理吗?
我正在尝试拟合在背景图像上显示的图.由于锐度的损失,我无法过度拉伸图像.因此,我必须在背景图像上拟合图,这比图更薄.我不知道怎么做.请参阅附图:
以下是示例R代码:
library(ggplot2)
library(readxl)
library(jpeg)
library(grid)
# find the ".jpg" image files and parse them to get the depth ranges for each image
setwd('~/R/Image_Example')
image_file <- "C1_9195-9197.jpg"
# read in the image file
img <- readJPEG(image_file)
g <- rasterGrob(img, interpolate = FALSE)
# read in the CT data
df_ct <- read_excel("CT_Doris25_short.xlsx", col_names = FALSE)
g_ct <- ggplot(data=df_ct) +
annotation_custom(g, xmin=min(df_ct$X1), xmax=max(df_ct$X1), ymin=-Inf, ymax=Inf) +
geom_path(aes_string(x=df_ct$X1, y=df_ct$X0), color='cyan') +
scale_y_reverse() +
theme(plot.margin = unit(c(0,0,0,0), "lines"))
g_ct
Run Code Online (Sandbox Code Playgroud)
如你看到的,
我试图在annotation_custom中调整xmin和xmax.是否有一种方法可以使"青色"颜色显示的图形完全适合背景图像的"宽度"?我不介意图表是否更薄并且未显示X轴.事实上,当我使用gridExtra包装组合其他一些图表时,我就是这么做的.
我想在所示图像的顶部显示起始深度9195,并在图像底部显示结束深度9197.然后我不需要Y轴.我知道如何抑制X轴和Y轴标签的显示.所以这不是问题.我打开它们进行澄清.可以通过编程方式完成吗?
如您所见,沿Y轴的刻度以0.5为步长变化,即9195,9195.5,9196 ......等等.我想让它们以0.1而不是0.5的步长上升(或下降).另外,我不想显示Y轴标签,只是勾选.图像顶部(9195)和底部(9197)的深度就足够了. …
我正在尝试在Windows 10计算机中使用Python。我的Anaconda环境可以通过执行以下命令来设置:
c:\Users\bharat.c.rupare.> call c:\Users\bharat.c.ruparel\AppData\Local\Continuum\anaconda3\Scripts\activate.bat
Run Code Online (Sandbox Code Playgroud)
这样就建立了conda环境,然后我就很好了。但是,我尝试使用预先安装在Power BI的Anaconda堆栈中的numpy和pandas运行Python代码。当我这样做时,Power BI抱怨找不到numpy。我明白为什么;因为尚未从Power BI中激活conda环境。
我需要怎么做才能激活conda环境,以便Power BI可以找到numpy,pandas等python包?