97 lines
3.2 KiB
C++
97 lines
3.2 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.4 企业对哪类大数据人才需求最为迫切
|
|
|
|
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);
|
|
|
|
map<string,int> mp;
|
|
conn.exec("select title,count(*) from lagou_job where ((title like '%大数据%') or (tags like '%大数据%')) group by title",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string title(val[0]);
|
|
mp[Trim(title)]=ParseInt(val[1]);
|
|
});
|
|
});
|
|
|
|
conn.exec("use bigdata5",nullptr);
|
|
conn.exec("select title,count(*) from pages where ((title like '%大数据%') or (tags like '%大数据%')) group by title",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string title(val[0]);
|
|
auto iter=mp.find(Trim(title));
|
|
if(iter!=mp.end())
|
|
{
|
|
iter->second += ParseInt(val[1]);
|
|
}
|
|
else
|
|
{
|
|
mp.insert(make_pair(Trim(title),ParseInt(val[1])));
|
|
}
|
|
});
|
|
});
|
|
|
|
conn.exec("use bigdata2",nullptr);
|
|
conn.exec("select title,count(*) from pages where title like '%大数据%' group by title",[&](MySQLResult& res)
|
|
{
|
|
res.stepRow([&](char** val,unsigned long* len)
|
|
{
|
|
string title(val[0]);
|
|
auto iter=mp.find(Trim(title));
|
|
if(iter!=mp.end())
|
|
{
|
|
iter->second += ParseInt(val[1]);
|
|
}
|
|
else
|
|
{
|
|
mp.insert(make_pair(Trim(title),ParseInt(val[1])));
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
vector<pair<string,int>> vec;
|
|
for(const auto& pr:mp)
|
|
{
|
|
vec.push_back(pr);
|
|
}
|
|
|
|
sort(vec.begin(),vec.end(),[&](const pair<string,int>& a,const pair<string,int>& b)
|
|
{
|
|
return a.second > b.second;
|
|
});
|
|
|
|
ofstream ofs("result/3.4.csv");
|
|
#define cout ofs
|
|
cout<<"职位,需求量"<<endl;
|
|
int szVec=vec.size();
|
|
int maxLoop=min(szVec,10);
|
|
for(int i=0;i<maxLoop;i++)
|
|
{
|
|
cout<<vec[i].first<<","<<vec[i].second<<endl;
|
|
}
|
|
#undef cout
|
|
|
|
return 0;
|
|
}
|