Data structure for a family tree with multiple partners and siblings? - json

I have a very basic family tree structure but I need to figure out how to make it support multiple partners and siblings without as much redundancy.
The base of the entire tree is the person that's creating the tree.
Consider this very simple structure:
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
]
}
This works nicely but what if I discovered I had a half sibling named Judy (Genghis Khan loved the ladies) and a full sibling named Brian and expanded it to this?
{
"name": "Me",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
],
"children": [
{
"name": "Tim",
"dob": "1992"
}
],
"siblings": [
{
"name": "Judy",
"dob": "1987",
"parents": [
{
"name": "Courtney Carano",
"dob": "1965"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
},
{
"name": "Brian",
"dob": "1988",
"parents": [
{
"name": "Gina Carano",
"dob": "1967"
},
{
"name": "Genghis Khan",
"dob": "1961"
}
]
}
]
}
This does map my 2 newfound siblings but now I have a bit of redundancy in my data, as Genghis Khan is in 3 different places. I could potentially create a one level list such as this:
[
{ "id": "1", "name": "Me", "dob": "1988", "parents": [2,3], "siblings": [4,5] },
{ "id": "2", "name": "Genghis Khan", "dob": "1961", "children": [1,4,5] },
{ "id": "3", "name": "Gina Carano", "dob": "1967", "children": [1] },
{ "id": "4", "name": "Tim", "dob": "1992", "parents" : [2,3] },
{ "id": "5", "name": "Judy", "dob": "1987", "parents": [2,6] },
{ "id": "6", "name": "Courtney Carano", "dob": "1965", "children": [5] }
]
Would this work out the same way without as much redundancy? And are there any foreseeable circumstances in which there would be any limitations in terms of mapping out multiple partners with children?
Note: I figure if I keep the initial structure, I'd have to add id keys to properly identify that Genghis Khan is the same in all 3 instances.
My end goal is mapping a pedigree tree (probably in d3.js) that is visually going to be in this manner, with a line in the middle between partners going to their children.
So with the dataset above, I'm trying to render:

Almost all genealogy systems have IDs for people, so I wouldn't worry about adding/requiring that.
The traditional way of doing this is to have a Family node type as well as a Person node type. This allows multiple marriages and also gives you a place to connect information like marriage date, marriage place, etc.
person[
{ "id": "p1", "name": "Me", "dob": "1988", "parents": "f3" },
{ "id": "p2", "name": "Genghis Khan", "dob": "1961", "parents": "f1", "spouse_families": ["f2", "f3"] },
{ "id": "p3", "name": "Gina Carano", "dob": "1967", "spouse_families" : ["f3"] },
{ "id": "p4", "name": "Brian", "dob": "1992", "parents" : "f3" },
{ "id": "p5", "name": "Judy", "dob": "1987", "parents": "f2" },
{ "id": "p6", "name": "Courtney Carano", "dob": "1965", "spouse_families": ["f2"] },
{"id": "p7", "name": "Mother of Ghengis"},
{"id": "p8", "name": "Father of Ghengis"},
]
family[
{"id":"f1","marriage date":"", "parents": ["p7", "p8"],"children":["p2"]},
{"id":"f2","marriage date":"", "parents": ["p6", "p2"],"children":["p5"]},
{"id":"f3","marriage date":"", "parents": ["p3","p2"],"children":["p1", "p4"]},
]
This gives you a place to connect all the parents and children together without redundancy and lots of special casing. (Note: I corrected "Tim" to "Brian" in the data structure to match the graphic.)

Related

I need to retrieve the index(number 1) information in mongodb compass

I just need to query all information of the doctor in the first index.
Here is my sample XML data
Here is my sample JSON data:
Both XML and JSON data are same. I just converted the XML to JSON format.
I have more documents like this.
I tried this query in this image
this query showing all information but I just need first doctors information.
I also tried in command prompt.Here is the query done in cmd
Here is my sample JSON code block: but I have more similar documents
{
"doctors": {
"doctor":[
{
"ssn": "257-79-xxxx",
"name": "Mavis Bxx",
"address": "xxxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": {
"patient": [
{
"gender": "Male",
"name": "Itch xxxx",
"address": "xx Cottonwood Avenue",
"revenue": "254",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon xxxxx",
"address": "xx David Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
]
},
"_id": "6"
},
{
"ssn": "179-45-xxxx",
"name": "Tobie Conxxxx",
"address": "x Comanche Center",
"country": "Spain",
"email": "tconringh#xxx.xxx",
"phone": "+86 998 262 xxxx",
"patients": {
"patient": {
"gender": "Male",
"name": "Vergil Tome",
"address": "x Melody Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
},
"_id": "18"
},
{
"ssn": "777-59-xxxx",
"name": "Gertrud Macxxxx",
"address": "x Buell Drive",
"country": "USA",
"email": "gmaclaig2#xxx.com",
"phone": "+62 975 394 xxxx",
"patients": {
"patient": [
{
"gender": "Non-binary",
"name": "Dre Skxxxx",
"address": "x Becker Circle",
"revenue": "400",
"_country": "Germany",
"_id": "20"
},
{
"gender": "Female",
"name": "Arleyne Lestxxxx",
"address": "xx Farragut Court",
"revenue": "225",
"_country": "France",
"_id": "22"
}
]
},
"_id": "3"
}
You needs to change your collect data format. Your current format is single big size data. Not a quarriable format.
So
From current format
{
"doctors": {
"docker": [
{
...
"patients": {
"patient": [
{
...
},
{
...
}
]
},
},
{
...
}
]
}
}
To this format
[
{
...
"patients": [
{
...
},
{
...
}
]
},
{
...
}
]
Test JSON
[
{
"ssn": "2xx-7x-4xxx",
"name": "Mavis Bxxxed",
"address": "9xxx Rusk Drive",
"country": "France",
"email": "",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Itch Txxx",
"address": "5xx Cottonwood Avenue",
"revenue": "25x",
"_country": "Spain",
"_id": "27"
},
{
"gender": "Male",
"name": "Damon Wxxx",
"address": "09xx Dxxxx Trail",
"revenue": "370",
"_country": "Germany",
"_id": "21"
}
],
"_id": "6"
},
{
"ssn": "19-45-xxxx",
"name": "Tobie Coxxxx",
"address": "8x Comxxxx Center",
"country": "Spain",
"email": "tconxxxxx#usa.gov",
"phone": "",
"patients": [
{
"gender": "Male",
"name": "Some one",
"address": "1 Mexxxx Drive",
"revenue": "254",
"_country": "Germany",
"_id": "15"
}
],
"_id": "18"
}
]
In Compass View after add data upper data
Find doctor by name query
{ name: "Mavis Bxxxed" }
Find doctor by patient name
{ "patients.name": "Some one" }
If same search with this query
{ "patients.name": "Itch Txxx" }
OR
{ "patients.name": "Damon Wxxx" }
will same result to find the first docker (Mavis Bxxxed)
Due to it's patients start [ and end ]. it is array type a single size of data.
You can filter by project option
{
patients: {
$filter:
{
input: "$patients",
cond: { $eq: [ "$$patient.name", "Itch Txxx"] },
as: "patient"
}
}
}
OR shows only address
{ "patients.address" : 1 }

Moving a JSON array which have another array elements to the same LEVEL

I have the following JSON which have an element array_within_array in another array. So I want to pull both array_within_array element and upper array element(event_array) to root level using jq.
So here there are 3 events.
meal_selection
login
placed_order
Event placed_order have two sub-events in array. So after conversion there should be 4 events(1 from meal_selection, 1 from login and 2 from placed_order). these all should be on the same level.
Here is the JSON
{
"region": "USA",
"user_id": "123",
"event_array": [{
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "meal_selection",
"created_at": "2021-08-13 01:28:57"
},
{
"event_name": "login",
"created_at": "2021-08-13 01:29:02"
},
{
"event_attributes": {
"array_within_array": [
{
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
{
"date": "2021-08-18",
"category": "dinner",
"location": "home"
}
]
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
]
}
and I want to convert to the below one
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "meal_selection",
"created_at": "2021-08-13 01:28:57"
}
{
"region": "USA",
"user_id": "123",
"event_name": "login",
"created_at": "2021-08-13 01:29:02"
}
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-17",
"category": "lunch",
"location": "office"
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
{
"region": "USA",
"user_id": "123",
"event_attributes": {
"date": "2021-08-18",
"category": "dinner",
"location": "home"
},
"event_name": "placed_order",
"created_at": "2021-08-13 01:28:08"
}
Here's a straightforward solution that keeps things simple by using two steps:
{ region, user_id} + (.event_array[] )
| if .event_attributes|has("array_within_array")
then .event_attributes.array_within_array as $a
| .event_attributes = $a[]
else .
end

Import JSON to Flask template

I'm passing JSON
{
"name": "Jo",
"surname": "Sin",
"market": "US",
"date": "2020-07-07T00:00:00",
"contactPerson": {
"name": "Jan Kowalski",
"position": "Nikt",
"address": "ul. Kolorowa 123",
"phone": "736537362",
"fax": "827283738",
"email": "koko#ko.pl"
},
"secondContactPerson": {
"name": "Anna Mark",
"position": "buk",
"address": "ul. Nowowiejska 37a",
"phone": "27637222342",
"fax": "347484748",
"email": "lala#la.pl"
},
"representatives": [
{
"name": "Wojciech Makowski",
"title": "master"
}
],
"customerRepresentatives": [
{
"name": "George Soros",
"title": "bogacz"
}
]
}
templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "pdf_template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
html = template.render(context_dict)
to Flask template and I would like to modify it for example from date I would like to get just day and month. I would like to list all representatives and more. How can I achieve it?
Try this:
{{ json.date.strftime('%A') }}

Accessing to the Facebook profile picture

I am using Firebase in order to do a Facebook auth, I would like to know how to display and access to the profile picture from the returned json which looks like this
{
"uid": "facebook:1419891304993631",
"provider": "facebook",
"facebook": {
"id": "1419891304993631",
"accessToken": "CAAJdUVn89vwBAKYZASyfcpTEeSNZApxJEy7xDoCe8M02xZBCJeW6bneWbPJiXYXo0Oe3BVt4hL4xmVkQG5DnQPUs4AeXf67vx2p5kXPvk0vgsB7EPWUhDQzDZAXa1JLdCZBaVhNDtv39dqyH24qwqVzTxKqH8DRPeSPqga5DjZBsAaqmhcaMyPNXZB26NPZA8RZCS8J0zZAmyO67Lq7W5y3der",
"displayName": "Aaron Hillel Swartz",
"email": "retana.marcelo#gmail.com",
"cachedUserProfile": {
"id": "1419891304993631",
"name": "Aaron Hillel Swartz",
"last_name": "Swartz",
"first_name": "Aaron",
"middle_name": "Hillel",
"gender": "male",
"link": "https://www.facebook.com/app_scoped_user_id/1419891304993631/",
"email": "retana.marcelo#gmail.com",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/s100x100/111…77b0ef39e0&oe=55A9B547&__gda__=1436644689_2ba73b2df6e584b46e5a2f8000d571d8"
}
},
"age_range": {
"min": 21
},
"locale": "es_LA",
"timezone": -6
}
},
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2IjowLCJkIjp7InVpZCI6ImZhY2Vib29rOjE0MTk4OTEzMDQ5OTM2MzEiLCJwcm92aWRlciI6ImZhY2Vib29rIn0sImlhdCI6MTQyOTA4NTA4OH0.ec-5bS1-sTSUfeBwDZRwncZxuABrHwnlIQY5eLYxQBQ",
"auth": {
"uid": "facebook:1419891304993631",
"provider": "facebook"
},
"expires": 1429171488
}
example, with this
<div ng-bind="user.uid"></div>
I can display de user uid which is facebook:1419891304993631 in this case, so, with angular, how can I access to the profile picture property ?
Is there a way to use like a kind of ng-src for this?

D3 - tree nodes not built from external JSON file

I'm having difficulty processing external JSON data to build/dispaly a tree. The issue is that nodes are not built from received JSON file. The code only looks as at the JSON data as one object and does not create leafs(other nodes)
When adding the same JSON data as array inside HTML file, the same code creates nodes and displays the tree correctly.
Here is an extract of the code in question:
<body onload="myFunction()">
<script type="text/javascript" >
function myFunction()
{
d3.json("/data/mydata.json", function (error, data) {
var root2 = [data];
root = root2[0];
........... other stuff comes here .....
var nodes = tree.nodes(root.reverse());
The browser debugger gives me the following:
nodes
[Array[1]0: Object
childern: Array[2]
name: "Max"
parent: "null"
proto: Object
depth: 0
length: 1
x: 230
y: 0
proto: Array[0]
JOSN file is at the bottom
I appreciate your feedback in this regard.
[{
"name": "Max",
"parent": "null",
"size": 4938,
"childern": [
{
"name": "David",
"parent": "Max",
"Childern": [
{
"name": "Craig",
"parent": "David",
"size": 3938
},
{
"name": "Robin",
"parent": "David",
"size": 3812
},
{
"name": "Anna",
"parent": "David",
"size": 743
}
]
},
{
"name": "Peter",
"parent": "Max",
"Childern": [
{
"name": "Jeff",
"parent": "Peter",
"size": 3534
},
{
"name": "Buffy",
"parent": "Peter",
"size": 5731
}
]
}
]
}
]
Your external JSON file appears to have the 'children' element with a capital 'C' for the lower tiers of data, but with lower case 'c' at the top tier.
Additionally they were misspelled as 'Childern' which may have been causing problems (you will want to check your JavaScript to see how you spelled it there and make it consistent).
I was able to do a quick experiment with an external JSON file and I can confirm that you will get a problem similar to what you describe. So use lower case characters (or at least consistent characters and spelling) for the word 'children' in your data.
Try with the data per below;
[{
"name": "Max",
"parent": "null",
"size": 4938,
"children": [
{
"name": "David",
"parent": "Max",
"children": [
{
"name": "Craig",
"parent": "David",
"size": 3938
},
{
"name": "Robin",
"parent": "David",
"size": 3812
},
{
"name": "Anna",
"parent": "David",
"size": 743
}
]
},
{
"name": "Peter",
"parent": "Max",
"children": [
{
"name": "Jeff",
"parent": "Peter",
"size": 3534
},
{
"name": "Buffy",
"parent": "Peter",
"size": 5731
}
]
}
]
}