handling multiple images w/ various sizes JSON - ios

"pictures": {
"sizes": [
{
"width": 100,
"height": 75,
"link": "https://i.vimeocdn.com/video/566955426_100x75.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_100x75.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
},
{
"width": 200,
"height": 150,
"link": "https://i.vimeocdn.com/video/566955426_200x150.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_200x150.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
},
{
"width": 295,
"height": 166,
"link": "https://i.vimeocdn.com/video/566955426_295x166.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_295x166.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
},
{
"width": 640,
"height": 360,
"link": "https://i.vimeocdn.com/video/566955426_640x360.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_640x360.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
},
{
"width": 960,
"height": 540,
"link": "https://i.vimeocdn.com/video/566955426_960x540.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_960x540.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
},
{
"width": 1280,
"height": 720,
"link": "https://i.vimeocdn.com/video/566955426_1280x720.jpg?r=pad",
"link_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F566955426_1280x720.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"
}
]
},
I am working on an ios app.
This is the JSON I am working with from the Vimeo API, and I want to know what is the proper way to handle these various images. I would like to grab the one with the height of 540, but in some cases the height might be 541, or something else. Also what if there is no image with a height of 540, should I grab the last image by default? What is the proper way to handle this? Should I just try and grab the second to last image (which is the one with height: 540 most of the time) and if there is only one image grab that one? From a production standpoint, how is this type of situation usually handled? Thank you very much for any help!

Your logic is up to you. Iterate through the list of images and find the one that is exactly 540. If that doesn't exist, it is up to you what to use instead. You can use the one that is closest to 540 (either bigger or smaller as you see fit). Picking the next larger one is probably best. It's usually better to make a larger image a little smaller than trying to show a smaller image scaled larger.

Related

How to set the column width in Tabulator's PDF export

I have been trying to set the column width for a PDF export in Tabulator. Using http://tabulator.info/docs/4.5/download#pdf and https://github.com/simonbengtsson/jsPDF-AutoTable#styling-options as references, I wrote this code:
table.download("pdf", "data.pdf", {
"orientation":"portrait",
"autoTable":{
"columnStyles": {
"allocated_site_name": {"cellWidth": 20}
},
margin: {
"top": 40,
"right": 20,
"bottom": 20,
"left": 20
}
}
});
However, it seems as though columnStyles is ignored, although margin works.
Am I doing anything wrong?
I am using:
Tabulator 4.5
jspdf 1.3.5
jspdf-autotable 3.0.5
Thank you!

Grafana/Graphite change y-axis labels to % for line chart

It doesn’t seem like graphite supports changing the y-axis labels to percentages on line charts, but they support it on pie charts, oddly enough: https://graphite.readthedocs.io/en/latest/render_api.html?highlight=y-axis#valuelabels
I looked at the meta data from an svg formatted image. Surely enough they have a y.labels array for y-axis, but you can’t modify it through their Render URL API as a parameter??
"y": {
"labelValues": [0, 0.25, 0.5, 0.75, 1.0],
"labels": ["0 ", "0.25 ", "0.50 ", "0.75 ", "1.00 "],
"step": 0.25
}
Any thoughts? Here’s their documentation on all the y-axis parameters: https://graphite.readthedocs.io/en/latest/render_api.html?highlight=y-axis#yaxisside
Here's what I currently have:
/render?target=asPercent(node.load_avg.one,1)&format=png&yMax=100&yStep=25
This takes the node load average and return percentages. For example, if a value was 0.75 it would convert it to 75. However, the y-axis does not display "%" character next to the ySteps. A small thing, but it would be nice if I could make it say 75% instead of 75...
Here's what I want:
"y": {
"labelValues": [0, 25, 50, 75, 100],
"labels": ["0%", "25%", "50%", "75%", "100%"],
"step": 25
}
Seems you are right. I expect this is easy to implement. I don't have time at the moment but if you want to give it a try I can review your PR and/or give some hints.

Vanishing when using the price difference

