已完成“成绩管理与学业档案”模块:
教师批量录入平时、期中、期末成绩。 自动计算总评、绩点和及格状态。 支持缺考、缓考、免修。 教师提交 → 学院审核/退回 → 校级发布。 学生只能查看正式发布成绩。 自动统计平均分、完成度、及格率和加权 GPA。 SQLite 本地增量升级和 MySQL 正式迁移均已完成。 分级权限在前后端同时校验。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Grades;
|
||||
|
||||
public static class GradeCalculator
|
||||
{
|
||||
public static bool AreWeightsValid(
|
||||
decimal regularWeight,
|
||||
decimal midtermWeight,
|
||||
decimal finalWeight) =>
|
||||
regularWeight is >= 0 and <= 100 &&
|
||||
midtermWeight is >= 0 and <= 100 &&
|
||||
finalWeight is >= 0 and <= 100 &&
|
||||
regularWeight + midtermWeight + finalWeight == 100;
|
||||
|
||||
public static decimal? CalculateTotal(
|
||||
decimal? regularScore,
|
||||
decimal? midtermScore,
|
||||
decimal? finalScore,
|
||||
decimal regularWeight,
|
||||
decimal midtermWeight,
|
||||
decimal finalWeight,
|
||||
GradeExamStatus examStatus)
|
||||
{
|
||||
if (examStatus != GradeExamStatus.Normal ||
|
||||
regularWeight > 0 && !regularScore.HasValue ||
|
||||
midtermWeight > 0 && !midtermScore.HasValue ||
|
||||
finalWeight > 0 && !finalScore.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var total =
|
||||
(regularScore ?? 0) * regularWeight / 100 +
|
||||
(midtermScore ?? 0) * midtermWeight / 100 +
|
||||
(finalScore ?? 0) * finalWeight / 100;
|
||||
return Math.Round(total, 1, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
public static decimal? CalculateGradePoint(decimal? totalScore)
|
||||
{
|
||||
if (!totalScore.HasValue) return null;
|
||||
return totalScore.Value switch
|
||||
{
|
||||
>= 90 => 4.0m,
|
||||
>= 85 => 3.7m,
|
||||
>= 82 => 3.3m,
|
||||
>= 78 => 3.0m,
|
||||
>= 75 => 2.7m,
|
||||
>= 72 => 2.3m,
|
||||
>= 68 => 2.0m,
|
||||
>= 64 => 1.5m,
|
||||
>= 60 => 1.0m,
|
||||
_ => 0m
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user