cxgj/web/test.html
2023-11-27 09:45:13 +08:00

706 lines
23 KiB
HTML
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.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
var access_token = "TmEzb3VKekEzRnpFVm1ySGovaVU1ZlJ3WjB0TlloM0I0RmpkaGp0MDRSbz0=";
const color_arr = {
0:'#000000',// 默认颜色
1:'绿色',// 绿色
2:'黄色',// 黄色
3:'红色',// 红色
}
/*************************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ******************************** 最新数据和历史数据 ************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
* ***********************************************************************************************************
*/
var box_money = 20; // 包厢金额
var box_time = 2; // 包厢时长
var integral = 10; // 当前积分
var vip = 10; // vip折扣
var res_box_money = box_money*box_time;
var res_integral = 0;
if(integral > 0){
// 抵扣积分
res_box_money -= integral
if(res_box_money < 0){
// 如果小于0则当前抵扣积分为支付积分【抵扣一部分】
res_integral = res_box_money
res_box_money = 0;
}else{
// 如果大于0则当前抵扣积分为当前支付金额【全部抵扣】
res_integral = integral
}
}
if(res_box_money > 0){
// 计算出会员折扣后的所需支付金额
res_box_money -= res_box_money*(vip/100)
}
console.log("总抵扣积分:"+res_integral)
console.log("总需要支付金额:"+res_box_money)
console.log("总金额:"+(box_money*box_time))
$.ajax({
url:"http://sms.com/api/center/latest-data?access_token="+access_token+"&type=v1",
headers:{'x-csrf':'ag7x1Afy1r0q8j4y05vk3s4118hx7124'},
crossDomain: true,
success:function(res){
let data = analysis(res.data.data_info)
let temp_data = dataToAvg(data['res_data'])
// 计算出能力值为1的数据
let res_data = [];
console.log('data:',data)
console.log('temp_data:',temp_data)
data.field_data.reverse() // 需要倒序
res_data = getType1(data.field_data,temp_data.data)
console.log('能力数据:',res_data)
res_data = getType2(data.field_data,temp_data.data)
console.log('初始数据:',res_data)
res_data = getType3(data.field_data,temp_data.data)
console.log('转速数据:',res_data)
res_data = getType4(data.field_data,temp_data.data)
console.log('结果数据:',res_data)
res_data = getType5(data.field_data,temp_data.data)
console.log('升降数据:',res_data)
res_data = getType6(data.field_data,temp_data.data)
console.log('路径数据:',res_data)
res_data = getType7(data.field_data,temp_data.data)
console.log('齿轮数据:',res_data)
res_data = getType8(data.field_data,temp_data.data)
console.log('几何数据:',res_data)
res_data = getType9(data.field_data,temp_data.data)
console.log('偏离数据:',res_data)
return false
}
})
// 解析数据,划分每根球杆的击球数据
function analysis(data){
let field_data = [];
let res_data = {};
for(let i = 0;i<data.length;i++){
let temp_key = "";
let pole_type = "";
let pole_class = "";
pole_class = (data[i].pop()).value;
pole_type = (data[i].pop()).value;
temp_key = pole_type +"_"+ pole_class;
temp_key = md5(temp_key);
if(res_data[temp_key] == undefined && data[i].length != 0){
field_data.push({
'pole_type':pole_type, // 球杆类型
'pole_class':pole_class, // 球杆品种
'search_index':temp_key,// 搜索主键,使用这个键去查找最终击球数据的每根球杆数据
})
res_data[temp_key] = [];
}
res_data[temp_key].push(data[i]);
}
return {
'field_data':field_data,
'res_data':res_data,
}
}
// 每根球杆的击球数据转成平均值
function dataToAvg(data){
let avg_data = [];
let click_avg_show = {};
for(let key in data){
// key -- 球杆
// i -- 击球次数
// k -- 击球数据详细
avg_data[key] = {}
for(let i=0;i<data[key].length;i++){
for(let k=0;k<data[key][i].length;k++){
if(data[key][i][k] == undefined){
continue
}
if(avg_data[key][data[key][i][k].title] == undefined){
avg_data[key][data[key][i][k].title] = []
}
avg_data[key][data[key][i][k].title].push(data[key][i][k].value)
if(click_avg_show[md5(key+'_'+data[key][i][k].title)] == undefined){
click_avg_show[md5(key+'_'+data[key][i][k].title)] = [];
}
click_avg_show[md5(key+'_'+data[key][i][k].title)].push(data[key][i][k].value)
}
}
}
let res = {};
for(let k in avg_data){
res[k] = []
for(let k1 in avg_data[k]){
res[k].push({
'title':k1,
'value':(sum(avg_data[k][k1])/avg_data[k][k1].length).toFixed(2),
'show_index':md5(k+'_'+k1),
})
}
}
return {
'data':res,
'click_avg_show':click_avg_show,
};
}
// 获取字段数据
function getFieldValue(avg_temp,field=[]){
let temp_data = {};
let temp_field = {};
for(let i=0;i<field.length;i++){
temp_data[i] = 0;
temp_field[field[i]] = i;
}
for(let k=0;k<avg_temp.length;k++){
if(temp_field[avg_temp[k].title] !== undefined){
temp_data[temp_field[avg_temp[k].title]] = {data:parseFloat(avg_temp[k].value),color:color_arr[0]};
}
}
return temp_data
}
// 获取类型1的数据 -- 能力数据
const getType1 = function(field_data,avg_data){
let res = {
0:[],// 挥速
1:[],// 球速
2:[],// 效能
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Club Speed','Ball Speed']);
if(temp_data[1] !== 0){
temp_data[2] = {data:(temp_data[1].data/temp_data[0].data).toFixed(2),color:color_arr[0]};;
}
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
res[2].push(temp_data[2]);
}
for (let i=0;i<length;i++){
if(i+1 >= length){
break;
}
let num = res[2][i].data;
let num_ = res[2][i+1].data;
if(num > num_){
// 绿色
res[2][i].color = color_arr[1];
continue;
}
if(num === num_){
// 黄色
res[2][i].color = color_arr[2];
continue;
}
if(num < num_){
// 红色
res[2][i].color = color_arr[3];
}
}
return {
'data':res,
'title':field_,
'name':['挥速','球速','效能'],
}
}
// 获取类型2的数据 -- 初始数据
const getType2 = function(field_data,avg_data){
let res = {
0:[],// 初始角
1:[],// 起飞角
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Launch Direction','Launch Angle']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
}
for (let i=0;i<length;i++){
if(i+1 >= length){
break;
}
let num = res[1][i].data;
let num_ = res[1][i+1].data;
if(i<1){
continue;
}
if(num < num_){
// 绿色
res[1][i+1].color = color_arr[1];
continue;
}
if(num === num_){
// 黄色
res[1][i+1].color = color_arr[2];
continue;
}
if(num > num_){
// 红色
res[1][i+1].color = color_arr[3];
}
}
for (let i=0;i<length;i++){
let num = res[0][i].data;
if(num <= 2 && num >= -2){
// 绿色
res[0][i].color = color_arr[1];
continue;
}
if(num <= 3 && num >= -3){
// 黄色
res[0][i].color = color_arr[2];
continue;
}
// 红色
res[0][i].color = color_arr[3];
}
return {
'data':res,
'title':field_,
'name':['初始角','起飞角'],
}
}
// 获取类型3的数据 -- 旋转数据
const getType3 = function(field_data,avg_data){
let res = {
0:[],// 侧旋
1:[],// 后旋
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Side Spin','Back Spin']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
}
for (let i=0;i<length;i++){
if(i+1 >= length){
break;
}
if(i<1){
if(i === 0){
// 第一根杆子
let num = res[1][i].data;
if(num < 2400){
// 绿色
res[1][i].color = color_arr[1];
continue;
}
if(num < 2800){
// 黄色
res[1][i].color = color_arr[2];
continue;
}
// 红色
res[1][i].color = color_arr[3];
}
continue;
}
let num = res[1][i].data;
let num_ = res[1][i+1].data;
if(num < num_){
// 绿色
res[1][i+1].color = color_arr[1];
continue;
}
if(num === num_){
// 黄色
res[1][i+1].color = color_arr[2];
continue;
}
// 红色
res[1][i+1].color = color_arr[3];
}
for (let i=0;i<length;i++){
let num = res[0][i].data;
if(num < 200 && num > -200){
// 绿色
res[0][i].color = color_arr[1];
continue;
}
if(num <= 400 && num >= -400){
// 黄色
res[0][i].color = color_arr[2];
continue;
}
// 红色
res[0][i].color = color_arr[3];
}
return {
'data':res,
'title':field_,
'name':['侧旋','后旋'],
}
}
// 获取类型4的数据 -- 结果数据
const getType4 = function(field_data,avg_data){
let res = {
0:[],// 落点
1:[],// 总距离
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Carry','Total']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
}
for (let i=0;i<length;i++){
if(i+1 >= length){
break;
}
let num = res[0][i].data;
let num_ = res[0][i+1].data;
let res_num = num - num_;
if(res_num >= 10 && res_num <= 15){
// 绿色
res[0][i].color = color_arr[1];
continue;
}
if(res_num >= 5 && res_num <= 9){
// 黄色
res[0][i].color = color_arr[2];
continue;
}
// 红色
res[0][i].color = color_arr[3];
}
return {
'data':res,
'title':field_,
'name':['落点','总距离'],
}
}
// 获取类型5的数据 -- 升降数据
const getType5 = function(field_data,avg_data){
let res = {
0:[],// 攻击角
1:[],// 高度
2:[],// 下降角
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Angle of Attack','Peak Height','Descent Angle']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
res[2].push(temp_data[2]);
}
for (let i=0;i<length;i++){
if(i+1 >= length){
break;
}
if(i<1){
if(i === 0){
// 计算第一根杆子
let num = res[0][i].data;
if(num >= -3 && num <= 3){
// 绿色
res[0][i].color = color_arr[1];
continue;
}
if(num >= -5 && num <= 5){
// 黄色
res[0][i].color = color_arr[2];
continue;
}
// 红色
res[0][i].color = color_arr[3];
}
continue;
}
let num = res[0][i].data;
let num_ = res[0][i+1].data;
if(num_ < num){
// 绿色
res[0][i+1].color = color_arr[1];
continue;
}
if(num === num_){
// 黄色
res[0][i+1].color = color_arr[2];
continue;
}
if(num_ > num){
// 红色
res[0][i+1] = {data:num_,color:color_arr[3]};
}
}
return {
'data':res,
'title':field_,
'name':['攻击角','高度','下降角'],
}
}
// 获取类型6的数据 -- 路径数据
const getType6 = function(field_data,avg_data){
let res = {
0:[],// 路径
1:[],// 杆面路径
2:[],// 杆面目标
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Club Path','Face To Path','Face To Target']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
res[2].push(temp_data[2]);
};
for (let i=0;i<length;i++){
let num_1 = res[1][i].data;
let num_2 = res[2][i].data;
if(num_1 >= 0){
num_1 = true
}else{
num_1 = false
}
if(num_2 >= 0){
num_2 = true
}else{
num_2 = false
}
if(num_1 === num_2){
// 绿色
res[1][i].color = color_arr[1];
res[2][i].color = color_arr[1];
}else{
// 黄色
res[1][i].color = color_arr[2];
res[2][i].color = color_arr[2];
}
let num = res[0][i].data;
if(num < 3 && num > -3){
// 绿色
res[0][i].color = color_arr[1];
continue;
}
if(num <= 5 && num >= -5){
// 黄色
res[0][i].color = color_arr[2];
continue;
}
// 红色
res[0][i].color = color_arr[3];
}
return {
'data':res,
'title':field_,
'name':['路径','杆面路径','杆面目标'],
}
}
// 获取类型7的数据 -- 齿轮数据
const getType7 = function(field_data,avg_data){
let res = {
0:[],// 水平点
1:[],// 垂直点
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Horizontal Impact','Vertical Impact']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
}
let num_fun = function(num){ // 计算范围
if(num < 7 && num > -7){
// 绿色
return color_arr[1];
}
if(num <= 12 && num >= -12){
// 黄色
return color_arr[2];
}
// 红色
return color_arr[3];
};
for (let i=0;i<length;i++){
let num_1 = res[1][i].data;
let num = res[0][i].data;
res[0][i].color = num_fun(num);
res[1][i].color = num_fun(num_1);
}
return {
'data':res,
'title':field_,
'name':['水平点','垂直点'],
}
}
// 获取类型8的数据 -- 几何数据
const getType8 = function(field_data,avg_data){
let res = {
0:[],// 面倾角
1:[],// 水平角
2:[],// 杆面角
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Dynamic Loft','Lie Angle','F-Axis']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
res[2].push(temp_data[2]);
}
let num_fun_1 = function(num){ // 计算范围
if(num < 3 && num > -3){
// 绿色
return color_arr[1];
}
if(num <= 6 && num >= -6){
// 黄色
return color_arr[2];
}
// 红色
return color_arr[3];
};
let num_fun_2 = function(num){ // 计算范围
if(num < 5 && num > -5){
// 绿色
return color_arr[1];
}
if(num <= 10 && num >= -10){
// 黄色
return color_arr[2];
}
// 红色
return color_arr[3];
};
for (let i=0;i<length;i++){
let num_2 = res[2][i].data;
let num_1 = res[1][i].data;
res[2][i].color = num_fun_2(num_2);
res[1][i].color = num_fun_1(num_1);
}
return {
'data':res,
'title':field_,
'name':['面倾角','水平角','杆面角'],
}
}
// 获取类型9的数据 -- 偏离数据
const getType9 = function(field_data,avg_data){
let res = {
0:[],// 目标差
1:[],// 偏离
}
let length = field_data.length;
let field_ = [];
for (let i=0;i<length;i++){
// 获取平均值数值
let avg_temp = avg_data[field_data[i].search_index];
field_.push(field_data[i].pole_class);
let temp_data = getFieldValue(avg_temp,['Offline','Lie Angle']);
res[0].push(temp_data[0]);
res[1].push(temp_data[1]);
}
let num_fun_1 = function(num){ // 计算范围
if(num < 3 && num > -3){
// 绿色
return color_arr[1];
}
if(num <= 7 && num >= -7){
// 黄色
return color_arr[2];
}
// 红色
return color_arr[3];
};
for (let i=0;i<length;i++){
let num_1 = res[1][i].data;
res[1][i].color = num_fun_1(num_1);
}
return {
'data':res,
'title':field_,
'name':['目标差','偏离'],
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////// 公共方法 ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
// 求和
function sum(arr){
let sum = 0
for(let i=0;i<arr.length;i++){
if(arr[i] == '-'){
continue;
}
sum += arr[i]
}
return sum
}
// 符合现有的代码
function md5(str){
return btoa(str)
}
</script>
</body>
</html>