Commit d778ec0b authored by Gaurav Kukreja's avatar Gaurav Kukreja

Assign1: Reporting time, and TPM

parent 0b5c8913
......@@ -5,6 +5,7 @@
#include <fcntl.h>
#include <list>
#include <ctime>
#include <sys/time.h>
#include "schema.h"
#include "data_migrate.h"
......@@ -12,11 +13,17 @@
using namespace std;
/*
ostream &operator<<(ostream &output, const warehouse &o)
{
output << o.w_id << ' ' << o.w_name << ' ' << o.w_zip << endl;
return output;
}*/
void display_warehouse(const warehouse w)
{
printf("%d\t%s\t%s\n",w.w_id, w.w_name, w.w_zip);
return;
}
int warehouses=5;
......@@ -35,58 +42,24 @@ int main(int argc, char* argv[]) {
//while(1) {
int choice;
timeval start_time, end_time, time_taken;
list<warehouse>::iterator i;
for(i=warehouse_list.begin(); i !=warehouse_list.end(); ++i)
cout << *i << " "; // print with overloaded operator
scanf("%d",&choice);
display_warehouse(*i);
//cout << *i << " "; // print with overloaded operator
gettimeofday(&start_time,NULL);
for(double i=0;i<1000;i++)
newOrderRandom(time(NULL), random()%warehouses+1);
/*
switch(choice) {
case 1: printf("\nWhich table to print?\n");
printf("1. customer\n");
printf("2. district\n");
printf("3. history\n");
printf("4. item\n");
printf("5. neworder\n");
printf("6. order\n");
printf("7. orderline\n");
printf("8. stock\n");
printf("9. warehouse\n");
scanf("%d",&choice);
gettimeofday(&end_time,NULL);
time_taken.tv_sec = end_time.tv_sec - start_time.tv_sec;
time_taken.tv_usec = end_time.tv_usec - start_time.tv_usec;
switch(choice) {
case 1: display_customer();
break;
case 2: display_district();
break;
case 3: display_history();
break;
case 4: display_item();
break;
case 5: display_neworder();
break;
case 6: display_order();
break;
case 7: display_orderline();
break;
case 8: display_stock();
break;
case 9: display_warehouse();
break;
default: printf("Wrong Option\n");
}
break;
case 2: return 0;
default: printf("Wrong Option\n");
}
}
cout << "Time Taken " << time_taken.tv_sec <<"s" << time_taken.tv_usec <<"us\n";
cout << "newOrder operations per second" << 1000000/time_taken.tv_sec;
*/
return 0;
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ void newOrder(int w_id, int d_id, int c_id, int items, int supware[15], int item
list<customer>::iterator cust_iter;
list<district>::iterator dist_iter;
printf("w_id is %d\n",w_id);
//printf("w_id is %d\n",w_id);
for(ware_iter=warehouse_list.begin(); (ware_iter!=warehouse_list.end() && (ware_iter->w_id!=w_id)); ++ware_iter);
for(cust_iter=customer_list.begin(); (cust_iter!=customer_list.end() && (cust_iter->c_w_id!=w_id && cust_iter->c_d_id!=d_id && cust_iter->c_id!=c_id)); ++cust_iter);
......
......@@ -106,7 +106,7 @@ void newOrderRandom(time_t now, int w_id) {
int itemid[15];
int qty[15];
printf("ol_cnt is %d\n",ol_cnt);
//printf("ol_cnt is %d\n",ol_cnt);
for(int i=0;i<ol_cnt;i++) {
if(urand(1,100) > 1)
......
......@@ -10,12 +10,12 @@
class warehouse {
public:
int w_id; // integer not null,
char w_name[10]; // varchar(10) not null,
char w_street_1[20]; // varchar(20) not null,
char w_street_2[20]; // varchar(20) not null,
char w_city[20]; // varchar(20) not null,
char w_state[2]; // varchar(2) not null,
char w_zip[9]; // varchar(9) not null,
char w_name[11]; // varchar(10) not null,
char w_street_1[21]; // varchar(20) not null,
char w_street_2[21]; // varchar(20) not null,
char w_city[21]; // varchar(20) not null,
char w_state[3]; // varchar(2) not null,
char w_zip[10]; // varchar(9) not null,
uint64_t w_tax;
uint64_t w_ytd;
......@@ -26,12 +26,12 @@ class district {
public:
int d_id;
int d_w_id;
char d_name[10];
char d_street_1[20];
char d_street_2[20];
char d_city[20];
char d_state[2];
char d_zip[9];
char d_name[11];
char d_street_1[21];
char d_street_2[21];
char d_city[21];
char d_state[3];
char d_zip[10];
uint64_t d_tax;
uint64_t d_ytd;
int d_next_o_id;
......@@ -46,24 +46,24 @@ class customer {
int c_id;
int c_d_id;
int c_w_id;
char c_first[16];
char c_middle[2];
char c_last[16];
char c_street_1[20];
char c_street_2[20];
char c_city[20];
char c_state[2];
char c_zip[9];
char c_phone[16];
char c_first[17];
char c_middle[3];
char c_last[17];
char c_street_1[21];
char c_street_2[21];
char c_city[21];
char c_state[3];
char c_zip[10];
char c_phone[17];
uint64_t c_since;
char c_credit[2];
char c_credit[3];
uint64_t c_credit_lim;
uint64_t c_discount;
uint64_t c_balance;
uint64_t c_ytd_paymenr;
uint64_t c_payment_cnt;
uint64_t c_delivery_cnt;
char c_data[500];
char c_data[501];
//primary key (c_w_id,c_d_id,c_id)
int parse(FILE **fp);
......@@ -82,7 +82,7 @@ class history {
int h_w_id;
uint64_t h_date;
uint64_t h_amount;
char h_data[24];
char h_data[25];
int parse(FILE **fp);
};
......@@ -138,7 +138,7 @@ class orderline {
uint64_t ol_delivery_d;
uint64_t ol_quantity;
uint64_t ol_amount;
char ol_dist_info[24];
char ol_dist_info[25];
//primary key (ol_w_id,ol_d_id,ol_o_id,ol_number)
orderline();
......@@ -152,9 +152,9 @@ class item {
public:
int i_id; // integer not null,
int i_im_id; // integer not null,
char i_name[24]; // varchar(24) not null,
char i_name[25]; // varchar(24) not null,
uint64_t i_price;
char i_data[50];
char i_data[51];
// primary key (i_id)
int parse(FILE **fp);
};
......@@ -164,20 +164,20 @@ class stock {
int s_i_id; // integer not null,
int s_w_id; // integer not null,
uint64_t s_quantity; // numeric(4,0) not null,
char s_dist_01[24]; // char(24) not null,
char s_dist_02[24]; // char(24) not null,
char s_dist_03[24]; // char(24) not null,
char s_dist_04[24]; // char(24) not null,
char s_dist_05[24]; // char(24) not null,
char s_dist_06[24]; // char(24) not null,
char s_dist_07[24]; // char(24) not null,
char s_dist_08[24]; // char(24) not null,
char s_dist_09[24]; // char(24) not null,
char s_dist_10[24]; // char(24) not null,
char s_dist_01[25]; // char(24) not null,
char s_dist_02[25]; // char(24) not null,
char s_dist_03[25]; // char(24) not null,
char s_dist_04[25]; // char(24) not null,
char s_dist_05[25]; // char(24) not null,
char s_dist_06[25]; // char(24) not null,
char s_dist_07[25]; // char(24) not null,
char s_dist_08[25]; // char(24) not null,
char s_dist_09[25]; // char(24) not null,
char s_dist_10[25]; // char(24) not null,
uint64_t s_ytd; // numeric(8,0) not null,
uint64_t s_order_cnt; // numeric(4,0) not null,
uint64_t s_remote_cnt; // numeric(4,0) not null,
char s_data[50]; // varchar(50) not null,
char s_data[51]; // varchar(50) not null,
// primary key (s_w_id,s_i_id)
int parse(FILE **fp);
};
......
......@@ -30,17 +30,17 @@ int warehouse::parse(FILE **fp) {
{
case 1: w_id = atoi(token);
break;
case 2: strcpy(token, w_name);
case 2: strcpy(w_name, token);
break;
case 3: strcpy(token, w_street_1);
case 3: strcpy(w_street_1, token);
break;
case 4: strcpy(token, w_street_2);
case 4: strcpy(w_street_2, token);
break;
case 5: strcpy(token, w_city);
case 5: strcpy(w_city, token);
break;
case 6: strcpy(token, w_state);
case 6: strcpy(w_state, token);
break;
case 7: strcpy(token, w_zip);
case 7: strcpy(w_zip, token);
break;
case 8: w_tax = (uint64_t) atof(token);
break;
......@@ -89,17 +89,17 @@ int district::parse(FILE **fp) {
break;
case 2: d_w_id = atoi(token);
break;
case 3: strcpy(token, d_name);
case 3: strcpy(d_name, token);
break;
case 4: strcpy(token, d_street_1);
case 4: strcpy(d_street_1, token);
break;
case 5: strcpy(token, d_street_2);
case 5: strcpy(d_street_2, token);
break;
case 6: strcpy(token, d_city);
case 6: strcpy(d_city, token);
break;
case 7: strcpy(token, d_state);
case 7: strcpy(d_state, token);
break;
case 8: strcpy(token, d_zip);
case 8: strcpy(d_zip, token);
break;
case 9: d_tax = (uint64_t) atof(token);
break;
......@@ -152,27 +152,27 @@ int customer::parse(FILE **fp) {
break;
case 3: c_w_id = atoi(token);
break;
case 4: strcpy(token, c_first);
case 4: strcpy(c_first, token);
break;
case 5: strcpy(token, c_middle);
case 5: strcpy(c_middle, token);
break;
case 6: strcpy(token, c_last);
case 6: strcpy(c_last, token);
break;
case 7: strcpy(token, c_street_1);
case 7: strcpy(c_street_1, token);
break;
case 8: strcpy(token, c_street_2);
case 8: strcpy(c_street_2, token);
break;
case 9: strcpy(token, c_city);
case 9: strcpy(c_city, token);
break;
case 10: strcpy(token, c_state);
case 10: strcpy(c_state, token);
break;
case 11: strcpy(token, c_zip);
case 11: strcpy(c_zip, token);
break;
case 12: strcpy(token, c_phone);
case 12: strcpy(c_phone, token);
break;
case 13: c_since = (uint64_t) atof(token);
break;
case 14: strcpy(token, c_credit);
case 14: strcpy(c_credit, token);
break;
case 15: c_credit_lim = (uint64_t) atof(token);
break;
......@@ -186,7 +186,7 @@ int customer::parse(FILE **fp) {
break;
case 20: c_delivery_cnt = (uint64_t) atof(token);
break;
case 21: strcpy(token, c_data);
case 21: strcpy(c_data, token);
//printf("all fields filled\n");
break;
default: printf("ERR\n");
......@@ -241,7 +241,7 @@ int history::parse(FILE **fp) {
break;
case 7: h_amount = (uint64_t) atof(token);
break;
case 8: strcpy(token, h_data);
case 8: strcpy(h_data, token);
//printf("all fields filled\n");
break;
default: printf("ERR\n");
......@@ -400,7 +400,7 @@ int orderline::parse(FILE **fp) {
break;
case 9: ol_amount = (uint64_t) atof(token);
break;
case 10: strcpy(token, ol_dist_info);
case 10: strcpy(ol_dist_info, token);
//printf("all fields filled\n");
break;
default: printf("ERR\n");
......@@ -445,11 +445,11 @@ int item::parse(FILE **fp) {
break;
case 2: i_im_id = atoi(token);
break;
case 3: strcpy(token, i_name);
case 3: strcpy(i_name, token);
break;
case 4: i_price = (uint64_t) atof(token);
break;
case 5: strcpy(token, i_data);
case 5: strcpy(i_data, token);
//printf("all fields filled\n");
break;
default: printf("ERR\n");
......@@ -496,25 +496,25 @@ int stock::parse(FILE **fp) {
break;
case 3: s_quantity = (uint64_t) atof(token);
break;
case 4: strcpy(token, s_dist_01);
case 4: strcpy(s_dist_01, token);
break;
case 5: strcpy(token, s_dist_02);
case 5: strcpy(s_dist_02, token);
break;
case 6: strcpy(token, s_dist_03);
case 6: strcpy(s_dist_03, token);
break;
case 7: strcpy(token, s_dist_04);
case 7: strcpy(s_dist_04, token);
break;
case 8: strcpy(token, s_dist_05);
case 8: strcpy(s_dist_05, token);
break;
case 9: strcpy(token, s_dist_06);
case 9: strcpy(s_dist_06, token);
break;
case 10: strcpy(token, s_dist_07);
case 10: strcpy(s_dist_07, token);
break;
case 11: strcpy(token, s_dist_08);
case 11: strcpy(s_dist_08, token);
break;
case 12: strcpy(token, s_dist_09);
case 12: strcpy(s_dist_09, token);
break;
case 13: strcpy(token, s_dist_10);
case 13: strcpy(s_dist_10, token);
break;
case 14: s_ytd = (uint64_t) atof(token);
break;
......@@ -522,7 +522,7 @@ int stock::parse(FILE **fp) {
break;
case 16: s_remote_cnt = (uint64_t) atof(token);
break;
case 17: strcpy(token, s_data);
case 17: strcpy(s_data, token);
//printf("all fields filled\n");
break;
default: printf("ERR\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment