| 1 | /* |
| 2 | * Legal Notice |
| 3 | * |
| 4 | * This document and associated source code (the "Work") is a part of a |
| 5 | * benchmark specification maintained by the TPC. |
| 6 | * |
| 7 | * The TPC reserves all right, title, and interest to the Work as provided |
| 8 | * under U.S. and international laws, including without limitation all patent |
| 9 | * and trademark rights therein. |
| 10 | * |
| 11 | * No Warranty |
| 12 | * |
| 13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
| 14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
| 15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
| 16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
| 17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
| 18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
| 20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
| 21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
| 22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
| 23 | * WITH REGARD TO THE WORK. |
| 24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
| 25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
| 26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
| 27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
| 28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
| 29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
| 30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
| 31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
| 32 | * |
| 33 | * Contributors: |
| 34 | * Gradient Systems |
| 35 | */ |
| 36 | #include "config.h" |
| 37 | #include "porting.h" |
| 38 | #include <stdio.h> |
| 39 | #include "genrand.h" |
| 40 | #include "w_inventory.h" |
| 41 | #include "columns.h" |
| 42 | #include "build_support.h" |
| 43 | #include "tables.h" |
| 44 | #include "scaling.h" |
| 45 | #include "constants.h" |
| 46 | #include "date.h" |
| 47 | #include "nulls.h" |
| 48 | #include "tdefs.h" |
| 49 | #include "scd.h" |
| 50 | |
| 51 | #include "append_info.h" |
| 52 | |
| 53 | struct W_INVENTORY_TBL g_w_inventory; |
| 54 | |
| 55 | /* |
| 56 | * Routine: |
| 57 | * Purpose: |
| 58 | * Algorithm: |
| 59 | * Data Structures: |
| 60 | * |
| 61 | * Params: |
| 62 | * Returns: |
| 63 | * Called By: |
| 64 | * Calls: |
| 65 | * Assumptions: |
| 66 | * Side Effects: |
| 67 | * TODO: None |
| 68 | */ |
| 69 | int mk_w_inventory(void *info_arr, ds_key_t index) { |
| 70 | static int bInit = 0; |
| 71 | struct W_INVENTORY_TBL *r; |
| 72 | static ds_key_t item_count; |
| 73 | static ds_key_t warehouse_count; |
| 74 | static int jDate; |
| 75 | date_t base_date_storage; |
| 76 | date_t *base_date = &base_date_storage; |
| 77 | int nTemp; |
| 78 | tdef *pTdef = getSimpleTdefsByNumber(INVENTORY); |
| 79 | |
| 80 | r = &g_w_inventory; |
| 81 | |
| 82 | if (!bInit) { |
| 83 | memset(&g_w_inventory, 0, sizeof(struct W_INVENTORY_TBL)); |
| 84 | item_count = getIDCount(ITEM); |
| 85 | warehouse_count = get_rowcount(WAREHOUSE); |
| 86 | strtodt(base_date, DATE_MINIMUM); |
| 87 | jDate = base_date->julian; |
| 88 | set_dow(base_date); |
| 89 | /* Make exceptions to the 1-rng-call-per-row rule */ |
| 90 | bInit = 1; |
| 91 | } |
| 92 | |
| 93 | nullSet(&pTdef->kNullBitMap, INV_NULLS); |
| 94 | nTemp = (int)index - 1; |
| 95 | r->inv_item_sk = (nTemp % item_count) + 1; |
| 96 | nTemp /= (int)item_count; |
| 97 | r->inv_warehouse_sk = (nTemp % warehouse_count) + 1; |
| 98 | nTemp /= (int)warehouse_count; |
| 99 | r->inv_date_sk = jDate + (nTemp * 7); /* inventory is updated weekly */ |
| 100 | |
| 101 | /* |
| 102 | * the join between item and inventory is tricky. The item_id selected above |
| 103 | * identifies a unique part num but item is an SCD, so we need to account |
| 104 | * for that in selecting the SK to join with |
| 105 | */ |
| 106 | r->inv_item_sk = matchSCDSK(r->inv_item_sk, r->inv_date_sk, ITEM); |
| 107 | |
| 108 | genrand_integer(&r->inv_quantity_on_hand, DIST_UNIFORM, INV_QUANTITY_MIN, INV_QUANTITY_MAX, 0, |
| 109 | INV_QUANTITY_ON_HAND); |
| 110 | |
| 111 | void *info = append_info_get(info_arr, INVENTORY); |
| 112 | append_row_start(info); |
| 113 | append_key(info, r->inv_date_sk); |
| 114 | append_key(info, r->inv_item_sk); |
| 115 | append_key(info, r->inv_warehouse_sk); |
| 116 | append_integer(info, r->inv_quantity_on_hand); |
| 117 | append_row_end(info); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Routine: |
| 124 | * Purpose: |
| 125 | * Algorithm: |
| 126 | * Data Structures: |
| 127 | * |
| 128 | * Params: |
| 129 | * Returns: |
| 130 | * Called By: |
| 131 | * Calls: |
| 132 | * Assumptions: |
| 133 | * Side Effects: |
| 134 | * TODO: None |
| 135 | */ |
| 136 | ds_key_t sc_w_inventory(int nScale) { |
| 137 | ds_key_t kRes; |
| 138 | date_t dTemp; |
| 139 | int nDays; |
| 140 | |
| 141 | kRes = getIDCount(ITEM); |
| 142 | kRes *= get_rowcount(WAREHOUSE); |
| 143 | strtodt(&dTemp, DATE_MAXIMUM); |
| 144 | nDays = dTemp.julian; |
| 145 | strtodt(&dTemp, DATE_MINIMUM); |
| 146 | nDays -= dTemp.julian; |
| 147 | nDays += 1; |
| 148 | nDays += 6; |
| 149 | nDays /= 7; /* each items inventory is updated weekly */ |
| 150 | kRes *= nDays; |
| 151 | |
| 152 | return (kRes); |
| 153 | } |
| 154 | |