我有一个像这样的numpy数组:
foo_array = [38,26,14,55,31,0,15,8,0,0,0,18,40,27,3,19,0,49,29,21,5,38,29,17,16]
Run Code Online (Sandbox Code Playgroud)
我想用整个数组的中值替换所有零(其中零值不包括在中位数的计算中)
到目前为止,我有这样的事情:
foo_array = [38,26,14,55,31,0,15,8,0,0,0,18,40,27,3,19,0,49,29,21,5,38,29,17,16]
foo = np.array(foo_array)
foo = np.sort(foo)
print "foo sorted:",foo
#foo sorted: [ 0 0 0 0 0 3 5 8 14 15 16 17 18 19 21 26 27 29 29 31 38 38 40 49 55]
nonzero_values = foo[0::] > 0
nz_values = foo[nonzero_values]
print "nonzero_values?:",nz_values
#nonzero_values?: [ 3 5 8 14 15 16 17 18 19 21 26 27 29 29 31 38 38 40 49 55]
size = …
Run Code Online (Sandbox Code Playgroud) 我如何构建这个sqlalchemy查询,以便它做正确的事情?
我已经给出了我能想到的所有别名,但我仍然得到:
ProgrammingError: (psycopg2.ProgrammingError) subquery in FROM must have an alias
LINE 4: FROM (SELECT foo.id AS foo_id, foo.version AS ...
Run Code Online (Sandbox Code Playgroud)
此外,正如IMSoP指出的那样,它似乎试图将其转换为交叉连接,但我只是希望它在同一个表上通过子查询加入一个具有组的表.
这是sqlalchemy:
(注意:我已经将它重写为一个尽可能完整的独立文件,可以从python shell运行)
from sqlalchemy import create_engine, func, select
from sqlalchemy import Column, BigInteger, DateTime, Integer, String, SmallInteger
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('postgresql://postgres:#######@localhost:5435/foo1234')
session = sessionmaker()
session.configure(bind=engine)
session = session()
Base = declarative_base()
class Foo(Base):
__tablename__ = 'foo'
__table_args__ = {'schema': 'public'}
id = Column('id', BigInteger, primary_key=True)
time = Column('time', DateTime(timezone=True))
version …
Run Code Online (Sandbox Code Playgroud) 我有一个包含数十万行以日期开头的文件,例如
2021-02-22...
Run Code Online (Sandbox Code Playgroud)
但有些奇怪的行并不是这样开始的。我的目的是编写一个宏来找到它们并将它们与上面的行连接起来。
我怎样才能从 vim 中搜索这些行?
例如,如果我想在 vim 中找到下一个匹配行,我会输入
/^2021
Run Code Online (Sandbox Code Playgroud)
它会带我到下一行以“2021”开头的
我想这样做,但搜索下一个不匹配的行。
我从命令行启动模拟器尝试使用这些参数加速它:
模拟器-avd foo_hvga2 -cpu-delay 0 -no-boot-anim
这是模拟器输出的详细转储....谢谢你的任何线索
模拟器-avd foo_hvga2 -cpu-delay 0 -no-boot-anim -verbose -debug all -show-kernel
emulator: found SDK root at /Users/foobear/android-sdks
emulator: Android virtual device file at: /Users/foobear/.android/avd/foo_hvga2.ini
emulator: /Users/foobear/.android/avd/foo_hvga2.ini: parsing as .ini file
emulator: 1: KEY='target' VALUE='android-16'
emulator: 2: KEY='path' VALUE='/Users/foobear/.android/avd/foo_hvga2.avd'
emulator: /Users/foobear/.android/avd/foo_hvga2.ini: parsing finished
emulator: virtual device content at /Users/foobear/.android/avd/foo_hvga2.avd
emulator: virtual device config file: /Users/foobear/.android/avd/foo_hvga2.avd/config.ini
emulator: /Users/foobear/.android/avd/foo_hvga2.avd/config.ini: parsing as .ini file
emulator: 1: KEY='hw.lcd.density' VALUE='160'
emulator: 2: KEY='skin.name' VALUE='HVGA'
emulator: 3: KEY='skin.path' VALUE='platforms/android-16/skins/HVGA'
emulator: 4: KEY='hw.cpu.arch' …
Run Code Online (Sandbox Code Playgroud) 我对在我的项目中使用测试容器非常感兴趣。
但是,我很难设置它以与Informix一起使用。
请注意,我可以使用适用于Mac的Docker启动一个notifyix容器,它将构建并启动。
虽然不确定它是否可以与测试容器一起使用。我希望能。
这是我到目前为止的
测试班
package com.example.demo;
import com.github.dockerjava.api.command.CreateContainerCmd;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import java.time.Duration;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
private static GenericContainer informix;
@BeforeClass
public static void init() {
informix = new GenericContainer("ibmcom/informix-innovator-c")
.withExposedPorts(9088)
.withEnv("LICENSE", "accept")
.withPrivilegedMode(true)
.withCreateContainerCmdModifier(command -> ((CreateContainerCmd)command).withTty(Boolean.TRUE))
.waitingFor(new WaitAllStrategy().withStrategy(new LogMessageWaitStrategy().withRegEx(".*listener on port.*\n"))
.withStrategy(new HostPortWaitStrategy())
.withStartupTimeout(Duration.ofMinutes(2)));
informix.start();
}
@AfterClass
public static void destroy(){
informix.close(); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个返回Long的命名本机查询.
这是我的orm.xml文件(尽可能简化)
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<named-native-query name="getCaseNumberByCommId" result-class="java.lang.Long">
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
</entity-mappings>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
错误 - org.hibernate.impl.SessionFactoryImpl - 命名查询中的错误:getCaseNumberByCommId [coral:launch] org.hibernate.MappingException:未知实体:java.lang.Long
我也尝试过指定"Long"
<named-native-query name="getCaseNumberByCommId" result-class="Long">
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
Run Code Online (Sandbox Code Playgroud)
并奇怪地得到这个错误:
引起:org.hibernate.AnnotationException:无法找到entity-class:Long ...引起:java.lang.ClassNotFoundException:Long
Java在java.lang中找不到Long?
谢谢你的任何线索
编辑:我尝试删除'result-class'注释:
<named-native-query name="getCaseNumberByCommId" >
<query>SELECT case_id FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
Run Code Online (Sandbox Code Playgroud)
并得到此错误:
嵌套异常是org.hibernate.cfg.NotYetImplementedException:尚不支持纯本机标量查询
更新*
我从来没有找到这样做的方法,但由于数据库对comm_id有唯一性约束,我只能返回映射的pojo对象而不是count.
例如
<named-native-query name="getByCommId" result-class="com.foo.model.Communication">
<query>SELECT * FROM communications WHERE comm_id =(?1)</query>
</named-native-query>
Run Code Online (Sandbox Code Playgroud)
然后从返回的pojo中拉出所需的case_id.
我想找到一个非常宽容的xml解析器.就像Python的BeautifulSoup一样.那里有什么吗?
我很欣赏Android的FloatingActionButton(fab)功能,并希望在我的项目中的许多不同地方使用它们。
现在,我有类似这样的内容,其中有几个针对它们的xml规范,除了id,icon和onclick外,其他所有规范都是相同的。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabFoo"
android:onClick="onFabFoo"
android:src="@drawable/ic_foo"
app:backgroundTint="?attr/colorButtonNormal"
app2:elevation="2dp"
app:fabSize="mini"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="2dp"
app:rippleColor="?attr/colorSwitchThumbNormal" />
Run Code Online (Sandbox Code Playgroud)
为了避免重复代码...有没有一种方法可以完全以编程方式创建fab,而无需在xml中指定它?
...
试用一些建议...在我将SDK升级到最新版本之前,没有“ setSize”(#25)
FloatingActionButton fab = new FloatingActionButton(this);
fab.setId(View.generateViewId());
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("DEBUG", "onFabFoo");
}
});
fab.setImageResource(R.drawable.ic_foo);
fab.setElevation(2);
fab.setSize(android.support.design.widget.FloatingActionButton.SIZE_MINI);
fab.setFocusable(true);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lay.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lay.setMargins(2,2,2,2);
fab.setLayoutParams(lay);
Run Code Online (Sandbox Code Playgroud)
现在还没有想出如何设置颜色
// app:backgroundTint="?attr/colorButtonNormal"
// app:rippleColor="?attr/colorSwitchThumbNormal"
Run Code Online (Sandbox Code Playgroud)
我看到有一些方法可以设置这些颜色(setBackgroundTintList和setRippleColor),但是我看不到如何将其设置为我在原始xml设置中选择的颜色(colorButtonNormal和colorSwitchThumbNormal)
另外,不知道如何将其附加到父项上并显示出来...
好吧,我想我现在意识到,如果你做这一切的程序,那么你就不能使用的功能,如Android Studio中的XML设计视图。因此,工作起来要困难得多。
我有一个不是网络服务的微服务。
它是一个 Spring Boot (1.5) CommandLineRunner 应用程序,不需要公开 API 或对 http 执行任何操作。
但是,我需要对 Kubernetes 进行活性探测。
这可以在不将其重构为网络服务应用程序的情况下完成吗?
我添加了此配置以启用 Spring 的信息端点
management:
endpoint:
health:
enabled: true
info:
enabled: true
# https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints
info:
app:
name: foo-parser
description: parses binary files from S3 and updates the database
Run Code Online (Sandbox Code Playgroud)
我实现了这个健康检查类
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
@Component
public class HealthCheck extends AbstractHealthIndicator {
Logger log = LoggerFactory.getLogger("jsonLogger");
private final MySQLAccessor mySQLAccessor;
private static final String FOO_TABLE = "foo";
@Autowired
public HealthCheck(final MySQLAccessor mySQLAccessor) {
this.mySQLAccessor = mySQLAccessor;
}
@Override …
Run Code Online (Sandbox Code Playgroud) 我查找并搜索了其他人,肯定是其他人正在使用API,在身份验证时,我似乎找不到正确的范围参数值:
我已经查看了所有这些作用域列表,没什么,尝试过OAuth 2.0游乐场,没有翻译。
任何线索都欢迎,谢谢。
错误信息:
Error: invalid_request
Missing required parameter: scope
Learn more
Request Details
Run Code Online (Sandbox Code Playgroud)
更新资料
用户Ezra解释说,翻译API不需要OAuth2身份验证。
我沿着这条路走这条路:
我正在尝试使示例代码在这里工作:
而且没有apiclient.discovery模块
from apiclient.discovery import build
Run Code Online (Sandbox Code Playgroud)
我去了寻找那它落在我这里这个快速启动配置 这给了我一个自动生成翻译API项目在这里:
这个应该为Translation API量身定制的入门项目包括一整套OAuth配置,因此由于这里提到的错误,我最终提出了一个问题
exception calling translation api: <HttpError 400 when requesting https://www.googleapis.com/language/translate/v2?q=zebra&source=en&alt=json&target=fr&key=MYSECRETKEYWENTHERE returned "Bad Request">
Run Code Online (Sandbox Code Playgroud)
我用来进行上述调用的代码,这种方式的错误是:
service = build('translate', 'v2',
developerKey='MYSECRETKEYWENTHERE')
result = service.translations().list(
source='en',
target=lang,
q='zebra'
).execute()
Run Code Online (Sandbox Code Playgroud)
如果我直接拨打该错误抱怨的电话,那就可以了
https://www.googleapis.com/language/translate/v2?key=MYSECRETKEYWENTHERE&q=zebra&target=fr&alt=json&source=en
Run Code Online (Sandbox Code Playgroud)
再次更新
好的,我从示例项目中删除了所有OAuth代码,然后再次运行它,最后发现我的密钥中有错字...
感谢您的回答!
。
谢谢
google-app-engine oauth-2.0 google-api-client oauth2client oauth2-playground
我很满意我得到的结果R.我的大多数叠加直方图都看起来很好,例如
和
但是,我有一些在传奇中有这么多类别的传说中,传说中的情节很多,例如
我怎样才能解决这个问题?
这是我的plot.r,我在命令行上调用这个
RScript plot.r foo.dat foo.png 1600 800
Run Code Online (Sandbox Code Playgroud)
foo.dat
account,operation,call_count,day
cal3510,foo-method,1,2016-10-01
cra4617,foo-method,1,2016-10-03
cus4404,foo-method,1,2016-10-03
hin4510,foo-method,1,2016-10-03
mas4484,foo-method,1,2016-10-04
...
Run Code Online (Sandbox Code Playgroud)
整个foo.dat:http://pastebin.com/xnJtJSrU
plot.r
library(ggplot2)
library(scales)
args<-commandArgs(TRUE)
filename<-args[1]
png_filename<-args[2]
wide<-as.numeric(args[3])
high<-as.numeric(args[4])
print(wide)
print(high)
print(filename)
print(png_filename)
dat = read.csv(filename)
dat$account = as.character(dat$account)
dat$operation = as.character(dat$operation)
dat$call_count = as.integer(dat$call_count)
dat$day = as.Date(dat$day)
png(png_filename,width=wide,height=high)
p <- ggplot(dat, aes(x=day, y=call_count, fill=account))
p <- p + geom_histogram(stat="identity")
p <- p + scale_x_date(labels=date_format("%b-%Y"), limits=as.Date(c('2016-10-01','2017-01-01')))
print(p)
dev.off()
Run Code Online (Sandbox Code Playgroud) 说,你有一个整数列表,例如
foo = [3,9,23,54,77,123,...]
Run Code Online (Sandbox Code Playgroud)
是否存在允许查询的高效数据结构
x = everything in foo between 10 and 100
Run Code Online (Sandbox Code Playgroud)
以便
x == [23,54,77]
Run Code Online (Sandbox Code Playgroud)
或x =一切<50
给
x = [3,9,23]
Run Code Online (Sandbox Code Playgroud)
等等?
python ×4
android ×3
java ×2
arrays ×1
emulation ×1
ggplot2 ×1
health-check ×1
hibernate ×1
histogram ×1
homescreen ×1
informix ×1
inheritance ×1
jpa-2.0 ×1
kubernetes ×1
legend ×1
numpy ×1
oauth-2.0 ×1
oauth2client ×1
orm ×1
postgresql ×1
psycopg2 ×1
python-2.7 ×1
r ×1
range ×1
regex ×1
replace ×1
search ×1
select ×1
spring-boot ×1
sqlalchemy ×1
updates ×1
vim ×1
window ×1
windows-10 ×1
xml ×1
xml-parsing ×1