项目总结(一)
程序员文章站
2022-03-05 08:09:23
...
1.List<int> to string[]
List<int> recommendSubjectCodes = GetRecommendSubjectListByResult(result, provinceCode);
string[] ids = Array.ConvertAll(recommendSubjectCodes.ToArray(), new Converter<int, string>(a => Convert.ToString(a)));
2.平均分:
raiInfo.avgScore = Math.Round((raiInfo.interest + raiInfo.ability) / 2, 2);
3.委托:
List<Func<ResultAnalyseInfo, bool>> quadrantCalcFuncList = new List<Func<ResultAnalyseInfo, bool>>
{
(p)=> p.interest >= 3 && p.ability >= 3, //第一象限
(p)=> p.interest >= 3 && p.ability < 3, //第二象限
(p)=> p.interest < 3 && p.ability >=3 //第四象限
};
public List<string> CalcQuadrantList(List<ResultAnalyseInfo> subjectList, string firstSubject, int needKemuCount, List<Func<ResultAnalyseInfo, bool>> funcList)
{
var resultSubjects = new List<string>();
foreach (var func in funcList)
{
var quadrantSubjects = new List<string>();
List<ResultAnalyseInfo> quadrantList = subjectList.Where(item => func(item)).ToList();
if (quadrantList.Any() && quadrantList.Count <= needKemuCount)
quadrantSubjects.AddRange(quadrantList.Select(p => p.name).ToList());
if (quadrantList.Count > needKemuCount)
{
//开始相同得分优先级算法
quadrantSubjects.AddRange(SortOverSubjects(quadrantList, firstSubject, needKemuCount));
}
needKemuCount = needKemuCount - quadrantSubjects.Count;
resultSubjects.AddRange(quadrantSubjects);
if (needKemuCount <= 0) break;
}
return resultSubjects;
}
上一篇: Linux shell编程学习笔记(一)
下一篇: PHP 二维数组根据某个字段排序