Studio HTTP Request - twilio-studio

I am dealing with Studio I am using an HTTP Request, which brings me the following information.
[
{
"id": 131316,
"name": "User 1",
"location_id": 38716,
"times": [
{
"day": 1,
"day_name": "Monday",
"open": "08:30",
"close": "13:00"
},
{
"day": 1,
"day_name": " Monday",
"open": "14:00",
"close": "18:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "08:30",
"close": "13:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "14:00",
"close": "18:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "08:30",
"close": "13:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "14:00",
"close": "18:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "08:30",
"close": "13:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "14:00",
"close": "18:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "08:30",
"close": "13:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "14:00",
"close": "17:00"
}
]
},
{
"id": 131313,
"name": "User 2",
"location_id": 38716,
"times": [
{
"day": 1,
"day_name": " Monday",
"open": "08:30",
"close": "14:00"
},
{
"day": 1,
"day_name": " Monday",
"open": "15:00",
"close": "18:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "08:30",
"close": "14:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "15:00",
"close": "18:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "08:30",
"close": "14:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "15:00",
"close": "18:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "08:30",
"close": "14:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "15:00",
"close": "18:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "08:30",
"close": "14:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "15:00",
"close": "17:00"
}
]
},
{
"id": 130975,
"name": "User 3",
"location_id": 38716,
"times": [
{
"day": 1,
"day_name": " Monday",
"open": "08:30",
"close": "13:00"
},
{
"day": 1,
"day_name": " Monday",
"open": "14:00",
"close": "18:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "08:30",
"close": "13:00"
},
{
"day": 2,
"day_name": "Tuesday",
"open": "14:00",
"close": "18:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "08:30",
"close": "13:00"
},
{
"day": 3,
"day_name": "Wednesday",
"open": "14:00",
"close": "18:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "08:30",
"close": "13:00"
},
{
"day": 4,
"day_name": "Thursday",
"open": "14:00",
"close": "18:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "08:30",
"close": "13:00"
},
{
"day": 5,
"day_name": "Friday",
"open": "14:00",
"close": "17:00"
}
]
}
]
I want to capture the "name" information that comes from the HTTP response but I have not been able to do it. I have used the following options without it working for me.
{{widgets.ListaPrestadores.response.parsed.name}}
{{widgets.ListaPrestadores.response.parsed.name[0]}}
{{widgets.ListaPrestadores.response.body.parsed.name}}
{{widgets.ListaPrestadores.response.body.parsed.name[0]}}
Does anyone have an idea how I could do this? Thank you.

I'm afraid that if you return a JSON response to the HTTP request widget that is an array, it won't parse the result.
You will need to return a plain object, perhaps by proxying the request via a Twilio Function to extract the data that you need.

Related

Scorm 2004 calculating completion percentage based on interactions

