agent-backend/contracts/AppDataSource/AppDataSource.yjs
2021-09-26 12:49:24 +08:00

1503 lines
56 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import "naiveDAC/naiveDAC.yjs"
@LogType("Arg")
contract AppDataSource {
function onCreate(){
initDAC(requester);
}
function queryDB(db) {
db = JSON.parse(db);
var conn = YancloudUtil.getMysqlConnection(db["ip"], db["user"], db["passwd"]);
if (conn != undefined && !conn.isClosed()) {
print("successfully connected");
}
else return null;
var sql = "select * from " + db["dbname"] + "." + db["formname"];
var statement = conn.createStatement();
var resultSet = statement.executeQuery(sql);
var resultList = [];
var meta = resultSet.getMetaData();
for (; resultSet.next();) {
var line = {
};
for (var j = 1; j <= meta.getColumnCount(); j++) {
line[meta.getColumnName(j)] = resultSet.getString(j);
}
resultList.push(line);
}
return resultList;
}
function queryElemeProvider(arg) {
if (!checkPermission(requester)){
return "access denied";
}
var ret = JSON.parse(executeContract("ElemeProvider", "queryDB", arg));
if (ret.status == "Success") {
return JSON.parse(ret.result);
}
else return null;
}
export function connectDBAndQuery(args) {
if (!checkPermission(requester)){
return "access denied";
}
//{"action":"connectDBAndQuery", "arg":"{\"type\":\"takeout\",\"detail\":\"overall\",\"district\":\"海淀\"}"}
args = JSON.parse(args);
if (args["type"] == "takeout") {
print("takeout");
if (this.waimailist_waimai == null) {
this.waimailist_waimai = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"newele\",\"formname\":\"data\"}",requester);
if (this.waimailist_waimai == null) {
print("failed");
return null;
}
}
var waimailist = (this.waimailist_waimai);
if (this.districtDict_waimai == null) {
var districtDict = {
};
var pattern = /朝阳|西城|丰台|海淀|密云|东城|昌平|怀柔|大兴|通州|房山|石景山|平谷|顺义|延庆|门头沟/g;
for (var i = 0; i < waimailist.length; i++) {
var addr = waimailist[i]["address"];
addr = addr.replace("北京", "");
addr = addr.replace("市", "");
var district = addr.match(pattern);
if (district == null)
continue;
district = district[0];
if (district.length > 5)
continue;
if (districtDict[district] == null)
districtDict[district] = [];
var item = {
}
if (waimailist[i]["avgPrice"] == null)
continue;
var avgPrice = waimailist[i]["avgPrice"].replace("¥", "").replace("/人", "");
avgPrice = parseInt(avgPrice);
if (waimailist[i]["monthlySalesNum"] == null)
continue;
item["orderNum"] = parseInt(waimailist[i]["monthlySalesNum"]);
item["saleNum"] = item["orderNum"] * avgPrice;
if (item["saleNum"] == null || item["orderNum"] == null)
continue;
if (!(item["saleNum"] > 0 && item["saleNum"] <= 500000))
continue;
if (waimailist[i]["overallRating"] == null)
continue;
item["score"] = waimailist[i]["overallRating"];
item["shopName"] = waimailist[i]["shopName"];
item["categories"] = waimailist[i]["categories"];
item["address"] = waimailist[i]["address"];
districtDict[district].push(item);
}
this.districtDict_waimai = districtDict;
}
districtDict = this.districtDict_waimai;
if (args["detail"] == "overall") {
var fig1 = [];
var dictkeys = Object.keys(districtDict);
for (var j = 0; j < dictkeys.length; j++) {
var key = dictkeys[j];
var item = {
}
var name = key + "区";
if (key == "延庆" || key == "密云")
name = key + "县";
item["name"] = name;
item["value"] = [];
item["value"].push(districtDict[key].length);
var wholeOrder = 0;
var wholeSale = 0;
for (var i = 0; i < districtDict[key].length; i++) {
if (districtDict[key][i]["orderNum"] == null || districtDict[key][i]["saleNum"] == null)
continue;
wholeOrder += districtDict[key][i]["orderNum"];
wholeSale += districtDict[key][i]["saleNum"];
}
item["value"].push(wholeOrder);
item["value"].push(wholeSale);
fig1.push(item);
}
var fig2 = [];
var cateDict = {
};
if (args["district"] == "") {
for (var i = 0; i < waimailist.length; i++) {
if (waimailist[i]["categories"] == null)
continue;
var category = waimailist[i]["categories"].split("/")[0];
if (cateDict[category] == null)
cateDict[category] = 0;
cateDict[category] += 1;
}
}
else {
args["district"] = args["district"].replace("区", "").replace("县", "");
for (var i = 0; i < districtDict[args["district"]].length; i++) {
if (districtDict[args["district"]][i]["categories"] == null)
continue;
var category = districtDict[args["district"]][i]["categories"].split("/")[0];
if (cateDict[category] == null)
cateDict[category] = 0;
cateDict[category] += 1;
}
}
var cateDictKeys = Object.keys(cateDict);
for (var j = 0; j < cateDictKeys.length; j++) {
var key = cateDictKeys[j];
var item = {
};
item["name"] = key;
item["value"] = cateDict[key];
fig2.push(item);
}
var fig3 = {
};
var desc2 = function (x, y) {
return (x["val"] < y["val"]) ? 1 : -1;
}
var shopList = [];
var dictKeys = Object.keys(districtDict);
if (args["district"] == "") {
for (var j = 0; j < dictKeys.length; j++) {
var key = dictKeys[j];
var districtItem = districtDict[key];
for (var i = 0; i < districtItem.length; i++) {
var item = {
};
item["name"] = districtItem[i]["shopName"];
item["val"] = districtItem[i]["saleNum"];
shopList.push(item);
}
}
}
else {
var districtItem = districtDict[args["district"]];
for (var i = 0; i < districtItem.length; i++) {
var item = {
};
item["name"] = districtItem[i]["shopName"];
item["val"] = districtItem[i]["saleNum"];
shopList.push(item);
}
}
shopList.sort(desc2);
var lineData = [];
var nameData = [];
for (var i = 14; i >= 0; i--) {
lineData.push(shopList[i]["val"]);
nameData.push(shopList[i]["name"]);
}
fig3["lineData"] = lineData;
fig3["nameData"] = nameData;
var ret = {
};
ret["fig1"] = fig1;
ret["fig2"] = fig2;
ret["fig3"] = fig3;
ret["district"] = args["district"];
return JSON.stringify(ret);
}
else if (args["detail"] == "rating") {
if (this.districtRateDict == null) {
var connRate = YancloudUtil.getMysqlConnection("39.106.6.6:3306", "loushuai", "loushuai");
if (connRate != undefined && !connRate.isClosed()) {
print("successfully connected");
}
else return "connect failed";
var sqlRate = "select * from newele.catering";
var statementRate = connRate.createStatement();
var resultSet_rate = statementRate.executeQuery(sqlRate);
var rateshoplist = [];
var meta_rate = resultSet_rate.getMetaData();
for (; resultSet_rate.next();) {
var line = {
};
for (var j = 1; j <= meta_rate.getColumnCount(); j++) {
line[meta_rate.getColumnName(j)] = resultSet_rate.getString(j);
}
rateshoplist.push(line);
}
var addrDict = {
};
var pattern_addr = /([^区]{1,})区/g;
for (var i = 0; i < rateshoplist.length; i++) {
var addr = rateshoplist[i]["address"].replace(pattern_addr, "");
addrDict[addr] = rateshoplist[i]["quantization_level"];
}
this.districtRateDict = {
};
var dictkeys = Object.keys(districtDict);
for (var i = 0; i < dictkeys.length; i++) {
districtRateDict[dictkeys[i]] = [];
var districtItem = districtDict[dictkeys[i]];
for (var j = 0; j < districtItem.length; j++) {
var addr = districtItem[j]["address"];
addr = addr.replace(pattern_addr, "");
if (addrDict[addr] != null) {
var item = districtItem[j];
item["rate"] = addrDict[addr];
districtRateDict[dictkeys[i]].push(item);
}
}
}
}
var dictkeys = Object.keys(districtDict);
var fig1 = [];
for (var i = 0; i < dictkeys.length; i++) {
var key = dictkeys[i];
var item = {
}
var name = key + "区";
if (key == "延庆" || key == "密云")
name = key + "县";
item["name"] = name;
item["value"] = [];
item["value"].push(districtRateDict[key].length);
var a = 0;
var b = 0;
var c = 0;
for (var j = 0; j < districtRateDict[key].length; j++) {
var shopItem = districtRateDict[key][j];
if (shopItem["rate"].search("A") >= 0)
a += 1;
if (shopItem["rate"].search("B") >= 0)
b += 1;
if (shopItem["rate"].search("C") >= 0)
c += 1;
}
item["value"].push(a);
item["value"].push(b);
item["value"].push(c);
fig1.push(item);
}
var fig2 = [];
var rateOrderDict = {
"A1": [],
"A2": [],
"A3": [],
"B1": [],
"B2": [],
"B3": [],
"C1": [],
"C2": [],
"C3": []
};
var rateSaleDict = {
"A1": [],
"A2": [],
"A3": [],
"B1": [],
"B2": [],
"B3": [],
"C1": [],
"C2": [],
"C3": []
};
var districtList = [];
if (args["district"] == "") {
districtList = Object.keys(districtRateDict);
}
else {
args["district"] = args["district"].replace("区", "").replace("县", "");
districtList.push(args["district"]);
}
for (var i = 0; i < districtList.length; i++) {
for (var j = 0; j < districtRateDict[districtList[i]].length; j++) {
var shopItem = districtRateDict[districtList[i]][j];
if (rateOrderDict[shopItem["rate"]] == null)
continue;
if (rateSaleDict[shopItem["rate"]] == null)
continue;
rateOrderDict[shopItem["rate"]].push(shopItem["orderNum"]);
rateSaleDict[shopItem["rate"]].push(shopItem["saleNum"]);
}
}
var rateList = Object.keys(rateOrderDict);
for (var i = 0; i < rateList.length; i++) {
var item = {
};
item["name"] = rateList[i];
item["value"] = rateOrderDict[rateList[i]];
fig2.push(item);
}
var fig3 = []
for (var i = 0; i < rateList.length; i++) {
var item = {
};
item["name"] = rateList[i];
item["value"] = rateSaleDict[rateList[i]];
fig3.push(item);
}
var fig4 = {
};
var pie1_shop = {
"A1": 0, "A2": 0, "A3": 0, "B1": 0, "B2": 0, "B3": 0, "C1": 0, "C2": 0, "C3": 0};
var pie1_order = {
"A1": 0, "A2": 0, "A3": 0, "B1": 0, "B2": 0, "B3": 0, "C1": 0, "C2": 0, "C3": 0};
var pie1_sale = {
"A1": 0, "A2": 0, "A3": 0, "B1": 0, "B2": 0, "B3": 0, "C1": 0, "C2": 0, "C3": 0};
for (var i = 0; i < districtList.length; i++) {
for (var j = 0; j < districtRateDict[districtList[i]].length; j++) {
var shopItem = districtRateDict[districtList[i]][j];
pie1_shop[shopItem["rate"]] += 1;
pie1_order[shopItem["rate"]] += shopItem["orderNum"];
pie1_sale[shopItem["rate"]] += shopItem["saleNum"];
}
}
fig4["shopNum_9"] = [];
fig4["orderNum_9"] = [];
fig4["saleNum_9"] = [];
for (var i = 0; i < rateList.length; i++) {
fig4["shopNum_9"].push({
"name": rateList[i], "value": pie1_shop[rateList[i]]}
);
fig4["orderNum_9"].push({
"name": rateList[i], "value": pie1_order[rateList[i]]}
);
fig4["saleNum_9"].push({
"name": rateList[i], "value": pie1_sale[rateList[i]]}
);
}
fig4["shopNum_3"] = [];
fig4["orderNum_3"] = [];
fig4["saleNum_3"] = [];
var nameList = ["A", "B", "C"];
for (var i = 0; i < 3; i++) {
var itemShop = {
"name": nameList[i]};
var itemOrder = {
"name": nameList[i]};
var itemSale = {
"name": nameList[i]};
itemShop["value"] = fig4["shopNum_9"][i * 3]["value"] + fig4["shopNum_9"][i * 3 + 1]["value"] + fig4["shopNum_9"][i * 3 + 2]["value"];
itemOrder["value"] = fig4["orderNum_9"][i * 3]["value"] + fig4["orderNum_9"][i * 3 + 1]["value"] + fig4["orderNum_9"][i * 3 + 2]["value"];
itemSale["value"] = fig4["saleNum_9"][i * 3]["value"] + fig4["saleNum_9"][i * 3 + 1]["value"] + fig4["saleNum_9"][i * 3 + 2]["value"];
fig4["shopNum_3"].push(itemShop);
fig4["orderNum_3"].push(itemOrder);
fig4["saleNum_3"].push(itemSale);
}
var ret = {
};
ret["fig1"] = fig1;
ret["fig2"] = fig2;
ret["fig3"] = fig3;
ret["fig4"] = fig4;
ret["district"] = args["district"];
return JSON.stringify(ret);
}
}
}
export function connectDBAndQueryTianjin(args) {
//{"action":"connectDBAndQueryTianjin", "arg":"{\"type\":\"takeout\",\"detail\":\"overall\",\"district\":\"南开\"}"}
args = JSON.parse(args);
if (args["type"] == "takeout") {
if (this.waimailist_tianjin == null) {
this.waimailist_tianjin = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"tianjin\",\"formname\":\"match_ele\"}");
if (this.waimailist_waimai == null) return null;
}
var waimailist = this.waimailist_tianjin;
if (this.districtDict_waimai_tianjin == null) {
var districtDict = {
};
var pattern = /和平|河西|河东|河北|红桥|南开|滨海新/g;
var pattern_addr = /([^区]{1,})区/g;
var score_pattern = /([^]{1,})/g;
for (var i = 0; i < waimailist.length; i++) {
var addr = waimailist[i]["address"];
addr = addr.replace("天津", "");
addr = addr.replace("市", "");
var district = addr.match(pattern);
if (district == null)
continue;
district = district[0];
if (district.length > 5)
continue;
if (districtDict[district] == null)
districtDict[district] = [];
var item = {
}
if (waimailist[i]["agentFee"] == null)
continue;
var avgPrice = waimailist[i]["agentFee"];
avgPrice = parseFloat(avgPrice);
if (waimailist[i]["monthlySalesNum"] == null)
continue;
item["orderNum"] = parseInt(waimailist[i]["monthlySalesNum"]);
item["saleNum"] = item["orderNum"] * avgPrice;
if (item["saleNum"] == null || item["orderNum"] == null)
continue;
if (!(item["saleNum"] > 0 && item["saleNum"] <= 5000000))
continue;
if (waimailist[i]["overallRating"] == null)
continue;
item["score"] = waimailist[i]["overallRating"];
item["shopName"] = waimailist[i]["shopName"];
item["address"] = waimailist[i]["address"].replace(pattern_addr, "");
;
item["rate"] = waimailist[i]["score"].replace(score_pattern, "")
districtDict[district].push(item);
}
this.districtDict_waimai_tianjin = districtDict;
}
districtDict = this.districtDict_waimai_tianjin;
// 获取天津市互联网餐饮活跃地图数据
var dictkeys = Object.keys(districtDict);
// fig1 获取天津市互联网餐饮活跃地图数据
var fig1 = [];
// 两个循环用于获取每一个区的优良中差数据
for (var i = 0; i < dictkeys.length; i++) {
var key = dictkeys[i];
var item = {
};
var name = key + "区";
item["name"] = name;
item["value"] = {
"all": districtDict[key].length, "优秀": 0, "良好": 0, "一般": 0, "不合格": 0};
item["unqualified_shop_list"] = [];
for (var j = 0; j < districtDict[key].length; j++) {
var shopItem = districtDict[key][j];
if (shopItem["rate"].search("一般") >= 0)
item["value"]["一般"] += 1;
if (shopItem["rate"].search("良好") >= 0)
item["value"]["良好"] += 1;
if (shopItem["rate"].search("不合格") >= 0){
item["value"]["不合格"] += 1;
var shop_unqualified = {
};
shop_unqualified["shopName"] = shopItem["shopName"];
shop_unqualified["address"] = shopItem["address"];
shop_unqualified["score"] = shopItem["score"];
item["unqualified_shop_list"].push(shop_unqualified);
}
if (shopItem["rate"].search("优秀") >= 0)
item["value"]["优秀"] += 1;
}
fig1.push(item);
}
var fig2 = [];
var rateOrderDict = {
"优秀": [], "良好": [], "一般": [], "不合格": []};
var rateSaleDict = {
"优秀": [], "良好": [], "一般": [], "不合格": []};
var districtList = [];
if (args["district"] == "") {
districtList = Object.keys(districtDict);
}
else {
args["district"] = args["district"].replace("区", "").replace("县", "");
districtList.push(args["district"]);
}
for (var i = 0; i < districtList.length; i++) {
for (var j = 0; j < districtDict[districtList[i]].length; j++) {
var shopItem = districtDict[districtList[i]][j];
if (rateOrderDict[shopItem["rate"]] == null)
continue;
if (rateSaleDict[shopItem["rate"]] == null)
continue;
rateOrderDict[shopItem["rate"]].push(shopItem["orderNum"]);
rateSaleDict[shopItem["rate"]].push(shopItem["saleNum"]);
}
}
var rateList = Object.keys(rateOrderDict);
for (var i = 0; i < rateList.length; i++) {
var item = {
};
item["name"] = rateList[i];
item["value"] = rateOrderDict[rateList[i]];
fig2.push(item);
}
var fig3 = []
for (var i = 0; i < rateList.length; i++) {
var item = {
};
item["name"] = rateList[i];
item["value"] = rateSaleDict[rateList[i]];
fig3.push(item);
}
var fig4 = {
};
var pie1_shop = {
"优秀": 0, "良好": 0, "一般": 0, "不合格": 0};
var pie1_order = {
"优秀": 0, "良好": 0, "一般": 0, "不合格": 0};
var pie1_sale = {
"优秀": 0, "良好": 0, "一般": 0, "不合格": 0};
for (var i = 0; i < districtList.length; i++) {
for (var j = 0; j < districtDict[districtList[i]].length; j++) {
var shopItem = districtDict[districtList[i]][j];
pie1_shop[shopItem["rate"]] += 1;
pie1_order[shopItem["rate"]] += shopItem["orderNum"];
pie1_sale[shopItem["rate"]] += shopItem["saleNum"];
}
}
fig4["shopNum"] = [];
fig4["orderNum"] = [];
fig4["saleNum"] = [];
for (var i = 0; i < rateList.length; i++) {
fig4["shopNum"].push({
"name": rateList[i], "value": pie1_shop[rateList[i]]}
);
fig4["orderNum"].push({
"name": rateList[i], "value": pie1_order[rateList[i]]}
);
fig4["saleNum"].push({
"name": rateList[i], "value": pie1_sale[rateList[i]]}
);
}
var fig5 = [];
var dictkeys = Object.keys(districtDict);
for (var j = 0; j < dictkeys.length; j++) {
var key = dictkeys[j];
var item = {
}
var name = key + "区";
item["name"] = name;
item["value"] = [];
item["value"].push(districtDict[key].length);
var wholeOrder = 0;
var wholeSale = 0;
for (var i = 0; i < districtDict[key].length; i++) {
if (districtDict[key][i]["orderNum"] == null || districtDict[key][i]["saleNum"] == null)
continue;
wholeOrder += districtDict[key][i]["orderNum"];
wholeSale += districtDict[key][i]["saleNum"];
}
item["value"].push(wholeOrder);
item["value"].push(wholeSale);
fig5.push(item);
}
var ret = {
};
ret["fig1"] = fig1;
ret["fig2"] = fig2;
ret["fig3"] = fig3;
ret["fig4"] = fig4;
ret["fig5"] = fig5;
ret["district"] = args["district"];
return JSON.stringify(ret);
}
else return null;
}
export function connectDBAndQueryHouse(args) {
args = JSON.parse(args);
if (args["type"] == "house") {
if (this.ret_ershou != null && this.ret_ershou[args["district"]] != null)
return JSON.stringify(this.ret_ershou[args["district"]]);
if (this.districtDict_ershou == null || this.houselist_ershou == null) {
var houselist = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"HouseSale\",\"formname\":\"ershoufang\"}");
var districtDict = {
};
var pattern = /朝阳|西城|丰台|海淀|密云|东城|昌平|怀柔|大兴|通州|房山|石景山|平谷|顺义|延庆|门头沟/g;
for (var i = 0; i < houselist.length; i++) {
var addr = houselist[i]["district"];
var district = addr.match(pattern);
if (district == null)
continue;
district = district[0];
if (district.length > 5)
continue;
if (districtDict[district] == null)
districtDict[district] = [];
var item = {
}
if (houselist[i]["unitPrice"] == null || houselist[i]["totalPrice"] == null)
continue;
if (houselist[i]["roomNum"] == null || houselist[i]["area"] == null)
continue;
var unitPrice = houselist[i]["unitPrice"].replace("元", "").replace("/平", "");
unitPrice = parseInt(unitPrice);
var totalPrice = houselist[i]["totalPrice"].replace("万", "");
totalPrice = parseInt(totalPrice);
houselist[i]["totalPrice"] = totalPrice;
houselist[i]["unitPrice"] = unitPrice;
item["unitPrice"] = unitPrice;
item["totalPrice"] = totalPrice;
item["roomNum"] = houselist[i]["roomNum"];
item["area"] = parseInt(houselist[i]["area"].replace("m²", ""));
houselist[i]["area"] = item["area"];
item["district"] = houselist[i]["district"];
item["bussiness"] = houselist[i]["bussiness"];
districtDict[district].push(item);
}
this.districtDict_ershou = districtDict;
this.houselist_ershou = houselist;
}
var districtDict = this.districtDict_ershou;
var houselist = this.houselist_ershou;
var districtkeys = Object.keys(districtDict);
var fig1 = [];
for (var j = 0; j < districtkeys.length; j++) {
var key = districtkeys[j];
var item = {
}
var name = key + "区";
if (key == "延庆" || key == "密云")
name = key + "县";
item["name"] = name;
item["value"] = {
};
item["value"]["num"] = districtDict[key].length;
var sumPrice = 0;
for (var i = 0; i < districtDict[key].length; i++) {
if (districtDict[key][i]["unitPrice"] >= 0 && districtDict[key][i]["unitPrice"] <= 10000000)
sumPrice += districtDict[key][i]["unitPrice"];
}
var avgPrice = sumPrice / districtDict[key].length;
item["value"]["avgPrice"] = avgPrice.toFixed(2);
fig1.push(item);
}
if (args["district"] != "" && districtDict[args["district"]] != null)
houselist = districtDict[args["district"]];
var fig2 = [];
var priceInterval = ["200万以下", "200-300万", "300-500万", "500-700万", "700-1000万", "1000万以上"];
var houseNum = [0, 0, 0, 0, 0, 0];
for (var i = 0; i < houselist.length; i++) {
if (houselist[i]["totalPrice"] < 200) {
houseNum[0] += 1;
}
if (houselist[i]["totalPrice"] >= 200 && houselist[i]["totalPrice"] < 300) {
houseNum[1] += 1;
}
if (houselist[i]["totalPrice"] >= 300 && houselist[i]["totalPrice"] < 500) {
houseNum[2] += 1;
}
if (houselist[i]["totalPrice"] >= 500 && houselist[i]["totalPrice"] < 700) {
houseNum[3] += 1;
}
if (houselist[i]["totalPrice"] >= 700 && houselist[i]["totalPrice"] < 1000) {
houseNum[4] += 1;
}
if (houselist[i]["totalPrice"] >= 1000) {
houseNum[5] += 1;
}
}
var cnt = 0;
for (var i = 0; i < 6; i++) {
var item = {
};
cnt += houseNum[i];
item["name"] = priceInterval[i];
item["value"] = cnt;
fig2.push(item);
}
var fig3 = [];
var areaNumDict = {
};
var areaPriceDict = {
};
for (var i = 0; i < houselist.length; i++) {
var area = houselist[i]["bussiness"];
if (areaNumDict[area] == null) {
areaNumDict[area] = 0;
areaPriceDict[area] = 0;
}
if (!(houselist[i]["unitPrice"] >= 0 && houselist[i]["unitPrice"] < 10000000))
continue;
areaNumDict[area] += 1;
areaPriceDict[area] += houselist[i]["unitPrice"];
}
var areaKeys = Object.keys(areaNumDict);
var tmpList = [];
var desc = function (x, y) {
return (x["value"] < y["value"]) ? 1 : -1;
}
for (var i = 0; i < areaKeys.length; i++) {
var item = {
"name": areaKeys[i]};
item["value"] = areaNumDict[areaKeys[i]];
if (item["value"] >= 0 && item["value"] < 10000000000)
tmpList.push(item);
}
tmpList.sort(desc);
var len = tmpList.length;
if (len > 50) len = 50;
for (var i = 0; i < len; i++) {
fig3.push(tmpList[i]);
}
var fig4 = [];
var roomTypeName = ["一居", "二居", "三居", "四居及以上"];
var areaSizeName = ["50m2以下", "50-80m2", "80-110m2", "110-150m2", "150m2以上"];
var unitPriceName = ["<1w", "1-2w", "2-3w", "3-4w", "4-5w", "5-6w", "6-7w", "7-8w", "8-9w", "9-10w", ">10w"];
var totalPriceName = ["200万以下", "200-300万", "300-500万", "500-700万", "700-1000万", "1000万以上"];
for (var k = 0; k < districtkeys.length; k++) {
var district = districtkeys[k];
var districtItem = {
"name": district};
districtItem["value"] = {
"roomType": [], "areaSize": [], "unitPrice": [], "totalPrice": []};
var roomTypeNum = [0, 0, 0, 0];
var areaSizeNum = [0, 0, 0, 0, 0];
var unitPriceNum = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var totalPriceNum = [0, 0, 0, 0, 0, 0];
for (var j = 0; j < districtDict[district].length; j++) {
var house = districtDict[district][j];
var flag = false;
if (house["roomNum"].match("1室") != null) {
roomTypeNum[0] += 1;
flag = true;
}
if (house["roomNum"].match("2室") != null) {
roomTypeNum[1] += 1;
flag = true;
}
if (house["roomNum"].match("3室") != null) {
roomTypeNum[2] += 1;
flag = true;
}
if (flag == false) {
roomTypeNum[3] += 1;
}
if (house["area"] < 50)
areaSizeNum[0] += 1;
if (house["area"] >= 50 && house["area"] < 80)
areaSizeNum[1] += 1;
if (house["area"] >= 80 && house["area"] < 110)
areaSizeNum[2] += 1;
if (house["area"] >= 110 && house["area"] < 150)
areaSizeNum[3] += 1;
if (house["area"] >= 150)
areaSizeNum[4] += 1;
var idx = parseInt(house["unitPrice"] / 10000);
if (idx > 10)
idx = 10;
unitPriceNum[idx] += 1;
if (house["totalPrice"] < 200)
totalPriceNum[0] += 1;
if (house["totalPrice"] >= 200 && house["totalPrice"] < 300)
totalPriceNum[1] += 1;
if (house["totalPrice"] >= 300 && house["totalPrice"] < 500)
totalPriceNum[2] += 1;
if (house["totalPrice"] >= 500 && house["totalPrice"] < 700)
totalPriceNum[3] += 1;
if (house["totalPrice"] >= 700 && house["totalPrice"] < 1000)
totalPriceNum[4] += 1;
if (house["totalPrice"] >= 100)
totalPriceNum[5] += 1;
}
for (var i = 0; i < 4; i++) {
var item = {
};
item["name"] = roomTypeName[i];
item["value"] = roomTypeNum[i];
districtItem["value"]["roomType"].push(item);
}
for (var i = 0; i < 5; i++) {
var item = {
};
item["name"] = areaSizeName[i];
item["value"] = areaSizeNum[i];
districtItem["value"]["areaSize"].push(item);
}
for (var i = 0; i < 11; i++) {
var item = {
};
item["name"] = unitPriceName[i];
item["value"] = unitPriceNum[i];
districtItem["value"]["unitPrice"].push(item);
}
for (var i = 0; i < 6; i++) {
var item = {
};
item["name"] = totalPriceName[i];
item["value"] = totalPriceNum[i];
districtItem["value"]["totalPrice"].push(item);
}
fig4.push(districtItem);
}
var ret = {
};
ret["fig1"] = fig1;
ret["fig2"] = fig2;
ret["fig3"] = fig3;
ret["fig4"] = fig4;
if (this.ret_ershou == null)
this.ret_ershou = {
}
if (this.ret_ershou[args["district"]] == null)
this.ret_ershou[args["district"]] = ret;
return JSON.stringify(ret);
}
else
return null;
}
export function connectDBAndQueryZufang(args) {
args = JSON.parse(args);
if (args["type"] == "zufang") {
if (this.ret_zufang != null && this.ret_zufang[args["district"]] != null) {
print("find!");
return JSON.stringify(this.ret_zufang[args["district"]]);
}
if (this.houselist_zufang == null || this.districtDict_zufang == null || this.bussinessDict_zufang == null) {
this.houselist_zufang = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"HouseSale\",\"formname\":\"zufang\"}")
var houselist = this.houselist_zufang;
var districtDict = {
};
var pattern = /朝阳|西城|丰台|海淀|密云|东城|昌平|怀柔|大兴|通州|房山|石景山|平谷|顺义|延庆|门头沟/g;
var bussinessDict2 = {
};
for (var i = 0; i < houselist.length; i++) {
var addr = houselist[i]["district"];
var district = addr.match(pattern);
if (district == null)
continue;
district = district[0];
if (district.length > 5)
continue;
if (districtDict[district] == null)
districtDict[district] = [];
if (bussinessDict2[district] == null)
bussinessDict2[district] = {
};
var buss = houselist[i]["bussiness"];
if (bussinessDict2[district][buss] == null)
bussinessDict2[district][buss] = [];
var item = {
}
if (houselist[i]["price"] == null || houselist[i]["area"] == null)
continue;
if (houselist[i]["roomNum"] == null)
continue;
var unitPrice = houselist[i]["price"].replace("元", "").replace("/月", "");
unitPrice = parseInt(unitPrice);
houselist[i]["price"] = unitPrice;
item["price"] = unitPrice;
item["roomNum"] = houselist[i]["roomNum"];
item["area"] = parseInt(houselist[i]["area"].replace("m²", ""));
houselist[i]["area"] = item["area"];
item["district"] = houselist[i]["district"];
item["bussiness"] = houselist[i]["bussiness"];
districtDict[district].push(item);
bussinessDict2[district][buss].push(item);
}
districtDict["延庆"] = [];
districtDict["怀柔"] = [];
districtDict["密云"] = [];
bussinessDict2["延庆"] = {
};
bussinessDict2["怀柔"] = {
};
bussinessDict2["密云"] = {
};
this.districtDict_zufang = districtDict;
var districtnames = Object.keys(districtDict);
var bussinessDict = {
};
for (var i = 0; i < districtnames.length; i++) {
var district = districtnames[i];
bussinessDict[district] = {
};
var desc = function (a, b) {
return (bussinessDict2[district][a].length < bussinessDict2[district][b].length) ? 1 : -1;
};
var bussnames = (Object.keys(bussinessDict2[district])).sort(desc);
var len = bussnames.length;
if (len > 20)
len = 20;
for (j = 0; j < len; j++) {
bussinessDict[district][bussnames[j]] = bussinessDict2[district][bussnames[j]];
}
}
this.bussinessDict_zufang = bussinessDict;
}
var houselist = this.houselist_zufang;
var districtDict = this.districtDict_zufang;
var bussinessDict = this.bussinessDict_zufang;
var districtkeys = Object.keys(districtDict);
var fig1 = [];
for (var j = 0; j < districtkeys.length; j++) {
var key = districtkeys[j];
var item = {
}
var name = key + "区";
if (key == "延庆" || key == "密云")
name = key + "县";
item["name"] = name;
item["value"] = {
};
item["value"]["num"] = districtDict[key].length;
var sumPrice = 0;
for (var i = 0; i < districtDict[key].length; i++) {
if (districtDict[key][i]["price"] >= 0 && districtDict[key][i]["price"] <= 10000000)
sumPrice += districtDict[key][i]["price"];
}
var avgPrice = 0;
if (districtDict[key].length > 0) {
avgPrice = sumPrice / districtDict[key].length;
}
item["value"]["avgPrice"] = avgPrice.toFixed(2);
fig1.push(item);
}
var houselist2 = houselist;
if (args["district"] != "" && districtDict[args["district"]] != null) {
houselist2 = districtDict[args["district"]];
}
var fig2 = [];
var priceInterval = ["<1500", "1500-2500", "2500-3500", "3500-5000", "5000-8000", "8000-10000", ">10000"];
var houseNum = [0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < houselist2.length; i++) {
if (houselist2[i]["price"] < 1500) {
houseNum[0] += 1;
}
if (houselist2[i]["price"] >= 1500 && houselist2[i]["price"] < 2500) {
houseNum[1] += 1;
}
if (houselist2[i]["price"] >= 2500 && houselist2[i]["price"] < 3500) {
houseNum[2] += 1;
}
if (houselist2[i]["price"] >= 3500 && houselist2[i]["price"] < 5000) {
houseNum[3] += 1;
}
if (houselist2[i]["price"] >= 5000 && houselist2[i]["price"] < 8000) {
houseNum[4] += 1;
}
if (houselist2[i]["price"] >= 8000 && houselist2[i]["price"] < 10000) {
houseNum[5] += 1;
}
if (houselist2[i]["price"] >= 10000) {
houseNum[6] += 1;
}
}
var cnt = 0;
for (var i = 0; i < priceInterval.length; i++) {
var item = {
};
cnt += houseNum[i];
item["name"] = priceInterval[i];
item["value"] = cnt;
fig2.push(item);
}
var districtDict2 = districtDict;
if (args["district"] != "" && districtDict[args["district"]] != null) {
districtDict2 = bussinessDict[args["district"]];
districtkeys = Object.keys(bussinessDict[args["district"]]);
}
var fig3 = [];
var tmpList = [];
var desc = function (x, y) {
return (x["value"] < y["value"]) ? 1 : -1;
}
for (var i = 0; i < districtkeys.length; i++) {
var item = {
"name": districtkeys[i]};
item["value"] = districtDict2[districtkeys[i]].length;
if (item["value"] >= 0 && item["value"] < 10000000000)
tmpList.push(item);
}
tmpList.sort(desc);
var len = tmpList.length;
if (len > 50) len = 50;
for (var i = 0; i < len; i++) {
fig3.push(tmpList[i]);
}
var fig4 = [];
var roomTypeName = ["一居", "二居", "三居", "四居及以上"];
var areaSizeName = ["20m2以下", "20-50m2", "50-80m2", "80-110m2", "110-150m2", "150m2以上"];
var priceName = ["<1500", "1500-2500", "2500-3500", "3500-5000", "5000-8000", "8000-10000", ">10000"];
for (var k = 0; k < districtkeys.length; k++) {
var district = districtkeys[k];
var districtItem = {
"name": district};
districtItem["value"] = {
"roomType": [], "areaSize": [], "price": []};
var roomTypeNum = [0, 0, 0, 0];
var areaSizeNum = [0, 0, 0, 0, 0, 0];
var priceNum = [0, 0, 0, 0, 0, 0, 0];
for (var j = 0; j < districtDict2[district].length; j++) {
var house = districtDict2[district][j];
var flag = false;
if (house["roomNum"].match("1室") != null) {
roomTypeNum[0] += 1;
flag = true;
}
if (house["roomNum"].match("2室") != null) {
roomTypeNum[1] += 1;
flag = true;
}
if (house["roomNum"].match("3室") != null) {
roomTypeNum[2] += 1;
flag = true;
}
if (flag == false) {
roomTypeNum[3] += 1;
}
if (house["area"] < 20)
areaSizeNum[0] += 1;
if (house["area"] >= 20 && house["area"] < 50)
areaSizeNum[1] += 1;
if (house["area"] >= 50 && house["area"] < 80)
areaSizeNum[2] += 1;
if (house["area"] >= 80 && house["area"] < 110)
areaSizeNum[3] += 1;
if (house["area"] >= 110 && house["area"] < 150)
areaSizeNum[4] += 1;
if (house["area"] >= 150)
areaSizeNum[5] += 1;
if (house["price"] < 1500)
priceNum[0] += 1;
if (house["price"] >= 1500 && house["price"] < 2500)
priceNum[1] += 1;
if (house["price"] >= 2500 && house["price"] < 3500)
priceNum[2] += 1;
if (house["price"] >= 3500 && house["price"] < 5000)
priceNum[3] += 1;
if (house["price"] >= 5000 && house["price"] < 8000)
priceNum[4] += 1;
if (house["price"] >= 8000 && house["price"] < 10000)
priceNum[5] += 1;
if (house["price"] >= 10000)
priceNum[6] += 1;
}
for (var i = 0; i < roomTypeName.length; i++) {
var item = {
};
item["name"] = roomTypeName[i];
item["value"] = roomTypeNum[i];
districtItem["value"]["roomType"].push(item);
}
for (var i = 0; i < areaSizeName.length; i++) {
var item = {
};
item["name"] = areaSizeName[i];
item["value"] = areaSizeNum[i];
districtItem["value"]["areaSize"].push(item);
}
for (var i = 0; i < priceNum.length; i++) {
var item = {
};
item["name"] = priceName[i];
item["value"] = priceNum[i];
districtItem["value"]["price"].push(item);
}
fig4.push(districtItem);
}
if (this.ret_zufang == null)
this.ret_zufang = {
};
var res = {
};
res["fig1"] = fig1;
res["fig2"] = fig2;
res["fig3"] = fig3;
res["fig4"] = fig4;
if (this.ret_zufang[args["district"]] == null)
this.ret_zufang[args["district"]] = res;
return JSON.stringify(res);
}
else
return null;
}
export function connectDBAndQueryChengjiao(args) {
args = JSON.parse(args);
if (args["type"] == "chengjiao") {
//TODO change!
if (this.ret_chengjiao != null && this.ret_chengjiao[args["district"]] != null) {
print("find!");
return JSON.stringify(this.ret_chengjiao[args["district"]]);
}
if (this.houselist_chengjiao == null || this.districtDict_chengjiao == null || this.bussinessDict_chengjiao == null) {
this.houselist_chengjiao = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"HouseSale\",\"formname\":\"chengjiao\"}")
var houselist = this.houselist_chengjiao;
var districtDict = {
};
var pattern = /朝阳|西城|丰台|海淀|密云|东城|昌平|怀柔|大兴|通州|房山|石景山|平谷|顺义|延庆|门头沟/g;
var bussinessDict2 = {
};
for (var i = 0; i < houselist.length; i++) {
var addr = houselist[i]["district"];
var district = addr.match(pattern);
if (district == null)
continue;
district = district[0];
if (district.length > 5)
continue;
if (districtDict[district] == null)
districtDict[district] = [];
if (bussinessDict2[district] == null)
bussinessDict2[district] = {
};
var buss = houselist[i]["bussiness"];
if (bussinessDict2[district][buss] == null)
bussinessDict2[district][buss] = [];
var item = {
}
if (houselist[i]["price"] == null || houselist[i]["area"] == null)
continue;
if (houselist[i]["roomNum"] == null)
continue;
var unitPrice = houselist[i]["price"].replace("挂牌", "").replace("万", "");
unitPrice = parseInt(unitPrice);
houselist[i]["price"] = unitPrice;
item["price"] = unitPrice;
item["roomNum"] = houselist[i]["roomNum"];
item["area"] = parseInt(houselist[i]["area"].replace("平米", ""));
houselist[i]["area"] = item["area"];
item["district"] = houselist[i]["district"];
item["bussiness"] = houselist[i]["bussiness"];
item["buildingAge"] = houselist[i]["buildingAge"].replace("塔结合", "").replace("年建板", "").replace("楼", "");
districtDict[district].push(item);
bussinessDict2[district][buss].push(item);
}
districtDict["延庆"] = [];
districtDict["怀柔"] = [];
bussinessDict2["延庆"] = {
};
bussinessDict2["怀柔"] = {
};
this.districtDict_chengjiao = districtDict;
var districtnames = Object.keys(districtDict);
var bussinessDict = {
};
for (var i = 0; i < districtnames.length; i++) {
var district = districtnames[i];
bussinessDict[district] = {
};
var desc = function (a, b) {
return (bussinessDict2[district][a].length < bussinessDict2[district][b].length) ? 1 : -1;
};
var bussnames = (Object.keys(bussinessDict2[district])).sort(desc);
var len = bussnames.length;
if (len > 20)
len = 20;
for (j = 0; j < len; j++) {
bussinessDict[district][bussnames[j]] = bussinessDict2[district][bussnames[j]];
}
}
this.bussinessDict_chengjiao = bussinessDict;
}
var houselist = this.houselist_chengjiao;
var districtDict = this.districtDict_chengjiao;
var bussinessDict = this.bussinessDict_chengjiao;
var districtkeys = Object.keys(districtDict);
var fig1 = [];
for (var j = 0; j < districtkeys.length; j++) {
var key = districtkeys[j];
var item = {
}
var name = key + "区";
if (key == "延庆" || key == "密云")
name = key + "县";
item["name"] = name;
item["value"] = {
};
item["value"]["num"] = districtDict[key].length;
var sumPrice = 0;
for (var i = 0; i < districtDict[key].length; i++) {
if (districtDict[key][i]["price"] >= 0 && districtDict[key][i]["price"] <= 10000000)
sumPrice += districtDict[key][i]["price"];
}
var avgPrice = 0;
if (districtDict[key].length > 0) {
avgPrice = sumPrice / districtDict[key].length;
}
item["value"]["avgPrice"] = avgPrice.toFixed(2);
fig1.push(item);
}
var houselist2 = houselist;
if (args["district"] != "" && districtDict[args["district"]] != null) {
houselist2 = districtDict[args["district"]];
}
var fig2 = [];
var priceInterval = ["<200w", "200-400w", "400-600w", "600-800w", "800-1000w", ">1000w"];
var houseNum = [0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < houselist2.length; i++) {
if (houselist2[i]["price"] < 200) {
houseNum[0] += 1;
}
if (houselist2[i]["price"] >= 200 && houselist2[i]["price"] < 400) {
houseNum[1] += 1;
}
if (houselist2[i]["price"] >= 400 && houselist2[i]["price"] < 600) {
houseNum[2] += 1;
}
if (houselist2[i]["price"] >= 600 && houselist2[i]["price"] < 800) {
houseNum[3] += 1;
}
if (houselist2[i]["price"] >= 800 && houselist2[i]["price"] < 1000) {
houseNum[4] += 1;
}
if (houselist2[i]["price"] >= 1000) {
houseNum[5] += 1;
}
}
var cnt = 0;
for (var i = 0; i < priceInterval.length; i++) {
var item = {
};
cnt += houseNum[i];
item["name"] = priceInterval[i];
item["value"] = cnt;
fig2.push(item);
}
var districtDict2 = districtDict;
if (args["district"] != "" && districtDict[args["district"]] != null) {
districtDict2 = bussinessDict[args["district"]];
districtkeys = Object.keys(bussinessDict[args["district"]]);
}
var fig3 = [];
var tmpList = [];
var desc = function (x, y) {
return (x["value"] < y["value"]) ? 1 : -1;
}
for (var i = 0; i < districtkeys.length; i++) {
var item = {
"name": districtkeys[i]};
item["value"] = districtDict2[districtkeys[i]].length;
if (item["value"] >= 0 && item["value"] < 10000000000)
tmpList.push(item);
}
tmpList.sort(desc);
var len = tmpList.length;
if (len > 50) len = 50;
for (var i = 0; i < len; i++) {
fig3.push(tmpList[i]);
}
var fig4 = [];
var roomTypeName = ["一居", "二居", "三居", "四居及以上"];
var areaSizeName = ["50m2以下", "50-80m2", "80-110m2", "110-150m2", "150-300m2", ">300m2"];
var priceName = ["<200w", "200-400w", "400-600w", "600-800w", "800-1000w", ">1000w"];
var yearName = ["<5年", "5-10年", "10-15年", "15-20年", "20-30年", ">30年"];
for (var k = 0; k < districtkeys.length; k++) {
var district = districtkeys[k];
var districtItem = {
"name": district};
districtItem["value"] = {
"roomType": [], "areaSize": [], "price": [], "age": []};
var roomTypeNum = [0, 0, 0, 0];
var areaSizeNum = [0, 0, 0, 0, 0, 0];
var priceNum = [0, 0, 0, 0, 0, 0];
var yearNum = [0, 0, 0, 0, 0, 0];
for (var j = 0; j < districtDict2[district].length; j++) {
var house = districtDict2[district][j];
var flag = false;
if (house["roomNum"].match("1室") != null) {
roomTypeNum[0] += 1;
flag = true;
}
if (house["roomNum"].match("2室") != null) {
roomTypeNum[1] += 1;
flag = true;
}
if (house["roomNum"].match("3室") != null) {
roomTypeNum[2] += 1;
flag = true;
}
if (flag == false) {
roomTypeNum[3] += 1;
}
if (house["area"] < 50)
areaSizeNum[0] += 1;
if (house["area"] >= 50 && house["area"] < 80)
areaSizeNum[1] += 1;
if (house["area"] >= 80 && house["area"] < 110)
areaSizeNum[2] += 1;
if (house["area"] >= 110 && house["area"] < 150)
areaSizeNum[3] += 1;
if (house["area"] >= 150 && house["area"] < 300)
areaSizeNum[4] += 1;
if (house["area"] >= 300)
areaSizeNum[5] += 1;
if (house["price"] < 200)
priceNum[0] += 1;
if (house["price"] >= 200 && house["price"] < 400)
priceNum[1] += 1;
if (house["price"] >= 400 && house["price"] < 800)
priceNum[2] += 1;
if (house["price"] >= 800 && house["price"] < 1000)
priceNum[3] += 1;
if (house["price"] >= 1000)
priceNum[4] += 1;
var age = 2019 - house["buildingAge"];
if (age < 5)
yearNum[0] += 1;
if (age >= 5 && age < 10)
yearNum[1] += 1;
if (age >= 10 && age < 15)
yearNum[2] += 1;
if (age >= 15 && age < 20)
yearNum[3] += 1;
if (age >= 20 && age < 30)
yearNum[4] += 1;
if (age >= 30)
yearNum[5] += 1;
}
for (var i = 0; i < roomTypeName.length; i++) {
var item = {
};
item["name"] = roomTypeName[i];
item["value"] = roomTypeNum[i];
districtItem["value"]["roomType"].push(item);
}
for (var i = 0; i < areaSizeName.length; i++) {
var item = {
};
item["name"] = areaSizeName[i];
item["value"] = areaSizeNum[i];
districtItem["value"]["areaSize"].push(item);
}
for (var i = 0; i < priceNum.length; i++) {
var item = {
};
item["name"] = priceName[i];
item["value"] = priceNum[i];
districtItem["value"]["price"].push(item);
}
for (var i = 0; i < yearNum.length; i++) {
var item = {
};
item["name"] = yearName[i];
item["value"] = yearNum[i];
districtItem["value"]["age"].push(item);
}
fig4.push(districtItem);
}
if (this.ret_chengjiao == null)
this.ret_chengjiao = {
};
var res = {
};
res["fig1"] = fig1;
res["fig2"] = fig2;
res["fig3"] = fig3;
res["fig4"] = fig4;
if (this.ret_chengjiao[args["district"]] == null)
this.ret_chengjiao[args["district"]] = res;
return JSON.stringify(res);
}
else
return null;
}
export function connectDBAndQueryNeimeng(args) {
//{"action":"connectDBAndQueryNeimeng", "arg":"{\"type\":\"takeout\",\"detail\":\"overall\"}"}
args = JSON.parse(args);
if (args["type"] == "takeout") {
if (this.waimailist_xlgl == null) {
var init_data = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"xlglm\",\"formname\":\"meituanwaimai\"}");
var waimailist = [];
for (var i = 0; i < init_data.length; i++) {
if (init_data[i]["avgPrice"] == null || init_data[i]["monthlySalesNum"] == null)
continue;
var price = parseInt(init_data[i]["avgPrice"].replace("人均 ¥", ""));
var saleNum = parseInt(init_data[i]["monthlySalesNum"].replace("月售", ""));
var sale = price * saleNum;
var item = init_data[i];
if (sale >= 0 && sale < 500000000000) {
item["sale"] = sale;
waimailist.push(item);
}
}
this.waimailist_xlgl = waimailist;
if (this.waimailist_xlgl == null) return null;
}
if (this.areadict_xlgl == null) {
var arealist = queryDB("{\"ip\":\"39.106.6.6:3306\",\"user\":\"loushuai\",\"passwd\":\"loushuai\",\"dbname\":\"xlglm\",\"formname\":\"meituan\"}");
var areaDict = {
};
for (var i = 0; i < arealist.length; i++) {
var area = arealist[i]["areaName"];
if (area == null)
continue;
if (areaDict[area] == null) {
areaDict[area] = [];
}
areaDict[area].push(arealist[i]);
}
this.areadict_xlgl = areaDict;
}
var waimailist = this.waimailist_xlgl;
var fig1 = [];
var cateDict = {
};
for (var i = 0; i < waimailist.length; i++) {
if (waimailist[i]["categories"] == null)
continue;
var category = waimailist[i]["categories"].split("/")[0];
if (cateDict[category] == null)
cateDict[category] = 0;
cateDict[category] += 1;
}
var cateDictKeys = Object.keys(cateDict);
for (var j = 0; j < cateDictKeys.length; j++) {
var key = cateDictKeys[j];
var item = {
};
item["name"] = key;
item["value"] = cateDict[key];
fig1.push(item);
}
var fig2 = {
};
var desc2 = function (x, y) {
return (x["val"] < y["val"]) ? 1 : -1;
}
var shopList = [];
for (var j = 0; j < waimailist.length; j++) {
var item = {
};
item["name"] = waimailist[j]["shopName"];
item["val"] = waimailist[j]["sale"];
shopList.push(item);
}
shopList.sort(desc2);
var lineData = [];
var nameData = [];
for (var i = 14; i >= 0; i--) {
lineData.push(shopList[i]["val"]);
nameData.push(shopList[i]["name"]);
}
fig2["lineData"] = lineData;
fig2["nameData"] = nameData;
var fig3 = [];
var areaDict = this.areadict_xlgl;
var areaKeys = Object.keys(areaDict);
for (var i = 0; i < areaKeys.length; i++) {
var item = {
};
item["area"] = areaKeys[i];
item["shopNum"] = areaDict[areaKeys[i]].length;
var sum = 0;
for (var j = 0; j < item["shopNum"]; j++) {
var price = parseInt(areaDict[areaKeys[i]][j]["avgPrice"]);
if (price >= 0 && price < 50000000) {
sum += price;
}
}
if (sum == 0)
continue;
item["saleNum"] = sum * 79;
fig3.push(item);
}
var fig4 = {
};
var desc2 = function (x, y) {
return (x["val"] < y["val"]) ? 1 : -1;
}
var shopList = [];
for (var j = 0; j < waimailist.length; j++) {
var item = {
};
item["name"] = waimailist[j]["shopName"];
item["val"] = parseFloat(waimailist[j]["overallRating"]);
shopList.push(item);
}
shopList.sort(desc2);
var lineData = [];
var nameData = [];
for (var i = 14; i >= 0; i--) {
lineData.push(shopList[i]["val"]);
nameData.push(shopList[i]["name"]);
}
fig4["lineData"] = lineData;
fig4["nameData"] = nameData;
var ret = {
};
ret["fig1"] = fig1;
ret["fig2"] = fig2;
ret["fig3"] = fig3;
ret["fig4"] = fig4;
return JSON.stringify(ret);
}
else return null;
}
}