不包括以前程序的价值评级

发布于 2025-02-10 18:11:28 字数 1401 浏览 2 评论 0原文

我有一个表格,该表显示申请人是否是某些计划的一部分,它将平均从以前的程序和当前程序中获得评级。一旦将申请人添加到新程序中,他们的评级为0,但是除非有人给他们的评级大于0,否则该评级将不包括在总体平均评级中,但是,如果将此人从当前程序中删除,并且然后稍后再次添加到同一程序中,然后将值0包括到整体评分。我不想那个,但是我一直在试图解决这个问题,即我的大脑都被扰乱了。我已经放置了使所有申请人都具有各自的程序,以前的程序和评级的代码。有什么帮助吗?我希望我有道理。

public async Task<T> GetAllApplicants()
        {
            // Other Code up here
            IList<T> participants = await GetAllParticipants();
            // applicants is being set somewhere else
            foreach (var applicant in applicants)
            {
                applicant.Programs = participants
                    .Where(p => p.Email.EqualsIgnoreCase(applicant.Email))
                    .Select(p => p.ProgramName)
                    .ToList();

                applicant.PreviousPrograms = participants
                    .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.IsPreviousParticipant)
                    .Select(p => p.ProgramName)
                    .ToList(p => p.ProgramName);

                applicant.AverageRating = participants
                      .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.Rating > 0)
                      .Select(p => p.Rating)
                      .DefaultIfEmpty(3)
                      .Average()
                      .ToDouble();
            }

            return applicants;
        }

I have a table that shows if an Applicant was part of certain program and it will average out their rating from previous programs and current programs. Once an applicant is added to a new program their rating is a 0 to start but it will not be included in the overall average rating unless someone gives them a different rating bigger than 0, however, if this person is removed from a current program and then later added again to that same program then it includes the value 0 to the overall rating. I don't want that but I've been trying to solve this issue that my brain is all scrambled. I have put the code that gets all Applicants with their respective programs, previous programs, and rating. Any help on this? I hope I made sense.

public async Task<T> GetAllApplicants()
        {
            // Other Code up here
            IList<T> participants = await GetAllParticipants();
            // applicants is being set somewhere else
            foreach (var applicant in applicants)
            {
                applicant.Programs = participants
                    .Where(p => p.Email.EqualsIgnoreCase(applicant.Email))
                    .Select(p => p.ProgramName)
                    .ToList();

                applicant.PreviousPrograms = participants
                    .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.IsPreviousParticipant)
                    .Select(p => p.ProgramName)
                    .ToList(p => p.ProgramName);

                applicant.AverageRating = participants
                      .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.Rating > 0)
                      .Select(p => p.Rating)
                      .DefaultIfEmpty(3)
                      .Average()
                      .ToDouble();
            }

            return applicants;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿嘿嘿 2025-02-17 18:11:28

我猜是,申请人没有正确地重新添加,因此以下返回一个空列表:

applicant.AverageRating = participants
                      .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.Rating > 0)
                      .Select(p => p.Rating)

以下仅给出了平均值的默认值3:

                      .DefaultIfEmpty(3)
                      .Average()
                      .ToDouble();

I'd guess is that the applicant is not being re-added correctly so the following returns an empty list:

applicant.AverageRating = participants
                      .Where(p => p.Email.EqualsIgnoreCase(applicant.Email) && p.Rating > 0)
                      .Select(p => p.Rating)

The the following just gives the default value of 3 for the average:

                      .DefaultIfEmpty(3)
                      .Average()
                      .ToDouble();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文