I am using Scorm 2004 and I am wondering if there is a way to calculate completion percentage based on interaction (i.e cmi.interactions.*)? or what's the straightforward way to calculate completion percentage?
The reason I was thinking about using interaction is because we have: cmi.interactions.0.objectives.n.id and I was thinking we can use cmi.objective.n.completion_status. But how to find the total number of objectives to find the completion ratio?
I appreciate any help or hint.
Update
I was able to parse suspended_data. Now the question is how to get completion progress out of it.
{
"progress": {
"lessons": {
"1": {
"c": 1,
"p": 100,
"i": {
"0": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"1": {
"c": 1
},
"2": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"3": {
"c": 1
},
"4": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"5": {
"c": 1
},
"6": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"7": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"8": {
"c": 1,
"i": {
"0": {
"c": 1
},
"1": {
"c": 1
},
"2": {
"c": 1
},
"3": {
"c": 1
},
"4": {
"c": 1
}
}
},
"9": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"10": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"11": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"12": {
"c": 1
},
"13": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"14": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"15": {
"c": 1
},
"16": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
}
}
},
"2": {
"c": 1,
"p": 100,
"i": {
"0": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"1": {
"c": 1
},
"2": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"3": {
"c": 1
},
"4": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"5": {
"c": 1
},
"6": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"7": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"8": {
"c": 1
},
"9": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
}
}
},
"3": {
"c": 1,
"p": 100,
"i": {
"0": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"1": {
"c": 1
},
"2": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"3": {
"c": 1
},
"4": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"5": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"6": {
"c": 1
},
"7": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"8": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"9": {
"c": 1
},
"10": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"11": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
},
"12": {
"c": 1
},
"13": {
"c": 1,
"i": {
"0": {
"c": 1
}
}
}
}
},
"4": {
"a": 7,
"p": 47,
"r": 1,
"s": 20,
"i": {
"0": {
"c": 1,
"k": 1,
"s": 0
},
"1": {
"c": 1,
"k": 0,
"s": 1
},
"2": {
"c": 1,
"k": 0,
"x": [1]
},
"3": {
"c": 1,
"k": 1,
"s": 3
},
"4": {
"c": 1,
"k": 0,
"s": 3
},
"5": {
"c": 1,
"k": 0,
"s": 2
},
"6": {
"c": 1,
"k": 1,
"s": 1
}
}
}
},
"p": 75
},
"score": 20
}
You are looking for the progress_measure field, likely in objectives. There are two, one for objective and one for overall sco:
You should be able to use cmi.objectives.n.progress_measure to get completion progress for the objective itself. There are some good examples here in this forum that may help: https://community.articulate.com/discussions/articulate-storyline/how-to-manage-cmi-data-model-variables
Description from the documentation of the data model:
cmi.objectives.n.progress_measure (real (10,7) range (0..1), RW)
Measure of the progress the learner has made toward completing the
objective
How to use the data stored in this calculated field to get completion %:
Notice that the range is from 0 to 1 so to get the completion % you need to multiply the value in cmi.objectives.n.progress_measure by 100 to get a percentage (e.g. 0.67 * 100 = 67%).

Vega-lite heat map text properties

Good time of day!
all text - https://github.com/vega/vega-lite/issues/5697
When building data in a block, I would like to change the font size and position of the text in the block. Used the documentation -https://vega.github.io/vega-lite/docs/title.html, but it does not work.
block:
{
"mark": "text"
"encoding": {
"text": {"field": "z", "type": "quantitative"}
"color": {"value": "black"}
"fontSize": 40
}
Changing the position will allow for the addition of a second text:
full code:
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.4.3.json",
"config": {"view": {"height": 300, "width": 400}},
"data": {
"values": [
{"x": 0, "y": 0, "z": 0},
{"x": 1, "y": 0, "z": 1},
{"x": 2, "y": 0, "z": 4},
#{"x": 3, "y": 0, "z": 9},
{"x": 4, "y": 0, "z": 16},
#{"x": 5, "y": 0, "z": 25},
{"x": 0, "y": 1, "z": 1},
{"x": 1, "y": 1, "z": 2},
{"x": 2, "y": 1, "z": 5},
{"x": 3, "y": 1, "z": 10},
#{"x": 4, "y": 1, "z": 17},
{"x": 5, "y": 1, "z": 26}]
},
"encoding": {
"x": {"field": "x", "type": "ordinal", title: "X"}
"y": {"field": "y", "type": "ordinal", title: "Y"}
}
"layer": [
{
"mark": "rect"
from: {data: "values"}
"encoding": {
"color": {
"field": "z"
"scale": {"scheme": "redyellowgreen"}
"type": "quantitative"
}
}
}
{
"mark": "text"
"encoding": {
"text": {"field": "z", "type": "quantitative"}
"color": {"value": "black"}
"fontSize": 40
}
}
]
}
2 I'd like a temperature map without spaces. It is possible if create a variable to count all x by "groupby":[y]
Help me please.
There is no fontSize encoding, but you can set a fontSize mark property:
{
"mark": {"type": "text", "fontSize": 40},
"encoding": {
"text": {"field": "z", "type": "quantitative"},
"color": {"value": "black"}
}
}
To offset text vertically, you can use the dy mark property, which specifies a number of pixels by which to vertically offset the text:
{
"mark": {"type": "text", "fontSize": 20, "dy": -20},
"encoding": {
"text": {"value": "text"},
"color": {"value": "black"}
}
}
As for computing new x values to fill-in spaces, you can do this with a Window Transform.
Here is a modified version of your example that puts all of this together (view in vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.4.3.json",
"config": {"view": {"height": 300, "width": 400}},
"data": {
"values": [
{"x": 0, "y": 0, "z": 0},
{"x": 1, "y": 0, "z": 1},
{"x": 2, "y": 0, "z": 4},
{"x": 4, "y": 0, "z": 16},
{"x": 0, "y": 1, "z": 1},
{"x": 1, "y": 1, "z": 2},
{"x": 2, "y": 1, "z": 5},
{"x": 3, "y": 1, "z": 10},
{"x": 5, "y": 1, "z": 26}
]
},
"transform": [
{"window": [{"op": "count", "field": "x", "as": "x2"}], "groupby": ["y"]}
],
"encoding": {
"x": {"field": "x2", "type": "ordinal", "title": "X"},
"y": {"field": "y", "type": "ordinal", "title": "Y"}
},
"layer": [
{
"mark": "rect",
"encoding": {
"color": {
"field": "z",
"scale": {"scheme": "redyellowgreen"},
"type": "quantitative"
}
}
},
{
"mark": {"type": "text", "fontSize": 20, "dy": -20},
"encoding": {
"text": {"value": "text"},
"color": {"value": "black"}
}
},
{
"mark": {"type": "text", "fontSize": 40, "dy": 20},
"encoding": {
"text": {"field": "z", "type": "quantitative"},
"color": {"value": "black"}
}
}
]
}

