Access scale value in Vega - vega

I have a simple scale like this:
{
"name": "x",
"type": "linear",
"nice": true,
"zero": true,
"domain": {
"data": "source",
"field": "x"
},
"range": {
"signal": "x_range"
}
}
How can I access the x-position for a value inside the domain?
I guessed I can do something like scale('x')(10) but that doesn't work.
I know normally one can use scale and value to achieve the most but I would like to compute something based on the pixel value.

Answering myself:
Usage: scale('x', 10)
Documentation: https://vega.github.io/vega/docs/expressions/#scale

Related

Different minimum and maximum for integer and number in json schema

Let's say I have schema where a property can be either an integer or a number. Is there a way to specify a different maximum depending on the type of value? For example:
{
"type": ["integer", "number"],
"max-if-integer": 255,
"max-if-number": 1.0
}
couldn't find anything about it in the docs.
if you are on draft7 or later, if/then/else is probably the best way to express this. if it's earlier, you can get there with oneOf, as discussed on gregsdennis's answer.
{
"if": {"type": "integer"},
"then": {
"minimum": integer-minimum,
"maximum": integer-maximum
},
"else": {
"type": "number",
"minimum": float-minimum,
"maximum": float-maximum
}
}
do note however that 1.0 and 1 are both considered integers according to the json schema spec, and will use the integer then, not the number else like non-whole-number floats.
oneOf is going to be your friend!
{
"oneOf": [
{ "type": "integer", "maximum": 255 },
{ "type": "number", "maximum": 1 }
]
}

Microsoft adaptive card choiceset iteration

i have a adaptive card choice set like below, as you can see am trying to get the value under title from a variable which is an array, is there a way i can iterate the choice set automatically because i don't know how many values the array has i want to show all the values inside the array in the choice set title
{
"type" : "Input.ChoiceSet",
"isMultiSelect": true,
"id": "myColor",
"style": "compact",
"value": "1",
"choices": [
{
"title": vars.responsedata.items[0].topic,
"value": "1"
},
{
"title": vars.responsedata.items[1].topic,
"value": "2"
},
{
"title": "Recording 3 sample",
"value": "3"
}
]
}
You can use the map() function.
Example in DataWeave:
{
choices: vars.responsedata.items map {
title: $.topic,
value: $$
}
}

How to use anyOf on different properties type?

In the schema below, I need items_list, price and variance as required keys. Condition is price and variance may or may not be null but both cannot be null.
Though I'm able to achieve it, I'm looking forward to if there's any shorter way to do this. Also, I'm not sure where exactly to put required and additionalProperties keys.
Any help is greatly appreciated.
{
"type": "object",
"properties": {
"items_list": {
"type": "array",
"items": {
"type": "string"
}
},
},
"anyOf": [
{
"properties": {
"price": {
"type": "number",
"minimum": 0,
},
"variance": {
"type": [
"number",
"null"
],
"minimum": 0,
},
},
},
{
"properties": {
"price": {
"type": [
"number",
"null"
],
"minimum": 0,
},
"variance": {
"type": "number",
"minimum": 0,
},
},
},
],
# "required": [
# "items_list",
# "price",
# "variance",
# ],
# "additionalProperties": False,
}
To answer the question, "can it be shorter?", the answer is, yes. The general rule of thumb is to never define anything in the boolean logic keywords. Use the boolean logic keywords only to add compound constraints. I use the term "compound constraint" to mean a constraint that is based on more that one value in a schema. In this case, the compound constraint is that price and variance can't both be null.
{
"type": "object",
"properties": {
"items_list": {
"type": "array",
"items": { "type": "string" }
},
"price": { "type": ["number", "null"], "minimum": 0 },
"variance": { "type": ["number", "null" ], "minimum": 0 }
},
"required": ["items_list", "price", "variance"],
"additionalProperties": false,
"allOf": [{ "$ref": "#/definitions/both-price-and-variance-cannot-be-null" }],
"definitions": {
"both-price-and-variance-cannot-be-null": {
"not": {
"properties": {
"price": { "type": "null" },
"variance": { "type": "null" }
},
"required": ["price", "variance"]
}
}
}
}
Not only do you not have to jump through hoops to get additionalProperties working properly, it's also easier to read. It even matches your description of the problem, "price and variance may or may not be null" (properties) but "both cannot be null" (not (compound constraint)). You could make this even shorter by inlining the definition, but I included it to show how expressive this technique can be while still being shorter than the original schema.
Looks like you have this mostly right. That's the right place to put required.
Using additionalProperties: false, you need to also define properties at the top level, additionalProperties cannot "see through" *Of keywords (applicators).
You can add properties: [prop] : true, but define all the properties.
You need to do this because additionalProperties only knows about properties within the same schema object at the same level.

