/* * File: * stubdata.c * Author: * Samuel A. Rebelsky * Version: * 0.1 of July 2003 * Summary: * Procedures and variables used to generate a simulated set * of visits. See clio.h for details. */ /********************************************************************* * Headers * ***********/ #include "clio.h" #include /* I use time() to seed the generator. */ #include /* I use INT_MAX. */ /********************************************************************* * Constants * *************/ /* The maximum number of page ids. */ #define MAXPAGE 100 /* The maximum length of a visit (in seconds). */ #define MAXLENGTH 100 /********************************************************************* * Variables * *************/ pagevisit *visits = NULL; int numvisits = 0; int starttime = 0; int endtime = 0; int pagetypes = 0; int maxlength = 0; /********************************************************************* * Local Functions * *******************/ /* * Compute a random value between 0 and max-1. */ int restrictedRand(int max) { return (int) ((((float) max)*rand())/(RAND_MAX+1.0)); } /* restrictedRand(int) */ /********************************************************************* * Exported Functions * **********************/ void loadData(selector *query) { int i; /* Counter variable. */ /* Prepare to generate random numbers. */ srand(time(NULL)); /* * Figure out how many visits there will be. I decided 20 to 50 * is a good starting point. */ numvisits = 20 + restrictedRand(30); fprintf(stderr, "Creating %d visits.\n", numvisits); /* * Set up preliminary information on all the visits. This * information will change as we fill in the visits. */ starttime = INT_MAX; endtime = 0; maxlength = 0; pagetypes = 0; /* Clear the old visits, if they're set. */ if (visits != NULL) { free(visits); } /* Allocate memory for the visits. No error checking here. */ visits = (pagevisit *) malloc(numvisits * sizeof(pagevisit)); /* Set up all the visits. */ for (i = 0; i < numvisits; i++) { visits[i].visitid = i; visits[i].userid = restrictedRand(3); visits[i].pageid = restrictedRand(MAXPAGE); visits[i].windowid = restrictedRand(3); visits[i].sessionid = restrictedRand(3); visits[i].uws = restrictedRand(10); visits[i].start = restrictedRand(1000); visits[i].length = restrictedRand(MAXLENGTH); visits[i].type = restrictedRand(5); if (visits[i].start < starttime) { starttime = visits[i].start; } if ((visits[i].start + visits[i].length) > endtime) { endtime = visits[i].start + visits[i].length; } if (visits[i].length > maxlength) { maxlength = visits[i].length; } if (visits[i].type > pagetypes) { pagetypes = visits[i].type; } } /* for */ /* That's it, we're done. */ } /* loadData() */