Last active
August 29, 2015 14:24
-
-
Save sumitasok/51b887069870a88ceb8d to your computer and use it in GitHub Desktop.
rethinkdb reports dummy data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn = r.connect(host="localhost", port=28015, db="arkinventory", auth_key="", timeout=20) | |
r.table("reportsdata"). | |
concat_map(lambda attendees: [attendees['attendees']]). | |
concat_map(lambda attendees: attendees['attendees']).sample(4).run(conn) | |
r.table("reportsdata"). | |
concat_map(lambda attendees: attendees['attendees']). | |
filter({'ticketId': "ticket-id-4321"}).sample(3).run(conn) | |
r.table("reportsdata").concat_map(lambda attendees: attendees['attendees']). | |
concat_map(lambda attendees: attendees['attendees']). | |
filter(r.row["email"] == "[email protected]").sample(4).run(conn) | |
# fetch list of attendees who have bouth tickets for this ticketId | |
r.table("reportsdata").concat_map(lambda attendees: attendees['attendees']). | |
filter(r.row["ticketId"] == "ticket-id-4321"). | |
concat_map(lambda attendees:attendees['attendees']).sample(4).run(conn) | |
r.table("reportsdata").filter(r.row["kart_id"] == "kart-id-4321").sample(4).count().run(conn) | |
r.table("reportsdata").filter(r.row["updated_at"] > "2012-01-01" and r.row["updated_at"] < "2015-01-01").sample(4).run(conn) | |
r.table("reportsdata").filter(r.row["updated_at"] > "2013-07-12" and r.row["updated_at"] < "2013-08-14"). | |
concat_map(lambda attendees: attendees['attendees']). | |
filter(r.row["ticketId"] == "ticket-id-4321"). | |
concat_map(lambda attendees:attendees['attendees']).sample(4).run(conn) | |
r.table("reportsdata").concat_map(lambda report: report["entities"]). | |
group("entity_id"). | |
reduce(lambda left, right: { | |
"entity_id":left["entity_id"],"quantity" : left["quantity"]+right["quantity"], "price": left["price"]+right["price"] | |
}).run(conn) | |
r.table("reportsdata").concat_map(lambda report: report["entities"]). | |
group("entity_id"). | |
reduce(lambda left, right: { | |
"entity_id":left["entity_id"],"quantity" : left["quantity"]+right["quantity"], "price": left["price"]+right["price"], "final_amount": left["final_amount"]+right["final_amount"] | |
}).run(conn) | |
# Map | |
r.table("reportsdata").concat_map(lambda report: report["entities"]). | |
group("entity_id"). | |
map(lambda entity: { | |
"entity_id":entity["entity_id"],"quantity" : entity["quantity"], "price": entity["price"], "final_amount": entity["final_amount"], "discount_amount": entity["offer_applied"]["discount_amount"] | |
}).run(conn) | |
# Reduce | |
r.table("reportsdata").concat_map(lambda report: report["entities"]). | |
group("entity_id").map(lambda entity: { | |
"entity_id":entity["entity_id"],"quantity" : entity["quantity"], "price": entity["price"], "final_amount": entity["final_amount"], "discount_amount": entity["offer_applied"]["discount_amount"] | |
}). | |
reduce(lambda left, right: { | |
"entity_id":left["entity_id"],"quantity" : left["quantity"]+right["quantity"], "price": left["price"], "final_amount": left["final_amount"]+right["final_amount"], "discount_amount": left["discount_amount"]+right["discount_amount"] | |
}).run(conn) | |
r.table("reportsdata").filter(r.row["updated_at"] > "2013-07-12" and r.row["updated_at"] < "2013-08-13"). | |
concat_map(lambda report: report["entities"]). | |
group("entity_id"). | |
map(lambda entity: { | |
"entity_id":entity["entity_id"],"quantity" : entity["quantity"], "price": entity["price"], "final_amount": entity["final_amount"], "discount_amount": entity["offer_applied"]["discount_amount"] | |
}). | |
reduce(lambda left, right: { | |
"entity_id":left["entity_id"],"quantity" : left["quantity"]+right["quantity"], "price": left["price"], "final_amount": left["final_amount"]+right["final_amount"], "discount_amount": left["discount_amount"]+right["discount_amount"] | |
}).run(conn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db("arkinventory").table("reportsdata"). | |
filter(r.row("updated_at").gt("2013-07-12 16:32:48 -0700") | |
.and(r.row("updated_at").lt("2013-12-14 16:32:48 -0700"))) | |
r.db("arkinventory").table("reportsdata").filter(function(cuse) {return cuse("updated_at").during(r.time(2013,07,12), r.time(2013,12,14))}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db("arkinventory").table("reportsdata").insert({ | |
order_id: 'session-id-4321', | |
kart_id: 'kart-id-4321', | |
entities: [ | |
{ | |
entity_id: "54d68a99-3ae9-4b2c-9de3-5ee55f57d3a5", | |
quantity: 1, | |
price: 1000.00, | |
intial_amount: 1000.00, | |
final_amount: 800.00, | |
offer_applied: { | |
offer_id: 'PERC20', | |
discount_amount: 200, | |
} | |
}, | |
{ | |
entity_id: "cbdd6ccd-ae7a-45c9-9627-a3322b2d4cc1", | |
quantity: 2, | |
price: 1000.00, | |
intial_amount: 2000.00, | |
final_amount: 1960.00, | |
offer_applied: { | |
offer_id: 'CASH20', | |
discount_amount: 20, | |
} | |
} | |
], | |
intial_amount: 3000, | |
final_amount: 2760, | |
attendees: [ | |
{ | |
ticketId: 'ticket-id-4321', | |
attendees: [ | |
{ | |
firstname: 'Sumit', | |
lastname: 'Asok', | |
email: '[email protected]', | |
mobile: '9895865899' | |
} | |
] | |
}, | |
{ | |
ticketId: 'ticket-id-7723', | |
attendees: [ | |
{ | |
firstname: 'Achu', | |
lastname: 'Kuttan', | |
email: '[email protected]', | |
mobile: '9897668222' | |
} | |
] | |
} | |
], | |
payee: { | |
firstname: 'Sumit', | |
lastname: 'Asok', | |
email: '[email protected]', | |
mobile: '9895865899', | |
address_1: 'Baker STreet', | |
address_2: 'Inglando', | |
city: 'Stathis', | |
state: 'Kerala', | |
country: 'India', | |
pincode: '680664', | |
pay_mode: 'CC', | |
pay_id: 'mhpayid-oqpweipie' | |
}, | |
updated_at: '2013-07-13 16:32:48 -0700' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment