Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KunalBhade-Module5 #90

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Problem1/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Number of Operations: 4

1. modify-overwrite-beta
2. shift
3. modify-overwrite-beta
4. remove

### Explanation:

1. Used modify-overwrite-beta operation and concating the firstName, lastName into new key fullName also concating the keys inside address (street, city,state,zip) into address field.

created new fields:-

inverse- inverse the quantity for multiplication.

newPrice- using divide function to multiply the inverse of quantity to price and updating price to double.

2. Used shift operation then to structure the fields to new location by shifting the newPrice in orders list.

3. used modify-overwrite-beta to modify newPrice to double.

4. Used remove operation removes unnecessary fields such as 'inverse' field from each item and the 'firstName' and 'lastName' fields from the customer.
58 changes: 58 additions & 0 deletions Problem1/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"orders": [
{
"orderId": 1,
"orderDate": "2022-02-20T12:34:56Z",
"customer": {
"customerId": 1,
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
},
"items": [
{
"itemId": 1,
"name": "Product A",
"quantity": 2,
"price": 10.0
},
{
"itemId": 2,
"name": "Product B",
"quantity": 1,
"price": 20.0
}
]
},
{
"orderId": 2,
"orderDate": "2022-02-21T09:12:34Z",
"customer": {
"customerId": 2,
"firstName": "Jane",
"lastName": "Smith",
"email": "[email protected]",
"address": {
"street": "456 Oak St",
"city": "Somewhere",
"state": "NY",
"zip": "67890"
}
},
"items": [
{
"itemId": 3,
"name": "Product C",
"quantity": 3,
"price": 15.0
}
]
}
]
}
40 changes: 40 additions & 0 deletions Problem1/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"orders" : [ {
"orderId" : 1,
"orderDate" : "2022-02-20T12:34:56Z",
"customer" : {
"customerId" : 1,
"email" : "[email protected]",
"address" : "123 Main St, Anytown, CA 12345",
"fullName" : "John Doe"
},
"items" : [ {
"itemId" : 1,
"name" : "Product A",
"quantity" : 2,
"price" : 10.0
}, {
"itemId" : 2,
"name" : "Product B",
"quantity" : 1,
"price" : 20.0
} ],
"newprice" : 40.0
}, {
"orderId" : 2,
"orderDate" : "2022-02-21T09:12:34Z",
"customer" : {
"customerId" : 2,
"email" : "[email protected]",
"address" : "456 Oak St, Somewhere, NY 67890",
"fullName" : "Jane Smith"
},
"items" : [ {
"itemId" : 3,
"name" : "Product C",
"quantity" : 3,
"price" : 15.0
} ],
"newprice" : 45.0
} ]
}
66 changes: 66 additions & 0 deletions Problem1/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"customer": {
"fullName": "=concat(@(1,firstName),' ',@(1,lastName))",
"address": "=concat(@(0,street),', ',@(0,city),', ',@(0,state),' ',@(0,zip))"
},
"items": {
"*": {
"inverse": "=divide(1,@(1,quantity))",
"newprice": "=divide(@(1,price),@(1,inverse))",
"price": "=toDouble(@(1,price))"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"*": "orders[&1].&",
"items": {
"*": {
"*": "orders[&3].items[&1].&",
"newprice": "orders[&3].&"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be total instead of newprice

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected the output and changed the name to total instead of newprice.

}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"newprice": "=doubleSum(@(1,newprice))"
}
}
}
},
{
"operation": "remove",
"spec": {
"orders": {
"*": {
"items": {
"*": {
"inverse": ""
}
},
"customer": {
"firstName": "",
"lastName": ""
}
}
}
}
}
]
10 changes: 10 additions & 0 deletions Problem10/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Number of Operations: 2

1. modify-overwrite-beta
2. shift

### Explanation:

1. Used modify-overwrite-beta operation first and split the name by space " " used firstElement, lastElement function to get first element and last element from name and then created two new keys first_name and last_name, also used size function to get the count of phone_numbers list of object store it in phone_number_count.

2. Used shift operation then to structure the field according to output.
20 changes: 20 additions & 0 deletions Problem10/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "John Smith",
"age": 35,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
},
"phone_numbers": [
{
"type": "home",
"number": "555-1234"
},
{
"type": "work",
"number": "555-5678"
}
]
}
19 changes: 19 additions & 0 deletions Problem10/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 35,
"address" : {
"street" : "123 Main St",
"city" : "Anytown",
"state" : "CA",
"zip" : "12345"
},
"phone_numbers" : [ {
"type" : "home",
"number" : "555-1234"
}, {
"type" : "work",
"number" : "555-5678"
} ],
"phone_number_count" : 2
}
22 changes: 22 additions & 0 deletions Problem10/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"operation": "modify-overwrite-beta",
"spec": {
"name": "=split(' ', @(1,name))",
"first_name": "=firstElement(@(1,name))",
"last_name": "=lastElement(@(1,name))",
"phone_number_count": "=size(@(1,phone_numbers))"
}
},
{
"operation": "shift",
"spec": {
"first_name": "&",
"last_name": "&",
"age": "&",
"address": "&",
"phone_numbers": "&",
"phone_number_count": "&"
}
}
]
7 changes: 7 additions & 0 deletions Problem11/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Number of Operations: 1

1. shift

### Explanation:

1. Used shift operation to change key 'name' and 'value' to 'itemName' and 'itemValue' inside items list by iterate over items.
12 changes: 12 additions & 0 deletions Problem11/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"items": [
{
"name": "item1",
"value": 10
},
{
"name": "item2",
"value": 20
}
]
}
9 changes: 9 additions & 0 deletions Problem11/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"items" : [ {
"itemName" : "item1",
"itemValue" : 10
}, {
"itemName" : "item2",
"itemValue" : 20
} ]
}
13 changes: 13 additions & 0 deletions Problem11/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"operation": "shift",
"spec": {
"items": {
"*": {
"name": "items.[#2].itemName",
"value": "items.[#2].itemValue"
}
}
}
}
]
10 changes: 10 additions & 0 deletions Problem12/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Number of Operations: 2

1. modify-overwrite-beta
2. shift

### Explanation:

1. Used modify-overwrite-beta operation to concat the firstName,lastName and stored in new field name, also concat the keys from address map (street, city, state, zip) in address key.

2. Used shift operation to change phones list of object to PhoneNumbers and shifted name and address keys.
22 changes: 22 additions & 0 deletions Problem12/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"employee": {
"firstName": "John",
"lastName": "Doe",
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
},
"phones": [
{
"type": "home",
"number": "555-555-1234"
},
{
"type": "work",
"number": "555-555-5678"
}
]
}
}
11 changes: 11 additions & 0 deletions Problem12/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name" : "John Doe",
"address" : "123 Main St, Anytown, CA 12345",
"PhoneNumbers" : [ {
"type" : "home",
"number" : "555-555-1234"
}, {
"type" : "work",
"number" : "555-555-5678"
} ]
}
21 changes: 21 additions & 0 deletions Problem12/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"operation": "modify-overwrite-beta",
"spec": {
"employee": {
"name": "=concat(@(1,firstName),' ',@(1,lastName))",
"address": "=concat(@(0,street),', ',@(0,city),', ',@(0,state),' ',@(0,zip))"
}
}
},
{
"operation": "shift",
"spec": {
"employee": {
"name": "name",
"address": "address",
"phones": "PhoneNumbers"
}
}
}
]
Loading