This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues/pull-requests.
BigDataProject/3.1.cpp

132 lines
4.4 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.1 计算机专业薪水最高的前10名招聘职位+岗位需求量
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);
vector<vector<string>> keywords
{
{ "Web程序设计", "Web程序开发" , "Web开发", "Web程序", "Web" }, /// WEB应用程序设计
{ "可视化程序设计", "可视化程序", "软件开发", "界面设计" , "人机交互", "交互" }, /// 可视化(软件)
{ "数据库管理", "DBA", "数据库开发", "数据库", "MySQL", "SQL Server", "SQL" }, /// 数据库
{ "多媒体应用", "Media", "多媒体开发", "视频", "音频", "播放器" }, /// 多媒体应用
{ "移动应用", "Android", "iOS", "安卓", "苹果", "移动客户端", "嵌入式" , "移动" }, /// 移动应用开发
{ "软件测试", "测试" }, /// 软件测试
{ "物流信息", "物流管理", "物流" }, /// 物流信息&物流管理
{ "计算机游戏开发", "游戏开发", "游戏设计", "Steam", "任天堂", "Nintendo", "PC游戏", "游戏客户端", "网页游戏" }, /// 游戏开发
{ "计算机图形学" , "计算机图形", "计算机图像", "人脸识别", "人脸", "识别" , "OpenCV" }, /// 计算机图形学
{ "网络管理", "网络系统管理", "网络调试", "网管" }, /// 网络管理
{ "物联网", "IoT" }, /// 物联
};
int szParts=keywords.size();
vector<vector<cash_pack>> cashvec(szParts);
for(int i=0;i<szParts;i++)
{
int szAlias=keywords[i].size();
for(int j=0;j<szAlias;j++)
{
ostringstream ostr;
ostr<<"select salary from lagou_job where ((title like '%"
<<keywords[i][j]<<"%') or (tags like '%"
<<keywords[i][j]<<"%')) ";
string sqlcmd=ostr.str();
conn.exec("use bigdata3",nullptr);
conn.exec(sqlcmd,[&](MySQLResult& res)
{
res.stepRow([&](char** val,unsigned long* len)
{
cashvec[i].push_back(ParseCash(val[0]));
});
});
ostr.str("");
ostr<<"select salary from pages where ((title like '%"
<<keywords[i][j]<<"%') or (tags like '%"
<<keywords[i][j]<<"%')) ";
sqlcmd=ostr.str();
conn.exec("use bigdata5",nullptr);
conn.exec(sqlcmd,[&](MySQLResult& res)
{
res.stepRow([&](char** val,unsigned long* len)
{
cashvec[i].push_back(ParseCashX(val[0]));
});
});
ostr.str("");
ostr<<"select salary from pages where title like '%"<<keywords[i][j]<<"%' ";
sqlcmd=ostr.str();
conn.exec("use bigdata2",nullptr);
conn.exec(sqlcmd,[&](MySQLResult& res)
{
res.stepRow([&](char** val,unsigned long* len)
{
cashvec[i].push_back(ParseCashX(val[0]));
});
});
}
}
/// pair<Index of cashvec,Average of salary>
vector<pair<int,int>> tvec;
for(int i=0;i<szParts;i++)
{
int sum=0;
for(const auto& ky:cashvec[i])
{
sum+=ky.ave();
}
int sz=cashvec[i].size();
sum/=sz;
tvec.push_back(make_pair(i,sum));
}
sort(tvec.begin(),tvec.end(),[](const pair<int,int>& a,const pair<int,int>& b)
{
return a.second > b.second ;
});
ofstream ofs("result/3.1.csv");
#define cout ofs
cout<<"岗位,平均薪水,需求量"<<endl;
int szLoop=min(10,szParts);
for(int i=0;i<szLoop;i++)
{
cout<<keywords[tvec[i].first][0]<<","<<tvec[i].second<<","<<cashvec[tvec[i].first].size()<<endl;
}
#undef cout
return 0;
}