четверг, 21 мая 2009 г.

GOOGLE ANALYTICS MANAGER

#include <iostream>

#include <fstream>

#include <string>
#include <vector>
#include <time.h>
#include "rx.h"


using namespace std;



vector<string> topics;

randomx g(time(NULL));

int ind = 0;

double percents = 0;

vector<int> sequence;

int back_ind = 0;

void read_db()

{

ifstream f("Topics_Min.txt");

char buf[4096];

string t("");

int vsego_uvedoml = 0;
while (f.getline(buf, sizeof buf))

{

if (string(buf) == "===========================================================================\x0d")

{

topics.push_back(t);

vsego_uvedoml++;

if (vsego_uvedoml>12500)
break;
t = "";

continue;

}

t += buf;

t += "\n";

}

}

//---------------------------------------------------------------------------

void go_next()

{

back_ind++;

if (back_ind >= sequence.size())

{

int count = topics.size();

percents = 1;

ind = (int) (g.rand_n(count)*percents);

sequence.push_back(ind);

back_ind = sequence.size()-1;

} else {

ind = sequence[back_ind];

}

string t = topics[ind];
system("clear");

puts(t.c_str());
}


void go_prev()

{

if (sequence.size() == 0 || back_ind == 0)

return;

back_ind--;

ind = sequence[back_ind];

string t = topics[ind];

system("clear");

puts(t.c_str());
}

//---------------------------------------------------------------------------


void save_sequence()

{

char log_file_name[512];

int D = random();

sprintf(log_file_name, "%d", D);

ofstream f(log_file_name);

int topics_count = sequence.size();

for (int i = 0; i < topics_count; i++)

{

f << topics[sequence[i]];

f << endl;

f << "===========================================================================";

f << endl;

}

}

//---------------------------------------------------------------------------





void report()

{

string term1 = "Test";

if (term1.size() == 0)

return;

vector<string> terms;

string word("");

int i = 0;

while (i < term1.size())

{

while (isspace(term1[i]))

i++;

if (i == term1.size())

break;

word += term1[i];

i++;

if (isspace(term1[i]) || i == term1.size())

{

terms.push_back(word);

word = "";

}

}

if (terms.size() == 0)

return;

char log_file_name[512];

int D = random();

sprintf(log_file_name, "%d", D);

ofstream f(log_file_name);

f << "-- search terms used -----------------------------\n";

for (int j = 0; j < terms.size(); j++)

f << "\"" << terms[j] << "\", ";

f << "\n--------------------------------------------------\n";

for (int i = 0; i < topics.size(); i++)

{

bool all_matched = true;

for (int j = 0; j < terms.size(); j++)

all_matched = all_matched & (strstr(topics[i].c_str(), terms[j].c_str()) != NULL);

if (all_matched)

{

f << topics[i];

f << endl;

f << "===========================================================================";

f << endl;

}

}

}

//---------------------------------------------------------------------------



int main()

{
read_db();
while (true) go_next();

return 1;
}

Комментариев нет:

Отправить комментарий