Angularjs ng-class multiple class

I am trying to apply the ng class in angularjs with such a condition that if the
value of the json is 1 to achieve the color of green, 2 would be red, 0 will be white. But for some reason I am not able to get the result. I also have a jsfiddle if you want to look the code more clearly.
https://jsfiddle.net/0xsv2aq3/42/
Any help will really be appreciate it. Thank you
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<script>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.schedule =
{
"days": [
{
"day": "2018-12-09T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 0,
"parts": []
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 2,
"parts": []
},
{
"name": "Jen C",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Kristene B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Lisa R",
"value": 1,
"parts": [
"3rd"
]
},
{
"name": "Mike B",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Nancy S",
"value": 0,
"parts": []
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 0,
"parts": []
},
{
"name": "Scott J",
"value": 2,
"parts": []
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2018-12-16T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 1,
"parts": [
"Keys 2"
]
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Jen C",
"value": 0,
"parts": []
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 0,
"parts": []
},
{
"name": "Kristene B",
"value": 0,
"parts": []
},
{
"name": "Lisa R",
"value": 1,
"parts": [
"3rd"
]
},
{
"name": "Mike B",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Nancy S",
"value": 1,
"parts": [
"2nd"
]
},
{
"name": "Paul N",
"value": 1,
"parts": [
"3rd"
]
},
{
"name": "Scott J",
"value": 2,
"parts": []
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2018-12-23T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 0,
"parts": []
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 0,
"parts": []
},
{
"name": "Jen C",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Kristene B",
"value": 2,
"parts": []
},
{
"name": "Lisa R",
"value": 2,
"parts": []
},
{
"name": "Mike B",
"value": 2,
"parts": []
},
{
"name": "Nancy S",
"value": 0,
"parts": []
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Trisha S",
"value": 1,
"parts": [
"2nd"
]
}
]
},
{
"day": "2018-12-30T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 1,
"parts": [
"Keys 2"
]
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 0,
"parts": []
},
{
"name": "Jen C",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Kristene B",
"value": 2,
"parts": []
},
{
"name": "Lisa R",
"value": 2,
"parts": []
},
{
"name": "Mike B",
"value": 2,
"parts": []
},
{
"name": "Nancy S",
"value": 1,
"parts": [
"2nd"
]
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 2,
"parts": []
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2019-01-06T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 0,
"parts": []
},
{
"name": "Debbie J",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 0,
"parts": []
},
{
"name": "Jen C",
"value": 0,
"parts": []
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Kristene B",
"value": 2,
"parts": []
},
{
"name": "Lisa R",
"value": 1,
"parts": [
"3rd"
]
},
{
"name": "Mike B",
"value": 2,
"parts": []
},
{
"name": "Nancy S",
"value": 0,
"parts": []
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2019-01-13T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 1,
"parts": [
"Keys 2"
]
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Jen C",
"value": 0,
"parts": []
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 0,
"parts": []
},
{
"name": "Kristene B",
"value": 0,
"parts": []
},
{
"name": "Lisa R",
"value": 1,
"parts": [
"3rd"
]
},
{
"name": "Mike B",
"value": 0,
"parts": []
},
{
"name": "Nancy S",
"value": 1,
"parts": [
"2nd"
]
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2019-01-20T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 1,
"parts": [
"Keys 2"
]
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Jen C",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Kristene B",
"value": 0,
"parts": []
},
{
"name": "Lisa R",
"value": 0,
"parts": []
},
{
"name": "Mike B",
"value": 0,
"parts": []
},
{
"name": "Nancy S",
"value": 1,
"parts": [
"2nd"
]
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Scott J",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Trisha S",
"value": 0,
"parts": []
}
]
},
{
"day": "2019-01-27T00:00:00",
"entries": [
{
"name": "Adam D",
"value": 1,
"parts": [
"EG"
]
},
{
"name": "Chris S",
"value": 2,
"parts": []
},
{
"name": "Debbie J",
"value": 2,
"parts": []
},
{
"name": "Dennis S",
"value": 1,
"parts": [
"Lead"
]
},
{
"name": "Jamie W",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Jen C",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Joe T",
"value": 1,
"parts": [
"Drums"
]
},
{
"name": "Karen B",
"value": 0,
"parts": []
},
{
"name": "Kristene B",
"value": 1,
"parts": [
"Melody"
]
},
{
"name": "Lisa R",
"value": 0,
"parts": []
},
{
"name": "Mike B",
"value": 1,
"parts": [
"AG"
]
},
{
"name": "Nancy S",
"value": 2,
"parts": []
},
{
"name": "Paul N",
"value": 2,
"parts": []
},
{
"name": "Scott J",
"value": 2,
"parts": []
},
{
"name": "Trisha S",
"value": 1,
"parts": [
"2nd"
]
}
]
}
]
}
}
</script>
<body>
<div ng-app="myApp" ng-controller="MyCtrl">
<table class="table" border=1>
<thead>
<tr>
<th>Name</th>
<th ng-repeat=" x in schedule.days" scope="col">{{x.day}}</th>
</tr>
</thead>
<style>
.red{background-color: red;}
.white{background-color: white;}
.green{background-color: green;}
</style>
<tbody>
<tr ng-class="{'red': day.entries[$parent.$index].value === 1, 'green': day.entries[$parent.$index].value === 2, 'white': day.entries[$parent.$index].value === 0}" ng-repeat="day1 in schedule.days[0].entries" scope="row">
<td>{{day1.name}}</td>
<td ng-repeat="day in schedule.days">{{day.entries[$parent.$index].parts[0]}}>{{day.entries[$parent.$index].value}}</td>
</tr>
</tbody>
</table>
</div>
<!-- <div ng-app="myApp" ng-controller="MyCtrl">
<table class="table" border=1>
<thead>
<tr>
<th>Name</th>
<th ng-repeat=" x in schedule.days" scope="col">{{x.day}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat=" item in schedule.days" scope="row">
<td ng-repeat="y in item.entries">{{y.value}}</td>
<td ng-repeat=" itm in item.parts">{{itm}}</td>
</tr>
</tbody>
</table>
</div>-->
</body>
</html>
I have create a custom filter for applying class to td
myApp.filter('color',function(){
return function(status){
console.log(status);
switch(status){
case 0:
return 'white';
break;
case 1:
return 'red';
break;
case 2:
return 'green';
break;
}
}
});
Add the filter in td tag
<td class="{{day.entries[$parent.$index].value | color}}" ng-repeat="day in schedule.days">{{day.entries[$parent.$index].parts[0]}}>{{day.entries[$parent.$index].value}}</td>
I was apply the style to the tr tag rather than td.
'https://jsfiddle.net/omelsoft/xL35psco/5/'
This solved my problem

Convert a tidy table to deeply nested list using R and tidyverse

I am trying to convert a tidy table (eg. example below) into a nested list using R/tidyverse. Using some tidyverse magic I was able to convert it to a list nested of depth three, but I cannot figure out how to nest it deeper.
Take the following example input:
library(tidyverse)
library(stringi)
n_patient = 2
n_samples = 3
n_readgroup = 4
n_mate = 2
df = data.frame(patient = rep(rep(LETTERS[1:n_patient], n_samples),2),
sample = rep(rep(seq(1:n_samples), each = n_patient),2),
readgroup = rep(stri_rand_strings(n_patient * n_samples * n_readgroup, 6, '[A-Z]'),2),
mate = rep(1:n_mate, each = n_patient * n_samples * n_readgroup)) %>%
mutate(file = sprintf("%s.%s.%s_%s", patient, sample, readgroup, mate)) %>%
arrange(file)
json = df %>%
nest(-patient, .key = samples) %>%
mutate(samples = map(samples, nest, -sample, .key=readgroups))
jsonlite::toJSON(json, pretty = T)
Which looks for example like this
> head(df)
patient sample readgroup mate file
1 A 1 FCSDRJ 1 A.1.FCSDRJ_1
2 A 1 FCSDRJ 2 A.1.FCSDRJ_2
3 A 1 IAXDPR 1 A.1.IAXDPR_1
4 A 1 IAXDPR 2 A.1.IAXDPR_2
5 A 1 MLDBKZ 1 A.1.MLDBKZ_1
6 A 1 MLDBKZ 2 A.1.MLDBKZ_2
The output looks like this:
[
{
"patient": "A",
"samples": [
{
"sample": 1,
"readgroups": [
{
"readgroup": "FCSDRJ",
"mate": 1,
"file": "A.1.FCSDRJ_1"
},
{
"readgroup": "FCSDRJ",
"mate": 2,
"file": "A.1.FCSDRJ_2"
},
{
"readgroup": "IAXDPR",
"mate": 1,
"file": "A.1.IAXDPR_1"
},
{
"readgroup": "IAXDPR",
"mate": 2,
"file": "A.1.IAXDPR_2"
},
{
"readgroup": "MLDBKZ",
"mate": 1,
"file": "A.1.MLDBKZ_1"
},
{
"readgroup": "MLDBKZ",
"mate": 2,
"file": "A.1.MLDBKZ_2"
},
{
"readgroup": "OMTWHK",
"mate": 1,
"file": "A.1.OMTWHK_1"
},
{
"readgroup": "OMTWHK",
"mate": 2,
"file": "A.1.OMTWHK_2"
}
]
},
{
"sample": 2,
"readgroups": [
{
"readgroup": "BHAEFA",
"mate": 1,
"file": "A.2.BHAEFA_1"
},
{
"readgroup": "BHAEFA",
"mate": 2,
"file": "A.2.BHAEFA_2"
},
{
"readgroup": "DIBRHT",
"mate": 1,
"file": "A.2.DIBRHT_1"
},
{
"readgroup": "DIBRHT",
"mate": 2,
"file": "A.2.DIBRHT_2"
},
{
"readgroup": "HHMOSV",
"mate": 1,
"file": "A.2.HHMOSV_1"
},
{
"readgroup": "HHMOSV",
"mate": 2,
"file": "A.2.HHMOSV_2"
},
{
"readgroup": "KJXTPN",
"mate": 1,
"file": "A.2.KJXTPN_1"
},
{
"readgroup": "KJXTPN",
"mate": 2,
"file": "A.2.KJXTPN_2"
}
]
},
{
"sample": 3,
"readgroups": [
{
"readgroup": "CHXJMM",
"mate": 1,
"file": "A.3.CHXJMM_1"
},
{
"readgroup": "CHXJMM",
"mate": 2,
"file": "A.3.CHXJMM_2"
},
{
"readgroup": "MDWRBS",
"mate": 1,
"file": "A.3.MDWRBS_1"
},
{
"readgroup": "MDWRBS",
"mate": 2,
"file": "A.3.MDWRBS_2"
},
{
"readgroup": "RHHKGK",
"mate": 1,
"file": "A.3.RHHKGK_1"
},
{
"readgroup": "RHHKGK",
"mate": 2,
"file": "A.3.RHHKGK_2"
},
{
"readgroup": "VVVJFD",
"mate": 1,
"file": "A.3.VVVJFD_1"
},
{
"readgroup": "VVVJFD",
"mate": 2,
"file": "A.3.VVVJFD_2"
}
]
}
]
},
{
"patient": "B",
"samples": [
{
"sample": 1,
"readgroups": [
{
"readgroup": "QAFCOS",
"mate": 1,
"file": "B.1.QAFCOS_1"
},
{
"readgroup": "QAFCOS",
"mate": 2,
"file": "B.1.QAFCOS_2"
},
{
"readgroup": "TJYYMQ",
"mate": 1,
"file": "B.1.TJYYMQ_1"
},
{
"readgroup": "TJYYMQ",
"mate": 2,
"file": "B.1.TJYYMQ_2"
},
{
"readgroup": "YMHWOI",
"mate": 1,
"file": "B.1.YMHWOI_1"
},
{
"readgroup": "YMHWOI",
"mate": 2,
"file": "B.1.YMHWOI_2"
},
{
"readgroup": "ZOMSBU",
"mate": 1,
"file": "B.1.ZOMSBU_1"
},
{
"readgroup": "ZOMSBU",
"mate": 2,
"file": "B.1.ZOMSBU_2"
}
]
},
{
"sample": 2,
"readgroups": [
{
"readgroup": "CZWHXP",
"mate": 1,
"file": "B.2.CZWHXP_1"
},
{
"readgroup": "CZWHXP",
"mate": 2,
"file": "B.2.CZWHXP_2"
},
{
"readgroup": "MIMMNH",
"mate": 1,
"file": "B.2.MIMMNH_1"
},
{
"readgroup": "MIMMNH",
"mate": 2,
"file": "B.2.MIMMNH_2"
},
{
"readgroup": "RCWMQY",
"mate": 1,
"file": "B.2.RCWMQY_1"
},
{
"readgroup": "RCWMQY",
"mate": 2,
"file": "B.2.RCWMQY_2"
},
{
"readgroup": "WDMLHE",
"mate": 1,
"file": "B.2.WDMLHE_1"
},
{
"readgroup": "WDMLHE",
"mate": 2,
"file": "B.2.WDMLHE_2"
}
]
},
{
"sample": 3,
"readgroups": [
{
"readgroup": "DWITMU",
"mate": 1,
"file": "B.3.DWITMU_1"
},
{
"readgroup": "DWITMU",
"mate": 2,
"file": "B.3.DWITMU_2"
},
{
"readgroup": "GCLWMA",
"mate": 1,
"file": "B.3.GCLWMA_1"
},
{
"readgroup": "GCLWMA",
"mate": 2,
"file": "B.3.GCLWMA_2"
},
{
"readgroup": "QZZKQB",
"mate": 1,
"file": "B.3.QZZKQB_1"
},
{
"readgroup": "QZZKQB",
"mate": 2,
"file": "B.3.QZZKQB_2"
},
{
"readgroup": "WJKGRB",
"mate": 1,
"file": "B.3.WJKGRB_1"
},
{
"readgroup": "WJKGRB",
"mate": 2,
"file": "B.3.WJKGRB_2"
}
]
}
]
}
]
Which is great, except that I also want to nest by "mate" (and in theory nest by any number of variables, without any depth limitation). Any suggestions how to accomplish this?
Thanks!
1st step is to notice you're doing it backward, this gives the same output as yours but is simpler:
json2 <- df %>% nest(-(1:2),.key=readgroups) %>% nest(-1,.key=samples)
Then we can expand it:
json3 <- df %>% nest(-(1:3),.key=mate) %>% nest(-(1:2),.key=readgroups) %>% nest(-1,.key=samples)
jsonlite::toJSON(json3,pretty=T)
output:
[
{
"patient": "A",
"samples": [
{
"sample": 1,
"readgroups": [
{
"readgroup": "FUPEYR",
"mate": [
{
"mate": 1,
"file": "A.1.FUPEYR_1"
},
{
"mate": 2,
"file": "A.1.FUPEYR_2"
}
...
And if necessary, generalize it:
vars <- names(df)[-1] # or whatever variables you want to nest, order matters!
var_pairs <- map((length(vars)-1):1,~vars[.x:(.x+1)])
json4 <- reduce(var_pairs,~{nm<-.y[1];nest(.x,.y,.key=!!enquo(nm))},.init=df)
jsonlite::toJSON(json4,pretty=T)
output:
[
{
"patient": "A",
"sample": [
{
"sample": 1,
"readgroup": [
{
"readgroup": "FUPEYR",
"mate": [
{
"mate": 1,
"file": "A.1.FUPEYR_1"
},
{
"mate": 2,
"file": "A.1.FUPEYR_2"
}
...

Google Places API - Places Details Request 404

Have a weird problem with Google Maps Api. I make an autocomplete request to the Google Api Places like this.
https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=true&language=en&types=geocode&components=country:ua&input=Kiev,%20Dn&radius=30000&location=50.431698,30.503237&key={key}
The result gives me 5 addresses. Here is the JSON response:
{
"predictions": [{
"description": "Dniprovs'kyi district, Kiev, Kyiv city, Ukraine",
"id": "023b6f6008f0b58208c7c1360c15966d591ebbf5",
"matched_substrings": [{
"length": 2,
"offset": 0
},
{
"length": 4,
"offset": 23
}
],
"place_id": "ChIJ-2Pud7La1EARRomoyKV9Nvg",
"reference": "CoQBcQAAAM61hA62d_nNjn2xs7ooCbeAFvnHn9tlTWYxqxotYheKHD6-XVLEcTvnkRss16cMRVXF-9Wk3EmvrRm_R4_Tnvwyd1XVno0TWSk30OBb8b7n_f9rZjOgir0LIFDVDgVJY0cWmx5WHG2rxxtW_qz1r37-tw39WA6g6Qfv0yGf8-H2EhB1B8ZaolsxZ6IKgSp49aJHGhTSd8BUIKFeJ4Rbvh5cjqytLN8mBQ",
"terms":
[
{
"offset": 0,
"value": "Dniprovs'kyi district"
},
{
"offset": 23,
"value": "Kiev"
},
{
"offset": 29,
"value": "Kyiv city"
},
{
"offset": 40,
"value": "Ukraine"
}
],
"types":
[
"sublocality_level_1",
"sublocality",
"political",
"geocode"
]
},
{
"description": "Dniprovs'ka embankment, Kiev, Kyiv city, Ukraine",
"id": "584f6c97be66f9dfd62c318ce83f6534004a6c8a",
"matched_substrings":
[{
"length": 2,
"offset": 0
},
{
"length": 4,
"offset": 24
}
],
"place_id": "EjBEbmlwcm92cydrYSBlbWJhbmttZW50LCBLaWV2LCBLeWl2IGNpdHksIFVrcmFpbmU",
"reference": "CmReAAAAtDXrk0vEFiKYHNPPhPXYBoQOJ38NGGjbUf7mTRH8-_cqtiIkTDDsZXzuUSATgr_uiflldtH4nUrhW0rsFmUtrkQIUz6CZCGRQTUdAJh83zagGLcuVEs1xchGY1A2izTOEhCaI_oBksWVRhO_CRaYvgSzGhQr0eOrWKZV1GJoHpGbvrtO6QZ_Ug",
"terms":
[{
"offset": 0,
"value": "Dniprovs'ka embankment"
},
{
"offset": 24,
"value": "Kiev"
},
{
"offset": 30,
"value": "Kyiv city"
},
{
"offset": 41,
"value": "Ukraine"
}
],
"types":
[
"route",
"geocode"
]
},
{
"description": "Dnepr, Kiev, Kyiv city, Ukraine",
"id": "a3c4a39941ac4c54c2b176849696118af448a090",
"matched_substrings": [{
"length": 2,
"offset": 0
},
{
"length": 4,
"offset": 7
}
],
"place_id": "ChIJjcChbKPP1EARTXya5VgHmOk",
"reference": "CmRYAAAAZuPj8SP1flByvXUVAcO3eeYb-das4IJeBPxo_usffK_Oq2mZFPZdPwhyCmyCfrCECX5ZwssyGQdaEWCCkSkyKbDCq3ZPxbEqYlyGXDFGNJ4DqGn7mXVoEHwMKKb5DG3sEhBaeZXXm9Fh-zh_Ajl0paRKGhSy1Z9s4Uv1AU609L0sztasqQU6rg",
"terms":
[
{
"offset": 0,
"value": "Dnepr"
},
{
"offset": 7,
"value": "Kiev"
},
{
"offset": 13,
"value": "Kyiv city"
},
{
"offset": 24,
"value": "Ukraine"
}
],
"types":
[
"subway_station",
"train_station",
"transit_station",
"establishment",
"geocode"
]
},
{
"description": "Dnepr, Parkova Road, Kiev, Kyiv city, Ukraine",
"id": "973dc14397b70d5be6d2ddd3c5bc2a6e2de04b59",
"matched_substrings":
[{
"length": 2,
"offset": 0
},
{
"length": 4,
"offset": 21
}
],
"place_id": "ChIJQ_49j7LP1EARLXp2vRI8pws",
"reference": "CnRlAAAAiR50_V3AfqkhvGnoHhc4n6QjXkm-aWerLtLHEhxD6cJmGuirRktoafooAdbbGOzh97TSk1MklDfBs0fyrQgRnVjkDzzjioCspJ1La6gh8I8BUC0LTpABJOlkjrvz5wpC0HhXgYm4EbHqwZZY2aBYdBIQVqbAYC42ALmzxEqWXL5H9RoU4g-MKNF34R3Y9c_-5Z7lxf9n1vY",
"terms":
[{
"offset": 0,
"value": "Dnepr"
},
{
"offset": 7,
"value": "Parkova Road"
},
{
"offset": 21,
"value": "Kiev"
},
{
"offset": 27,
"value": "Kyiv city"
},
{
"offset": 38,
"value": "Ukraine"
}
],
"types":
[
"establishment",
"geocode"
]
},
{
"description": "Dnipro, Kiev, Kyiv city, Ukraine",
"id": "9e94078fbf056913f1bf0e3de90b04fc261d21b0",
"matched_substrings":
[{
"length": 2,
"offset": 0
},
{
"length": 4,
"offset": 8
}
],
"place_id": "ChIJMe5dbqPP1EARSnZi_bKNY0A",
"reference": "CmRYAAAAbkjesqoz4jiN86mZU5KG_hNatcXIc5GJMHvSzmIKgedGz5hmlVl_QKqyO1vupXGBLOi-wx64i0e_15mgNQbwjzGBabLTDuAC0H73PD9Dz3w0C4hMqHhsNjJmRsKLYTFMEhCvwWcBT_EWiCU5Fmr32bn2GhRKADBuv9Qq52rH2Ru5-0EdDPWlGw",
"terms":
[{
"offset": 0,
"value": "Dnipro"
},
{
"offset": 8,
"value": "Kiev"
},
{
"offset": 14,
"value": "Kyiv city"
},
{
"offset": 25,
"value": "Ukraine"
}
],
"types":
[
"bus_station",
"transit_station",
"establishment",
"geocode"
]
}
],
"status": "OK"
}
After this I try to get the place details for each address. Everything works fine for 4 of the addresses, but for the address "Dniprovs'ka embankment, Kiev, Kyiv city, Ukraine" with placeid
EjBEbmlwcm92cydrYSBlbWJhbmttZW50LCBLaWV2LCBLeWl2IGNpdHksIFVrcmFpbmU
the Google Places API responses
404: request:
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjBEbmlwcm92cydrYSBlbWJhbmttZW50LCBLaWV2LCBLeWl2IGNpdHksIFVrcmFpbmU&key={key}
, response: {"html_attributions": [ ],"status": "NOT_FOUND"}
What am I doing wrong?
Thanks for help.

Resources