const courseTargetList = [
  {
    targetId: "1",
    targetName: "课程目标1",
    evaluationDesc:
      "系统掌握高等数学中的基本概念、基本方法、基本技巧(A1)\n熟练掌握求极限的基本方法与技巧、判断函数的连续性(A2)\n熟练掌握求导数的基本方法与技巧(A3)\n熟练掌握求不定积分与定积分的基本方法与技巧(A4)\n掌握一阶及二阶微分方程的解法(A5)\n熟练掌握多元函数极限的求法、偏导数及全微分的求法，复合函数求导的基本方法与技巧(A6)\n熟练掌握多元函数积分学的基本方法与解题技巧(A7)\n掌握级数敛散性判别法，简单的幂级数求和函数及函数展开成幂级数(A8)",
    evaluationValue: 0.67,
    evaluationList: [
      {
        name: "平时作业",
        weight: "10%",
        score: 40,
        avg: 25.93,
      },
      {
        name: "期中考查",
        weight: "20%",
        score: 5,
        avg: 4.23,
      },
      {
        name: "期末考试",
        weight: "70%",
        score: 10,
        avg: 7.82,
      },
    ],
  },
  {
    targetId: "2",
    targetName: "课程目标2",
    evaluationDesc:
      "掌握数列极限、函数极限的基本概念、性质并会求极限(B1)\n微分中值定理的证明及其应用(B2)\n隐函数求导(B3)\n幂级数求和函数及函数展开成幂级数(B4)",
    evaluationValue: 0.75,
    evaluationList: [
      {
        name: "平时作业",
        weight: "10%",
        score: 40,
        avg: 27.93,
      },
      {
        name: "期中考查",
        weight: "20%",
        score: 5,
        avg: 4.23,
      },
      {
        name: "期末考试",
        weight: "70%",
        score: 10,
        avg: 7.82,
      },
    ],
  },
  {
    targetId: "3",
    targetName: "课程目标3",
    evaluationDesc:
      "掌握微分的应用、微分中值定理的应用、函数的图形与性态、求函数的极值与最值(C1)\n掌握定积分几何应用(C2)\n掌握多元函数微分学的应用(C3)\n熟练掌握二重积分(C4)",
    evaluationValue: 0.82,
    evaluationList: [
      {
        name: "平时作业",
        weight: "10%",
        score: 40,
        avg: 32.93,
      },
      {
        name: "期中考查",
        weight: "20%",
        score: 5,
        avg: 4.23,
      },
      {
        name: "期末考试",
        weight: "70%",
        score: 10,
        avg: 8.82,
      },
    ],
  },
];
const structs = [
  {
    subQuestionCount: 15,
    score: 2,
  },
  {
    subQuestionCount: 5,
    score: 2,
  },
  {
    subQuestionCount: 6,
    score: 5,
  },
  {
    subQuestionCount: 3,
    score: 10,
  },
];
const questionInfo = [];
structs.forEach((item, index) => {
  for (let i = 0; i < item.subQuestionCount; i++) {
    questionInfo.push({
      mainNumber: index + 1,
      subNumber: i + 1,
      score: item.score,
      targetList: getQuestionInfoTarget(),
    });
  }
});

function getQuestionInfoTarget() {
  const targets = getRandamItems(courseTargetList, getRandomNum(2, 1));
  return targets.map((item) => {
    return {
      targetId: item.targetId,
      targetName: item.targetName,
      dimensionList: [1],
    };
  });
}

const dimensionNames = [
  "A1",
  "A2",
  "A3",
  "A4",
  "B1",
  "B2",
  "B3",
  "C1",
  "C2",
  "C3",
  "C4",
];
const workNames = ["作业1", "作业2", "作业3", "作业4", "作业5"];
const students = [
  "周晓",
  "张华",
  "李佳",
  "徐琦",
  "陈真",
  "李阳",
  "张五",
  "赵明",
];
function getRandomNum(num, minnum = 0) {
  return Math.ceil(Math.random() * (num - minnum)) + minnum;
}

function getRandamItems(list, num) {
  const sources = [...list];
  if (!num || num >= list.length) return sources;

  let no = num;
  let data = [];
  while (no) {
    const ind = getRandomNum(sources.length);
    data.push(sources[ind - 1]);
    sources.splice(ind - 1, 1);
    no--;
  }
  return data;
}

const courseStructs = courseTargetList.map((target) => {
  const endRate = getRandomNum(10, 2);
  return {
    targetId: target.targetId,
    targetName: target.targetName,
    evaluationValue: target.evaluationValue,
    endExam: "期末考试",
    endDimensions: getRandamItems(dimensionNames, 4),
    endRate: endRate / 10,
    normalExam: "平时考试",
    normalWorks: getRandamItems(workNames, 3),
    normalRate: (10 - endRate) / 10,
  };
});

const examStudentList = [...getRandamItems(students, 4), "平均分"].map(
  (item, index) => {
    const targetList = courseStructs.map((target) => {
      const ntarget = {
        targetId: target.targetId,
        targetName: target.targetName,
        evaluationValue: target.evaluationValue,
      };
      ntarget.finalScore = {
        weight: target.endRate,
        dimensionList: target.endDimensions.map((ditem) => {
          return {
            dimensionId: ditem,
            dimensionCode: ditem,
            dimensionName: ditem,
            dimensionScore: getRandomNum(5),
          };
        }),
      };
      ntarget.usualScore = {
        weight: target.normalRate,
        scoreList: target.normalWorks.map((witem) => {
          return {
            name: witem,
            score: getRandomNum(100),
          };
        }),
      };
      return ntarget;
    });

    const nitem = {
      name: item,
      studentCode: "082001" + index,
      score: getRandomNum(100),
      targetList,
    };
    return nitem;
  }
);

export const reportData = {
  commonInfo: {
    //公共信息
    examId: "1",
    courseCode: "1001",
    couserName: "数学",
    paperNumber: "1235678909",
  },
  courseBasicInfo: {
    //课程基本情况
    credit: 2,
    period: 60,
    courseType: "",
    evaluationMode: "",
    openTime: "2022-2023学年第2学期",
    teachingObject: "2019级生物科学2班",
    selectionCount: null,
    participantCount: 45,
    courseDegree: 0.5,
    teacher: "李老师",
    director: "评价责任人",
    participant: "评价参与人",
  },
  courseEvaluationSpreadInfo: {
    questionInfo,
    scoreList: {
      failCount: 1,
      failRate: 160,
      scoreRange: [
        {
          studentCount: 6,
          minScore: 1,
          maxScore: 9.5,
          rate: 144,
        },
        {
          studentCount: 7,
          minScore: 10,
          maxScore: 19.5,
          rate: 168,
        },
        {
          studentCount: 0,
          minScore: 20,
          maxScore: 29.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 30,
          maxScore: 39.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 40,
          maxScore: 49.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 50,
          maxScore: 59.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 60,
          maxScore: 69.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 70,
          maxScore: 79.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 80,
          maxScore: 89.5,
          rate: 0,
        },
        {
          studentCount: 0,
          minScore: 90,
          maxScore: 100,
          rate: 0,
        },
      ],
    },
  },
  courseEvaluationResultInfo: {
    target: "课程总目标",
    targetValue: 0.89,
    targetList: courseTargetList,
  },
  courseEvaluationResultDetailInfo: {
    examStudentList,
    courseTargetList: courseTargetList.map((item) => {
      return {
        targetId: item.targetId,
        targetName: item.targetName,
        usualScore: getRandomNum(10, 5) / 10,
        finalScore: getRandomNum(10, 5) / 10,
      };
    }),
  },
};
// console.log(reportData);
