Преглед изворни кода

[新增]成绩比例调控

soleil пре 7 година
родитељ
комит
2faaeabebe

+ 1 - 0
src/api/codehw.js

@@ -116,6 +116,7 @@ export const getAvailableMirrorList = ({ homeworkId, projectId }) => {
  * @return {Promise<{data:{success:boolean}}>}
  */
 export const makeDeploy = ({ projectId, mirrorId, replicas }) => {
+  console.log(mirrorId);
   return request(`${CODE_HOMEWORK_MODULE}/deploy`, {
     method: "POST",
     body: { replicas, projectId, mirrorId }

+ 20 - 0
src/api/resultstatistics.js

@@ -10,3 +10,23 @@ export const getStudentFinaleResult = (courseId = 123) => {
     method: "POST"
   });
 };
+
+/**
+ * 设置作业成绩比例
+ * @returns {Promise<{data:string}>}
+ */
+export const setResultPercentList = (
+  courseId,
+  docPercentList,
+  codePercentList,
+  reviewPercentList
+) => {
+  return request(`${RESULTSTATISTICS_MODULE}/course/${courseId}/percent`, {
+    method: "POST",
+    body: {
+      documents: docPercentList,
+      codes: codePercentList,
+      reviews: reviewPercentList
+    }
+  });
+};

+ 13 - 8
src/views/student/Code/ProjectDetail/DeployDetail.vue

@@ -101,23 +101,22 @@ export default {
   watch: {
     projectDetail: function(newVal) {
       //获取最新一次部署详细信息
-      if (newVal.latestDeploy.id) {
+      if (newVal.latestDeploy && newVal.latestDeploy.id) {
         this.haveDeployRecord = true;
         this.getLatestDeployInfo(newVal.latestDeploy.id);
         // this.getLatestDeployInfo(17);
         this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
-        this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
-        //this.getLatestBuildInfo(95,5);
       }
+      this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
     }
   },
   mounted() {
     if (this.projectDetail.latestDeploy) {
       this.getLatestDeployInfo(this.projectDetail.latestDeploy.id);
       this.getDeployLogInfo(this.projectDetail.latestDeploy.id);
-      //this.getLatestDeployInfo(17);
-      this.getLatestBuildInfo(this.projectDetail && this.projectDetail.id, 5);
-      // this.getLatestBuildInfo(95,5);
+    }
+    if (this.projectDetail.id) {
+      this.getLatestBuildInfo(this.projectDetail.id, 5);
     }
   },
   methods: {
@@ -155,13 +154,18 @@ export default {
       } else {
         let mirrorId = this.getSelectedMirrorId();
         //触发部署
-        makeDeploy(this.projectDetail.id, mirrorId, 1)
+        makeDeploy({
+          projectId: this.projectDetail.id,
+          mirrorId: mirrorId,
+          replicas: 1
+        })
           .then(res => {
             console.log(res);
             this.$toast.open({
               message: "开始部署",
               type: "is-success"
             });
+
             this.isRunning = true;
           })
           .then(e => {
@@ -212,8 +216,9 @@ export default {
     },
     //选择镜像ID
     getSelectedMirrorId() {
-      for (let item in this.latestBuildList) {
+      for (let item of this.latestBuildList) {
         if (item.id == this.radio) {
+          console.log(item.mirrorId);
           return item.mirrorId;
         }
       }

+ 169 - 72
src/views/teacher/Result/index.vue

@@ -112,69 +112,92 @@
       </div>
     </page-body>
     <!-- 成绩比例调控模态框 -->
-    <b-modal :active.sync="isCardModalActive" width="420px" scroll="keep">
+    <b-modal :active.sync="isCardModalActive" scroll="keep">
       <div class="card">
         <div class="title">
           成绩比例调控<small>&nbsp;&nbsp;请按百分比填写</small>
         </div>
         <div class="content">
-          <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"
-              >
+          <b-table
+            :data="resultPercentList"
+            class="customer-table"
+            :striped="true"
+            :narrowed="true"
+          >
+            <template slot-scope="props">
+              <b-table-column field="id" label="作业ID" width="50" numeric>
+                {{ props.row.id }}
+              </b-table-column>
+              <b-table-column field="name" label="作业名称">
+                {{ props.row.name }}
+              </b-table-column>
+              <b-table-column field="type" label="作业类型" email>
+                {{ props.row.type }}
+              </b-table-column>
+              <b-table-column field="percent" label="当前比例">
                 <b-input
-                  v-model="$v.percent.$model"
-                  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 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>
+                  v-model="resultPercentList[props.index].percent"
+                ></b-input>
+              </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 }]"
@@ -192,7 +215,10 @@ import PageBody from "@/components/PageBody/index";
 import Chart from "chart.js";
 import BInput from "buefy/src/components/input/Input";
 import { required, numeric, between } from "vuelidate/lib/validators";
-import { getStudentFinaleResult } from "@/api/resultstatistics";
+import {
+  getStudentFinaleResult,
+  setResultPercentList
+} from "@/api/resultstatistics";
 import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
 
 const RESULT_SECTION = [
@@ -234,17 +260,38 @@ export default {
       data: [],
       isCardModalActive: false,
       myChart2: {},
-      percent: "",
+      percent: [],
       finalResultPercentage: [20, 20, 20, 10, 10, 10, 10],
       submitting: false,
       isServerError: false,
       errorMessage: "服务器错误,请稍后重试",
       isResultLoading: true,
       finalResult: [],
-      homeworkNum: 0
+      homeworkNum: 0,
+      resultPercentList: []
     };
   },
   methods: {
+    //生成成绩百分比表格
+    createResultPercentList() {
+      let resultPercentList = [];
+      //let percentList = [];
+      let resultData = this.data[0];
+      for (let codesHw of resultData.codes) {
+        codesHw.type = "CODE";
+        resultPercentList.push(codesHw);
+      }
+      for (let documentsHw of resultData.documents) {
+        documentsHw.type = "DOCUMENT";
+        resultPercentList.push(documentsHw);
+      }
+      for (let reviewHw of resultData.reviews) {
+        reviewHw.type = "REVIEW";
+        resultPercentList.push(reviewHw);
+      }
+      this.resultPercentList = resultPercentList;
+      console.log(resultPercentList);
+    },
     //初始化成绩比例
     initialResultPercent(studentResults) {
       if (studentResults.length < 1) return;
@@ -299,33 +346,39 @@ export default {
       }
       let res = 0;
       for (let item of resultList) {
-        res += item.score;
+        if (item.score) {
+          res += item.score;
+        }
       }
       return res / resultList.length;
     },
     //计算总评
     getFinalResult(resultList) {
-      console.log(resultList);
       let finalResultList = [];
       for (let i = 0; i < resultList.length; i++) {
         let finalRes = 0;
         let result = resultList[i];
-        console.log(result);
         //let currentIndex = 0;
         for (let docRes of result.documents) {
-          finalRes += docRes.score;
+          if (docRes.score) {
+            finalRes += docRes.score;
+          }
           // finalRes +=
           //   docRes.score * (this.finalResultPercentage[currentIndex] / 100);
           // currentIndex++;
         }
         for (let codeRes of result.codes) {
-          finalRes += codeRes.score;
+          if (codeRes.score) {
+            finalRes += codeRes.score;
+          }
           // finalRes +=
           //   codeRes.score * (this.finalResultPercentage[currentIndex] / 100);
           // currentIndex++;
         }
         for (let reviewRes of result.reviews) {
-          finalRes += reviewRes.score;
+          if (reviewRes.score) {
+            finalRes += reviewRes.score;
+          }
           // finalRes +=
           //   reviewRes.score * (this.finalResultPercentage[currentIndex] / 100);
           // currentIndex++;
@@ -335,12 +388,55 @@ export default {
       }
       this.data = finalResultList;
     },
+    //调整成绩比例
     confirmPercent() {
-      this.submitting = true;
-      this.$toast.open({
-        message: "成绩比例调整成功",
-        type: "is-success"
-      });
+      //检查是否满足100%
+      let percentSum = 0;
+      let docPercentList = [];
+      let codePercentList = [];
+      let reviewPercentList = [];
+      for (let item of this.resultPercentList) {
+        percentSum += parseInt(item.percent);
+        switch (item.type) {
+          case "DOCUMENT":
+            docPercentList.push({ id: item.id, percent: item.percent });
+            break;
+          case "CODE":
+            codePercentList.push({ id: item.id, percent: item.percent });
+            break;
+          case "REVIEW":
+            reviewPercentList.push({ id: item.id, percent: item.percent });
+            break;
+        }
+      }
+      if (percentSum != 100) {
+        this.$toast.open({
+          message: "请使比例加和为100%",
+          type: "is-warning"
+        });
+      } else {
+        this.submitting = true;
+        setResultPercentList(
+          this.$route.params.courseId,
+          docPercentList,
+          codePercentList,
+          reviewPercentList
+        )
+          .then(res => {
+            console.log(res);
+            this.$toast.open({
+              message: "成绩比例调整成功",
+              type: "is-success"
+            });
+            this.isCardModalActive = false;
+          })
+          .catch(e => {
+            this.$toast.open({
+              message: e.message || "服务器未知错误",
+              type: "is-danger"
+            });
+          });
+      }
     }
   },
   async mounted() {
@@ -353,8 +449,9 @@ export default {
     console.log(this.data);
     //初始化默认成绩比例
     this.initialResultPercent(this.data);
+    //初始化各作业比例
+    this.createResultPercentList();
     //统计学生总评
-    console.log(resultData.data);
     this.getFinalResult(resultData.data);
     //统计学生分数
     let studentResultStatistics = this.studenResultStatistics(this.data);