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

Apurva Shukla- Module 5 #89

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
863e134
Solved all questions of Module 5
apurvaone May 22, 2023
bae17c7
added the solution of Problem 14
apurvaone May 23, 2023
d17576a
Corrected Problem 1: concatination of firstName and lastName
apurvaone May 24, 2023
d8058b2
Corrected the output in Problem 16
apurvaone May 24, 2023
2e3b42b
Added the missing 'department' field in Problem 8
apurvaone May 25, 2023
b9f7c62
Added the missing 'salary' field in Problem 8
apurvaone May 25, 2023
1ed18f6
Added explanation.md file in problems 1-4
apurvaone May 30, 2023
c7e3cbc
Optimized the transformation of Problem 5
apurvaone May 30, 2023
f6863d9
Added explanation.md file for Problem 5-6
apurvaone May 30, 2023
661c422
Optimized the transformation of problem 7 and added explanation.md file
apurvaone May 30, 2023
570afe6
Corrected the mention of used operation in Problem 7
apurvaone May 30, 2023
90d02c5
Added another solution for Problem 8 Transformation
apurvaone May 30, 2023
587c4c5
Added the explanation.md file for Problems 8-10
apurvaone May 30, 2023
17ecbc3
Added optimized solution for problem 11
apurvaone May 30, 2023
8a9f4aa
Added the explanation.md file for problem 11
apurvaone May 30, 2023
e1e9b35
Optimized the transformation spec of Problem 12
apurvaone May 30, 2023
3847138
Added the explanation.md file for problem 12-13
apurvaone May 31, 2023
641c989
Corrected the spec of problem 14 to add the missing 'department' field
apurvaone May 31, 2023
3dcdb70
Added the explanation.md file for problems 14-25
apurvaone May 31, 2023
26484cd
Optimized the transformation spec of Problem 26
apurvaone May 31, 2023
69ddb4c
Added the explanation.md file for problems 26-34
apurvaone May 31, 2023
4af606c
Added the missing 'totalPrice' field in problem 15
apurvaone Jun 6, 2023
eab9b22
Resolved problem 8 issue: removed the usage of field 'tempBonus'
apurvaone Jun 7, 2023
cf48fb1
Added alternate solution in problem 8,assuming the bonus is given dep…
apurvaone Jun 7, 2023
0b8aa2a
Optimized Problem 5 spec:used '&' to access the keys of map
apurvaone Jun 7, 2023
0b82846
Corrected the level in problem 10
apurvaone Jun 7, 2023
276f9c3
Optimized problem 1: removed the usage of duplicate field 'itemsTemp'
apurvaone Jun 7, 2023
5a76e63
Problem 12: Corrected the key of list 'phone' to 'phoneNumbers'
apurvaone Jun 7, 2023
8e5e059
Optimized Problem 14 :used wildcard '&' to access the keys of map
apurvaone Jun 7, 2023
731df98
Problem 15: Removed the operation 'sort'
apurvaone Jun 7, 2023
dc110c5
Optimized Problem 29: Reduced no. of operation
apurvaone Jun 7, 2023
615ad7c
Corrected Problem 30: Taken name field from 'person' insted of 'emplo…
apurvaone Jun 7, 2023
b5b38b8
Optimized Problem 33: Reduced no. of operation
apurvaone Jun 7, 2023
87113cc
Optimized Problem 27: Made the spec more dynamic,reduced operations
apurvaone Jun 7, 2023
c3540bb
Used '&' to naviagte on levels instead of '#' in Problem 6
apurvaone Jun 7, 2023
009ceb1
Updated the explanation.md file for problem 1
apurvaone Jun 12, 2023
23015c1
Updated the explanation file for problem 5
apurvaone Jun 12, 2023
44c0cc1
Updated the explanation file for problem 8
apurvaone Jun 12, 2023
51cd391
Updated the explanation file for problem 10
apurvaone Jun 12, 2023
b01f32b
Updated the explanation file for problem 12
apurvaone Jun 12, 2023
72efc66
Updated the explanation file for problem 15
apurvaone Jun 12, 2023
4c9e232
Updated the explanation file for problem 29
apurvaone Jun 12, 2023
fec0f1d
Updated the explanation file for problem 30
apurvaone Jun 12, 2023
5cb15fe
Updated the explanation file for problem 33
apurvaone Jun 12, 2023
6351102
Updated the explanation file for problem 27
apurvaone Jun 12, 2023
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
15 changes: 15 additions & 0 deletions Module 5/Problem 1/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Explanation

