items = collection.aggregate([
{"$match": {}},
{"$project": {
'temp_score': {
"$add": ["$total_score", 100],
},
'temp_votes': {
"$add": ["$total_votes", 20],
},
'weight': {
"$divide": ["$temp_score", "$temp_votes"]
}
}
}
])
Run Code Online (Sandbox Code Playgroud)
total_score 和 total_votes 已经存储在文档中,
我可以按预期获得 temp_score 和 temp_votes,但无法获得体重,有什么建议吗?
mongodb pymongo mongoengine mongodb-query aggregation-framework
当我在全屏窗口中生成折线图时,显示的颜色在声明的半径中,但是当我尝试调整窗口大小时,图表会正确调整大小,但渐变颜色会混乱.我试图通过听众解决这个问题,但它不起作用.
有人有想法吗?
这是我的代码:
var chrt = document.getElementById("mycanvas");
var ctx = chrt.getContext("2d");
var gradient = ctx.createLinearGradient(300, 0, 300, 600);
gradient.addColorStop(0, 'black');
gradient.addColorStop(0.25, 'red');
gradient.addColorStop(0.5, 'orange');
gradient.addColorStop(0.75, 'yellow');
gradient.addColorStop(1, 'green');
mycanvas.addEventListener("resize", gradient_declaration);
function gradient_declaration() {
var w = mycanvas.innerWidth;
var h = mycanvas.innerHeight;
if (gradient) { gradient.destroy(); } else {
var gradient = ctx.createLinearGradient(w / 2, 0, w / 2, h);
gradient.addColorStop(0, 'black');
gradient.addColorStop(0.25, 'red');
gradient.addColorStop(0.5, 'orange');
gradient.addColorStop(0.75, 'yellow');
gradient.addColorStop(1, 'green');
}
}
Run Code Online (Sandbox Code Playgroud) 我已经使用邮差(https://www.getpostman.com/)测试我的API,API在AWS ApiGateway和Lambda函数(NodeJS)中
(1)当我第一次向服务器发送post方法请求时,它给出了正确的响应,我暂时没有发送任何post参数。
这是请求标头-
Connection ?keep-alive
Content-Length ?61
Content-Type ?application/json
Date ?Fri, 24 Mar 2017 09:09:13 GMT
Via ?1.1 440f7503597ca64245c4258c03b08e0c.cloudfront.net (CloudFront)
X-Amz-Cf-Id ?t50_SeWgC3Qb2ZFtf4fksUTdi5viINCaAEj8MPTvhRbtMHu-LK1mwA==
X-Amzn-Trace-Id ?Root=1-58d4e239-76404c1ab9912d010fac33a2
X-Cache ?Miss from cloudfront
x-amzn-RequestId ?8c8f9bd2-1071-11e7-9490-79b68cde95e0
Run Code Online (Sandbox Code Playgroud)
这是回应
{
"response": "false",
"message": "Please enter a valid email !"
}
Run Code Online (Sandbox Code Playgroud)
当没有任何发布参数发送请求时,它的工作正常。
(2)现在,当我向请求发送参数时,请求标头已更改,并删除了一个标头prama X-Amzn-Trace-Id
这是请求标头-
Connection ?keep-alive
Content-Length ?37
Content-Type ?application/json
Date ?Fri, 24 Mar 2017 09:02:52 GMT
Via ?1.1 d6cd0a105a9b074288944d270dfa7321.cloudfront.net (CloudFront)
X-Amz-Cf-Id ?UZLUL1lYwAIrnwaa7kPVrPBx462sa7sV0x0WFQFGJ2OXVbrp9gaNYg==
X-Cache ?Error from cloudfront
x-amzn-RequestId ?a9c4116a-1070-11e7-b08c-c3cf73411cde
Run Code Online (Sandbox Code Playgroud)
这是请求正文
{
"userEmail":"rahul@gmail.com",
"userPasswod":"123456",
"userName":"rahul"
} …Run Code Online (Sandbox Code Playgroud) 我正在创建一个猫鼬模式,但我得到了一个MongooseError.
这是我的方案:
let RestaurantSchema = new Schema({
ratings: {
type: [{
id: Number,
value: Number,
_id: false
}],
default: [
{ id: 1, value: 0 },
{ id: 2, value: 0 },
{ id: 3, value: 0 },
{ id: 4, value: 0 },
{ id: 5, value: 0 }
]
},
menu: [{
ratings: {
type: [{
id: Number,
value: Number,
_id: false
}],
default: [
{ id: 1, value: 0 },
{ id: 2, value: 0 …Run Code Online (Sandbox Code Playgroud) 我会很容易地解释我的问题:
我想与 github webhooks 交互以在我的用户(或登录用户)单击 repo 上的 star(应该是这个钩子事件)时获取。
我有一个带有 node + express 的简单服务器,但我真的不明白如何执行它。有人可以帮助我吗?
const chalk = require('chalk');
const express = require('express');
const serverConfig = require('./config/server.config');
const app = express();
const port = process.env.PORT || serverConfig.port;
console.log(chalk.bgGreen(chalk.black('### Starting server... ###'))); // eslint-disable-line
app.listen(port, () => {
const uri = `http://localhost:${port}`;
console.log(chalk.red(`> Listening ${chalk.white(serverConfig.env)} server at: ${chalk.bgRed(chalk.white(uri))}`)); // eslint-disable-line
});
Run Code Online (Sandbox Code Playgroud) 我正在使用 Github 的 GraphQL (v4) API 进行一些调用。我正在尝试获取有关存储库的提交信息,但在定义对象连接的since属性时遇到问题。historyCommit
我收到以下错误:
{
"data": null,
"errors": [
{
"message": "Argument 'since' on Field 'history' has an invalid value. Expected type 'GitTimestamp'.",
"locations": [
{
"line": 38,
"column": 9
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 GraphQL 中提取的导致错误的部分:
query {
search(query:"is:public", type:REPOSITORY, first:10){
edges{
node{
... on Repository{
ref(qualifiedName: "master"){
target{
... on Commit{
history(first: 10, since:"2017-07-15"){
totalCount
pageInfo{
startCursor
endCursor
}
edges{
node{
... on Commit{
committedDate
}
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在从json文件中读取一些数据,并将其转换为用于将数据发送到配置单元的字符串。
数据在Hive中可以很好地到达,但它被分配到错误的列中,我举了一个小例子
在Hive中:
Table name = TestTable, Column1 = test1, Column2 = test2`
Run Code Online (Sandbox Code Playgroud)
我的代码:
data = hiveContext.sql("select \"hej\" as test1, \"med\" as test2")
data.write.mode("append").saveAsTable("TestTable")
data = hiveContext.sql("select \"hej\" as test2, \"med\" as test1")
data.write.mode("append").saveAsTable("TestTable")
Run Code Online (Sandbox Code Playgroud)
此结果在"hej"显示出来的test1两倍和"med"表示了test2两次,而不是一个上显示的是每个。
它总是似乎总是按照书写的顺序显示,而没有进入我用'as'关键字提到的列。
有人有想法么?
GitHub的新GraphQL API需要使用令牌作为以前的版本进行身份验证。那么,我们如何在HttpLink里面添加“ Header”信息Apollo-Client呢?
const client = new ApolloClient({
link: new HttpLink({ uri: 'https://api.github.com/graphql' }),
cache: new InMemoryCache()
});
Run Code Online (Sandbox Code Playgroud) I have a websocket url created by AWS. URL is created by aws ssm start session using .net sdk. Start session method gives me streamUrl, token and session ID. URL is in following format:
wss://ssmmessages.ap-south-1.amazonaws.com/v1/data-channel/sessionidhere?role=publish_subscribe
Run Code Online (Sandbox Code Playgroud)
There is actual session id at placeof "sessionidhere" that I can not share.
I want to open terminal on web using xterm.js. I've read that xterm.js can connect to websocket URL, send messages and receive outputs.
My javascript code is here :
<!doctype html> …Run Code Online (Sandbox Code Playgroud) javascript ×4
github-api ×3
github ×2
mongodb ×2
node.js ×2
android ×1
apache-spark ×1
api ×1
apollo ×1
aws-ssm ×1
charts ×1
gradient ×1
graphql ×1
hive ×1
mongoengine ×1
mongoose ×1
postman ×1
pymongo ×1
reactjs ×1
responsive ×1
rest ×1
websocket ×1
wifi ×1
xtermjs ×1