How could i structure data for following scenario?
There is an app called Food Ordering System. It contains
Username(Who is registering this restaurant menus for online order)
Restaurant_name
Description
Location
Estimated Delivery
Menu(Has multiple menus for one restaurant)
My design
"restaurant":{
"username":{
"restaurant_name":"KFC Restaurant",
"description":"short description on restaurant",
"estimated delivery":"1hour/km",
"distance":"20km away",
"location":"Kathmandu",
"rating":"rating star up to 5",
"menus":{
"menu":{
"item":"buff momo",
"price":"$5",
"rating":"rating star up to 5"
},
"menu":{
"item":"Fried Chicken",
"price":"$10",
"rating":"rating star up to 5"
},
"menu":{
"item":"BBQ",
"price":"$20",
"rating":"rating star up to 5"
}
}
}
}
Is my design the best practice design?
It actually depends on what you want to do with this data.
If in your website you want to show a list of all restaurant and when you click on restaurant show the list of menu they are offering, storing the menu inside the restaurant might not be a good idea.
Because according to the doc :
When we read a data node in our Firebase database, we also retrieve all of its children!
(the old one) https://www.firebase.com/docs/rest/guide/structuring-data.html#section-denormalizing-data
Also, imagine if you want to do a search bar and look for a menu (like chicken nuggets) and return the list of restaurant offering this I would design your database this way:
"restaurant":{
"$username":{
"restaurant_name":"KFC Restaurant",
"description":"short description on restaurant",
"estimated delivery":"1hour/km",
"distance":"20km away",
"location":"Kathmandu",
"rating":"rating star up to 5",
...
}
}
"menus":{
"$username" : {
"menu":{
"item":"buff momo",
"price":"$5",
"rating":"rating star up to 5"
},
"menu":{
"item":"Fried Chicken",
"price":"$10",
"rating":"rating star up to 5"
},
"menu":{
"item":"BBQ",
"price":"$20",
"rating":"rating star up to 5"
}
}
}
Related
The Enhanced Ecommerce dataLayer sends only the last subcategory to Google Analytics. I've shown which it sends in the first screenshot below
However, I would like the dataLayer to send the full category to Analytics (main category/subcategory etc.). I figured I could somehow use these breadcrumbs 2nd screenshot below.
Those all are list elements in a navigation menu. The list elements don't have an ID or a class, however, the whole menu (navigation) has a class. Is there any way to overwrite the category sent to Analytics with these breadcrumbs?
Here is an example of a dataLayer used:
ecommerce: {
currencyCode: "EUR",
detail: {
products: [
{
name: "Men's waterproof mountain hiking shoes - SALOMON X U" +
"LTRA 3 GTX",
id: "8396527",
reference: "2350488",
price: "115",
category: "Mountain Hiking Shoes",
variant: "272#40, 8396527",
link: "men-s-waterproof-mountain-hiking-shoes-salomon-x-ult" +
"ra-3-gtx",
model_id: "8396527",
price_tax_exc: "95.04",
wholesale_price: "0"
}
]
}
},
I`m performing API automation testing and use GET request via Cypress and receive in the body the next structure:
{
my_list: [
{
code: "SAT-12-33-1",
description: "FLOOR 1",
payment: "128"
},
{
code: "SAT-12-33-2",
description: "FLOOR 2",
payment: "33"
},
{
code: "SAT-12-33-3",
description: "FLOOR 3",
payment: "311"
},
{
code: "SAT-12-33-4",
description: "FLOOR 4",
payment: "342"
},
{
....and so on. The full structure is 3400 records.
Could somebody give me an exact example, HOW to validate, that for instance this chunk (2 elements only) of code:
{
code: "SAT-12-33-2",
description: "FLOOR 2",
payment: "33"
},
{
code: "SAT-12-33-3",
description: "FLOOR 3",
payment: "311"
}
exactly matching on the received array of 3400 records. In my case, I will have 3 or 4 elements and I have to compare them/validate versus the big array.
I have tried expect(response.body).to.contain(), deep.equal(), .should('include') and more, but does not work to me.
Can someone provide the exact code that matching part of the structure above to the whole request body with the same structure? Again, I will have 2 or 3 elements and want to compare them together to a big array of 3400 elements?
Thank you very much!
I have a local .json file formated below
{
"results": [
{
"id": 1,
"title": "2 bedroom apartment to rent",
"location": "30 South Colonnade London E14 5EZ",
"description": "The building offers a communal lifestyle which consists of a large lounge area with dining room, working space, TV lounge, gym, stylish meeting rooms, free table tennis, free WIFI and a spacious communal roof terrace. Local transport includes Canning Town DLR and Jubilee Line (0.1 miles). Argo Apartments is managed by Grainger plc, one of the UK's leading professional landlords with over 100 years experience.",
"price": "1,800",
"beds": 2,
"bathrooms": 1,
"landlord": "Hamptons International Lettings",
"images": ["image1", "image2"]
},
{
"id": 2,
"title": "2 bedroom flat to rent",
"location": "Textile Building, Chatham Place, Hackney, London, E9",
"description": "SHORT LET - Forming part of the new eagerly awaited Textile Building in Hackney Central E8, this stunning two double bedroom property has been finished to the highest standard, featuring two modern fitted bathrooms (one en-suite), two equal double bedrooms, spacious open plan reception with brand new integrated kitchen, exposed brickwork and communal underground bike storage.",
"price": "2,400",
"beds": 2,
"bathrooms": 1,
"landlord": "Stirling Ackroyd, Hackney",
"images": ["image1", "image2"]
},
{
"id": 3,
"title": "3 bedroom apartment to rent",
"location": "Sixth Floor Tower Building 11 York Road London SE1 7NX",
"description": "A fantastic three bedroom apartment set in this popular development close to Vauxhall and Stockwell tube stations. The apartment is neutrally decorated throughout and is available either furnished or unfurnished. Residents will enjoy the plethora of shops, bars and restaurants and leisure activities in this popular part of London as well as the excellent commuter links towards Central London.",
"price": "2,050",
"beds": 3,
"bathrooms": 2,
"landlord": "Regent Letting and Property Management",
"images": ["image1", "image2"]
}
],
"newResults" : [
{
"id": 4,
"title": "2 bedroom flat to rent",
"location": "Conway Street, Fitzrovia, W1T",
"description": "Complete is delighted to market this newly renovated period property situated on the corner of Fitzroy Square in the heart of Fitzrovia, W1. The property is located on the ground floor and comes with 2 double bedrooms, shower room, open plan living and kitchen area. The kitchen is fully fitted with Siemens appliances and Duravit fittings in the bathroom. This apartment has high ceiling and retains its original period features. Located on the corner of this garden square this development was built in the 18th Century and benefits from being in the heart of vibrant London whilst also being a quiet residential area.",
"price": "1,500",
"beds": 2,
"bathrooms": 1,
"landlord": "Barnard Marcus Lettings",
"images": ["image1", "image2"]
}
]
}
I want to be able to call the relevent information mapped to a component as below
class ResultsLists extends React.Component {
constructor(props) {
super(props)
this.state = {
results: resultsData
}
}
render() {
const results = this.state.results.results.map((result) =>
<li>{result}</li>
);
return (
<div className="rst-List">
<ul className="rst-List_Items">
{results}
</ul>
</div>
)
}
}
I can't seem to get it too work and am getting the error - Objects are not valid as a React child. There seems to be a varying variety as to why this isn't working, wondered whether someone could sanity check.
You're mapping over the results, but then you're putting the whole result object into the JSX.
This is an example of how to map over data:
const someData = [{ name: "Colin" }, { name: "Ricardo" }];
const App = () => {
const temp = someData.map(o => <li>{o.name}</li>);
return (
<div>
<ul>{temp}</ul>
</div>
);
};
Note that we have {o.name} and not just {o}.
Working example here.
So in your case, you need something like:
const results = this.state.results.results.map((result) =>
<li>{result.title}</li>
);
I am trying to learn/use Node and Javascript by re-coding a PHP/MYSQL application I made that is not very efficient - as I built it while I was trying to earn those technologies as well.
I am trying to re-use a some of the information that is created or stored in JSON format.
I have in one file a set of 52 questions that looks like such...
//questions.json
{
"School" : {
"Question 1": "The facilities of the school adequately provide for a positive learning/working experience.",
"Question 2": "School provides adequate access to teaching materials without any extra expense by the teacher (books, lab supplies, art supplies, materials, copying, etc.",
"Question 3": "School is well funded to provide students and faculty with adequate materials to support their course offering.",
"Question 4": "Parent community is actively involved in supporting the school's mission and their child's education endeavors.",
"Question 5": "Classroom student to teacher ratios are kept low."
},
"Students" : {
"Question 6": "Students are generally of high aptitude.",
"Question 7": "Student interactions with faculty are primarily characterized by respectability.",
"Question 8": "Students are of diverse ethnicity."
},
"Administration" : {
"Question 9": "Administration positively supports faculty in a professional manner.",
"Question 10": "Administration actively encourages a dialogue concerning school related issues.",
"Question 11": "Administration is actively engaged in developing/supporting/maintaining a clear school vision.",
"Question 12": "Administration makes sure that the financial stability and integrity of the school is well maintained.",
"Question 13": "Administration/Ownership uses school funds to support the well being of the school."
},...
I also have a Knex script that does a query on the data and returns an array like below....
[ { Q1: 8.44,
Q2: 9.13,
Q3: 8.81,
Q4: 8.38,
Q5: 7.63,
Q6: 8.06,
Q7: 8.56,
Q8: 8.5,
Q9: 7.63,
Q10: 8.13,
Q11: 8.5,
Q12: 8.88,
Q13: 8.75,
Q14: 7.38,
Q15: 8.13,
Q16: 8.56,...
I would like to try to combine these two arrays to look like...
{
"School" : {
{"Question 1" : {
"Question" : "The facilities of the school adequately provide for a positive learning/working experience.",
"Average" : 8.44
},
{"Question 2" : {
"Question" : ""School provides adequate access to teaching materials without any extra expense by the teacher (books, lab supplies, art supplies, materials, copying, etc."",
"Average" : 9.13
}
If need be I can remove the category divisions within the .json file if that make combining easier, but in the end applications I display the data in sections, so I will eventually filter it. I just thought maybe dividing it in the json file would make it easier.
I am able to concat the arrays, and I have looked at .map but I am not sure how I would apply it to this. It looks like I would need a nested loop?
Using a double forEach loop:
const questions = {
"School" : {
"Question 1": "The facilities of the school adequately provide for a positive learning/working experience.",
"Question 2": "School provides adequate access to teaching materials without any extra expense by the teacher (books, lab supplies, art supplies, materials, copying, etc.",
"Question 3": "School is well funded to provide students and faculty with adequate materials to support their course offering.",
"Question 4": "Parent community is actively involved in supporting the school's mission and their child's education endeavors.",
"Question 5": "Classroom student to teacher ratios are kept low."
},
"Students" : {
"Question 6": "Students are generally of high aptitude.",
"Question 7": "Student interactions with faculty are primarily characterized by respectability.",
"Question 8": "Students are of diverse ethnicity."
}
};
const scores = {
Q1: 8.44,
Q2: 9.13,
Q3: 8.81,
Q4: 8.38,
Q5: 7.63,
Q6: 8.06,
Q7: 8.56,
Q8: 8.5
};
// Placeholder for your result
const result = {};
// Iterate through the question categories:
const categories = Object.keys(questions);
categories.forEach(cat => {
// Add category to result
result[cat] = {};
// Get the question keys for that category
const questionKeys = Object.keys(questions[cat]);
questionKeys.forEach(q => {
// Get the score key. i.e: Question 1 -> Q1
const scoreKey = q.replace('Question ', 'Q');
// Add question to result
result[cat][q] = {
Question: questions[cat][q],
Average: scores[scoreKey]
};
});
});
console.log(result);
What I do below is basically:
I take the question number out of "Question 1"
Combine it with "Q" to get "Q1"
And then the plain old key lookup in the object you have based on this new string.
All this, in loops below
var newObj = {};
// replace /*questions.json*/ with your actual object.
for (var category in /*questions.json*/){
var questionsObj = /*questions.json*/[category];
newObj[category] = {}
for (var question in questionsObj) {
newObj[category][question] = {};
newObj[category][question].question = questionsObj[question];
var qNumber = question.split("Question ")[1];
newObj[category][question].Average = dataArray[0]["Q"+qNumber];
}
}
I have a dropdown that has a list of countries where a client operates.
I also have a JSON file with the following (dummy info, obviously):
[
{
title: "Malaysia",
lineOne: "Address one",
lineTwo: "Address two,",
lineThree: "Address three,",
lineFour: "Address four,",
postCode: "AA1 1AA",
email: "email#address.com",
tel: "+44 1234 567 890",
mob: "",
name: "Name McName",
lat: 00.000000,
lng: -00.000000
},
{
title: "USA",
lineOne: "Address one",
lineTwo: "Address two,",
lineThree: "Address three,",
lineFour: "Address four,",
postCode: "AA1 1AA",
email: "email#address.com",
tel: "+44 1234 567 890",
mob: "",
name: "Name McName",
lat: 00.000000,
lng: -00.000000
},
]
So the issue that I'm facing is that when someone selects a country, JS iterates through the JSON file and generates a contact info block in the front end for every item where the 'title' matches the country in the data-country tag in the option for that country.
I'm relatively new to working with JSON and all the tutorials I've found are close, but not quite what I need. Is anyone able to give me a bit of guidance where to look or help me directly?
p.s. that there is also an SVG map where the available countries have a custom class that will have to update with the country selected in the dropdown and vice versa but I thought it would be easier to get one working first then worry about the map once the dropdown is working
Sorry if this isn't very clear, but as mentioned, I'm pretty fresh to this sort of JS.
Thanks,
Jay