Opeartions: modify-overwrite-beta, shift , remove

The transformation involves following operation:

* **`modify-overwrite-beta`** : Adds "customer.address" and "customer.fullname" fields to each order by concatenating address fields and customer names, also created a copy of items in each order and naming it itemTemp.

* **`modify-overwrite-beta`** : Adds "inverseValue" and "temp" fields to each item by dividing 1 by the price effictively resulting in multipication of price and quantity and storing it in variable named temp, inside itemTemp lsit.

* **`shift`**: Restructures the JSON by moving the temp value (total amount of each order) into a list named total containing the price of each order, and placing it on each order object.

* **`modify-overwrite-beta`**" : Computes the sum of "total" values within "orders" and assigns it to each order's "total" field.

* `"remove"`: Removes "firstName", and "lastName" fields from each order.
189 changes: 189 additions & 0 deletions Module 5/Problem 1/problem1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
Input:


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



Transformation:

[
{
"operation": "modify-overwrite-beta",
"spec": {
"orders": {
"*": {
"customer": {
"address": "=concat(@(1,address.street),' ',@(1,address.city), ' ', @(1,address.state), ' ',@(1,address.zip))",
"fullname": "=concat(@(1,firstName),' ',@(1,lastName))"
},
"itemTemp": "@(1,items)"
Copy link

@Nidhipal09 Nidhipal09 Jun 6, 2023

Choose a reason for hiding this comment

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

It can be easily done without creating a duplicate of the 'items' list. Please optimize this.

}
}
}
},

{
"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": ""
}
},
"customer": {
"firstName": "",
"lastName": ""
}
}
}
}
}
]


Output:

{
"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
} ],
"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
} ]
}
8 changes: 8 additions & 0 deletions Module 5/Problem 10/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Explanation:


The transformation involves following operations:

* `modify-overwrite-beta:` The field 'fullname' is splitted with space and the the values of generated lists are assigned to 'first_name' and 'last_name' using firstElement and lastElement methods, also the size of list 'phone_numbers' is calculated using size function and is mapped to key 'phone_number_count'.

* `remove`: Removes the "fullname" and "name" fields from the output JSON.
67 changes: 67 additions & 0 deletions Module 5/Problem 10/problem10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Input:

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

Transformation:

[
{
"operation": "modify-overwrite-beta",
"spec": {
"fullname": "=split(' ',@(2,name))",
"first_name": "=firstElement(@(2,fullname))",
"last_name": "=lastElement(@(2,fullname))",

Choose a reason for hiding this comment

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

It is giving the desired output but 2 is not the correct level here. Please check.

"phone_number_count": "=size(1,phone_numbers)"
}
},
{
"operation": "remove",
"spec": {
"fullname": "",
"name": ""
}
}
]


Ouput:

{
"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"
} ],
"first_name" : "John",
"last_name" : "Smith",
"phone_number_count" : 2
}

8 changes: 8 additions & 0 deletions Module 5/Problem 11/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Explanation:

=> problem_11b

The transformation involves following operations:

* `shift:` ': navigate to each object to items list, access the value of name and value fields and map them to items list 2 level up with keys itemName and itemValue respectively.

55 changes: 55 additions & 0 deletions Module 5/Problem 11/problem11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Input:

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


Transformation:

[
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": {
"itemName": "@(1,name)",
"itemValue": "@(1,value)"
}
}
}
},
{
"operation": "remove",
"spec": {
"items": {
"*": {
"name": "",
"value": ""
}
}
}
}
]


Output:

{
"items" : [ {
"itemName" : "item1",
"itemValue" : 10
}, {
"itemName" : "item2",
"itemValue" : 20
} ]
}
43 changes: 43 additions & 0 deletions Module 5/Problem 11/problem11_b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Input:

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


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


Output:

{
"items" : [ {
"itemName" : "item1",
"itemValue" : 10
}, {
"itemName" : "item2",
"itemValue" : 20
} ]
}
Loading