void KDModule::propagateUsers() { groupmap.clear(); emit clearUsers(); QMap< QString, int > lusers; QMapConstIterator< QString, QPair< int, QStringList > > it; QStringList::ConstIterator jt; QMap< QString, int >::Iterator gmapi; for(it = usermap.begin(); it != usermap.end(); ++it) { int uid = it.data().first; if(!uid || (uid >= minshowuid && uid <= maxshowuid)) { lusers[it.key()] = uid; for(jt = it.data().second.begin(); jt != it.data().second.end(); ++jt) if((gmapi = groupmap.find(*jt)) == groupmap.end()) { groupmap[*jt] = 1; lusers['@' + *jt] = -uid; } else (*gmapi)++; } } emit addUsers(lusers); updateOK = true; }
void LLPanelGroupBulkImpl::onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name) { if (mAvatarNameCacheConnections[agent_id].connected()) { mAvatarNameCacheConnections[agent_id].disconnect(); } std::vector<std::string> names; uuid_vec_t agent_ids; agent_ids.push_back(agent_id); std::string name; LLAvatarNameCache::getPNSName(av_name, name); names.push_back(name); addUsers(names, agent_ids); }
void KDModule::slotMinMaxUID(int min, int max) { if(updateOK) { QMap< QString, int > alusers, dlusers; QMapConstIterator< QString, QPair< int, QStringList > > it; QStringList::ConstIterator jt; QMap< QString, int >::Iterator gmapi; for(it = usermap.begin(); it != usermap.end(); ++it) { int uid = it.data().first; if(!uid) continue; if((uid >= minshowuid && uid <= maxshowuid) && !(uid >= min && uid <= max)) { dlusers[it.key()] = uid; for(jt = it.data().second.begin(); jt != it.data().second.end(); ++jt) { gmapi = groupmap.find(*jt); if(!--(*gmapi)) { groupmap.remove(gmapi); dlusers['@' + *jt] = -uid; } } } else if((uid >= min && uid <= max) && !(uid >= minshowuid && uid <= maxshowuid)) { alusers[it.key()] = uid; for(jt = it.data().second.begin(); jt != it.data().second.end(); ++jt) if((gmapi = groupmap.find(*jt)) == groupmap.end()) { groupmap[*jt] = 1; alusers['@' + *jt] = -uid; } else (*gmapi)++; } } emit delUsers(dlusers); emit addUsers(alusers); } minshowuid = min; maxshowuid = max; }
int serverInit(LUser* luser){ DIR *dir,*user_dir,*dir_user; FILE *user_pass_file; struct dirent *dit,*dit_user; char *aux_path,*pass, *name; aux_path = (char*)malloc(256*sizeof(char)); //char path[100]; int num_user = 0,num_friends = 0; User *user; luser->numUser = 0; // Abrir el directorio server_data if ((dir = opendir(DATA_PATH)) == NULL){ sprintf(aux_path,"mkdir %s",DATA_PATH); system(aux_path); //perror("opendir"); return 0; } if(DEBUG_MODE) printf("serverInit -> Directorio: %s\n",DATA_PATH); // Recorrer el directorio server_data while ((dit = readdir(dir)) != NULL){ if(strcmp(dit->d_name,".") != 0 && strcmp(dit->d_name,"..") != 0){ //LEER CLAVE num_user++; // Directorio del pass del usuario = aux_path sprintf(aux_path,"%s%s/.pass",DATA_PATH,dit->d_name); if((user_pass_file = fopen(aux_path, "r")) == NULL){ perror("Error abriendo fichero"); return 0; } pass = (char*)malloc(256*sizeof(char)); fscanf( user_pass_file, "%s\\n", pass); addUsers(luser,dit->d_name,pass); if(DEBUG_MODE){ printf("serverInit -> Se ha añadido: %s %s\n",dit->d_name,pass); } if(fclose(user_pass_file) == -1){ perror("Error cerrando fichero"); } // LEER peticiones enviadas // Directorio de la lista de enviados = aux_path sprintf(aux_path,"%s%s/.send",DATA_PATH,dit->d_name); if((user_pass_file = fopen(aux_path, "r")) == NULL) perror("Error abriendo fichero"); name = (char*)malloc(256*sizeof(char)); while(!feof(user_pass_file)) { if(fgets(name,100,user_pass_file) != NULL) { //fscanf(user_pass_file,"%s\\n",name); name[strlen(name)-1] = '\0'; if(DEBUG_MODE) printf("serverInit -> Send: %s\n",name); user = luser->listU[num_user-1];// Coger el usuario actual addFriendRequestSend(user,name); } } if(fclose(user_pass_file) == -1) perror("Error abriendo fichero"); // LEER peticiones recibidas // Directorio de la lista de enviados = aux_path sprintf(aux_path,"%s%s/.pending",DATA_PATH,dit->d_name); if((user_pass_file = fopen(aux_path, "r")) == NULL) perror("Error abriendo fichero"); while(!feof(user_pass_file)) { if(fgets(name,100,user_pass_file) != NULL) { //fscanf(user_pass_file,"%s\\n",name); name[strlen(name)-1] = '\0'; if(DEBUG_MODE) printf("serverInit -> Pending: %s\n",name); user = luser->listU[num_user-1];// Coger el usuario actual addFriendRequestPending(user,name); } } if(fclose(user_pass_file) == -1) perror("Error abriendo fichero"); //LEER AMIGOS // Directorio del usuario = aux_path sprintf(aux_path,"%s%s/",DATA_PATH,dit->d_name); if ((dir_user = opendir(aux_path)) == NULL){ perror("opendir"); return 0; } //num_friends = 0; user = luser->listU[num_user-1];// Coger el usuario actual // Recorrer el directorio del usuario para añadir los amigos while ((dit_user = readdir(dir_user)) != NULL){ if(strcmp(dit_user->d_name,".") != 0 && strcmp(dit_user->d_name,"..") != 0 && strcmp(dit_user->d_name,".pass") != 0 && strcmp(dit_user->d_name,".pending") != 0 && strcmp(dit_user->d_name,".send") != 0){ addFriend(user,dit_user->d_name); if(DEBUG_MODE){ printf("serverInit -> %s añade a %s\n",user->nick,dit_user->d_name); } //num_friends++; } } if (closedir(dir_user) == -1){ perror("closedir"); return 0; } free(pass); free(name); //user->numFriends = num_friends; /*printf("\n%s", dit->d_name); printf(" %d", dit->d_reclen);*/ } } free(aux_path); /* int closedir(DIR *dir); * * Close the stream to argv[1]. And check for errors. */ if (closedir(dir) == -1){ perror("closedir"); return 0; } luser->numUser = num_user; if(DEBUG_MODE) printf("serverInit -> Exit Directorio: %s Users: %d\n",DATA_PATH,luser->numUser); return 0; }
int main(int argc, char *argv[]) { /* First, we need to take in input from the items file. */ if (argc != 6) { printf("Usage: workload total alpha beta gamma delta\n"); printf("The values for alpha, beta, gamma and delta need to be integers that sum to 100.\n"); exit(0); } int i, j, k, numrecs; // These are the parameters that come from the user. int total, nalpha, nbeta, ngamma, ndelta; // These represent thresholds. int talpha, tbeta, tgamma, tdelta; // These are derived parameters from the database. int alphacells, betacells, gammacells, deltacells; char **recs; PGconn *psql; AttributeInfo *head_alpha, *head_beta, *head_gamma, *head_delta; AttributeInfo *tail_alpha, *tail_beta, *tail_gamma, *tail_delta; AttributeInfo **alpha, **beta, **gamma, **delta; head_alpha = NULL; head_beta = NULL; head_gamma = NULL; head_delta = NULL; tail_alpha = NULL; tail_beta = NULL; tail_gamma = NULL; tail_delta = NULL; // Storing our parameters. total = atoi(argv[1]); nalpha = atoi(argv[2]); nbeta = atoi(argv[3]); ngamma = atoi(argv[4]); ndelta = atoi(argv[5]); // Establish thresholds for our RNG. tdelta = 100 - ndelta; tgamma = tdelta - ngamma; tbeta = tgamma - nbeta; talpha = 0; if (nalpha+nbeta+ngamma+ndelta != 100) { printf("The values for alpha, beta, gamma and delta need to be integers that sum to 100.\n"); exit(0); } // Seeding our RNG. srand(time(NULL)); // We start off by getting a recommender list. recs = recommenderList(&numrecs); printf("Numrecs: %d\n",numrecs); /* Connect to the database. */ psql = PQconnectdb("host = 'localhost' port = '5432' dbname = 'recathon'"); if (PQstatus(psql) != CONNECTION_OK) printf("bad conn\n"); printf("%s, %s, %s, %s, %s\n",PQdb(psql), PQuser(psql), PQpass(psql), PQhost(psql), PQport(psql)); if (psql == NULL) printf("connection failed\n"); // Next, we need to query the index of each recommender, to get the attribute information and // cell types. for (i = 0; i < numrecs; i++) { char *querystring, *celltype; PGresult *query; int rows, cols; AttributeInfo *newatt; querystring = (char*) malloc(1024*sizeof(char)); // Since we don't know all of the attributes, we need to request everything. sprintf(querystring,"select * from %sindex;",recs[i]); query = PQexec(psql,querystring); rows = PQntuples(query); cols = PQnfields(query); // A new AttributeInfo for each row. for (j = 0; j < rows; j++) { // Get query information. Cell type is attribute #8. Recommender-specific // attributes begin at #13. newatt = (AttributeInfo*) malloc(sizeof(AttributeInfo)); newatt->next = NULL; newatt->recname = (char*) malloc(128*sizeof(char)); sprintf(newatt->recname,"%s",recs[i]); newatt->numatts = cols - 12; newatt->attnames = (char**) malloc(newatt->numatts*sizeof(char*)); for (k = 0; k < newatt->numatts; k++) newatt->attnames[k] = (char*) malloc(64*sizeof(char)); newatt->attvalues = (char**) malloc(newatt->numatts*sizeof(char*)); for (k = 0; k < newatt->numatts; k++) newatt->attvalues[k] = (char*) malloc(64*sizeof(char)); celltype = PQgetvalue(query,j,7); if (strcmp(celltype,"Alpha") == 0) newatt->celltype = CELL_ALPHA; else if (strcmp(celltype,"Beta") == 0) newatt->celltype = CELL_BETA; else if (strcmp(celltype,"Gamma") == 0) newatt->celltype = CELL_GAMMA; else newatt->celltype = CELL_DELTA; // Get column information. for (k = 0; k < cols-12; k++) { sprintf(newatt->attnames[k],"%s",PQfname(query,k+12)); sprintf(newatt->attvalues[k],"%s",PQgetvalue(query,j,k+12)); } // With the item complete, we put it into the appropriate bucket. switch (newatt->celltype) { case CELL_ALPHA: if (!head_alpha) { head_alpha = newatt; tail_alpha = newatt; } else { tail_alpha->next = newatt; tail_alpha = newatt; } break; case CELL_BETA: if (!head_beta) { head_beta = newatt; tail_beta = newatt; } else { tail_beta->next = newatt; tail_beta = newatt; } break; case CELL_GAMMA: if (!head_gamma) { head_gamma = newatt; tail_gamma = newatt; } else { tail_gamma->next = newatt; tail_gamma = newatt; } break; default: if (!head_delta) { head_delta = newatt; tail_delta = newatt; } else { tail_delta->next = newatt; tail_delta = newatt; } break; } } PQclear(query); free(querystring); } // For easy randomization, we should flatten our AttributeInfo lists. alpha = flatten(head_alpha, &alphacells); beta = flatten(head_beta, &betacells); gamma = flatten(head_gamma, &gammacells); delta = flatten(head_delta, &deltacells); // DEBUG: loop through the lists of alpha/beta/gamma/delta cells and print info. if (DEBUG) { printf("--- ALPHA CELLS ---\n"); printCellList(alpha, alphacells); printf("--- BETA CELLS ---\n"); printCellList(beta, betacells); printf("--- GAMMA CELLS ---\n"); printCellList(gamma, gammacells); printf("--- DELTA CELLS ---\n"); printCellList(delta, deltacells); } // One more thing we need to do is obtain a list of users that will work for // each AttributeInfo. We can semi-randomize by sorting based on zip code. addUsers(alpha, alphacells, psql); addUsers(beta, betacells, psql); addUsers(gamma, gammacells, psql); addUsers(delta, deltacells, psql); // Now to issue the given number of queries, with the frequencies established // probabilistically. for (i = 0; i < total; i++) { int randnum, randatt, randuser, userid; recathon_cell celltype; bool valid = false; PGresult *workquery; char *qstring; AttributeInfo *queryatt; // It's possible one of our buckets will have nothing in it, so // we need to continue choosing until we get something valid. while (!valid) { // A RNG chooses which kind of cell we work with. randnum = rand() % 100; if (randnum < tbeta) { if (alphacells > 0) { valid = true; celltype = CELL_ALPHA; } } else if (randnum < tgamma) { if (betacells > 0) { valid = true; celltype = CELL_BETA; } } else if (randnum < tdelta) { if (gammacells > 0) { valid = true; celltype = CELL_GAMMA; } } else { if (deltacells > 0) { valid = true; celltype = CELL_DELTA; } } } // Depending on our cell type, we'll have a different set of possible // queries to issue; we can choose from the alpha, beta, gamma or delta // buckets. Which item we get is also random. switch (celltype) { case CELL_ALPHA: randatt = rand() % alphacells; queryatt = alpha[randatt]; break; case CELL_BETA: randatt = rand() % betacells; queryatt = beta[randatt]; break; case CELL_GAMMA: randatt = rand() % gammacells; queryatt = gamma[randatt]; break; default: randatt = rand() % deltacells; queryatt = delta[randatt]; break; } randuser = rand() % 10; userid = queryatt->valid_users[randuser]; qstring = (char*) malloc(1024*sizeof(char)); sprintf(qstring,"select itemid from %s recommend(10) userid=%d",queryatt->recname,userid); if (queryatt->numatts > 0) { strncat(qstring," and ",5); for (j = 0; j < queryatt->numatts; j++) { char addition[128]; sprintf(addition,"%s = '%s' ", queryatt->attnames[j],queryatt->attvalues[j]); strncat(qstring,addition,strlen(addition)); if (j+1 < queryatt->numatts) strncat(qstring,"and ",5); } } strncat(qstring,";",1); workquery = PQexec(psql,qstring); PQclear(workquery); free(qstring); } PQfinish(psql); }