How can I map data from json file in recat native - react-native

I am trying to fish data with images but how can I do two map inside each othe I need only the first image from every item
here is the JSON file
`
"items": Array [
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/5staYrHq4jR1NiBfRR2XWr",
},
"followers": Object {
"href": null,
"total": 433,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/5staYrHq4jR1NiBfRR2XWr",
"id": "5staYrHq4jR1NiBfRR2XWr",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5eb038f9071ec89962e7ad16b77",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174038f9071ec89962e7ad16b77",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178038f9071ec89962e7ad16b77",
"width": 160,
},
],
"name": "DOXX",
"popularity": 6,
"type": "artist",
"uri": "spotify:artist:5staYrHq4jR1NiBfRR2XWr",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1MVFEpYdHtdV3k8Bgs79Pl",
},
"followers": Object {
"href": null,
"total": 404,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1MVFEpYdHtdV3k8Bgs79Pl",
"id": "1MVFEpYdHtdV3k8Bgs79Pl",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5ebd1578a57ff89ac9aeed23863",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174d1578a57ff89ac9aeed23863",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178d1578a57ff89ac9aeed23863",
"width": 160,
},
],
"name": "DOXY",
"popularity": 14,
"type": "artist",
"uri": "spotify:artist:1MVFEpYdHtdV3k8Bgs79Pl",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1HliyC4gHWRHHFy3CjR3Bp",
},
"followers": Object {
"href": null,
"total": 2,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1HliyC4gHWRHHFy3CjR3Bp",
"id": "1HliyC4gHWRHHFy3CjR3Bp",
"images": Array [],
"name": "Doxy601",
"popularity": 5,
"type": "artist",
"uri": "spotify:artist:1HliyC4gHWRHHFy3CjR3Bp",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/7d8a8D8ZfVdYsuAcMk4Kxy",
},
"followers": Object {
"href": null,
"total": 97,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/7d8a8D8ZfVdYsuAcMk4Kxy",
"id": "7d8a8D8ZfVdYsuAcMk4Kxy",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b2736862f6dfd64d0c65d70c4623",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e026862f6dfd64d0c65d70c4623",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d000048516862f6dfd64d0c65d70c4623",
"width": 64,
},
],
"name": "Miles Davis & Milt Jackson",
"popularity": 5,
"type": "artist",
"uri": "spotify:artist:7d8a8D8ZfVdYsuAcMk4Kxy",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/6NrhhuvYUPDmZ7RiZAWQih",
},
"followers": Object {
"href": null,
"total": 546,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/6NrhhuvYUPDmZ7RiZAWQih",
"id": "6NrhhuvYUPDmZ7RiZAWQih",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5ebe2cae73d43e39e83aebc2bf5",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174e2cae73d43e39e83aebc2bf5",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178e2cae73d43e39e83aebc2bf5",
"width": 160,
},
],
"name": "DOX",
"popularity": 25,
"type": "artist",
"uri": "spotify:artist:6NrhhuvYUPDmZ7RiZAWQih",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/6792Ts7YzD8dhGkgSHPNEL",
},
"followers": Object {
"href": null,
"total": 125,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/6792Ts7YzD8dhGkgSHPNEL",
"id": "6792Ts7YzD8dhGkgSHPNEL",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273e2318a139e0f022870baac23",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02e2318a139e0f022870baac23",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851e2318a139e0f022870baac23",
"width": 64,
},
],
"name": "Miles Davis And Milt Jackson Sextet",
"popularity": 1,
"type": "artist",
"uri": "spotify:artist:6792Ts7YzD8dhGkgSHPNEL",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/2b69LpXVfEagXEJpHjj3vW",
},
"followers": Object {
"href": null,
"total": 10,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/2b69LpXVfEagXEJpHjj3vW",
"id": "2b69LpXVfEagXEJpHjj3vW",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab6761610000e5eb634c7182d6152094085cf475",
"width": 640,
},
Object {
"height": 320,
"url": "https://i.scdn.co/image/ab67616100005174634c7182d6152094085cf475",
"width": 320,
},
Object {
"height": 160,
"url": "https://i.scdn.co/image/ab6761610000f178634c7182d6152094085cf475",
"width": 160,
},
],
"name": "XODUS MMXXI",
"popularity": 12,
"type": "artist",
"uri": "spotify:artist:2b69LpXVfEagXEJpHjj3vW",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/1IhDCe20UkuG9o00cnhvS8",
},
"followers": Object {
"href": null,
"total": 106,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/1IhDCe20UkuG9o00cnhvS8",
"id": "1IhDCe20UkuG9o00cnhvS8",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b273802c20b22f713bf4ca551ea9",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e02802c20b22f713bf4ca551ea9",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d00004851802c20b22f713bf4ca551ea9",
"width": 64,
},
],
"name": "Doxi",
"popularity": 11,
"type": "artist",
"uri": "spotify:artist:1IhDCe20UkuG9o00cnhvS8",
},
Object {
"external_urls": Object {
"spotify": "https://open.spotify.com/artist/0joBZjd7WSxAGlRC2pvaJM",
},
"followers": Object {
"href": null,
"total": 0,
},
"genres": Array [],
"href": "https://api.spotify.com/v1/artists/0joBZjd7WSxAGlRC2pvaJM",
"id": "0joBZjd7WSxAGlRC2pvaJM",
"images": Array [
Object {
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b27375b17d2e3f94ae1bddd65046",
"width": 640,
},
Object {
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e0275b17d2e3f94ae1bddd65046",
"width": 300,
},
Object {
"height": 64,
"url": "https://i.scdn.co/image/ab67616d0000485175b17d2e3f94ae1bddd65046",
"width": 64,
},
],
"name": "Prod.Dozy",
"popularity": 1,
"type": "artist",
"uri": "spotify:artist:0joBZjd7WSxAGlRC2pvaJM",
},
`
I did this to map data {items.map((data,i)=>({data.name}))}
I do this and it works but I want also to get the first image for each item can I do two maps inside each other ??
but how I can get these data with the first image for every item

