Add Support For All Value Querying.
This commit is contained in:
parent
49ef7423a6
commit
b9250a7ed1
59
main.cpp
59
main.cpp
@ -15,7 +15,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
double parseValue(string Filename)
|
||||
int parseValue(string Filename,double& val,double& val2)
|
||||
{
|
||||
printf("Filename : %s\n",Filename.c_str());
|
||||
|
||||
@ -27,23 +27,48 @@ double parseValue(string Filename)
|
||||
|
||||
string target="amt";
|
||||
string::size_type ans=s.find(target);
|
||||
printf("Found in ... %u\n",ans);
|
||||
printf("Found value 1 in ... %u\n",ans);
|
||||
if(ans==string::npos)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
istringstream istr(s.substr(ans+7));
|
||||
double a=-1;
|
||||
istr>>a;
|
||||
return a;
|
||||
|
||||
ans=s.find(target,ans+target.size());
|
||||
printf("Found value 2 in ... %u\n",ans);
|
||||
if(ans==string::npos)
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
|
||||
double LocalParse(int id)
|
||||
istr.str(s.substr(ans+7));
|
||||
double b=-1;
|
||||
istr>>b;
|
||||
|
||||
val=a;
|
||||
val2=b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cashinfo
|
||||
{
|
||||
cashinfo(bool Status=false,double Current=0,double TransForming=0):status(Status),current(Current),transforming(TransForming){}
|
||||
bool status;
|
||||
double current;
|
||||
double transforming;
|
||||
};
|
||||
|
||||
cashinfo LocalParse(int id)
|
||||
{
|
||||
char buff[1024];
|
||||
sprintf(buff,"data/%d.txt",id);
|
||||
string Filename(buff);
|
||||
return parseValue(Filename);
|
||||
cashinfo info;
|
||||
info.status=(parseValue(Filename,info.current,info.transforming)==0);
|
||||
return info;
|
||||
}
|
||||
|
||||
void prepareCookie()
|
||||
@ -93,8 +118,10 @@ void RemoteQuery(string PreCode,int ID)
|
||||
this_thread::sleep_for(chrono::seconds(rand()%3+1));
|
||||
}
|
||||
|
||||
#define HEAD_STR "15080901"
|
||||
#define NUM 40
|
||||
#define HEAD_STR "15080801"
|
||||
#define NUM 5
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -115,14 +142,14 @@ int main()
|
||||
}
|
||||
|
||||
printf("查询完成,开始解析...\n");
|
||||
vector<double> vec;
|
||||
vector<cashinfo> vec;
|
||||
queue<pair<int,int>> needrefetch;
|
||||
|
||||
for(int i=0;i<NUM;i++)
|
||||
{
|
||||
printf("解析第 %d of %d\n",i+1,NUM);
|
||||
double val=LocalParse(i+1);
|
||||
if(val==-2)
|
||||
cashinfo val=LocalParse(i+1);
|
||||
if(!val.status)
|
||||
{
|
||||
needrefetch.push(make_pair(i+1,0));
|
||||
}
|
||||
@ -145,8 +172,8 @@ int main()
|
||||
int id=pack.first;
|
||||
printf("重新获取ID: %d\n",id);
|
||||
RemoteQuery(HEAD_STR,id);
|
||||
double val=LocalParse(id);
|
||||
if(val==-2)
|
||||
cashinfo val=LocalParse(id);
|
||||
if(!val.status)
|
||||
{
|
||||
printf("重新获取ID: %d 失败.\n",id);
|
||||
|
||||
@ -171,14 +198,16 @@ int main()
|
||||
getline(cin,fname);
|
||||
s_time now=whattime();
|
||||
char gpbuff[1024];
|
||||
sprintf(gpbuff,"%04d%02d%02d%02d%02d%02d",now.year,now.mon,now.day,now.hour,now.min,now.sec);
|
||||
fname+=".txt";
|
||||
sprintf(gpbuff,"-%04d%02d%02d-%02d%02d%02d",now.year,now.mon,now.day,now.hour,now.min,now.sec);
|
||||
fname.append(gpbuff);
|
||||
fname.append(".txt");
|
||||
printf("正在保存到 %s\n",fname.c_str());
|
||||
|
||||
ofstream ofs(fname);
|
||||
for(size_t i=0;i<vec.size();i++)
|
||||
{
|
||||
ofs<<i+1<<" "<<vec.at(i)<<endl;
|
||||
if(vec.at(i).status) ofs<<i+1<<" "<<vec.at(i).current<<" "<<vec.at(i).transforming<<endl;
|
||||
else ofs<<i+1<<" -1 -1"<<endl;
|
||||
}
|
||||
ofs.flush();
|
||||
|
||||
|
Reference in New Issue
Block a user