コード例 #1
0
ファイル: wm_cmdp.c プロジェクト: sdhczw/winnermicro
void tls_cmd_init_socket_cfg(void)
{
    int timeout = 0, host_len;
    struct tls_param_socket remote_socket_cfg;
    tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);
    /* read default socket params */
    socket_cfg.proto = remote_socket_cfg.protocol;
    socket_cfg.client = remote_socket_cfg.client_or_server ? 0 : 1;
    socket_cfg.port = remote_socket_cfg.port_num;
	TLS_DBGPRT_INFO("socket_cfg.proto = %d, socket_cfg.client = %d, socket_cfg.port = %d\n", socket_cfg.proto, socket_cfg.client, socket_cfg.port);
    host_len = strlen((char *)remote_socket_cfg.host);  
    if (socket_cfg.client) {
        /*  host name */
		if (host_len){
	        MEMCPY(socket_cfg.host, 
	                remote_socket_cfg.host, host_len);
			string_to_ipaddr((char *)remote_socket_cfg.host, &socket_cfg.ip_addr[0]);
		}
    } else if (!socket_cfg.client && socket_cfg.proto == 0) {
	    if (strtodec(&timeout, (char *)remote_socket_cfg.host)<0){
			timeout = 0;
	    }

        socket_cfg.timeout = timeout; 
    } else
        ;
}
コード例 #2
0
/*
* mk_store_sales
*/
static void
mk_master (void *row, ds_key_t index)
{
	struct W_STORE_SALES_TBL *r;
	static decimal_t dMin,
		dMax;
	static int bInit = 0,
		nMaxItemCount;
	static ds_key_t kNewDateIndex = 0;

	if (row == NULL)
		r = &g_w_store_sales;
	else
		r = row;

	if (!bInit)
	{
      strtodec (&dMin, "1.00");
      strtodec (&dMax, "100000.00");
		nMaxItemCount = 20;
		jDate = skipDays(STORE_SALES, &kNewDateIndex);
		pItemPermutation = makePermutation(NULL, nItemCount = (int)getIDCount(ITEM), SS_PERMUTATION);
		
		bInit = 1;
	}

	
   while (index > kNewDateIndex)	/* need to move to a new date */
   {
      jDate += 1;
      kNewDateIndex += dateScaling(STORE_SALES, jDate);
   }
		r->ss_sold_store_sk = mk_join (SS_SOLD_STORE_SK, STORE, 1);
		r->ss_sold_time_sk = mk_join (SS_SOLD_TIME_SK, TIME, 1);
		r->ss_sold_date_sk = mk_join (SS_SOLD_DATE_SK, DATE, 1);
		r->ss_sold_customer_sk = mk_join (SS_SOLD_CUSTOMER_SK, CUSTOMER, 1);
		r->ss_sold_cdemo_sk = mk_join (SS_SOLD_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1);
		r->ss_sold_hdemo_sk = mk_join (SS_SOLD_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1);
		r->ss_sold_addr_sk = mk_join (SS_SOLD_ADDR_SK, CUSTOMER_ADDRESS, 1);
		r->ss_ticket_number = index;
		genrand_integer(&nItemIndex, DIST_UNIFORM, 1, nItemCount, 0, SS_SOLD_ITEM_SK);

      return;
}
コード例 #3
0
ファイル: s_customer.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_s_customer (void *pDest, ds_key_t kIndex)
{
  static int bInit = 0;
  struct S_CUSTOMER_TBL *r;
  static date_t dtMin,
    dtMax, dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo;
  static decimal_t dMinIncome, dMaxIncome;
  int nTemp;
  ds_key_t kTempDemographic;
  char *szTemp;
  static int *pPermutation;

  if (pDest == NULL)
    r = &g_s_customer;
  else
    r = pDest;

  if (!bInit)
    {
      memset (&g_s_customer, 0, sizeof (struct S_CUSTOMER_TBL));
      setUpdateDateRange (S_CUSTOMER, &dtMin, &dtMax);
      strtodec (&dMinIncome, "0.00");
      strtodec (&dMaxIncome, "200000.00");
      r->pBirthCountry = strdup ("<UNKNOWN>");
      strtodt (&dtBirthMin, "1924-01-01");
      strtodt (&dtBirthMax, "1992-12-31");
      strtodt (&dtToday, TODAYS_DATE);
      jtodt (&dt1YearAgo, dtToday.julian - 365);
      jtodt (&dt10YearsAgo, dtToday.julian - 365);
      pPermutation =
	makePermutation (NULL, (int) getIDCount (CUSTOMER), S_CUST_ID);

      bInit = 1;
    }

  r->kID = getPermutationEntry (pPermutation, (int) kIndex);
  kTempDemographic = mk_join (S_CUST_GENDER, CUSTOMER_DEMOGRAPHICS, 1) - 1;
  bitmap_to_dist (&szTemp, "gender", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  switch (*szTemp)
    {
    case 'M':			/* male */
      r->sGender[0] = 'M';
      pick_distribution (&r->pFirstName, "first_names", 1, 1,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 2,
			 S_CUST_SALUTATION);
      break;
    case 'F':			/* female */
      r->sGender[0] = 'F';
      pick_distribution (&r->pFirstName, "first_names", 1, 2,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 3,
			 S_CUST_SALUTATION);
      break;
    default:			/* gender neutral */
      r->sGender[0] = 'U';
      pick_distribution (&r->pFirstName, "first_names", 1, 3,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 1,
			 S_CUST_SALUTATION);
      break;
    }
  bitmap_to_dist (&r->pMaritalStatus, "marital_status", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->pEducation, "education", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->nPurchaseEstimate, "purchase_band", &kTempDemographic,
		  1, CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->pCreditRating, "credit_rating", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  r->nDependents = (int) (kTempDemographic % (ds_key_t) CD_MAX_CHILDREN);
  kTempDemographic /= (ds_key_t) CD_MAX_CHILDREN;
  r->nEmployed = (int) (kTempDemographic % (ds_key_t) CD_MAX_EMPLOYED);
  kTempDemographic /= (ds_key_t) CD_MAX_EMPLOYED;
  r->nCollege = (int) (kTempDemographic % (ds_key_t) CD_MAX_COLLEGE);

  pick_distribution (&r->pLastName, "last_names", 1, 1, S_CUST_LAST_NAME);
  r->bPreferredFlag =
    (genrand_integer (NULL, DIST_UNIFORM, 1, 100, 0, S_CUST_PREFERRED_FLAG) >
     50) ? 1 : 0;
  genrand_date (&r->dtBirthDate, DIST_UNIFORM, &dtBirthMin, &dtBirthMax, NULL,
		S_CUST_BIRTH_DATE);
  genrand_date (&r->dtFirstPurchaseDate, DIST_UNIFORM, &dt10YearsAgo,
		&dt1YearAgo, NULL, S_CUST_FIRST_PURCHASE_DATE);
  genrand_integer (&nTemp, DIST_UNIFORM, 1, 30, 0, S_CUST_FIRST_SHIPTO_DATE);
  jtodt (&r->dtFirstShipToDate, r->dtFirstPurchaseDate.julian + nTemp);
  gen_charset (r->szLogin, ALPHANUM, 5, RS_S_CUST_LOGIN, S_CUST_LOGIN);
  genrand_email (r->szEmail, r->pFirstName, r->pLastName, S_CUST_EMAIL);
  genrand_date (&r->dtLastLogin, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL,
		S_CUST_LAST_LOGIN);
  genrand_date (&r->dtReview, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL,
		S_CUST_LAST_REVIEW);
  genrand_ipaddr (r->szPrimaryMachine, S_CUST_PRIMARY_MACHINE);
  genrand_ipaddr (r->szSecondaryMachine, S_CUST_SECONDARY_MACHINE);
  pick_distribution (&r->pLocationType, "location_type", 1, 1,
		     S_CUST_LOCATION_TYPE);
  pick_distribution (&r->nVehicle, "vehicle_count", 1, 1, S_CUST_VEHICLE_CNT);
  genrand_decimal (&r->dIncome, DIST_UNIFORM, &dMinIncome, &dMaxIncome, NULL,
		   S_CUST_INCOME);
  pick_distribution (&r->pBuyPotential, "buy_potential", 1, 1,
		     S_CUST_PURCHASE_ESTIMATE);
  mk_w_customer_address (NULL, kIndex);

  return (0);
}
コード例 #4
0
/*
 * the validation process requires generating a single lineitem
 * so the main mk_xxx routine has been split into a master record portion
 * and a detail/lineitem portion.
 */
static void
mk_master (void *row, ds_key_t index)
{
   static decimal_t dMin,
      dMax;
   int nGiftPct;
   struct W_WEB_SALES_TBL *r;
   static int bInit = 0,
	   nItemCount;
	
	if (row == NULL)
		r = &g_w_web_sales;
	else
		r = row;

	if (!bInit)
	{
		strtodec (&dMin, "1.00");
		strtodec (&dMax, "100000.00");
		jDate = skipDays(WEB_SALES, &kNewDateIndex);	
		nItemCount = (int)getIDCount(ITEM);
		bInit = 1;
	}
		
	
	/***
	* some attributes reamin the same for each lineitem in an order; others are different
	* for each lineitem. Since the number of lineitems per order is static, we can use a 
	* modulo to determine when to change the semi-static values 
	*/
   while (index > kNewDateIndex)	/* need to move to a new date */
   {
      jDate += 1;
      kNewDateIndex += dateScaling(WEB_SALES, jDate);
   }

   r->ws_sold_date_sk = mk_join (WS_SOLD_DATE_SK, DATE, 1);
   r->ws_sold_time_sk = mk_join(WS_SOLD_TIME_SK, TIME, 1);
   r->ws_bill_customer_sk = mk_join (WS_BILL_CUSTOMER_SK, CUSTOMER, 1);
   r->ws_bill_cdemo_sk = mk_join (WS_BILL_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1);
   r->ws_bill_hdemo_sk = mk_join (WS_BILL_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1);
   r->ws_bill_addr_sk = mk_join (WS_BILL_ADDR_SK, CUSTOMER_ADDRESS, 1);
		
   /* most orders are for the ordering customers, some are not */
   genrand_integer(&nGiftPct, DIST_UNIFORM, 0, 99, 0, WS_SHIP_CUSTOMER_SK);
   if (nGiftPct > WS_GIFT_PCT)
   {
      r->ws_ship_customer_sk =
         mk_join (WS_SHIP_CUSTOMER_SK, CUSTOMER, 2);
      r->ws_ship_cdemo_sk =
         mk_join (WS_SHIP_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 2);
      r->ws_ship_hdemo_sk =
         mk_join (WS_SHIP_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 2);
      r->ws_ship_addr_sk =
         mk_join (WS_SHIP_ADDR_SK, CUSTOMER_ADDRESS, 2);
   }
   else
   {
      r->ws_ship_customer_sk =	r->ws_bill_customer_sk;
      r->ws_ship_cdemo_sk =	r->ws_bill_cdemo_sk;
      r->ws_ship_hdemo_sk =	r->ws_bill_hdemo_sk;
      r->ws_ship_addr_sk =	r->ws_bill_addr_sk;
   }

   r->ws_order_number = index;
   genrand_integer(&nItemIndex, DIST_UNIFORM, 1, nItemCount, 0, WS_ITEM_SK);

return;
}
コード例 #5
0
ファイル: pricing.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* Routine: set_pricing(int nTabId, ds_pricing_t *pPricing)
* Purpose: handle the various pricing calculations for the fact tables
* Notes:
*	the RNG usage is not kept in sync between sales pricing and returns pricing. If the calculations look wrong, it may 
*	be necessary to "waste" some RNG calls on one side or the other to bring things back in line
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
void set_pricing(int nTabId, ds_pricing_t *pPricing)
{
	static int nLastId = -1, 
		init = 0,
		nQuantityMax,
		nQuantityMin = 1;
	static decimal_t dQuantity, dMarkupMin, dDiscountMin, dWholesaleMin,
		 dMarkupMax, dDiscountMax, dWholesaleMax, dCouponMin, dCouponMax,
		 dZero, dOneHalf, d9pct, dOne, dTemp, dHundred;
	decimal_t dMarkup, dCoupon, dShipping, dDiscount, dTemp2;
	int i,
		nCashPct,
		nCreditPct,
		nCouponUsage;
	
	if (!init)
	{
		strtodec(&dMarkupMin, "0.00");
		strtodec(&dDiscountMin, "0.00");
		strtodec(&dWholesaleMin, "1.00");
		strtodec(&dCouponMin, "0.00");
		strtodec(&dZero, "0.00");
		strtodec(&dOneHalf, "0.50");
		strtodec(&d9pct, "0.09");
		strtodec(&dWholesaleMin, "1.00");
		strtodec(&dHundred, "100.00");
		strtodec(&dOne, "1.00");

		init = 1;
	}
	
	if (nTabId != nLastId)
	{
		nLastId = -1;
		for (i=0; i < MAX_LIMIT; i++)
		{
			if (nTabId == aPriceLimits[i].nId)
				nLastId = i;
		}
		if (nLastId == -1)
			INTERNAL("No pricing limits defined");
		nQuantityMax = atoi(aPriceLimits[nLastId].szQuantity);
		strtodec(&dDiscountMax, aPriceLimits[nLastId].szDiscount);
		strtodec(&dMarkupMax, aPriceLimits[nLastId].szMarkUp);
		strtodec(&dWholesaleMax, aPriceLimits[nLastId].szWholesale);
		strtodec(&dCouponMax, aPriceLimits[nLastId].szCoupon);
	}

	switch(nTabId)
	{
	case SS_PRICING:
	case CS_PRICING:
	case WS_PRICING:
	case S_PLINE_PRICING:
	case S_CLIN_PRICING:
	case S_WLIN_PRICING:
		genrand_integer(&pPricing->quantity, DIST_UNIFORM, nQuantityMin, nQuantityMax, 0, nTabId);
		itodec(&dQuantity, pPricing->quantity);
		genrand_decimal(&pPricing->wholesale_cost, DIST_UNIFORM, &dWholesaleMin, &dWholesaleMax, NULL, nTabId);

		/* ext_wholesale_cost = wholesale_cost * quantity */
		decimal_t_op(&pPricing->ext_wholesale_cost, OP_MULT, &dQuantity, &pPricing->wholesale_cost);
		
		/* list_price = wholesale_cost * (1 + markup) */
		genrand_decimal(&dMarkup, DIST_UNIFORM, &dMarkupMin, &dMarkupMax, NULL, nTabId);
		decimal_t_op(&dMarkup, OP_PLUS, &dMarkup, &dOne);
		decimal_t_op(&pPricing->list_price, OP_MULT, &pPricing->wholesale_cost, &dMarkup);
		
		/* sales_price = list_price * (1 - discount)*/
		genrand_decimal(&dDiscount, DIST_UNIFORM, &dDiscountMin, &dDiscountMax, NULL, nTabId);
		NegateDecimal(&dDiscount);
		decimal_t_op(&pPricing->ext_discount_amt, OP_PLUS, &dDiscount, &dOne);
		decimal_t_op(&pPricing->sales_price, OP_MULT, &pPricing->list_price, &pPricing->ext_discount_amt);
		
		/* ext_list_price = list_price * quantity */
		decimal_t_op(&pPricing->ext_list_price, OP_MULT, &pPricing->list_price, &dQuantity);
		
		/* ext_sales_price = sales_price * quantity */
		decimal_t_op(&pPricing->ext_sales_price, OP_MULT, &pPricing->sales_price, &dQuantity);
		
		/* ext_discount_amt = ext_list_price - ext_sales_price */
		decimal_t_op(&pPricing->ext_discount_amt, OP_MINUS, &pPricing->ext_list_price, &pPricing->ext_sales_price);
		
		/* coupon_amt = ext_sales_price * coupon */
		genrand_decimal(&dCoupon, DIST_UNIFORM, &dZero, &dOne, NULL, nTabId);
		genrand_integer(&nCouponUsage, DIST_UNIFORM, 1, 100, 0, nTabId);
		if (nCouponUsage <= 20)	/* 20% of sales employ a coupon */
			decimal_t_op(&pPricing->coupon_amt, OP_MULT, &pPricing->ext_sales_price, &dCoupon);
		else
			memcpy(&pPricing->coupon_amt, &dZero, sizeof(decimal_t));
		
		/* net_paid = ext_sales_price - coupon_amt */
		decimal_t_op(&pPricing->net_paid, OP_MINUS, &pPricing->ext_sales_price, &pPricing->coupon_amt);
		
		/* shipping_cost = list_price * shipping */
		genrand_decimal(&dShipping, DIST_UNIFORM, &dZero, &dOneHalf, NULL, nTabId);
		decimal_t_op(&pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping);

      /* ext_shipping_cost = shipping_cost * quantity */
		decimal_t_op(&pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity);
		
		/* net_paid_inc_ship = net_paid + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship, OP_PLUS, &pPricing->net_paid, &pPricing->ext_ship_cost);
		
		/* ext_tax = tax * net_paid */
		genrand_decimal(&pPricing->tax_pct, DIST_UNIFORM, &dZero, &d9pct, NULL, nTabId);
		decimal_t_op(&pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct);
		
		/* net_paid_inc_tax = net_paid + ext_tax */
		decimal_t_op(&pPricing->net_paid_inc_tax, OP_PLUS, &pPricing->net_paid, &pPricing->ext_tax);
		
		/* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship_tax, OP_PLUS, &pPricing->net_paid_inc_ship, &pPricing->ext_tax);
		
		/* net_profit = net_paid - ext_wholesale_cost */
		decimal_t_op(&pPricing->net_profit, OP_MINUS, &pPricing->net_paid, &pPricing->ext_wholesale_cost);
		break;
	case CR_PRICING:
	case SR_PRICING:
	case WR_PRICING:
		/* quantity is determined before we are called */
		/* ext_wholesale_cost = wholesale_cost * quantity */
		itodec(&dQuantity, pPricing->quantity);
		decimal_t_op(&pPricing->ext_wholesale_cost, OP_MULT, &dQuantity, &pPricing->wholesale_cost);
		
		/* ext_list_price = list_price * quantity */
		decimal_t_op(&pPricing->ext_list_price, OP_MULT, &pPricing->list_price, &dQuantity);
		
		/* ext_sales_price = sales_price * quantity */
		decimal_t_op(&pPricing->ext_sales_price, OP_MULT, &pPricing->sales_price, &dQuantity);
		
		/* net_paid = ext_list_price (couppons don't effect returns) */
		memcpy(&pPricing->net_paid, &pPricing->ext_sales_price, sizeof(decimal_t));
		
		/* shipping_cost = list_price * shipping */
		genrand_decimal(&dShipping, DIST_UNIFORM, &dZero, &dOneHalf, NULL, nTabId);
		decimal_t_op(&pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping);

      /* ext_shipping_cost = shipping_cost * quantity */
		decimal_t_op(&pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity);
				
		/* net_paid_inc_ship = net_paid + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship, OP_PLUS, &pPricing->net_paid, &pPricing->ext_ship_cost);
		
		/* ext_tax = tax * net_paid */
		decimal_t_op(&pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct);
		
		/* net_paid_inc_tax = net_paid + ext_tax */
		decimal_t_op(&pPricing->net_paid_inc_tax, OP_PLUS, &pPricing->net_paid, &pPricing->ext_tax);
		
		/* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship_tax, OP_PLUS, &pPricing->net_paid_inc_ship, &pPricing->ext_tax);
		
		/* net_profit = net_paid - ext_wholesale_cost */
		decimal_t_op(&pPricing->net_profit, OP_MINUS, &pPricing->net_paid, &pPricing->ext_wholesale_cost);
		
		/* see to it that the returned amounts add up to the total returned */
		/* allocate some of return to cash */
		genrand_integer(&nCashPct, DIST_UNIFORM, 0, 100, 0, nTabId);
		itodec(&dTemp, nCashPct);
		decimal_t_op(&pPricing->refunded_cash, OP_DIV, &dTemp, &dHundred);
		decimal_t_op(&pPricing->refunded_cash, OP_MULT, &pPricing->refunded_cash, &pPricing->net_paid);
		
		/* allocate some to reversed charges */
		genrand_integer(&nCreditPct, DIST_UNIFORM, 1, 100, 0, nTabId);
		itodec(&dTemp2, nCreditPct);
		decimal_t_op(&dTemp, OP_DIV, &dTemp2, &dHundred);
		decimal_t_op(&dTemp2, OP_MINUS, &pPricing->net_paid, &pPricing->refunded_cash);
		decimal_t_op(&pPricing->reversed_charge, OP_MULT, &dTemp2, &dTemp);
		
		/* the rest is store credit */
		decimal_t_op(&pPricing->store_credit, OP_MINUS, &pPricing->net_paid, &pPricing->reversed_charge);
		decimal_t_op(&pPricing->store_credit, OP_MINUS, &pPricing->store_credit, &pPricing->refunded_cash);
		
		/* pick a fee for the return */
		genrand_decimal(&pPricing->fee, DIST_UNIFORM, &dOneHalf, &dHundred, &dZero, nTabId);
		
		/* and calculate the net effect */
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_paid_inc_ship_tax, &pPricing->store_credit);
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_loss, &pPricing->refunded_cash);
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_loss, &pPricing->reversed_charge);
		decimal_t_op(&pPricing->net_loss, OP_PLUS, &pPricing->net_loss, &pPricing->fee);
		break;
	}

	return;

}
コード例 #6
0
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int MatchDistWeight(void *dest, char *szDist, int nWeight, int nWeightSet, int ValueSet)
{
		d_idx_t *d;
		dist_t *dist;
		int	index = 0,
			dt,
			i_res,
			nRetcode;
		char *char_val;
		
		if ((d = find_dist(szDist)) == NULL)
		{
			char msg[80];
			sprintf(msg, "Invalid distribution name '%s'", szDist);
			INTERNAL(msg);
		}
		
		dist = d->dist;
		nWeight %= dist->maximums[nWeightSet - 1];
		
		while (nWeight > dist->weight_sets[nWeightSet - 1][index] && 
			index < d->length)
			index += 1;
		dt = ValueSet - 1;
		if (index >= d->length)
			index = d->length - 1;
		char_val = dist->strings + dist->value_sets[dt][index];
		
		switch(dist->type_vector[dt])
		{
		case TKN_VARCHAR:
			if (dest)
				*(char **)dest = (char *)char_val;
			break;
		case TKN_INT:
			i_res = atoi(char_val);
			if (dest)
				*(int *)dest = i_res;
			break;
		case TKN_DATE:
			if (dest == NULL)
			{
				dest = (date_t *)malloc(sizeof(date_t));
				MALLOC_CHECK(dest);
			}
			strtodt(*(date_t **)dest, char_val);
			break;
		case TKN_DECIMAL:
			if (dest == NULL)
			{
				dest = (decimal_t *)malloc(sizeof(decimal_t));
				MALLOC_CHECK(dest);
			}
			strtodec(*(decimal_t **)dest,char_val);
			break;
		}
		
		nRetcode = 1;
		index = 1;
		while (index < dist->maximums[nWeightSet - 1])
		{
			nRetcode += 1;
			index *= 2;
		}

		return(nRetcode);
}
コード例 #7
0
/*
* Routine: void *dist_op()
* Purpose: select a value/weight from a distribution
* Algorithm:
* Data Structures:
*
* Params:	char *d_name
*			int vset: which set of values
*			int wset: which set of weights
* Returns: appropriate data type cast as a void *
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 20000317 Need to be sure this is portable to NT and others
*/
int
dist_op(void *dest, int op, char *d_name, int vset, int wset, int stream)
{
	d_idx_t *d;
	dist_t *dist;
	int	level,
		index = 0,
		dt;
	char *char_val;
	int i_res = 1;
	
	if ((d = find_dist(d_name)) == NULL)
	{
		char msg[80];
		sprintf(msg, "Invalid distribution name '%s'", d_name);
		INTERNAL(msg);
		assert(d != NULL);
	}
		
	dist = d->dist;
	
	if (op == 0)
	{
		genrand_integer(&level, DIST_UNIFORM, 1, 
			dist->maximums[wset - 1], 0, stream);
		while (level > dist->weight_sets[wset - 1][index] && 
			index < d->length)
			index += 1;
		dt = vset - 1;
		if ((index >= d->length) || (dt > d->v_width))
			INTERNAL("Distribution overrun");
		char_val = dist->strings + dist->value_sets[dt][index];
	}
	else
	{ 
		index = vset - 1;
		dt = wset - 1;
		if (index >= d->length || index < 0)
		{
			fprintf(stderr, "Runtime ERROR: Distribution over-run/under-run\n");
			fprintf(stderr, "Check distribution definitions and usage for %s.\n",
			d->name);
			fprintf(stderr, "index = %d, length=%d.\n",
				index, d->length);
			exit(1);
		}
		char_val = dist->strings + dist->value_sets[dt][index];
	}
	
	
	switch(dist->type_vector[dt])
	{
	case TKN_VARCHAR:
		if (dest)
			*(char **)dest = (char *)char_val;
		break;
	case TKN_INT:
		i_res = atoi(char_val);
		if (dest)
			*(int *)dest = i_res;
		break;
	case TKN_DATE:
		if (dest == NULL)
		{
			dest = (date_t *)malloc(sizeof(date_t));
			MALLOC_CHECK(dest);
		}
		strtodt(*(date_t **)dest, char_val);
		break;
	case TKN_DECIMAL:
		if (dest == NULL)
		{
			dest = (decimal_t *)malloc(sizeof(decimal_t));
			MALLOC_CHECK(dest);
		}
		strtodec(*(decimal_t **)dest,char_val);
		break;
	}
	
	return((dest == NULL)?i_res:index + 1);	/* shift back to the 1-based indexing scheme */
}
コード例 #8
0
/*
* Routine: mk_store_returns()
* Purpose: populate a return fact *sync'd with a sales fact*
* Algorithm: 
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_w_store_returns (void * row, ds_key_t index)
{
	int res = 0,
		nTemp;
	struct W_STORE_RETURNS_TBL *r;
	struct W_STORE_SALES_TBL *sale = &g_w_store_sales;
	static int bInit = 0;
   tdef *pT = getSimpleTdefsByNumber(STORE_RETURNS);
	
	static decimal_t dMin,
		dMax;
	/* begin locals declarations */
	
	if (row == NULL)
		r = &g_w_store_returns;
	else
		r = row;

	if (!bInit)
	{
        strtodec (&dMin, "1.00");
        strtodec (&dMax, "100000.00");
	}
	
	nullSet(&pT->kNullBitMap, SR_NULLS);
	/*
	* Some of the information in the return is taken from the original sale
	* which has been regenerated
	*/
	r->sr_ticket_number = sale->ss_ticket_number;
	r->sr_item_sk = sale->ss_sold_item_sk;
	memcpy((void *)&r->sr_pricing, (void *)&sale->ss_pricing, sizeof(ds_pricing_t));

	/*
	 * some of the fields are conditionally taken from the sale 
	 */
	r->sr_customer_sk = mk_join (SR_CUSTOMER_SK, CUSTOMER, 1);
	if (genrand_integer(NULL, DIST_UNIFORM, 1, 100, 0, SR_TICKET_NUMBER) < SR_SAME_CUSTOMER)
		r->sr_customer_sk = sale->ss_sold_customer_sk;

	/*
	* the rest of the columns are generated for this specific return
	*/
	/* the items cannot be returned until they are sold; offset is handled in mk_join, based on sales date */
	r->sr_returned_date_sk = mk_join (SR_RETURNED_DATE_SK, DATE, sale->ss_sold_date_sk);
	genrand_integer(&nTemp, DIST_UNIFORM, (8 * 3600) - 1, (17 * 3600) - 1, 0, SR_RETURNED_TIME_SK);
	r->sr_returned_time_sk = nTemp;
	r->sr_cdemo_sk =
		mk_join (SR_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1);
	r->sr_hdemo_sk =
		mk_join (SR_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1);
	r->sr_addr_sk = mk_join (SR_ADDR_SK, CUSTOMER_ADDRESS, 1);
	r->sr_store_sk = mk_join (SR_STORE_SK, STORE, 1);
	r->sr_reason_sk = mk_join (SR_REASON_SK, REASON, 1);
	genrand_integer(&r->sr_pricing.quantity, DIST_UNIFORM,
		1, sale->ss_pricing.quantity, 0, SR_PRICING);
	set_pricing(SR_PRICING, &r->sr_pricing);
	
	return (res);
}
コード例 #9
0
ファイル: w_item.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* mk_item
*/
int
mk_w_item (void* row, ds_key_t index)
{
	
	int32_t res = 0;
	/* begin locals declarations */
	decimal_t dMinPrice, 
		dMaxPrice,
		dMarkdown;
	static decimal_t dMinMarkdown, dMaxMarkdown;
	int32_t bUseSize,
		bFirstRecord = 0,
		nFieldChangeFlags,
		nMin,
		nMax,
		nIndex,
		nTemp;
	char *cp;
	struct W_ITEM_TBL *r;
	static int32_t bInit = 0;
	struct W_ITEM_TBL *rOldValues = &g_OldValues;
	char *szMinPrice = NULL,
		*szMaxPrice = NULL;
   tdef *pT = getSimpleTdefsByNumber(ITEM);


	if (row == NULL)
		r = &g_w_item;
	else
		r = row;
	
	
	if (!bInit)
	{
		/* some fields are static throughout the data set */
		strtodec(&dMinMarkdown, MIN_ITEM_MARKDOWN_PCT);
		strtodec(&dMaxMarkdown, MAX_ITEM_MARKDOWN_PCT);

		bInit = 1;
	}
	
	memset(r, 0, sizeof(struct W_ITEM_TBL));

	/* build the new value */
	nullSet(&pT->kNullBitMap, I_NULLS);
	r->i_item_sk = index;

	nIndex = pick_distribution(&nMin, "i_manager_id", 2, 1, I_MANAGER_ID);
	dist_member(&nMax, "i_manager_id", nIndex, 3);
	genrand_key(&r->i_manager_id, DIST_UNIFORM, 
		(ds_key_t)nMin, 
		(ds_key_t)nMax, 
		0, I_MANAGER_ID);



	/* if we have generated the required history for this business key and generate a new one 
	 * then reset associated fields (e.g., rec_start_date minimums)
	 */
	if (setSCDKeys(I_ITEM_ID, index, r->i_item_id, &r->i_rec_start_date_id, &r->i_rec_end_date_id))
	{
	/* 
	 * some fields are not changed, even when a new version of the row is written 
	 */
		bFirstRecord = 1;
	}
	
	 /*
	  * this is  where we select the random number that controls if a field changes from 
	  * one record to the next. 
	  */
	nFieldChangeFlags = next_random(I_SCD);


	/* the rest of the record in a history-keeping dimension can either be a new data value or not;
	 * use a random number and its bit pattern to determine which fields to replace and which to retain
	 */
	gen_text (r->i_item_desc, 1, RS_I_ITEM_DESC, I_ITEM_DESC);
	changeSCD(SCD_CHAR, &r->i_item_desc, &rOldValues->i_item_desc,  &nFieldChangeFlags,  bFirstRecord);
	
	nIndex = pick_distribution(&szMinPrice, "i_current_price", 2, 1, I_CURRENT_PRICE);
	dist_member(&szMaxPrice, "i_current_price", nIndex, 3);
	strtodec(&dMinPrice, szMinPrice);
	strtodec(&dMaxPrice, szMaxPrice);
	genrand_decimal(&r->i_current_price, DIST_UNIFORM, &dMinPrice, &dMaxPrice, NULL, I_CURRENT_PRICE);
	changeSCD(SCD_INT, &r->i_current_price, &rOldValues->i_current_price,  &nFieldChangeFlags,  bFirstRecord);

	genrand_decimal(&dMarkdown, DIST_UNIFORM, &dMinMarkdown, &dMaxMarkdown, NULL, I_WHOLESALE_COST);
	decimal_t_op(&r->i_wholesale_cost, OP_MULT, &r->i_current_price, &dMarkdown);
	changeSCD(SCD_DEC, &r->i_wholesale_cost, &rOldValues->i_wholesale_cost,  &nFieldChangeFlags,  bFirstRecord);

	hierarchy_item (I_CATEGORY, &r->i_category_id, &r->i_category, index);
	/*
         * changeSCD(SCD_INT, &r->i_category_id, &rOldValues->i_category_id,  &nFieldChangeFlags,  bFirstRecord);
         */

	hierarchy_item (I_CLASS, &r->i_class_id, &r->i_class, index);
	changeSCD(SCD_KEY, &r->i_class_id, &rOldValues->i_class_id,  &nFieldChangeFlags,  bFirstRecord);

	cp = &r->i_brand[0];
	hierarchy_item (I_BRAND, &r->i_brand_id, &cp, index);
	changeSCD(SCD_KEY, &r->i_brand_id, &rOldValues->i_brand_id,  &nFieldChangeFlags,  bFirstRecord);

	/* some categories have meaningful sizes, some don't */
	if (r->i_category_id)
   {
      dist_member(&bUseSize, "categories", (int)r->i_category_id, 3);
	pick_distribution (&r->i_size, "sizes", 1, bUseSize + 2, I_SIZE);
	changeSCD(SCD_PTR, &r->i_size, &rOldValues->i_size,  &nFieldChangeFlags,  bFirstRecord);
   }
   else
   {
      bUseSize = 0;
      r->i_size = NULL;
   }

	nIndex = pick_distribution(&nMin, "i_manufact_id", 2, 1, I_MANUFACT_ID);
	genrand_integer(&nTemp, DIST_UNIFORM, 
		nMin, 
		dist_member(NULL, "i_manufact_id", nIndex, 3), 
		0, I_MANUFACT_ID);
	r->i_manufact_id = nTemp;
	changeSCD(SCD_KEY, &r->i_manufact_id, &rOldValues->i_manufact_id,  &nFieldChangeFlags,  bFirstRecord);

	mk_word (r->i_manufact, "syllables", (int) r->i_manufact_id, RS_I_MANUFACT, ITEM);
	changeSCD(SCD_CHAR, &r->i_manufact, &rOldValues->i_manufact,  &nFieldChangeFlags,  bFirstRecord);

	gen_charset(r->i_formulation, DIGITS, RS_I_FORMULATION, RS_I_FORMULATION, I_FORMULATION);
	embed_string(r->i_formulation, "colors", 1, 2, I_FORMULATION);
	changeSCD(SCD_CHAR, &r->i_formulation, &rOldValues->i_formulation,  &nFieldChangeFlags,  bFirstRecord);

	pick_distribution (&r->i_color, "colors", 1, 2, I_COLOR);
	changeSCD(SCD_PTR, &r->i_color, &rOldValues->i_color,  &nFieldChangeFlags,  bFirstRecord);

	pick_distribution (&r->i_units, "units", 1, 1, I_UNITS);
	changeSCD(SCD_PTR, &r->i_units, &rOldValues->i_units,  &nFieldChangeFlags,  bFirstRecord);

	pick_distribution (&r->i_container, "container", 1, 1, ITEM);
	changeSCD(SCD_PTR, &r->i_container, &rOldValues->i_container,  &nFieldChangeFlags,  bFirstRecord);

	mk_word (r->i_product_name, "syllables", (int) index, RS_I_PRODUCT_NAME,
		ITEM);

	r->i_promo_sk = mk_join(I_PROMO_SK, PROMOTION, 1);
	genrand_integer(&nTemp, DIST_UNIFORM, 1, 100, 0, I_PROMO_SK);
	if (nTemp > I_PROMO_PERCENTAGE)
		r->i_promo_sk = -1;

/* 
 * if this is the first of a set of revisions, then baseline the old values
 */
 if (bFirstRecord)
   memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL));

 if (index == 1)
   memcpy(&g_OldValues, r, sizeof(struct W_ITEM_TBL));

	return (res);
}
コード例 #10
0
ファイル: monitors.cpp プロジェクト: MarcusSchwarz/netmrg2
uint process_monitor(DeviceInfo info, MYSQL *mysql, RRDInfo rrd)
{
	debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Starting Monitor.");

	info.parameters.push_front(ValuePair("parameters", info.test_params));

	switch (info.test_type)
	{
		case  1:	info.curr_val = process_script_monitor(info, mysql);
					break;

		case  2:	info.curr_val = process_snmp_monitor(info, mysql);
					break;

		case  3:	info.curr_val = process_sql_monitor(info, mysql);
					break;

		case  4:	info.curr_val = process_internal_monitor(info, mysql);
					break;

		default:	debuglogger(DEBUG_MONITOR, LEVEL_WARNING, &info, "Unknown test type (" + inttostr(info.test_type) + ").");
					info.curr_val = "U";

	} // end switch

	debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value: " + strstripnl(info.curr_val));

	// strip out anything not numeric
	info.curr_val = remove_nonnumerics(info.curr_val);
	
	if (rrd.data_type != "")
	{
		update_monitor_rrd(info, rrd);
	}

	// what type of value are we dealing with?
	if (info.curr_val == "U")
	{
		// value is unknown
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is unknown.");
	}
	else if (info.curr_val == inttostr(strtoint(info.curr_val)))
	{
		// value is an integer
		// (do nothing)
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is an integer.");
	}
	else if (info.curr_val == "")
	{
		// value is non-numeric
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is not numeric.");
		info.curr_val = "U";
	}
	else
	{
		//value is probably decimal
		debuglogger(DEBUG_MONITOR, LEVEL_INFO, &info, "Value is a decimal.");
		info.curr_val = inttostr(ROUND_VAL(strtodec(info.curr_val)));
	}

	if ((info.curr_val == "U") || (info.last_val == "U"))
	{
		info.delta_val = "U";
		info.rate_val  = "U";
	}
	else
	{
		info.delta_val = inttostr(strtoint(info.curr_val) - strtoint(info.last_val));
		if (info.delta_time != 0)
		{
			info.rate_val  = inttostr(strtoint(info.delta_val) / info.delta_time);
		}
		else
		{
			info.rate_val  = "U";
		}
	}
	
	// populate parameters
	info.parameters.push_front(ValuePair("current_value", info.curr_val));
	info.parameters.push_front(ValuePair("delta_value", info.delta_val));
	info.parameters.push_front(ValuePair("rate_value", info.rate_val));
	info.parameters.push_front(ValuePair("last_value", info.last_val));

	uint status = process_events(info, mysql);

	info.status = status;
	update_monitor_db(info, mysql, rrd);

	return status;
}