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 <assert.h> |
40 | #include "w_call_center.h" |
41 | #include "date.h" |
42 | #include "decimal.h" |
43 | #include "genrand.h" |
44 | #include "r_params.h" |
45 | #include "scaling.h" |
46 | #include "columns.h" |
47 | #include "tables.h" |
48 | #include "misc.h" |
49 | #include "dist.h" |
50 | #include "build_support.h" |
51 | #include "tdefs.h" |
52 | #include "nulls.h" |
53 | #include "scd.h" |
54 | |
55 | #include "append_info.h" |
56 | |
57 | struct CALL_CENTER_TBL g_w_call_center; |
58 | static struct CALL_CENTER_TBL g_OldValues; |
59 | |
60 | /* |
61 | * Routine: mk_w_call_center() |
62 | * Purpose: |
63 | * Algorithm: |
64 | * Data Structures: |
65 | * |
66 | * Params: |
67 | * Returns: |
68 | * Called By: |
69 | * Calls: |
70 | * Assumptions: |
71 | * Side Effects: |
72 | * TODO: |
73 | * 20020830 jms Need to populate open and close dates |
74 | */ |
75 | int mk_w_call_center(void *info_arr, ds_key_t index) { |
76 | static int32_t jDateStart, nDaysPerRevision; |
77 | int32_t nSuffix, bFirstRecord = 0, nFieldChangeFlags, jDateEnd, nDateRange; |
78 | char *cp, *sName1, *sName2; |
79 | static decimal_t dMinTaxPercentage, dMaxTaxPercentage; |
80 | tdef *pTdef = getSimpleTdefsByNumber(CALL_CENTER); |
81 | |
82 | /* begin locals declarations */ |
83 | date_t dTemp; |
84 | static int bInit = 0, nScale; |
85 | struct CALL_CENTER_TBL *r, *rOldValues = &g_OldValues; |
86 | |
87 | r = &g_w_call_center; |
88 | |
89 | if (!bInit) { |
90 | /* begin locals allocation/initialization */ |
91 | strtodt(&dTemp, DATA_START_DATE); |
92 | jDateStart = dttoj(&dTemp) - WEB_SITE; |
93 | strtodt(&dTemp, DATA_END_DATE); |
94 | jDateEnd = dttoj(&dTemp); |
95 | nDateRange = jDateEnd - jDateStart + 1; |
96 | nDaysPerRevision = nDateRange / pTdef->nParam + 1; |
97 | nScale = get_int("SCALE" ); |
98 | |
99 | /* these fields need to be handled as part of SCD code or further |
100 | * definition */ |
101 | r->cc_division_id = -1; |
102 | r->cc_closed_date_id = -1; |
103 | strcpy(r->cc_division_name, "No Name" ); |
104 | |
105 | strtodec(&dMinTaxPercentage, MIN_CC_TAX_PERCENTAGE); |
106 | strtodec(&dMaxTaxPercentage, MAX_CC_TAX_PERCENTAGE); |
107 | bInit = 1; |
108 | } |
109 | |
110 | nullSet(&pTdef->kNullBitMap, CC_NULLS); |
111 | r->cc_call_center_sk = index; |
112 | |
113 | /* if we have generated the required history for this business key and |
114 | * generate a new one then reset associate fields (e.g., rec_start_date |
115 | * minimums) |
116 | */ |
117 | if (setSCDKeys(CC_CALL_CENTER_ID, index, r->cc_call_center_id, &r->cc_rec_start_date_id, &r->cc_rec_end_date_id)) { |
118 | r->cc_open_date_id = jDateStart - genrand_integer(NULL, DIST_UNIFORM, -365, 0, 0, CC_OPEN_DATE_ID); |
119 | |
120 | /* |
121 | * some fields are not changed, even when a new version of the row is |
122 | * written |
123 | */ |
124 | nSuffix = (int)index / distsize("call_centers" ); |
125 | dist_member(&cp, "call_centers" , (int)(index % distsize("call_centers" )) + 1, 1); |
126 | if (nSuffix > 0) |
127 | sprintf(r->cc_name, "%s_%d" , cp, nSuffix); |
128 | else |
129 | strcpy(r->cc_name, cp); |
130 | |
131 | mk_address(&r->cc_address, CC_ADDRESS); |
132 | bFirstRecord = 1; |
133 | } |
134 | |
135 | /* |
136 | * this is where we select the random number that controls if a field |
137 | * changes from one record to the next. |
138 | */ |
139 | nFieldChangeFlags = next_random(CC_SCD); |
140 | |
141 | /* the rest of the record in a history-keeping dimension can either be a new |
142 | * data value or not; use a random number and its bit pattern to determine |
143 | * which fields to replace and which to retain |
144 | */ |
145 | pick_distribution(&r->cc_class, "call_center_class" , 1, 1, CC_CLASS); |
146 | changeSCD(SCD_PTR, &r->cc_class, &rOldValues->cc_class, &nFieldChangeFlags, bFirstRecord); |
147 | |
148 | genrand_integer(&r->cc_employees, DIST_UNIFORM, 1, CC_EMPLOYEE_MAX * nScale * nScale, 0, CC_EMPLOYEES); |
149 | changeSCD(SCD_INT, &r->cc_employees, &rOldValues->cc_employees, &nFieldChangeFlags, bFirstRecord); |
150 | |
151 | genrand_integer(&r->cc_sq_ft, DIST_UNIFORM, 100, 700, 0, CC_SQ_FT); |
152 | r->cc_sq_ft *= r->cc_employees; |
153 | changeSCD(SCD_INT, &r->cc_sq_ft, &rOldValues->cc_sq_ft, &nFieldChangeFlags, bFirstRecord); |
154 | |
155 | pick_distribution(&r->cc_hours, "call_center_hours" , 1, 1, CC_HOURS); |
156 | changeSCD(SCD_PTR, &r->cc_hours, &rOldValues->cc_hours, &nFieldChangeFlags, bFirstRecord); |
157 | |
158 | pick_distribution(&sName1, "first_names" , 1, 1, CC_MANAGER); |
159 | pick_distribution(&sName2, "last_names" , 1, 1, CC_MANAGER); |
160 | sprintf(&r->cc_manager[0], "%s %s" , sName1, sName2); |
161 | changeSCD(SCD_CHAR, &r->cc_manager, &rOldValues->cc_manager, &nFieldChangeFlags, bFirstRecord); |
162 | |
163 | genrand_integer(&r->cc_market_id, DIST_UNIFORM, 1, 6, 0, CC_MARKET_ID); |
164 | changeSCD(SCD_INT, &r->cc_market_id, &rOldValues->cc_market_id, &nFieldChangeFlags, bFirstRecord); |
165 | |
166 | gen_text(r->cc_market_class, 20, RS_CC_MARKET_CLASS, CC_MARKET_CLASS); |
167 | changeSCD(SCD_CHAR, &r->cc_market_class, &rOldValues->cc_market_class, &nFieldChangeFlags, bFirstRecord); |
168 | |
169 | gen_text(r->cc_market_desc, 20, RS_CC_MARKET_DESC, CC_MARKET_DESC); |
170 | changeSCD(SCD_CHAR, &r->cc_market_desc, &rOldValues->cc_market_desc, &nFieldChangeFlags, bFirstRecord); |
171 | |
172 | pick_distribution(&sName1, "first_names" , 1, 1, CC_MARKET_MANAGER); |
173 | pick_distribution(&sName2, "last_names" , 1, 1, CC_MARKET_MANAGER); |
174 | sprintf(&r->cc_market_manager[0], "%s %s" , sName1, sName2); |
175 | changeSCD(SCD_CHAR, &r->cc_market_manager, &rOldValues->cc_market_manager, &nFieldChangeFlags, bFirstRecord); |
176 | |
177 | genrand_integer(&r->cc_company, DIST_UNIFORM, 1, 6, 0, CC_COMPANY); |
178 | changeSCD(SCD_INT, &r->cc_company, &rOldValues->cc_company, &nFieldChangeFlags, bFirstRecord); |
179 | |
180 | genrand_integer(&r->cc_division_id, DIST_UNIFORM, 1, 6, 0, CC_COMPANY); |
181 | changeSCD(SCD_INT, &r->cc_division_id, &rOldValues->cc_division_id, &nFieldChangeFlags, bFirstRecord); |
182 | |
183 | mk_word(r->cc_division_name, "syllables" , r->cc_division_id, RS_CC_DIVISION_NAME, CC_DIVISION_NAME); |
184 | changeSCD(SCD_CHAR, &r->cc_division_name, &rOldValues->cc_division_name, &nFieldChangeFlags, bFirstRecord); |
185 | |
186 | mk_companyname(r->cc_company_name, CC_COMPANY_NAME, r->cc_company); |
187 | changeSCD(SCD_CHAR, &r->cc_company_name, &rOldValues->cc_company_name, &nFieldChangeFlags, bFirstRecord); |
188 | |
189 | genrand_decimal(&r->cc_tax_percentage, DIST_UNIFORM, &dMinTaxPercentage, &dMaxTaxPercentage, NULL, |
190 | CC_TAX_PERCENTAGE); |
191 | changeSCD(SCD_DEC, &r->cc_tax_percentage, &rOldValues->cc_tax_percentage, &nFieldChangeFlags, bFirstRecord); |
192 | |
193 | // append the newly created row |
194 | char szTemp[128]; |
195 | |
196 | void *info = append_info_get(info_arr, CALL_CENTER); |
197 | |
198 | append_row_start(info); |
199 | |
200 | append_key(info, r->cc_call_center_sk); |
201 | append_varchar(info, r->cc_call_center_id); |
202 | append_date(info, r->cc_rec_start_date_id); |
203 | append_date(info, r->cc_rec_end_date_id); |
204 | append_key(info, r->cc_closed_date_id); |
205 | append_key(info, r->cc_open_date_id); |
206 | append_varchar(info, r->cc_name); |
207 | append_varchar(info, &r->cc_class[0]); |
208 | append_integer(info, r->cc_employees); |
209 | append_integer(info, r->cc_sq_ft); |
210 | append_varchar(info, r->cc_hours); |
211 | append_varchar(info, &r->cc_manager[0]); |
212 | append_integer(info, r->cc_market_id); |
213 | append_varchar(info, &r->cc_market_class[0]); |
214 | append_varchar(info, &r->cc_market_desc[0]); |
215 | append_varchar(info, &r->cc_market_manager[0]); |
216 | append_integer(info, r->cc_division_id); |
217 | append_varchar(info, &r->cc_division_name[0]); |
218 | append_integer(info, r->cc_company); |
219 | append_varchar(info, &r->cc_company_name[0]); |
220 | append_integer(info, r->cc_address.street_num); |
221 | |
222 | if (r->cc_address.street_name2) { |
223 | sprintf(szTemp, "%s %s" , r->cc_address.street_name1, r->cc_address.street_name2); |
224 | append_varchar(info, szTemp); |
225 | } else { |
226 | append_varchar(info, r->cc_address.street_name1); |
227 | } |
228 | |
229 | append_varchar(info, r->cc_address.street_type); |
230 | append_varchar(info, &r->cc_address.suite_num[0]); |
231 | append_varchar(info, r->cc_address.city); |
232 | append_varchar(info, r->cc_address.county); |
233 | append_varchar(info, r->cc_address.state); |
234 | sprintf(szTemp, "%05d" , r->cc_address.zip); |
235 | append_varchar(info, szTemp); |
236 | append_varchar(info, &r->cc_address.country[0]); |
237 | append_integer(info, r->cc_address.gmt_offset); |
238 | append_decimal(info, &r->cc_tax_percentage); |
239 | |
240 | append_row_end(info); |
241 | |
242 | return 0; |
243 | } |
244 | |