Explorar o código

[修改]成绩统计模块数据

soleil %!s(int64=7) %!d(string=hai) anos
pai
achega
ab7c4f46ee

+ 13 - 2
src/api/codehw.js

@@ -52,15 +52,26 @@ export const getBuildDetail = buildId => {
 
 /**
  * 获得最近n个构建的信息
- * @param {string|number} buildId
+ * @param {string|number} projectId
  * @return {Promise<{id:string,data:BuildSerializerType[]}>}
  */
-export const getLatestBuildInfoList = (projectId, limit) => {
+export const getLatestBuildInfoList = (projectId, limit = 5) => {
   return request(
     `${CODE_HOMEWORK_MODULE}/project/${projectId}/build/record?limit=${limit}`
   );
 };
 
+/**
+ * 获得最近n个部署的信息
+ * @param {string|number} projectId
+ * @return {Promise<{id:string,data:DeploySerializerType[]}>}
+ */
+export const getLatestDeployInfoList = (projectId, limit = 5) => {
+  return request(
+    `${CODE_HOMEWORK_MODULE}/project/deploy/record/${projectId}?limit=${limit}`
+  );
+};
+
 /**
  * 获得一次部署的详细信息
  * @param {string|number} deployId

+ 47 - 7
src/views/student/Code/ProjectDetail/DeployDetail.vue

@@ -8,7 +8,20 @@
         <div class="latest-build">
           <div class="test-item" :key="item.id" v-for="item in latestBuildList">
             <div>
-              <b-radio v-model="radio" :native-value="item.id"> </b-radio>
+              <b-radio v-model="radio" :native-value="`b${item.id}`"> </b-radio>
+              <strong>构建ID: #</strong> {{ item.id }}
+              <span style="padding-left: 10px">
+                <strong>镜像ID: #</strong> {{ item.mirrorId }}
+              </span>
+            </div>
+          </div>
+          <div
+            class="test-item"
+            :key="item.id"
+            v-for="item in latestDeployList"
+          >
+            <div>
+              <b-radio v-model="radio" :native-value="`d${item.id}`"> </b-radio>
               <strong>构建ID: #</strong> {{ item.id }}
               <span style="padding-left: 10px">
                 <strong>镜像ID: #</strong> {{ item.mirrorId }}
@@ -20,6 +33,7 @@
       <button
         :class="['button', 'block', 'is-link', { 'is-loading': isRunning }]"
         @click="startDeploy"
+        style="margin-top: 20px;"
       >
         开始部署
       </button>
@@ -71,7 +85,8 @@ import {
   getDeployDetail,
   getDeployLogInfo,
   getLatestBuildInfoList,
-  makeDeploy
+  makeDeploy,
+  getLatestDeployInfoList
 } from "@/api/codehw";
 
 export default {
@@ -85,6 +100,8 @@ export default {
       deployLog: "",
       unfoldDeployLogInfo: false,
       latestBuildList: [],
+      latestDeployList: [],
+      latestMirrorIdList: [],
       radio: -1
     };
   },
@@ -100,6 +117,7 @@ export default {
   },
   watch: {
     projectDetail: function(newVal) {
+      console.log(newVal);
       //获取最新一次部署详细信息
       if (newVal.latestDeploy && newVal.latestDeploy.id) {
         this.haveDeployRecord = true;
@@ -108,6 +126,10 @@ export default {
         this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
       }
       this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
+      this.getLastNDeployInfoList(
+        this.projectDetail && this.projectDetail.id,
+        5
+      );
     }
   },
   mounted() {
@@ -117,6 +139,7 @@ export default {
     }
     if (this.projectDetail.id) {
       this.getLatestBuildInfo(this.projectDetail.id, 5);
+      this.getLastNDeployInfoList(this.projectDetail.id, 5);
     }
   },
   methods: {
@@ -176,11 +199,26 @@ export default {
           });
       }
     },
+    //获取最近n次部署成功记录
+    getLastNDeployInfoList(projectId, limit) {
+      getLatestDeployInfoList(projectId, limit)
+        .then(res => {
+          this.latestDeployList = res.data;
+          // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
+        })
+        .catch(e => {
+          this.$toast.open({
+            message: e.message || " 服务器未知错误",
+            type: "is-danger"
+          });
+        });
+    },
     //获取最近n个构建的信息
-    getLatestBuildInfo(buildId, limit) {
-      getLatestBuildInfoList(buildId, limit)
+    getLatestBuildInfo(projectId, limit) {
+      getLatestBuildInfoList(projectId, limit)
         .then(res => {
           this.latestBuildList = res.data;
+          // this.latestMirrorIdList = this.latestMirrorIdList.concat(res.data);
         })
         .catch(e => {
           this.$toast.open({
@@ -216,9 +254,11 @@ export default {
     },
     //选择镜像ID
     getSelectedMirrorId() {
-      for (let item of this.latestBuildList) {
-        if (item.id == this.radio) {
-          console.log(item.mirrorId);
+      let list =
+        this.radio[0] == "b" ? this.latestBuildList : this.latestDeployList;
+      let id = this.radio.substring(1);
+      for (let item of list) {
+        if (item.id == id) {
           return item.mirrorId;
         }
       }

+ 1 - 0
src/views/student/Code/ProjectDetail/index.vue

@@ -62,6 +62,7 @@ export default {
     const { projectId } = this.$route.params;
     this.detailLoading = true;
     const detail = await getProjectDetail(projectId);
+    console.log(detail.data);
     this.projectDetail = detail.data;
     this.detailLoading = false;
   }

+ 95 - 141
src/views/teacher/Result/index.vue

@@ -29,7 +29,7 @@
         <!--题目table-->
         <div class="question-list">
           <b-table
-            :data="data"
+            :data="studentFinalResultList"
             paginated
             per-page="50"
             detailed
@@ -43,20 +43,21 @@
                 {{ props.row.user.nickname }}
               </b-table-column>
               <b-table-column label="文档作业" centered sortable>
-                {{ average(props.row.documents) }}
+                {{ addSum(props.row.documents) }}
               </b-table-column>
 
               <b-table-column label="代码作业" centered sortable>
-                {{ average(props.row.codes) }}
+                {{ addSum(props.row.codes) }}
               </b-table-column>
 
               <b-table-column label="互评作业" centered sortable>
-                {{ average(props.row.reviews) }}
+                {{ addSum(props.row.reviews) }}
               </b-table-column>
               <b-table-column
-                field="finalResult"
+                field="finalRes"
                 label="总评"
                 sortable
+                numeric
                 centered
               >
                 <span :class="['tag', type(props.row.finalRes)]">
@@ -141,63 +142,6 @@
               </b-table-column>
             </template>
           </b-table>
-          <!--<div class="homework-item">-->
-          <!--<label>文档作业</label>-->
-          <!--<div class="homework-percent">-->
-          <!--<b-field position="is-centered">-->
-          <!--<b-input placeholder="第一次作业百分比"> </b-input>-->
-          <!--<p class="control">-->
-          <!--<button class="button is-light">%</button>-->
-          <!--</p>-->
-          <!--</b-field>-->
-          <!--</div>-->
-          <!--<div class="homework-percent">-->
-          <!--<b-field position="is-centered">-->
-          <!--<b-input placeholder="第二次作业百分比"> </b-input>-->
-          <!--<p class="control">-->
-          <!--<button class="button is-light">%</button>-->
-          <!--</p>-->
-          <!--</b-field>-->
-          <!--</div>-->
-          <!--<div class="homework-percent">-->
-          <!--<b-field-->
-          <!--:type="$v.percent.$error ? 'is-danger' : ''"-->
-          <!--:message="$v.percent.$error ? '请填写1-100之间的数字' : ''"-->
-          <!--position="is-centered"-->
-          <!--&gt;-->
-          <!--<b-input-->
-          <!--v-model="$v.percent.$model"-->
-          <!--placeholder="第三次作业百分比"-->
-          <!--&gt;-->
-          <!--</b-input>-->
-          <!--<p class="control">-->
-          <!--<button class="button is-light">%</button>-->
-          <!--</p>-->
-          <!--</b-field>-->
-          <!--</div>-->
-          <!--</div>-->
-          <!--<div class="homework-item">-->
-          <!--<label>互评作业</label>-->
-          <!--<div class="homework-percent">-->
-          <!--<b-field position="is-centered">-->
-          <!--<b-input placeholder="第一次作业百分比"> </b-input>-->
-          <!--<p class="control">-->
-          <!--<button class="button is-light">%</button>-->
-          <!--</p>-->
-          <!--</b-field>-->
-          <!--</div>-->
-          <!--</div>-->
-          <!--<div class="homework-item">-->
-          <!--<label>代码作业</label>-->
-          <!--<div class="homework-percent">-->
-          <!--<b-field position="is-centered">-->
-          <!--<b-input placeholder="第一次作业百分比"> </b-input>-->
-          <!--<p class="control">-->
-          <!--<button class="button is-light">%</button>-->
-          <!--</p>-->
-          <!--</b-field>-->
-          <!--</div>-->
-          <!--</div>-->
         </div>
         <a
           :class="['button', 'is-link', { 'is-loading': submitting }]"
@@ -268,14 +212,41 @@ export default {
       isResultLoading: true,
       finalResult: [],
       homeworkNum: 0,
-      resultPercentList: []
+      resultPercentList: [],
+      studentFinalResultList: [],
+      studentResultChartData: [],
+      resultChart: {}
     };
   },
   methods: {
-    //生成成绩百分比表格
+    //绘制成绩图表
+    drawResultChart() {
+      let myChart2 = new Chart(this.resultChart, {
+        type: "bar",
+        data: {
+          labels: RESULT_SECTION,
+          datasets: [
+            {
+              label: "人数",
+              backgroundColor: "rgba(54,162,235,0.3)",
+              borderColor: "rgba(54,162,235,1)",
+              borderWidth: 1,
+              pointStrokeColor: "#fff",
+              pointStyle: "crossRot",
+              data: this.studentResultChartData,
+              cubicInterpolationMode: "monotone",
+              spanGaps: "false",
+              fill: "false"
+            }
+          ]
+        },
+        options: {}
+      });
+      this.myChart2 = myChart2;
+    },
+    //生成成绩百分比
     createResultPercentList() {
       let resultPercentList = [];
-      //let percentList = [];
       let resultData = this.data[0];
       for (let codesHw of resultData.codes) {
         codesHw.type = "CODE";
@@ -292,17 +263,6 @@ export default {
       this.resultPercentList = resultPercentList;
       console.log(resultPercentList);
     },
-    //初始化成绩比例
-    initialResultPercent(studentResults) {
-      if (studentResults.length < 1) return;
-      let resultSample = studentResults[0];
-      let homeworkNum = 0;
-      homeworkNum =
-        resultSample.codes.length +
-        resultSample.documents.length +
-        resultSample.reviews.length;
-      this.homeworkNum = homeworkNum;
-    },
     //统计学生成绩分段
     studenResultStatistics(studentResults) {
       let resultStatisticsData = [];
@@ -327,7 +287,8 @@ export default {
         }
         resultStatisticsData.push(count);
       }
-      return resultStatisticsData;
+      this.studentResultChartData = resultStatisticsData;
+      // return resultStatisticsData;
     },
     type(value) {
       const number = parseFloat(value);
@@ -339,54 +300,58 @@ export default {
         return "is-success";
       }
     },
-    //计算平均成绩
-    average(resultList) {
-      if (resultList.length < 1) {
-        return "--";
-      }
-      let res = 0;
+    //计算每种作业平均成绩
+    addSum(resultList) {
+      let finalRes = 0;
       for (let item of resultList) {
-        if (item.score) {
-          res += item.score;
-        }
+        finalRes += item.calScore;
       }
-      return res / resultList.length;
+      return finalRes;
     },
-    //计算总评
-    getFinalResult(resultList) {
-      let finalResultList = [];
-      for (let i = 0; i < resultList.length; i++) {
+    //计算学生总评
+    getFinalResult(studentResultList) {
+      let studentFinalResultList = [];
+      for (let i = 0; i < studentResultList.length; i++) {
+        let studentRes = studentResultList[i];
+        let resultPercentList = this.resultPercentList;
+        let index = 0;
+        let codesResList = [];
+        let docsResList = [];
+        let reviewsResList = [];
         let finalRes = 0;
-        let result = resultList[i];
-        //let currentIndex = 0;
-        for (let docRes of result.documents) {
-          if (docRes.score) {
-            finalRes += docRes.score;
-          }
-          // finalRes +=
-          //   docRes.score * (this.finalResultPercentage[currentIndex] / 100);
-          // currentIndex++;
+        for (let codeRes of studentRes.codes) {
+          //根据成绩比例计算分数
+          codeRes.calScore = codeRes.score
+            ? (codeRes.score * resultPercentList[index].percent) / 100
+            : 0;
+          // console.log(codeRes.calScore);
+          codesResList.push(codeRes);
+          finalRes += codeRes.calScore;
+          index++;
         }
-        for (let codeRes of result.codes) {
-          if (codeRes.score) {
-            finalRes += codeRes.score;
-          }
-          // finalRes +=
-          //   codeRes.score * (this.finalResultPercentage[currentIndex] / 100);
-          // currentIndex++;
+        studentRes.codes = codesResList;
+        for (let docRes of studentRes.documents) {
+          docRes.calScore = docRes.score
+            ? (docRes.score * resultPercentList[index].percent) / 100
+            : 0;
+          docsResList.push(docRes);
+          finalRes += docRes.calScore;
+          index++;
         }
-        for (let reviewRes of result.reviews) {
-          if (reviewRes.score) {
-            finalRes += reviewRes.score;
-          }
-          // finalRes +=
-          //   reviewRes.score * (this.finalResultPercentage[currentIndex] / 100);
-          // currentIndex++;
+        studentRes.documents = docsResList;
+        for (let reviewRes of studentRes.reviews) {
+          reviewRes.calScore = reviewRes.score
+            ? (reviewRes.score * resultPercentList[index].percent) / 100
+            : 0;
+          reviewsResList.push(reviewRes);
+          finalRes += reviewRes.calScore;
+          index++;
         }
-        result.finalRes = parseInt(finalRes / this.homeworkNum);
-        finalResultList.push(result);
+        studentRes.reviews = reviewsResList;
+        studentRes.finalRes = finalRes;
+        studentFinalResultList.push(studentRes);
       }
-      this.data = finalResultList;
+      this.studentFinalResultList = studentFinalResultList;
     },
     //调整成绩比例
     confirmPercent() {
@@ -415,6 +380,7 @@ export default {
           type: "is-warning"
         });
       } else {
+        //提交成绩修改结果
         this.submitting = true;
         setResultPercentList(
           this.$route.params.courseId,
@@ -429,6 +395,14 @@ export default {
               type: "is-success"
             });
             this.isCardModalActive = false;
+            this.submitting = false;
+            //重新计算成绩比例
+            this.getFinalResult(this.data);
+            this.studenResultStatistics(this.studentFinalResultList);
+            let myChart2 = this.myChart2;
+            console.log(myChart2);
+            myChart2.data.datasets[0].data = this.studentResultChartData;
+            myChart2.update();
           })
           .catch(e => {
             this.$toast.open({
@@ -448,37 +422,17 @@ export default {
     this.data = resultData.data;
     console.log(this.data);
     //初始化默认成绩比例
-    this.initialResultPercent(this.data);
+    // this.initialResultPercent(this.data);
     //初始化各作业比例
     this.createResultPercentList();
     //统计学生总评
     this.getFinalResult(resultData.data);
     //统计学生分数
-    let studentResultStatistics = this.studenResultStatistics(this.data);
+    this.studenResultStatistics(this.data);
     //绘制图表
     let resultChart = document.getElementById("result-chart");
-    let myChart2 = new Chart(resultChart, {
-      type: "bar",
-      data: {
-        labels: RESULT_SECTION,
-        datasets: [
-          {
-            label: "人数",
-            backgroundColor: "rgba(54,162,235,0.3)",
-            borderColor: "rgba(54,162,235,1)",
-            borderWidth: 1,
-            pointStrokeColor: "#fff",
-            pointStyle: "crossRot",
-            data: studentResultStatistics,
-            cubicInterpolationMode: "monotone",
-            spanGaps: "false",
-            fill: "false"
-          }
-        ]
-      },
-      options: {}
-    });
-    this.myChart2 = myChart2;
+    this.resultChart = resultChart;
+    this.drawResultChart();
   }
 };
 </script>