I´d like to change a whole row color depending on the value of a row´s field:
POST
https://sheets.googleapis.com/v4/spreadsheets/19D_Ctr5pzfuwfT2XlFDIEVsQv2ezMyShwCm-AAq7KY0:batchUpdate
BODY:
{
"requests": [
{
"addConditionalFormatRule": {
"rule": {
"ranges": [
{
"sheetId": 0
}
],
"booleanRule": {
"condition": {
"type": "TEXT_EQ",
"values": [
{
"userEnteredValue": "ERROR"
}
]
},
"format": {
"backgroundColor": {
"green": 0.2,
"red": 0.8
}
}
}
},
"index": 0
}
}
]
}
With this request, I´m changing the cell, but not thew whole row.
Any help will be greatly appreciated.
Thanks in advance.
This Works:
{
"requests": [
{
"addConditionalFormatRule": {
"rule": {
"ranges": [
{
"sheetId": 0,
"startRowIndex": 0
}
],
"booleanRule": {
"condition": {
"type": "CUSTOM_FORMULA",
"values": [
{
"userEnteredValue": "=$D1=\"ERROR\""
}
]
},
"format": {
"backgroundColor": {
"green": 0.2,
"red": 0.8
}
}
}
},
"index": 0
}
}
]
}
Related
I'm pretty sure the below can be done, I'm struggling to understand how to do it in MongoDB.
My data is structured like this (demo data):
db={
"recipes": [
{
"id": 1,
"name": "flatbread pizza",
"ingredients": {
"1010": 1,
"1020": 2,
"1030": 200
}
},
{
"id": 2,
"name": "cheese sandwich",
"ingredients": {
"1040": 1,
"1050": 2
}
}
],
"ingredients": [
{
"id": 1010,
"name": "flatbread",
"unit": "pieces"
},
{
"id": 1020,
"name": "garlic",
"unit": "clove"
},
{
"id": 1030,
"name": "tomato sauce",
"unit": "ml"
},
{
"id": 1040,
"name": "bread",
"unit": "slices"
},
{
"id": 1050,
"name": "cheese",
"unit": "slices"
}
]
}
The output I'm trying to achieve would look like this:
[
{
"id": 1,
"name": "flatbread pizza",
“flatbread”: “1 pieces”,
“garlic”: “2 cloves”,
“tomato sauce”: “200 ml”
},
{
"id": 2,
"name": "cheese sandwich",
“bread”: “1 slices”,
“cheese”: “2 slices”
}
]
I've tried several approaches, and I get stuck at the bit where I need to do a lookup based on the ingredient name (which actually is the id). I tried using $objectToArray to turn it into a k-v document, but then I get stuck in how to construct the lookup pipeline.
This is not a simple solution, and probably can be improved:
db.recipes.aggregate([
{
"$addFields": {
ingredientsParts: {
"$objectToArray": "$ingredients"
}
}
},
{
$unwind: "$ingredientsParts"
},
{
"$group": {
_id: "$id",
name: {
$first: "$name"
},
ingredientsParts: {
$push: {
v: "$ingredientsParts.v",
id: {
$toInt: "$ingredientsParts.k"
}
}
}
}
},
{
"$lookup": {
"from": "ingredients",
"localField": "ingredientsParts.id",
"foreignField": "id",
"as": "ingredients"
}
},
{
$unwind: "$ingredients"
},
{
"$addFields": {
"ingredientsPart": {
"$filter": {
input: "$ingredientsParts",
as: "item",
cond: {
$eq: [
"$$item.id",
"$ingredients.id"
]
}
}
}
}
},
{
$project: {
ingredients: 1,
ingredientsPart: {
"$arrayElemAt": [
"$ingredientsPart",
0
]
},
name: 1
}
},
{
"$addFields": {
units: {
k: "$ingredients.name",
v: {
"$concat": [
{
$toString: "$ingredientsPart.v"
},
" ",
"$ingredients.unit"
]
}
}
}
},
{
$group: {
_id: "$_id",
name: {
$first: "$name"
},
units: {
$push: "$units"
}
}
},
{
"$addFields": {
"data": {
"$arrayToObject": "$units"
}
}
},
{
"$addFields": {
"data.id": "$_id",
"data.name": "$name"
}
},
{
"$replaceRoot": {
"newRoot": "$data"
}
}
])
You can see it works here
As rickhg12hs said, it can be modeled better.
I'm trying to create a new spreadsheet using spreadsheets#create, with specified row groups.
In the API Explorer, I am entering in the JSON below. which corresponds to the following appearance:
No errors are flagged or returned when I execute the call, but when the sheet is created, the specified grouping is not created - only the values are set.
{ "properties": {
"title": "Test Spreadsheet",
"locale": "en"
},
"sheets": [
{ "properties": {"title": "Test1"},
"data": [
{
"startRow": 0,
"startColumn": 0,
"rowData": [
{ "values": [
{ "userEnteredValue": { "stringValue": "Top1" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top2" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2A" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2B" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2C" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top3" } }
]
}
]
}
],
"rowGroups": [
{ "range": {
"dimension": "ROWS",
"startIndex": 2,
"endIndex": 5
}
}
]
}
]
}
Even when I create the rowGroups JSON directly on the page, with its structured editor to make sure it is properly defined, the created spreadsheet still doesn't group the specified rows. I have triple-checked all my objects from the top down, and can't see what I am doing wrong.
I'm trying to set a data validation for one cell A1 using a "List from a range" to B1:B5
From this page,
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#booleancondition
It seems to be ONE_OF_RANGE, but can't get the code to work. Not sure where to put the specified range for list B1:B5
There is no example of ONE_OF_RANGE and how to use it.
{
"requests": [
{
"setDataValidation": {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 0
},
"rule": {
"condition": {
"type": "ONE_OF_RANGE",
"values": [
{
}
]
},
,
"strict": true
}
}
}
]
}
I have tried:
"type": "ONE_OF_RANGE",
"values": [{
"userEnteredValue": "=Sheet1!B1:B5"}
I don't get an error when running it, but nothing happens.
Got it to work.
data={
"requests": [
{
"setDataValidation": {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": 1,
"startColumnIndex": 0,
"endColumnIndex": 1
},
"rule": {
"condition": {
"type": "ONE_OF_RANGE",
"values": [{
"userEnteredValue": "=Sheet5!B1:B5"}
]
},
"strict": 'true'
}
}
}
]
}
How would you implement the following request in NEST?
I'm struggling with putting the "terms" aggregation in another "terms".
http://localhost:9200/my_index/responses/_search
{
"size":0,
"aggs":{
"FILTER":{
"filter":{"term":{"field":{"value":"INPUT_VARIABLE_OF_THE_METHOD"}}},
"aggs":{
"TERMS_ROWS":{
"terms":{
"field":"row"
},
"aggs": {
"TERMS_COLUMNS": {
"terms": {
"field": "column"
}
}
}
}
}
}
}
}
Working on Elasticsearch 5.4
NEST API version 5.3.0
My mapping:
{
"responses": {
"dynamic": "strict",
"_parent": {
"type": "panelists"
},
"_routing": {
"required": true
},
"properties": {
"column": {
"type": "text",
"analyzer": "index_analyzer_text_value",
"fielddata": true
},
"field": {
"type": "keyword"
},
"row": {
"type": "text",
"analyzer": "index_analyzer_text_value",
"fielddata": true
}
}
}
My settings:
{
"hoard_v0.2_2018-03-19_6dcb7ba5eea448b99f21837a52b5699c": {
"settings": {
"index": {
"mapping": {
"total_fields": {
"limit": "10000"
}
},
"number_of_shards": "8",
"provided_name": "hoard_v0.2_2018-03-19_6dcb7ba5eea448b99f21837a52b5699c",
"creation_date": "1521447172612",
"analysis": {
"analyzer": {
"index_analyzer_text_value": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "keyword"
}
}
},
"number_of_replicas": "1",
"uuid": "TmEBCNHXT_uN5N6q5XbNtw",
"version": {
"created": "5040099"
}
}
}
}
}
Working on Elasticsearch 5.4
NEST API version 5.3.0
Thanks!
Found it!
var columnAggregation = new TermsAggregation("COLUMN_TERMS")
{
Fie`enter code here`ld = "column",
Size = GetSize(termsItem.Limit)
};
searchRequest.Aggregations(a2 => a2
.Filter("FILTER", fAgg => fAgg
.Filter(f => f
.Term("field", termsItem.Field)
)
.Aggregations(a3 => a3
.Terms("TERMS_ROWS", a4 => a4
.Field("row")
.Aggregations( a5 => a5
.Terms("TERMS_COLUMNS", a6 => columnAggregation)
)
)
)
)
)
Hi guys I've been trying all day to construct this simple mongo query but I can't get the desire output. Below is the query and the current output.
db.customers.aggregate(
{ $match : { "status" : "Closed" } },
{ $unwind: "$lines" },
{ $group : {
_id:{label: "$lines.label",date: {$substr: [ "$date", 0, 10 ]}},
values: { $push: { date: {$substr: [ "$date", 0, 10 ]}} },
count: { $sum: 1 }
}},
{ $project : {
_id : 1,
values:1,
count:1
}}
);
Which outputs the following.
{
"result": [
{
"_id": {
"label": "label",
"date": "2010-10-01"
},
"values": [
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
},
{
"date": "2010-10-01"
}
],
"count": 4
},
{
"_id": {
"label": "label",
"date": "2010-10-10"
},
"values": [
{
"date": "2010-10-10"
}
],
"count": 1
},
{
"_id": {
"label": "label",
"date": "2010-07-25"
},
"values": [
{
"date": "2010-07-25"
}
],
"count": 1
}
]
}
However the output below is the one that I'm looking for and just can't get. I can obviously get all the data I desire, just in the wrong places.
{
"result": [
{
"_id": "label",
"values": [
{
"date": "2010-11-27",
"count": 4
},
{
"date": "2010-10-10",
"count": 1
},
{
"date": "2010-07-25",
"count": 1
}
]
}
]
}
Like always thanks for the help and support.
Can you try this:
db.customers.aggregate([
{ $match : { "status" : "Closed" } },
{ $unwind: "$lines" },
{ $group : {
_id:{label: "$lines.label",date: {$substr: [ "$date", 0, 10 ]}},
values: { $push: { date: {$substr: [ "$date", 0, 10 ]}} },
count: { $sum: 1 }
}},
// This one I added to group them behind a single label in an array list
{ $group : {
_id:{
label: "$_id.label"
},
values : {
$push : { date : "$date", count : "$count" }
}
}
},
{ $project : {
_id : 1,
values:1,
count:1
}
}
]);
If I got your problem right, you like to group the counts + dates in an values array. That you can do with $push after the 1st group stage.