一、需求描述:如下图,目前有ABC三个维度的评分,每个维度有10个得分区间,客户评分落在1-4区间则等级为E,落在5—8区间则等级为D,落在9-10区间则等级为C,C为对称轴,B和D对称,A和E对称。
说明:E和A形成立体三角,D和B形成立体菱形,C为中轴。
二、分层分析:以C维为垂直线,AB形成平面,从上往下切割为10层,依次形成10层平面,分别列出10层得分,最后基于10层评分写代码。
第一层:只有EDC
第二层:EDC均向左上角缩进一步
第三层:EDC均继续向左上角缩进一步,此时右下角B已出现。
第四层:EDCB均继续向左上角缩进一步,此时左上角剩1个E,右下角B已出现3个。
第五层:EDCB均继续向左上角缩进一步,此时左上角E消失。
第六层:DCB均继续向左上角缩进一步。
第七层:DCB均继续向左上角缩进一步,此时右下角A出现。
第八层:DCBA均继续向左上角缩进一步。
第九层:DCBA均继续向左上角缩进一步,此时D消失。
第十层:CBA均继续向左上角缩进一步。
三、构建矩阵代码
var scoreA = 445;
var scoreB = 500;
var scoreC = 666;
var scoreLevel = 'C';
if(scoreA==null || scoreA=='' || scoreB==null || scoreB=='' || scoreC==null || scoreC==''){
return 'C';
}
if(300<=scoreC && scoreC<=565){//第一层(以scoreC为垂直线,形成scoreA x scoreB平面)
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=705){//4E
scoreLevel = 'E';
}else if(705<scoreA && scoreA<=817){//4D
scoreLevel = 'D';
}else if(817<scoreA && scoreA<=1000){//2C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=678){//3E
scoreLevel = 'E';
}else if(678<scoreA && scoreA<=773){//4D
scoreLevel = 'D';
}else if(773<scoreA && scoreA<=1000){//3C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=637){//2E
scoreLevel = 'E';
}else if(637<scoreA && scoreA<=753){//4D
scoreLevel = 'D';
}else if(753<scoreA && scoreA<=1000){//4C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=570){//1E
scoreLevel = 'E';
}else if(570<scoreA && scoreA<=737){//4D
scoreLevel = 'D';
}else if(737<scoreA && scoreA<=1000){//5C
scoreLevel = 'C';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=705){//4D
scoreLevel = 'D';
}else if(705<scoreA && scoreA<=1000){//6C
scoreLevel = 'C';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(759<scoreB && scoreB<=900){//第九、十排
scoreLevel = 'C';
}
}else if(565<scoreC && scoreC<=585){//第二层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=678){//3E
scoreLevel = 'E';
}else if(678<scoreA && scoreA<=773){//4D
scoreLevel = 'D';
}else if(773<scoreA && scoreA<=1000){//3C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=637){//2E
scoreLevel = 'E';
}else if(637<scoreA && scoreA<=753){//4D
scoreLevel = 'D';
}else if(753<scoreA && scoreA<=1000){//4C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=570){//1E
scoreLevel = 'E';
}else if(570<scoreA && scoreA<=737){//4D
scoreLevel = 'D';
}else if(737<scoreA && scoreA<=1000){//5C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=705){//4D
scoreLevel = 'D';
}else if(705<scoreA && scoreA<=1000){//6C
scoreLevel = 'C';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(713<scoreB && scoreB<=900){//第八、九、十排
scoreLevel = 'C';
}
}else if(585<scoreC && scoreC<=598){//第三层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=637){//2E
scoreLevel = 'E';
}else if(637<scoreA && scoreA<=753){//4D
scoreLevel = 'D';
}else if(753<scoreA && scoreA<=1000){//4C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=570){//1E
scoreLevel = 'E';
}else if(570<scoreA && scoreA<=737){//4D
scoreLevel = 'D';
}else if(737<scoreA && scoreA<=1000){//5C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=705){//4D
scoreLevel = 'D';
}else if(705<scoreA && scoreA<=1000){//6C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(687<scoreB && scoreB<=816){//第七、八、九排
scoreLevel = 'C';
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=861){//9D
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}
}else if(598<scoreC && scoreC<=609){//第四层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=570){//1E
scoreLevel = 'E';
}else if(570<scoreA && scoreA<=737){//4D
scoreLevel = 'D';
}else if(737<scoreA && scoreA<=1000){//5C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=705){//4D
scoreLevel = 'D';
}else if(705<scoreA && scoreA<=1000){//6C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(657<scoreB && scoreB<=759){//第六、七、八排
scoreLevel = 'C';
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}
}else if(609<scoreC && scoreC<=617){//第五层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=705){//4D
scoreLevel = 'D';
}else if(705<scoreA && scoreA<=1000){//6C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(630<scoreB && scoreB<=713){//第五、六、七排
scoreLevel = 'C';
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}
}else if(617<scoreC && scoreC<=626){//第六层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=678){//3D
scoreLevel = 'D';
}else if(678<scoreA && scoreA<=1000){//7C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=596){//第三排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(596<scoreB && scoreB<=687){//第四、五、六排
scoreLevel = 'C';
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=753){//6C
scoreLevel = 'C';
}else if(753<scoreA && scoreA<=1000){//4B
scoreLevel = 'B';
}
}
}else if(626<scoreC && scoreC<=635){//第七层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=637){//2D
scoreLevel = 'D';
}else if(637<scoreA && scoreA<=1000){//8C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=551){//第二排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(551<scoreB && scoreB<=657){//第三、四、五排
scoreLevel = 'C';
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=753){//6C
scoreLevel = 'C';
}else if(753<scoreA && scoreA<=1000){//4B
scoreLevel = 'B';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=737){//5C
scoreLevel = 'C';
}else if(737<scoreA && scoreA<=861){//4B
scoreLevel = 'B';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'A';
}
}
}else if(635<scoreC && scoreC<=646){//第八层
if(300<=scoreB && scoreB<=477){//第一排
if(300<=scoreA && scoreA<=570){//1D
scoreLevel = 'D';
}else if(570<scoreA && scoreA<=1000){//9C
scoreLevel = 'C';
}
}else if(477<scoreB && scoreB<=630){//第二、三、四排
scoreLevel = 'C';
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=753){//6C
scoreLevel = 'C';
}else if(753<scoreA && scoreA<=1000){//4B
scoreLevel = 'B';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=737){//5C
scoreLevel = 'C';
}else if(737<scoreA && scoreA<=861){//4B
scoreLevel = 'B';
}else if(861<scoreA && scoreA<=1000){//1A
scoreLevel = 'A';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=705){//4C
scoreLevel = 'C';
}else if(705<scoreA && scoreA<=817){//4B
scoreLevel = 'B';
}else if(817<scoreA && scoreA<=1000){//2A
scoreLevel = 'A';
}
}
}else if(646<scoreC && scoreC<=661){//第九层
if(300<=scoreB && scoreB<=596){//第一、二、三排
scoreLevel = 'C';
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=753){//6C
scoreLevel = 'C';
}else if(753<scoreA && scoreA<=1000){//4B
scoreLevel = 'B';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=737){//5C
scoreLevel = 'C';
}else if(737<scoreA && scoreA<=861){//4B
scoreLevel = 'B';
}else if(861<scoreA && scoreA<=1000){//1A
scoreLevel = 'A';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=705){//4C
scoreLevel = 'C';
}else if(705<scoreA && scoreA<=817){//4B
scoreLevel = 'B';
}else if(817<scoreA && scoreA<=1000){//2A
scoreLevel = 'A';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=678){//3C
scoreLevel = 'C';
}else if(678<scoreA && scoreA<=773){//4B
scoreLevel = 'B';
}else if(773<scoreA && scoreA<=1000){//3A
scoreLevel = 'A';
}
}
}else if(661<scoreC && scoreC<=900){//第十层
if(300<=scoreB && scoreB<=596){//第一、二、三排
scoreLevel = 'C';
}else if(596<scoreB && scoreB<=630){//第四排
if(300<=scoreA && scoreA<=861){//9C
scoreLevel = 'C';
}else if(861<scoreA && scoreA<=1000){//1B
scoreLevel = 'B';
}
}else if(630<scoreB && scoreB<=657){//第五排
if(300<=scoreA && scoreA<=817){//8C
scoreLevel = 'C';
}else if(817<scoreA && scoreA<=1000){//2B
scoreLevel = 'B';
}
}else if(657<scoreB && scoreB<=687){//第六排
if(300<=scoreA && scoreA<=773){//7C
scoreLevel = 'C';
}else if(773<scoreA && scoreA<=1000){//3B
scoreLevel = 'B';
}
}else if(687<scoreB && scoreB<=713){//第七排
if(300<=scoreA && scoreA<=753){//6C
scoreLevel = 'C';
}else if(753<scoreA && scoreA<=1000){//4B
scoreLevel = 'B';
}
}else if(713<scoreB && scoreB<=759){//第八排
if(300<=scoreA && scoreA<=737){//5C
scoreLevel = 'C';
}else if(737<scoreA && scoreA<=861){//4B
scoreLevel = 'B';
}else if(861<scoreA && scoreA<=1000){//1A
scoreLevel = 'A';
}
}else if(759<scoreB && scoreB<=816){//第九排
if(300<=scoreA && scoreA<=705){//4C
scoreLevel = 'C';
}else if(705<scoreA && scoreA<=817){//4B
scoreLevel = 'B';
}else if(817<scoreA && scoreA<=1000){//2A
scoreLevel = 'A';
}
}else if(816<scoreB && scoreB<=900){//第十排
if(300<=scoreA && scoreA<=678){//3C
scoreLevel = 'C';
}else if(678<scoreA && scoreA<=773){//4B
scoreLevel = 'B';
}else if(773<scoreA && scoreA<=1000){//3A
scoreLevel = 'A';
}
}
}
return scoreLevel;