You can load multiple items from an array using just one map.
To get the first image of every item you'll have to access the first item from the image array [0] and from that image you'll need the url to fill the source property of an <Image/> component (from React Native). You'll also need to supply the width and height to the style property like so:
{items.map((data) => ( <>
<Image style={{width: `${data.images[0].width}`, height: `${data.images[0].height}` }} source={require(`${data.images[0].url}`)}/>
<div>{data.name}</div> </>))}
I also wrapped Image and div in a React fragment: <></>

Related

How I print a value from response (React Native)?

How do I print the URI value from this response?
Response = {"assets": [{"fileName": "rn_image_picker_lib_temp73410.jpg", "fileSize": 208402, "height": 1280, "type": "image/jpeg", "uri": "file:///data/user/0/com.react/cache/rn_image_picker_lib_temp73410.jpg", "width": 1028}]}
You can achieve it doing like this:
let Response = {
"assets": [
{
"fileName": "rn_image_picker_lib_temp73410.jpg",
"fileSize": 208402,
"height": 1280,
"type": "image/jpeg",
"uri": "file:///data/user/0/com.react/cache/rn_image_picker_lib_temp73410.jpg",
"width": 1028
}
]
}
Response.assets[0].uri

what path to use for jsonb_insert when column is a json array

I have a postgres table with a column (information) that looks like this
[
{
"col": "title",
"source": film.title
"width": 100
},
{
"col": "director",
"source": film.director,
"width": 150
},
{
"col": "year",
"source": film.releaseyear,
"width": 40
}
]
How do I add to array after the director element so it looks like this
[
{
"col": "title",
"source": film.title
"width": 100
},
{
"col": "director",
"source": film.director,
"width": 150
},
{
"col": "length",
"source": film.duration,
"width": 50
},
{
"col": "year",
"source": film.releaseyear,
"width": 40
}
]
I know it's the jsonb_insert function but I'm not sure what the path should be. I tried
jsonb_insert(information, {1}, filmLength::jsonb, true) but that doesn't work.
My confusion is that the array I'm inserting into is the whole json not just a key/value in the object.

Vega-Lite: How to use slider value in transform calculation