Transloadit: PDF to Video, variable length

/video/merge docs
I need a template that converts a PDF to a video. Unfortunately, the /video/merge robot seems to require both a framerate (slide length) as well as a video duration. Since I don't know how many pages the PDF will have, I'm unable to supply duration.
Is there a way around this?
This is a section of my current template:
"pdf_to_images": {
"use": ":original",
"robot": "/document/thumbs",
"format": "png",
"width": 1920,
"height": 1080
},
"encode": {
"use": {
"steps": [
{
"name": "pdf_to_images",
"as": "image"
}
]
},
"robot": "/video/merge",
"preset": "iphone",
"width": 1920,
"height": 1080,
"ffmpeg": {
"b": "8000K"
},
"framerate": "${fields.framerate}",
"duration": "100"
},
//...store...
I need to replace "framerate" from a field in the upload, but can I replace "duration" from dynamically counting the number of results from "pdf_to_images"?
Otherwise I'm stuck creating individual videos from each image result from "pdf_to_images" and then concatenating them, which seems rather excessive in terms of resource capitalization.
Thoughts?
What you could be looking for is ${file.meta.page_count} – which, as expected, will return the number of pages in the PDF from /document/thumbs. For example, if you wanted to make a video where each page of the PDF lasts a second you'd use a template like so:
{
"steps": {
":original": {
"robot": "/upload/handle"
},
"pdf_to_images": {
"use": ":original",
"robot": "/document/thumbs",
"format": "png",
"results": true,
"width": 1920,
"height": 1080,
"imagemagick_stack": "v2.0.7"
},
"merged": {
"robot": "/video/merge",
"use": {
"steps": [
{
"name": "pdf_to_images",
"as": "image"
}
]
},
"result": true,
"framerate": "1",
"duration": "${file.meta.page_count}",
"ffmpeg_stack": "v4.3.1",
"preset": "iphone",
"resize_strategy": "fillcrop"
}
}
}

Cumulocity measurement representation

I create measurements at reception of an event, I can get them using the API, but they are not represented graphically in the Device Management interface. I there a specific format they would have to respect to be representable automatically? If so, is there a place I can find all the formats supported by Cumulocity? I infered the c8y_TemperatureMeasurement from the examples in the doc but I didn't find an exhaustive list of the native formats.
Here are examples of the measurements I have at the moment:
{
"time": "2016-06-29T12:10:02.000+02:00",
"id": "27006",
"self": "https://<tenant-id>/measurement/measurements/27006",
"source": {
"id": "26932",
"self": "https://<tenant-id>/inventory/managedObjects/26932"
},
"type": "c8y_BatteryMeasurement",
"c8y_BatteryMeasurement": {
"unit": "V",
"value": 80
}
},
{
"time": "2016-06-29T10:15:22.000+02:00",
"id": "27010",
"self": "https://<tenant-id>/measurement/measurements/27010",
"source": {
"id": "26932",
"self": "https://<tenant-id>/inventory/managedObjects/26932"
},
"type": "c8y_TemperatureMeasurement",
"c8y_TemperatureMeasurement": {
"T": {
"unit": "C",
"value": 24
}
}
}
The measurements have to be sent to Cumulocity in the following format:
{
"fragment": {
"series": {
"unit": "x",
"value": y
}
}
}