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

Vishal Singh-Module5 #87

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
183 changes: 183 additions & 0 deletions Module 5/Question 1/Problem1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
Input Json: {
"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
},
{
"itemId": 2,
"name": "Product B",
"quantity": 1,
"price": 20
}
]
},
{
"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
}
]
}
]
}



Json Spec: [
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"customer": {
"address": "=concat(@(1,address.street),' ',@(1,address.city), ' ', @(1,address.state), ' ',@(1,address.zip))"
},
"itemTemp": "@(1,items)"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"itemTemp": {
"*": {
"inverseValue": "=divide(1,@(1,price))",
"temp": "=divideAndRound(2, @(1,quantity), @(1,inverseValue))"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"*": "orders[&1].&",
"itemTemp": {
"*": {
"temp": "orders[#4].total"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"total": "=doubleSum(@(1,total))"
}
}
}
},
{
"operation": "remove",
"spec": {
"orders": {
"*": {
"items": {
"*": {
"inverseValue": "",
"temp": ""
}
}
}
}
}
}
]


Output Json: {
"orders": [
{
"orderId": 1,
"orderDate": "2022-02-20T12:34:56Z",
"customer": {
"customerId": 1,
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"address": "123 Main St Anytown CA 12345"
},
"items": [
{
"itemId": 1,
"name": "Product A",
"quantity": 2,
"price": 10
},
{
"itemId": 2,
"name": "Product B",
"quantity": 1,
"price": 20

Choose a reason for hiding this comment

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

Price should have double type value, please correct in all questions.

}
],
"total": 40.0
},
{
"orderId": 2,
"orderDate": "2022-02-21T09:12:34Z",
"customer": {
"customerId": 2,
"firstName": "Jane",
"lastName": "Smith",
"email": "[email protected]",
"address": "456 Oak St Somewhere NY 67890"
},
"items": [
{
"itemId": 3,
"name": "Product C",
"quantity": 3,
"price": 15
}
],
"total": 45.0
}
]
}
16 changes: 16 additions & 0 deletions Module 5/Question 1/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Number of Oprations 3
1. modify-overwrite-beta (3 times)
2. shift (1 times)
3. remove (1 times)

## Explanation

* In the first operation **(modify-oveerwrite-beta)** all the address get concat (joined separated by space) and a new tempItem is created in which i have stored items tempararly.

* In the second operation **(modify-oveerwrite-beta)** i have calculated the inverseValue and the divide that value with quantity. For getting the product of price and quantity.

* In the third operation **(shift)** I have created a list of total value of all items purchased by a customer for calculating the total price.

* In fourth opration **(modify-overwrite-beta)** calculated the total price using **doubleSum** function.

* At the last I have used **remove** operation to delete the unwanted fields from the json / final output..
68 changes: 68 additions & 0 deletions Module 5/Question 10/Problem10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Input Json

{
"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"
}
]
}

Json Spec

[
{
"operation": "modify-default-beta",
"spec": {
"nameList": "=split(' ', @(1,name))",
"firstName": "=firstElement(@(1,nameList))",
"lastName": "=lastElement(@(1,nameList))",
"phone_number_count": "=size(@(1,phone_numbers))"
}
},
{
"operation": "remove",
"spec": {
"name": "",
"nameList": ""
}
}
]

Output Json

{
"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"
}
],
"firstName": "John",
"lastName": "Smith",
"phone_number_count": 2
}
9 changes: 9 additions & 0 deletions Module 5/Question 10/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Number of Operation 2
1. "modify-default-beta (1 times)
2. remove (1 times)

## Explanation:

* First operation **(modify-default-beta)** is used split the name and then assign then separately in fname and lname keys. Ath last I have used size function to count the number of object present inside the phone_numbers.

* At last **(remove)** operation is used remove the name and temp key nameList.
45 changes: 45 additions & 0 deletions Module 5/Question 11/Problem11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Input Json

{
"items": [
{
"name": "item1",
"value": 10
},
{
"name": "item2",
"value": 20
}
]
}

Json Spec

[
{
"operation": "shift",
"spec": {
"items": {
"*": {
"name": "items[#2].itemName",
"value": "items[#2].itemValue"
}
}
}
}
]


Output Json
{
"items": [
{
"itemName": "item1",
"itemValue": 10
},
{
"itemName": "item2",
"itemValue": 20
}
]
}
6 changes: 6 additions & 0 deletions Module 5/Question 11/approach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Number of operations 1
1. shift (1 times)

## Explanation:

* In first operation **(shift)** i have rename the keys from name to itemName and from value to itemValue.
Loading