How do I use the value of a slider in the transform?
This example from vega online editor plots a sine and cosine wave.
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Plots two functions using a generated sequence.",
"width": 300,
"height": 150,
"data": {
"sequence": {
"start": 0,
"stop": 12.7,
"step": 0.1,
"as": "x"
}
},
"transform": [
{
"calculate": "sin(datum.x)",
"as": "sin(x)"
},
{
"calculate": "cos(datum.x)",
"as": "cos(x)"
},
{
"fold": ["sin(x)", "cos(x)"]
}
],
"mark": "line",
"encoding": {
"x": {
"type": "quantitative",
"field": "x"
},
"y": {
"field": "value",
"type": "quantitative"
},
"color": {
"field": "key",
"type": "nominal",
"title": null
}
}
}
I would like to add two sliders and use their values in the calculation. I can define sliders using:
"selection" : {
"amp" : {
"type" : "single",
"fields" : ["sin", "cos"],
"bind": {
"sin": { "input" : "range", "min": 0.0, "max": 10.0, "step": 0.1},
"cos": { "input" : "range", "min": 0.0, "max": 10.0, "step": 0.1}
}
}
},
How do I access the slider values to use in the calculations? Something like
{
"calculate": "amp.sin * sin(datum.x)",
"as": "sin(x)"
},
You can do this in exactly the way you wrote in your question. Additionally, adding an initial value will make the selections valid before you interact with them.
Here is a full example (vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Plots two functions using a generated sequence.",
"width": 300,
"height": 150,
"data": {"sequence": {"start": 0, "stop": 12.7, "step": 0.1, "as": "x"}},
"transform": [
{"calculate": "amp.sin * sin(datum.x)", "as": "sin(x)"},
{"calculate": "amp.cos * cos(datum.x)", "as": "cos(x)"},
{"fold": ["sin(x)", "cos(x)"]}
],
"mark": "line",
"encoding": {
"x": {"type": "quantitative", "field": "x"},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "key", "type": "nominal", "title": null}
},
"selection": {
"amp": {
"type": "single",
"fields": ["sin", "cos"],
"init": {"sin": 1, "cos": 1},
"bind": {
"sin": {"input": "range", "min": 0, "max": 10, "step": 0.1},
"cos": {"input": "range", "min": 0, "max": 10, "step": 0.1}
}
}
}
}

How to prepare VOTT JSON dataset to retrain COCO SSD Tensorflow api?

Hi I have annotated multi object dataset and exported as tensorflow format in VoTT. however I have no clue how to use it with tensorflow api.
Vott produces json file for each annotated images as follows:
"asset": {
"format": "jpg",
"id": "0b1e1aac9a6f2cc4e51d95ef368dbfe7",
"name": "lemon160.jpg",
"path": "file:/Volumes/Solix/Datasets/limedata/imgs_raw/lemon160.jpg",
"size": {
"width": 1280,
"height": 720
},
"state": 2,
"type": 1
},
"regions": [
{
"id": "HWaHAokRV",
"type": "RECTANGLE",
"tags": [
"Expired Lime"
],
"boundingBox": {
"height": 362.8564453125,
"width": 510.81555834378923,
"left": 625.7465495608532,
"top": 355.5866350446429
},
"points": [
{
"x": 625.7465495608532,
"y": 355.5866350446429
},
{
"x": 1136.5621079046425,
"y": 355.5866350446429
},
{
"x": 1136.5621079046425,
"y": 718.4430803571429
},
{
"x": 625.7465495608532,
"y": 718.4430803571429
}
]
}
}
can somebody suggest me a way to convert these files to tfrecords?

Parsing Twitter Information with jq ("text": null)

