I'm using the google docs API and trying to set the width of a table column using batchUpdate that includes this request:
{
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_index
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': my_width,
'unit': 'PT'
}
},
'fields': 'width'
}
}
But I'm getting an error back:
{
"error": {
"code": 400,
"message": "Invalid requests[4].updateTableColumnProperties: Width type must be provided when updating column width.",
"status": "INVALID_ARGUMENT"
}
}
This is confusing. I think I am specifying the widthType. Suggestions welcome.
The solution here is to specify widthType in fields:
BEFORE
'fields': 'width'
AFTER
'fields': 'width,widthType'
Here's the complete request:
{
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_index
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': my_width,
'unit': 'PT'
}
},
'fields': 'width,widthType'
}
}
Related
I have several documents indexed on mongodb example :
{
id: randomId1,
field1:['param1', 'param2', 'param3'],
field2:['dparam1', 'dparam2', 'dparam3']
},
{
id: randomId2,
field1:['param0', 'param12', 'param3'],
field2:['dparam1', 'dparam2', 'dparam5']
},
{
id: randomId3,
field1:['param1', 'param3', 'param5'],
field2:['dparam0', 'dparam2', 'dparam7']
}
I want to aggregate on them, and I want the score to be counted for each common params between my query and my documents while using a should, for now the only solution I found is to do something like this
[
{
'$search': {
'index': 'index',
'compound': {
'should': [
{
'text': {
'query': 'param1',
'path': 'field1',
'score': {
'constant': {
'value': 1
}
}
}
}, {
'text': {
'query': 'param2',
'path': 'field1',
'score': {
'constant': {
'value': 1
}
}
}
}
],
'minimumShouldMatch': 1
}
}
}, {
'$project': {
'score': {
'$meta': 'searchScore'
},
}
}, {
'$sort': {
'score': -1,
}
}
]
And so this way, for each occurrence of my query I have a higher score, my question is there another way to optimize this ? as to not create a should statement for each of my parameters, provided it's the same path ? The score should be calculated depending on the matching elements in the array
I have the following query:
router.get('/date', (req, res)=>{
let query = {
index: 'decisions',
size: 5000,
from: 0,
body:{
query:{
filtered:{
filter:{
bool:{
must:[{
"range": {
"Date_Lecture": {
"gt": "2019-04-04",
"lt": "2019-04-06"
}
}
}]
}
}
}
}
},
}
if(req.query.decisions) query.q = `*${req.query.decisions}`
client.search(query)
.then(resp=>{
return res.status(200).json({
decisions: resp.hits
})
.catch(err=>{
console.log(500).json({
msg:'Error',
err
})
})
})})
I want to get those records from elastic which are within the stated range of dates, but it displays an error that says it doesn’t know the filtered and if I removed the filtered; it then displays another error stating it doesn’t know the filter and if I used the range alone; another error is displayed saying it doesn’t know the range keyword.
root_cause: [
{
type: 'parsing_exception',
reason: 'unknown query [filtered]',
line: 1,
col: 22
}
],
The filtered query is long gone (since ES 5.0), you should just change your query to this:
body:{
query:{
bool:{
filter:[{
"range": {
"Date_Lecture": {
"gt": "2019-04-04",
"lt": "2019-04-06"
}
}
}]
}
}
},
When I make a post REQUEST in thunder client I can't get my data back in response but I get 500 internal server error, this is the error that I got the posting request in thunder client or postman
{
"code": 79,
"codeName": "UnknownReplWriteConcern",
"errInfo": {
"writeConcern": {
"w": "majority;",
"wtimeout": 0,
"provenance": "clientSupplied"
}
},
"result": {
"n": 1,
"opTime": {
"ts": {
"$timestamp": "7022899934215012355"
},
"t": 99
},
"electionId": "7fffffff0000000000000063",
"ok": 1,
"writeConcernError": {
"code": 79,
"codeName": "UnknownReplWriteConcern",
"errmsg": "No write concern mode named 'majority;' found in replica set configuration",
"errInfo": {
"writeConcern": {
"w": "majority;",
"wtimeout": 0,
"provenance": "clientSupplied"
}
}
},
"$clusterTime": {
"clusterTime": {
"$timestamp": "7022899934215012355"
},
"signature": {
"hash": "/gnrM/bYkyRYi4XXXmEnkaLJJpg=",
"keyId": {
"low": 1,
"high": 1620408145,
"unsigned": false
}
}
},
"operationTime": {
"$timestamp": "7022899934215012355"
}
}
}
I have faced the same problem and put this code which contain ( writeConcern )in my schema and it works
const schema = new Schema({
name: String
}, {
writeConcern: {
w: 'majority',
j: true,
wtimeout: 1000
}
});
another thing I did I removed a single quotes that was around my db url
checkout this https://pretagteam.com/question/mongowriteconcernerror-no-write-concern-mode-named-majority-found-in-replica-set-configuration
React-Table
I have made an axios.get request to the back-end which in turn gives a large data-set from mongodb. The
structure of data returned is :
[
1: {_id: "5dd3be2ecf55e1ec388f502b", timestamp: 1574157870567, message: "{"temperature":58,"humidity":59,"pressure":"1 bar"}"}
2: {_id: "5dd3be2ecf55e1ec388f502a", timestamp: 1574157870067, message: "{"temperature":78,"humidity":79,"pressure":"1 bar"}"}
...
]
I want to show it to react-table.The id and timestamp is being displayed but the temperature and other variable are not being displayed.The message is string.How can I parse such amount of data at back-end to convert message into object?
Back-end code
router.get('/viewData',async(req,res) =>{
collection.find({},{_id:0,timestamp:0}).sort({timestamp:-1}).limit(400).toArray(function (err, resultantData) {
if (err)
throw err;
//var storedDataArray ;
//var gotData=[];
//var index =0;
//storedDataArray=resultantData;
//console.log(storedDataArray)
// storedDataArray.forEach(element => {
// gotData[index]=JSON.parse(element);
// console.log(gotData[index])
// index++;
// })
// console.log(gotData.length);
res.status(200).json(resultantData);
});
Is there any way to show temperature and other quantities in react table?
React-Table
class deviceData extends Component {
constructor(props) {
super(props)
this.state = {
dataList:[],
data : ' '
};
}
componentDidMount(){
const url="http://localhost:5000/api/data/viewData";
fetch (url,{
method: "GET"
}).then(response=> response.json()).then(result=>{
console.log(result);
this.setState({
dataList : result,
});
});
}
render() {
const columns =[
{
Header:"Message ID",
accessor:"_id",
sortable: true,
filterable: false,
style:{
textAlign: "left"
},
width: 300,
maxWidth: 100,
minWidth: 100,
},
{
Header:"Time Stamp",
accessor:"timestamp",
width: 300,
maxWidth: 100,
minWidth: 100,
},
{
Header:"Temperature",
id:'temperature',
filterable: false,
accessor: 'temperature'
},
{
Header:"Pressure",
id:'pressure',
filterable: false,
accessor: 'pressure'
},
{
Header:"Humidity",
id:'humidity',
filterable: false,
accessor: 'humidity'
},
]
return(
<div className="ReactTable">
<ReactTable
columns={columns}
data={this.state.dataList}
defaultPageSize={10}
className="-striped -highlight"
>
</ReactTable>
<div id={"#"+ this.props.id} ></div>
</div>
);
}
}
[![React-Table][1]][1]
Backend Response
[
{
"_id": "5dd3be2fcf55e1ec388f502c",
"timestamp": 1574157871067,
"message": "{\"temperature\":93,\"humidity\":94,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2ecf55e1ec388f502b",
"timestamp": 1574157870567,
"message": "{\"temperature\":58,\"humidity\":59,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2ecf55e1ec388f502a",
"timestamp": 1574157870067,
"message": "{\"temperature\":78,\"humidity\":79,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2dcf55e1ec388f5029",
"timestamp": 1574157869567,
"message": "{\"temperature\":88,\"humidity\":89,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2dcf55e1ec388f5028",
"timestamp": 1574157869066,
"message": "{\"temperature\":99,\"humidity\":100,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2ccf55e1ec388f5027",
"timestamp": 1574157868567,
"message": "{\"temperature\":38,\"humidity\":39,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2ccf55e1ec388f5026",
"timestamp": 1574157868067,
"message": "{\"temperature\":82,\"humidity\":83,\"pressure\":\"1 bar\"}"
},
{
"_id": "5dd3be2bcf55e1ec388f5025",
"timestamp": 1574157867566,
"message": "{\"temperature\":76,\"humidity\":77,\"pressure\":\"1 bar\"}"
}
]
Convert string back to object by using parse()
ex: var object = JSON.parse(str);
Important thing is to define column with correct accessor. Try this one:
const columns = [
{
Header: "Id",
accessor: "_id"
},
{
Header: "timestamp",
accessor: "timestamp"
},
{
Header: "Temprature",
accessor: "message.temprature"
},
{
Header: "humidity",
accessor: "message.humidity"
},
{
Header: "pressure",
accessor: "message.pressure"
}
];
And Use it in React-table like this:
<ReactTable
data={loans} // Instead of loans, use variable where you store your response
columns={columns}
defaultPageSize={10}
sortable={true}
/>
I think you can try with adding a headers in your fetch method
fetch (url,{
method: "GET",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
}
})
It will ensure your response is JSON
N.B. Try your url with postman first, setting those headers and see whether result is JSON or not, if it is JSON I believe my code will help you, if it is not a JSON return try to change your back-end code to ensure it return JSON using postman
I'm trying to finish telegram bot that will after several commands respond with message... Lost any hope of trying that i can solve this alone. Those commands with predefined message are done and working like a charm.. But now im stucked on the /price command which should show coin value in the message from coinmarket API respond..
I tried many variants but following results always called for API Call error: or message like [object Object]..
ALQO: $0.0443407142 | 9.73% 🙂
ETH: 0.000313592 | 10.14% 🙂
BTC: 0.0000107949 | 9.5% 🙂
Cap: $2,545,718
This text above is correct respond from bot... Unfortunately with free API from CMC i can do only price with USD so correct answer should be
Coinname: Price | Change%
Cap: Marketcap
My code of /price command
//This is /price command code
'use strict';
const Telegram = require('telegram-node-bot');
const rp = require('request-promise');
const requestOptions = {
method: 'GET',
uri: 'https://pro-
api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?
id=3501&convert=USD',
headers: {
'X-CMC_PRO_API_KEY': 'MYFREEAPIKEYFROMCMC'
},
json: true,
gzip: true
};
rp(requestOptions).then(response => {
console.log('API call response:', response['data'][3501]);
}).catch((err) => {
console.log('API call error:', err.message);
});
class PriceController extends Telegram.TelegramBaseController {
PriceHandler($) {
rp(requestOptions).then(response => {
console.log('API call response:', response['data'][3501]);
$.sendMessage('Cryptosoul: price', response['data']['USD']['price']
[3501]);
}).catch((err) => {
$.sendMessage('API call error:', err.message);
});
}
get routes() {
return {
'priceCommand': 'PriceHandler'
};
};
}
module.exports = PriceController;
Respond from API after node index.js (turning bot on, (message from visual studio terminal)
API call response: { id: 3501,
name: 'CryptoSoul',
symbol: 'SOUL',
slug: 'cryptosoul',
circulating_supply: 143362580.31,
total_supply: 499280500,
max_supply: null,
date_added: '2018-10-25T00:00:00.000Z',
num_market_pairs: 3,
tags: [],
platform:
{ id: 1027,
name: 'Ethereum',
symbol: 'ETH',
slug: 'ethereum',
token_address: '0xbb1f24c0c1554b9990222f036b0aad6ee4caec29' },
cmc_rank: 1194,
last_updated: '2019-04-01T23:03:07.000Z',
quote:
{ USD:
{ price: 0.000188038816143,
volume_24h: 11691.5261174775,
percent_change_1h: 0.29247,
percent_change_24h: 0.0222015,
percent_change_7d: 4.69888,
market_cap: 26957.72988069816,
last_updated: '2019-04-01T23:03:07.000Z' } } }
The messages that appears after /price command triggered
"API call error:"
"[object Object]"
"Error while running node index.js (bad code)"Chat with Bot
As I could see, you are incorrectly accessing the resulting json response object here:
$.sendMessage('Cryptosoul: price', response['data']['USD']['price']
[3501])
Just pretty printing that response object gives a correct way to access certain properties.
{
"status": {
"timestamp": "2019-04-02T08:38:09.230Z",
"error_code": 0,
"error_message": null,
"elapsed": 14,
"credit_count": 1
},
"data": {
"3501": {
"id": 3501,
"name": "CryptoSoul",
"symbol": "SOUL",
"slug": "cryptosoul",
"circulating_supply": 143362580.31,
"total_supply": 499280500,
"max_supply": null,
"date_added": "2018-10-25T00:00:00.000Z",
"num_market_pairs": 3,
"tags": [],
"platform": {
"id": 1027,
"name": "Ethereum",
"symbol": "ETH",
"slug": "ethereum",
"token_address": "0xbb1f24c0c1554b9990222f036b0aad6ee4caec29"
},
"cmc_rank": 1232,
"last_updated": "2019-04-02T08:37:08.000Z",
"quote": {
"USD": {
"price": 0.000201447607597,
"volume_24h": 12118.3983544441,
"percent_change_1h": 1.48854,
"percent_change_24h": 6.88076,
"percent_change_7d": 12.4484,
"market_cap": 28880.04882238228,
"last_updated": "2019-04-02T08:37:08.000Z"
}
}
}
}
}
So we could see that price field is located under USD object wich itself located under quote object, which is missing in your code.
Proper way to get it would be:
const price = response["data"][3501]["quote"]["USD"]["price"];
PriceHandler code:
PriceHandler($) {
rp(requestOptions)
.then((response) => {
const price = response["data"][3501]["quote"]["USD"]["price"];
$.sendMessage("Cryptosoul: price", price);
})
.catch((err) => {
console.error("API call error:", err.message);
});
}