With a team, we are studying how it is possible to predict the price movement with high-frequency. Instead of predicting the price directly, we have decided to try predicting price difference as well as the features. In other words, at time t+1, we predict the price difference and the features for time t+2. We use the predicted features from time t+1 to predict the price at time t+2.
We got very excited, because we thought getting good results with the following graph
We got problems in production and we wasn't known the problem till we plot the price difference.
Here is the content of the config file
{
"data": {
"sequence_length":30,
"train_test_split": 0.85,
"normalise": false,
"num_steps": 5
},
"training": {
"epochs":200,
"batch_size": 64
},
"model": {
"loss": "mse",
"optimizer": "adam",
"layers": [
{
"type": "lstm",
"neurons": 51,
"input_timesteps": 30,
"input_dim": 101,
"return_seq": true,
"activation": "relu"
},
{
"type": "dropout",
"rate": 0.1
},
{
"type": "lstm",
"neurons": 51,
"activation": "relu",
"return_seq": false
},
{
"type": "dropout",
"rate": 0.1
},
{
"type": "dense",
"neurons": 101,
"activation": "relu"
},
{
"type": "dense",
"neurons": 101,
"activation": "linear"
}
]
}
}
How can we fix the problem of the vanishing price difference?
Predicting the next price to within 1% or so is very easy. You could just use the old price as a prediction and achieve 1%. Prices don't change very fast. Therefore, the next price is almost always very close to the last price. The model has picked up on that.
I guess your model learned almost nothing except the very simple relationship that the next price is close to the last price. There is not necessarily anything wrong with your model. Predicting stock prices should be a very hard problem. The solution to this problem would make you rich. It is that hard.

YouTube Data API returns wrong size for "maxres" thumbnail image?

With the YouTube Data API, I can retrieve a list of thumbnail images for a video resource. This request...
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=DUM1284TqFc&fields=items%2Fsnippet%2Fthumbnails&key={YOUR_API_KEY}
...generates this response...
{
"items": [
{
"snippet": {
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/DUM1284TqFc/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/DUM1284TqFc/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/DUM1284TqFc/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/DUM1284TqFc/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/DUM1284TqFc/maxresdefault.jpg",
"width": 1280,
"height": 720
}
}
}
}
]
}
(API Explorer)
The maxres object has a width and height of 1280 and 720. However, the url (https://i.ytimg.com/vi/DUM1284TqFc/maxresdefault.jpg) actually points to a 1920x1080 image.
It seems that the "maxres" thumbnail is generated with the same size as the original uploaded video, and the size of this particular video (https://youtu.be/DUM1284TqFc) was 1920x1080.
I cannot find a 1280x720 thumbnail image for this video.
What do the width and height properties refer to?
How do I get the real width and height of the thumbnail images with the YouTube Data API?
Is there a 1280x720 version of the thumbnail image?
This appears to be a bug in YouTube's API. According to the documentation, the maxres thumbnail corresponds to:
The highest resolution version of the thumbnail image. This image size is available for some videos and other resources that refer to videos, like playlist items or search results. This image is 1280px wide and 720px tall.

how to make a scatter with regression line graph in amcharts / highcharts?

I read all amcharts and highcharts demo and cant figure out how to draw chart like
The issue I am having is the X axis is text, not numeric like most amcharts/highcharts demos are.
It doesn't matter that you have categories on the x axis, as far as the scatter plot is concerned - your x values are the array index of the categories (0-5 in the case of your image).
There is a plugin to auto calculate a regression line, here:
http://www.highcharts.com/plugin-registry/single/22/Highcharts%20regression
Or, you can calculate your own and plot it normally.
However, a regression line through a group of categories doesn't make much sense. I don't see how it can tell you anything useful, and is probably more likely to cause confusion or outright misunderstanding.
This seems to me to be data that would be more appropriate to plot with a bar chart than a scatter plot.
FWIW
{{edit:
After looking at this longer, I am somewhat unclear: is that actually a regression line, or is that an average, or a target...?
If that's the case, you can either plot it is a line series, or you can use plotLines:
http://api.highcharts.com/highcharts#yAxis.plotLines
Example with a plotLine:
http://jsfiddle.net/jlbriggs/3d3fuhbb/63/
The chart like this is very easily done using amCharts regular Serial chart with line graph with bullets (bullet: "diamond") and no line (lineAlpha: 0).
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"dataProvider": [ {
"category": "Civil",
"value": 0.87
}, {
"category": "Piping",
"value": 1.1
}, {
"category": "Mechanical",
"value": 0.69
}, {
"category": "Electrical",
"value": 0.82
}, {
"category": "Insulation",
"value": 1.42
}, {
"category": "Completion",
"value": 1.1
} ],
"valueAxes": [ {
"guides": [{
"value": 1,
"lineAlpha": 1,
"lineThickness": 2,
"lineColor": "#f00"
}]
} ],
"startDuration": 1,
"graphs": [ {
"lineAlpha": 0,
"bullet": "diamond",
"valueField": "value",
"lineColor": "#5782bf"
} ],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "category",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start"
}
} );
<script src="http://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="http://www.amcharts.com/lib/3/serial.js"></script>
<div id="chartdiv" style="width: 600px; height: 200px;"></div>

Resources