I am trying to do some Twitter-analysis via Twurl and extract some information via jq.
I firstly get some tweets via twurl with the command
twurl /1.1/users/search.json?q=judo
Then i used the following line to structure the outpot with jq:
twurl /1.1/users/search.json?q=judo | jq
i get something like this:
[
{
"id": 173752759,
"id_str": "173752759",
"name": "#JudoWorlds πŸ₯‹",
"screen_name": "Judo",
"location": "Worldwide",
"description": "The Official Twitter Account of the International Judo Federation πŸ₯‹",
"url": "https:.....",
"entities": {
"url": {
"urls": [
{
"url": "https://......",
"expanded_url": "https://www.ijf.org/news/show/5-must-see-preliminary-round-clashes-2",
"display_url": "ijf.org/news/show/5-mu…",
"indices": [
0,
23
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 59854,
"friends_count": 847,
"listed_count": 529,
"created_at": "Mon Aug 02 07:55:15 +0000 2010",
"favourites_count": 7074,
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"verified": true,
"statuses_count": 16532,
"lang": null,
"status": {
"created_at": "Fri Aug 30 08:27:10 +0000 2019",
"id": 1167353053282013200,
"id_str": "1167353053282013184",
"text": "#JudoWorlds The Alternative Promo \n\n#NeilAdamsJudo https://.....",
"truncated": false,
"entities": {
"hashtags": [
{
"text": "JudoWorlds",
"indices": [
0,
11
]
}
],
"symbols": [],
"user_mentions": [
{
"screen_name": "NeilAdamsJudo",
"name": "Neil Adams MBE",
"id": 40488733,
"id_str": "40488733",
"indices": [
36,
50
]
}
],
"urls": [],
"media": [
{
"id": 1167352899267002400,
"id_str": "1167352899267002369",
"indices": [
51,
74
],
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"url": "https://......",
"display_url": "pic.twitter.com/0RlLbKLkN8",
"expanded_url": "https://twitter.com/Judo/status/1167353053282013184/video/1",
"type": "photo",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 1200,
"h": 675,
"resize": "fit"
},
"small": {
"w": 680,
"h": 383,
"resize": "fit"
},
"large": {
"w": 1280,
"h": 720,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 1167352899267002400,
"id_str": "1167352899267002369",
"indices": [
51,
74
],
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"url": "https://.....",
"display_url": "pic.twitter.com/0RlLbKLkN8",
"expanded_url": "https://twitter.com/Judo/status/1167353053282013184/video/1",
"type": "video",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 1200,
"h": 675,
"resize": "fit"
},
"small": {
"w": 680,
"h": 383,
"resize": "fit"
},
"large": {
"w": 1280,
"h": 720,
"resize": "fit"
}
},
"video_info": {
"aspect_ratio": [
16,
9
],
"duration_millis": 48800,
"variants": [
{
"bitrate": 256000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/480x270/v4nkTg6qs9rpLq8M.mp4?tag=10"
},
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/pl/SQN57QxQFYcKWV7l.m3u8?tag=10"
},
{
"bitrate": 2176000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/1280x720/8cyNocB_8CRjwVCI.mp4?tag=10"
},
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/640x360/uy2U7D_AEmbLdqEK.mp4?tag=10"
}
]
},
"additional_media_info": {
"monetizable": false
}
}
]
},
"source": "Twitter for Android",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 4,
"favorite_count": 17,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
},
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "0099CC",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/1057928008797970433/O3l2sKj0_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1057928008797970433/O3l2sKj0_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/173752759/1565853008",
"profile_link_color": "0C3C42",
"profile_sidebar_border_color": "8F320A",
"profile_sidebar_fill_color": "F2CF41",
"profile_text_color": "000000",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
Because i am only interested in certain informations i tried to get the name and the text of the tweet with the following command:
twurl /1.1/users/search.json?q=judo | jq ".[] | { name: .name, text: .text }"
and i get this:
{
"name": "#JudoWorlds πŸ₯‹",
"text": null
}
{
"name": "#WeAreGBJudo",
"text": null
}
{
"name": "CBJ",
"text": null
}
{
"name": "Santos Futebol Clube",
"text": null
}
{
"name": "Marius Vizer",
"text": null
}
{
"name": "FF Judo",
"text": null
}
{
"name": "Santos FC πŸ‡Ί πŸ‡Έ πŸ‡¬ πŸ‡§ ",
"text": null
}
{
"name": "USA Judo",
"text": null
}
{
"name": "ε…¨ζ—₯ζœ¬ζŸ”ι“ι€£η›Ÿ -ゴジラジャパン-",
"text": null
}
{
"name": "Vila Belmiro",
"text": null
}
{
"name": "Deutscher Judo-Bund",
"text": null
}
{
"name": "Bruno Secco",
"text": null
}
{
"name": "Bobby Judo",
"text": null
}
{
"name": "African Judo Union",
"text": null
}
{
"name": "JudoInside.com",
"text": null
}
{
"name": "For competitive judo",
"text": null
}
{
"name": "Judo Canada",
"text": null
}
{
"name": "Neil Adams MBE",
"text": null
}
{
"name": "Sophie Cox",
"text": null
}
{
"name": "Galatasaray Judo",
"text": null
}
Why is this and how can i fix it?
I tried other commands like :
twurl /1.1/search/tweets.json?q=afd | jq ".[] | { name: .name, text: .text }"
but got the error
jq: error (at <stdin>:0): Cannot index array with string "name"
If you need nested 'text' value from 'status' field you should use:
.[] | { name: .name, text: .status.text }
Or shorter version:
.[] | { name, text: .status.text }