我开始严重依赖IPython笔记本应用程序来开发和记录算法.太棒了; 但有些东西似乎应该是可能的,但我无法弄清楚如何做到这一点:
我想将本地图像插入到我的(本地)IPython笔记本标记中以帮助记录算法.我知道可以添加类似<img src="image.png">降价的东西,但这就是我的知识.我假设我可以将图像放在由127.0.0.1:8888(或某个子目录)表示的目录中以便能够访问它,但我无法弄清楚该目录的位置.(我正在使用Mac.)那么,是否有可能在没有太多麻烦的情况下做我想做的事情?
我想验证我的控制器中的请求参数之一。请求参数应该来自给定值列表之一,如果不是,则应该抛出错误。在下面的代码中,我希望请求参数 orderBy 来自@ValuesAllowed 中存在的值列表。
@RestController
@RequestMapping("/api/opportunity")
@Api(value = "Opportunity APIs")
@ValuesAllowed(propName = "orderBy", values = { "OpportunityCount", "OpportunityPublishedCount", "ApplicationCount",
"ApplicationsApprovedCount" })
public class OpportunityController {
@GetMapping("/vendors/list")
@ApiOperation(value = "Get all vendors")
public ResultWrapperDTO getVendorpage(@RequestParam(required = false) String term,
@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size,
@RequestParam(required = false) String orderBy, @RequestParam(required = false) String sortDir) {
Run Code Online (Sandbox Code Playgroud)
我编写了一个自定义 bean 验证器,但不知何故这不起作用。即使我为查询 param 传递了任何随机值,它也不会验证并抛出错误。
@Repeatable(ValuesAllowedMultiple.class)
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {ValuesAllowedValidator.class})
public @interface ValuesAllowed {
String message() default "Field value should …Run Code Online (Sandbox Code Playgroud) validation controller spring-annotations http-request-parameters spring-boot
我正在尝试过滤资源并根据字段排除一些元素。要排除,我有一个集合(包含需要排除的 id)和一个列表(它包含需要排除的多个 id 范围)。我写了下面的逻辑,我对第二个过滤器逻辑不满意。我们有没有更好的方法可以用 Java 8 做到这一点?我也需要为包括范围做同样的事情。
Set<String> extensionsToExclude = new HashSet<>(Arrays.asList("20","25","60","900"));
List<String> rangesToExclude = new ArrayList<>(Arrays.asList("1-10","20-25","50-70","1000-1000000"));
return directoryRecords.stream()
.filter((directoryRecord) -> !extensionsToExclude.contains(directoryRecord.getExtensionNumber()))
.filter((directoryRecord -> {
Boolean include = true;
for(String s : rangesToExclude) {
String [] rangeArray = s.split("-");
Integer extension = Integer.parseInt(directoryRecord.getExtensionNumber());
if(extension <= Integer.parseInt(rangeArray[0]) && extension >= Integer.parseInt(rangeArray[1])) {
include = false;
}
}
return include;
}))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
谢谢 :)
我有一个要模拟的服务类,但是在运行测试时,我的原因是: java.lang.IllegalStateException: Duplicate mock definition [MockDefinition@482ba4b1 name = '', typeToMock = com.service.ThirdPartyService, extraInterfaces = set[[empty]], answer = RETURNS_DEFAULTS, serializable = false, reset = AFTER]
我尝试在类级别、字段级别使用 @MockBean 创建模拟服务,并使用 @Qualifier 来解决问题
@Service
public class ThirdPartyService{
.......................
public String decrypt(String encryptedText) {
//third party SDK I am using
return Service.decrypt.apply(encryptedText);
}
.........
..............
}
@ComponentScan("com")
@PropertySource({"classpath:/api.properties", "classpath:/common.properties"})
@SpringBootConfiguration
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Transactional
public class TestControllerTest extends IntegrationTest {
@MockBean
ThirdPartyService thirdPartyService;
@Before
public void initMocks(){
MockitoAnnotations.initMocks(this);
}
@Test
public …Run Code Online (Sandbox Code Playgroud) 最近我们开始在日志中收到很多死锁错误。(Postgres 服务器 9.6.5)
我们的表由两列组成,一列是自增主键,另一列是 json 对象。来自 json 对象的两个属性被定义为 unique 。现在在日志中,我们不断收到错误,即不同行上的两个简单插入查询相互阻塞。
============
process 65325 detected deadlock while waiting for ShareLock on transaction 2934224126 after 1000.050 ms
DETAIL: Process holding the lock: 35530. Wait queue: .
CONTEXT: while inserting index tuple (128,10) in relation "A"
STATEMENT: INSERT INTO A AS t (info) VALUES('{"x":"y",....)
ERROR: deadlock detected
DETAIL: Process 65325 waits for ShareLock on transaction 2934224126; blocked by process 35530.
Process 35530 waits for ShareLock on transaction 2934224125; blocked by process 65325.
Process …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 Eclipse 和 Java 从事我的工作。我们应该使用 SonarLint 来获得一些更清晰的代码,直到昨天一切都很好。但是昨天早上,当我打开 Eclipse 时,SonarLint 向我抛出以下错误消息。
我已经在谷歌搜索过,删除了 .sonarlint 文件夹,还有 eclipse 的 settingsfolder 和 eclipse-workspace 内的 .sonarlint 文件夹。他们每个人都通过重新启动 eclipse 重新创建,但在这里没有任何帮助。我仍然收到错误:
Starting SonarLint for Eclipse 4.2.0.201909192007
SonarLint processing file /rap-server-core/src/main/java/com/rapidclipse/framework/server/ui/filter/FilterComponent.java...
Starting standalone SonarLint engine 4.2.0.201909192007...
Found 17 issue(s)
Error during execution of SonarLint analysis
java.lang.IllegalStateException: Failed to read local issue store index
at org.sonarlint.eclipse.core.internal.tracking.StringStoreIndex.load(StringStoreIndex.java:55)
at org.sonarlint.eclipse.core.internal.tracking.StringStoreIndex.keys(StringStoreIndex.java:45)
at org.sonarlint.eclipse.core.internal.tracking.IndexedObjectStore.deleteInvalid(IndexedObjectStore.java:78)
at org.sonarlint.eclipse.core.internal.tracking.IssueStore.<init>(IssueStore.java:62)
at org.sonarlint.eclipse.core.internal.SonarLintCorePlugin.lambda$0(SonarLintCorePlugin.java:102)
at org.sonarlint.eclipse.core.internal.tracking.IssueTrackerRegistry.newTracker(IssueTrackerRegistry.java:54)
at org.sonarlint.eclipse.core.internal.tracking.IssueTrackerRegistry.getOrCreate(IssueTrackerRegistry.java:43)
at org.sonarlint.eclipse.core.internal.SonarLintCorePlugin.getOrCreateIssueTracker(SonarLintCorePlugin.java:146)
at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.trackIssues(AbstractAnalyzeProjectJob.java:317)
at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.lambda$15(AbstractAnalyzeProjectJob.java:302)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2295)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
at org.sonarlint.eclipse.core.internal.jobs.AbstractAnalyzeProjectJob.updateMarkers(AbstractAnalyzeProjectJob.java:302) …Run Code Online (Sandbox Code Playgroud) 我想读取一个 .csv 文件并返回一个 groupby 函数作为回调,以显示为带有“dash_table”库的简单数据表。@Lawliet 的有用答案显示了如何使用“dash_table_experiments”库来做到这一点。这是我被困的地方:
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash.dependencies import Input, Output, State
df = pd.read_csv(
'https://gist.githubusercontent.com/chriddyp/'
'c78bf172206ce24f77d6363a2d754b59/raw/'
'c353e8ef842413cae56ae3920b8fd78468aa4cb2/'
'usa-agricultural-exports-2011.csv')
app = dash.Dash()
application = app.server
app.layout = html.Div([
dash_table.DataTable(
id = 'datatable',
),
html.Div([
html.Button(id='submit-button',
children='Submit'
)
]),
])
@app.callback(Output('datatable','data'),
[Input('submit-button','n_clicks')],
[State('submit-button','n_clicks')])
def update_datatable(n_clicks,csv_file):
if n_clicks:
dfgb = df.groupby(['state']).sum()
return dfgb.to_dict('rows')
if __name__ == '__main__':
application.run(debug=False, port=8080)
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,并且使用以下代码进行样式设置,但只要满足条件,即红色。我想将值替换为 0。我使用了 applymap(function, subset=['col1','col2']) ,它返回样式数据帧,但我也需要替换这些值。
import pandas as pd
import numpy as np
def applystyle(value):
if float(value) < 1.0:
color = 'red'
else:
color = 'white'
return 'background-color: %s; text:0;' % color
data = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC'))
data.style.applymap(applystyle, subset=['C','A'])
Run Code Online (Sandbox Code Playgroud)
"devDependencies": {\n "@babel/core": "^7.8.4",\n "@babel/preset-env": "^7.8.4",\n "@babel/preset-react": "^7.8.3",\n "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",\n "enzyme": "^3.11.0",\n "enzyme-adapter-react-16": "^1.15.2",\n "react": "^15.3.1",\n "redux-mock-store": "^1.5.4"\n }\nRun Code Online (Sandbox Code Playgroud)\n\n "devDependencies": {\n "@babel/core": "^7.8.4",\n "@babel/preset-env": "^7.8.4",\n "@babel/preset-react": "^7.8.3",\n "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",\n "enzyme": "^3.11.0",\n "enzyme-adapter-react-16": "^1.15.2",\n "react": "^15.3.1",\n "redux-mock-store": "^1.5.4"\n }\nRun Code Online (Sandbox Code Playgroud)\r\n我收到这个错误
\n\n\xe2\x97\x8f 测试套件无法运行。\n我尝试配置 jest 和 babelrc,但没有任何效果。\n它适用于纯反应组件,但当我开始使用 redux 存储测试组件时会抛出错误。
\n\nCannot find module \'react\' from \'Provider.js\'\n\nHowever, Jest was able to find:\n \'components/Provider.js\'\n\nYou might want to include a file extension in your import, or update your …Run Code Online (Sandbox Code Playgroud) 我无法发表评论,因为我是 stackoverflow 的新手,所以不能直接在线程中提问,但我想澄清这个问题中的解决方案:
Run Code Online (Sandbox Code Playgroud)# From Paul H import numpy as np import pandas as pd np.random.seed(0) df = pd.DataFrame({'state': ['CA', 'WA', 'CO', 'AZ'] * 3, 'office_id': list(range(1, 7)) * 2, 'sales': [np.random.randint(100000, 999999) for _ in range(12)]}) state_office = df.groupby(['state', 'office_id']).agg({'sales': 'sum'}) # Change: groupby state_office and divide by sum state_pcts = state_office.groupby(level=0).apply(lambda x: 100 * x / float(x.sum()))
我了解多索引选择(级别 0 与级别 1),但我不清楚xlambda 函数中的每个索引是指什么。将x在x.sum()会向我提及level = 0(总结中的每个分组在所有的结果level = 0),但 …
python ×4
pandas ×3
java ×2
java-8 ×2
lambda ×2
analysis ×1
babel-jest ×1
controller ×1
deadlock ×1
eclipse ×1
ipython ×1
java-stream ×1
javascript ×1
jupyter ×1
plotly-dash ×1
postgresql ×1
react-redux ×1
reactjs ×1
redux-saga ×1
sonarlint ×1
spring-boot ×1
styling ×1
validation ×1