129 lines
3.9 KiB
C++
129 lines
3.9 KiB
C++
#include "MySQLWrapper.h"
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <set>
|
|
#include <cstdlib>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
#include <fstream>
|
|
using namespace std;
|
|
|
|
#include "local_db_account.h"
|
|
#include "util.hpp"
|
|
|
|
int main()
|
|
{
|
|
/// 3.3 大数据岗位需求量前十个
|
|
|
|
MySQLConn conn;
|
|
conn.connect("127.0.0.1",db_user,db_passwd,"bigdata3",3306);
|
|
cout<<"Connected to DB"<<endl;
|
|
conn.exec("set names gbk",nullptr);
|
|
|
|
auto fn1=[](map<string,vector<int>>& mp)
|
|
{
|
|
for(auto iter=mp.begin(); iter!=mp.end(); )
|
|
{
|
|
bool updated=false;
|
|
for(auto xiter=mp.begin(); xiter!=iter; )
|
|
{
|
|
if(iter->first.find(xiter->first)!=string::npos)
|
|
{
|
|
/// Found something?
|
|
/// targetvec.push_back(thisvec) : Add current vector to the previous vector.
|
|
xiter->second.insert(xiter->second.end(),
|
|
iter->second.begin(),iter->second.end());
|
|
|
|
|
|
/// iter should now be deleted. Get next iter first
|
|
auto nowiter=iter;
|
|
++iter;
|
|
mp.erase(nowiter);
|
|
|
|
/// Stop internal loop.
|
|
updated=true;
|
|
break;
|
|
}
|
|
else ++xiter;
|
|
}
|
|
|
|
if(!updated) ++iter;
|
|
}
|
|
|
|
for(auto& pr:mp)
|
|
{
|
|
int sum=0;
|
|
int n=pr.second.size();
|
|
for(int i=0; i<n; i++)
|
|
{
|
|
sum+=pr.second[i];
|
|
}
|
|
pr.second[0]=sum;
|
|
}
|
|
|
|
};
|
|
|
|
/// title, vector<int>
|
|
map<string,vector<int>> dmp;
|
|
|
|
conn.exec("use bigdata3",nullptr);
|
|
conn.exec("select title,count(*) as want_num from lagou_job where ((title like '%大数据%' ) or ( tags like '%大数据%')) group by title order by want_num desc",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string title(val[0]);
|
|
int cc=ParseInt(val[1]);
|
|
dmp[Trim(title)].push_back(cc);
|
|
});
|
|
});
|
|
|
|
conn.exec("use bigdata5",nullptr);
|
|
conn.exec("select title,count(*) as want_num from pages where ((title like '%大数据%' ) or ( tags like '%大数据%')) group by title order by want_num desc",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string city(val[0]);
|
|
int cc=ParseInt(val[1]);
|
|
dmp[Trim(city)].push_back(cc);
|
|
});
|
|
});
|
|
|
|
conn.exec("use bigdata2",nullptr);
|
|
conn.exec("select title,count(*) as want_num from pages where ( title like '%大数据%' ) group by title order by want_num desc",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string city(val[0]);
|
|
int cc=ParseInt(val[1]);
|
|
dmp[Trim(city)].push_back(cc);
|
|
});
|
|
});
|
|
|
|
fn1(dmp);
|
|
|
|
vector<pair<string,int>> vec;
|
|
for(const auto& pr:dmp)
|
|
{
|
|
vec.push_back(make_pair(pr.first,pr.second[0]));
|
|
}
|
|
sort(vec.begin(),vec.end(),[](const pair<string,int>& a,const pair<string,int>& b)
|
|
{
|
|
return a.second > b.second;
|
|
});
|
|
|
|
ofstream ofs("result/3.3.csv");
|
|
#define cout ofs
|
|
cout<<"岗位名称,需求量"<<endl;
|
|
int szLoop=min(10u,vec.size());
|
|
for(int i=0;i<szLoop;i++)
|
|
{
|
|
cout<<vec[i].first<<","<<vec[i].second<<endl;
|
|
}
|
|
#undef cout
|
|
|
|
return 0;
|
|
}
|