I am getting the output in list
[
(u'Shift 1', u'NURSES', u'ANITHA M.N.', u'A'),
(u'Shift 1', u'Counsellors', u'SUSHMITHA B.', u'A'),
(u'Shift 2', u'Counsellors', u'ALEX THOMAS MATHEW', u'B')
]
I want to format the output as the follows.
{
name: "Shift 1",
id: "A",
expanded: true,
children: [{
name: "Counsellors",
id: "A.1",
children: [{
name: "SUSHMITHA B.",
id: "A.1.1"
}, ]
}, {
name: "Nurses",
id: "A.2",
children: [{
name: "ANITHA M.N",
id: "A.2.1"
}, ]
},
]
}, {
name: "Shift 2",
id: "B",
expanded: true,
children: [{
name: "Counsellors",
id: "B.1",
children: [{
name: "ALEX THOMAS MATHEW",
id: "B.1.1"
}, ]
},
]
},
The below format has to be done.
Have used the concepts of multiple group by list of tuples in python.
from itertools
import groupby
import pdb
L = [(u 'Shift 1', u 'NURSES', u 'ANITHA. BHARATHAN', u 'A'), (u 'Shift 1', u 'NURSES', u 'ANITHA M.N.', u 'A'), (u 'Shift 1', u 'Counsellors', u 'SUSHMITHA B.', u 'A'), (u 'Shift 2', u 'Counsellors', u 'ALEX THOMAS MATHEW', u 'B')]
for x, y in groupby(sorted(L), lambda t: t[0]):
children = []
for c, d in groupby(sorted(y), lambda t: t[1]):
children.append('children: {}: {}'.format(c, ', '.join(c[2]
for c in d)))
could not get the above format but getting close to it. Any help will be appreciated.
Related
I created this chartJS map to showcase the distribution of registrations for this course. However, i can only see US in the map. Is there an issue with the library or should i use a different project ?
Thank you in Advance
Here is the code:
fetch('https://unpkg.com/world-atlas/countries-50m.json').then((r) => r.json()).then((data) = {
const countries = ChartGeo.topojson.feature(data, data.objects.countries).features;
const dataCountries = <?= json_encode($WorldMapData) ?>;
const chart = new Chart(canvas.getContext("2d"), {
type: 'choropleth',
data: {
labels: countries.map((d) => d.properties.name),
datasets: [{
label: 'Course Registrations',
data: countries.map((d) => ({
feature: d,
value: dataCountries[dataCountries.indexOf(d.properties.name) + 1],
})),
}]
},
options: {
legend: {
display: true
},
scale: {
projection: 'equalEarth'
},
geo: {
colorScale: {
display: true,
position: 'bottom',
quantize: 1,
legend: {
position: 'bottom-right',
},
},
},
}
});
});
This is what I see:
enter image description here
I tried to get a map showcasing the entire earth but it is only showing US.
Can you help me try to correct this code ?
I would like to make sure I have a list of customer orders. Each order must be able to be unrolled so that we can access the details of the number of items, their detail and the price of the order.
I wanted to try to do this with react-native-paper and the list component of this package.
However, I get an error on the key of each item. How can I solve it?
Thanks for your help.
> Warning: Each child in a list should have a unique "key" prop.
import * as React from 'react';
import { ScrollView } from 'react-native';
import { List } from 'react-native-paper';
const Completed = () => {
const [expanded, setExpanded] = React.useState(true);
const handlePress = () => setExpanded(!expanded);
const list = [
{
title: 'Commande 1',
date:'01/01/2020',
icon: 'av-timer'
},
{
title: 'Commande 2',
icon: 'flight-takeoff'
},
{
title: 'Commande 3',
date:'01/01/2020',
icon: 'av-timer'
},
{
title: 'Commande 4',
date:'01/01/2020',
icon: 'flight-takeoff'
},
{
title: 'Commande 5',
date:'01/01/2020',
icon: 'av-timer'
},
{
title: 'Commande 6',
date:'01/01/2020',
icon: 'flight-takeoff'
},
]
return (
<ScrollView>
{
list.map((item, i) => (
<List.Section title={item.date}>
<List.Accordion
title={item.title}
left={props => <List.Icon {...props} icon="folder" />}>
<List.Item title="Nombre d'articles : ..." />
<List.Item title="Prix total : ...€" />
</List.Accordion>
</List.Section>
))
}
</ScrollView>
);
}
export default Completed;
Add key prop like
list.map((item, i) => (
<List.Section title={item.date} key={i.toString()}> // Like here
....
</List.Section>
))
Make sure to provide a key to the first item in any loop.
In your case add the key to List.Section
<List.Section key={item.title} title={item.date}>
........
</List.Section>
Key can be any unique string in your data
Page has a polymorphic 1:1 relationship with a model called PageContent. PageContent has two subtypes (TextOnly and Video). I want to be able to able to do a findAll for "page" and get all of the content back. What am I doing wrong?
JSBin
This seems to work: http://jsbin.com/names/1/edit
Only wrong thing I could see is the App.Page.FIXTURES.
It should be:
App.Page.FIXTURES = [
{
id: 1,
title: "Introduction",
pageContent: 1,
pageContentType: "textOnly"
},{
id: 2,
title: "Summary",
pageContent: 1,
pageContentType: "Video"
}
];
or
App.Page.FIXTURES = [
{
id: 1,
title: "Introduction",
pageContent: {
id: 1,
type: "textOnly"
}
},{
id: 2,
title: "Summary",
pageContent: {
id: 1,
type: "Video"
}
}
];
I am very new to ember, can any one tell me how to write ember model for json show below. I searched lot but couldn't come up with any solution
{id:1, name: "A", children: [
{ id:1, name: "A1" },
{ id:2, name: "A2" },
{
id:3, name: "A3", children: [
{
id:1, name: "A31", children: [
{ id:1, name: "A311" },
{ id:2, name: "A312" },
]
},
]
},
]
Thanks
Have you already tried something like the following? I have not worked with ember data yet, but i imagine it to work like this:
App.Person = DS.Model.extend({
id : DS.attr("number"),
name : DS.attr("string"),
children : DS.hasMany("App.Person"),
parent : DS.belongsTo("App.Person")
});
Somehow I figure out the solution after a long time. I am answering this question because it may help others
here is the json data I have used
{"parent":[
{"id":1, "name":"A", "children_ids":[1,2]}
],
"children":[
{"id":1, "name":"A1", "children_ids":[3,4]},
{"id":2, "name":"A2", "children_ids":[5]},
{"id":3, "name":"A11"},
{"id":4, "name":"A12"},
{"id":5, "name":"A21"}
]
}
Ember model
App.Parent= DS.Model.extend({
name: DS.attr('string'),
children: DS.hasMany('App.Children')
});
App.Children = DS.Model.extend({
name: DS.attr('string'),
children: DS.hasMany('App.Children')
});
Don't forget to make plural of children is children
DS.RESTAdapter.configure(
"plurals",{
children:"children"
}
)
I am working in Google visualization charts. I had designed a orgChart. Here is my code.
<script type='text/javascript'>
google.load('visualization', '1', { packages: ['orgchart'] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addRows([
[{ v: 'TOP', f: 'TOP' }, ''],
[{ v: 'TOP CO', f: 'TOP CO' }, 'TOP'],
[{ v: 'TOP FR', f: 'TOP FR' }, 'TOP'],
[{ v: 'EAST', f: 'EAST' }, 'TOP CO'],
[{ v: 'WEST', f: 'WEST' }, 'TOP CO'],
[{ v: 'FRAN', f: 'FRAN' }, 'TOP FR'],
[{ v: 'ADIRAN', f: 'ADIRAN' }, 'EAST'],
[{ v: 'FINGER', f: 'FINGER' }, 'EAST'],
[{ v: 'CENTRAL', f: 'CENTRAL' }, 'WEST'],
[{ v: 'NORTH', f: 'NORTH' }, 'WEST']
]);
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
chart.draw(data, { allowHtml: true });
google.visualization.events.addListener(chart, 'select', function () {
var selection = chart.getSelection()[0];
var label = data.getColumnLabel(selection.column);
alert(label);
});
}
I am very new to this concept. Whenever i am clicking any data, i am getting the error like
Microsoft JScript runtime error: Invalid column index undefined. Should be an integer in the range [0-1].
Whether the data format which i had given is wrong or else i need to any other thing. My requirement is, when i click the data means, the clicked value should be displayed in ALERT BOX.
I realize that this is an old post, but I thought it might help others if it gets solved.
You are not able to achieve your goal since the table visualization only handles row selections. The column will always be undefined.