模板抽題優化

2021-08-08 09:44:22 字數 3433 閱讀 4588

經過測試,我對考評的模板抽題演算法做了相應的優化調整,優化後經過單元測試確認是可用的。在上篇部落格中,我只是寫出了相應的**片段,並做了相應的分析,在這個部落格中,我們首先來看一下模板抽題的整體實現。

public exam*****model randomquestion(exam*****model exam*****model,listmainlist,listchapterlist)

//endregion

//region 為試卷上每個大題中小題的難度等級分配空間

//宣告變數,存放每個大題的難度等級,並分配空間

int typedegrees = new int[typemodellist.size()];

//宣告變數,用於存放每個大題的所有小題的難度等級

int temptypedegrees = new int[typemodellist.size()];

for (int i = 0; i < typemodellist.size(); i++)

//endregion

//region 為每章分配記憶體空間,並填充每章所對應的分數

//獲取試卷的總分數

double *****score = exam*****model.getscore();

//宣告變數,用於存放每個章節的分數,並分配空間

double chapterscore = new double[chapterlist.size()];

//宣告變數,用於存放已選題每個章節的分數,並分配空間

double tempchapterscore = new double[chapterlist.size()];

for (int i = 0; i < chapterlist.size(); i++)

//endregion

//endregion

//遍歷試卷上每個大題

for (int i = 0; i < typemodellist.size(); i++)

}//endregion

//region 隨機抽題

//根據獲取題幹的數量與試卷上某大題中所有小題數量對比,執行不同方法

if (typemainlist.size() < typemodellist.get(i).getquestiontypenum()) else if (typemainlist.size() == typemodellist.get(i).getquestiontypenum())

//endregion

} else

//region 獲取不重複的題幹索引

//region 方案一:set不重複隨機

//產生隨機數,用於作為所抽題的索引

int typemainindex = random.nextint(typemainlist.size());

//利用set結合的特性,防止產生的隨機數有重複的

boolean flag = randomcollct.add(typemainindex);

if (flag==false)

//endregion

//endregion

//根據抽取的 typemainindex 索引進行判斷

examquestionmainmodel exammain = typemainlist.get(typemainindex);

//region 等級分布條件判斷

//獲得當前題幹的難度等級

int degree = exammain.getdegree();

//定義變數用於存放某難度等級的題型個數

int temptypedegreenumber = temptypedegrees[i][degree] + exammain.getblankcount();

//當前題型個數與試卷要求的題型個數對比

if (temptypedegreenumber > typedegrees[i][degree])

//endregion

//region 章節比例條件判斷

string mainchapter = exammain.getchapter();//獲取題幹章節

//定義章節索引變數

int chapterindex = -1;

//遍歷所有章節

for (int k = 0; k < chapterlist.size(); k++)

}//計算平均每個題的分數

double typemainscore = typemodellist.get(i).getquestiontypescore() / typemodellist.get(i).getquestiontypenum();

//計算該小題實際的分數(該題有兩個空則按兩個小題計算)

double mainscore = typemainscore * exammain.getblankcount();

//定義變數並賦值(本章節已選題的分數+該小題分數)

double chaptermainscore = tempchapterscore[chapterindex] + mainscore;

//判斷現在該分數是否超過該章要求的總分數

if (chaptermainscore > chapterscore[chapterindex])

//endregion

//儲存已選題本章節累計總分數

temptypedegrees[i][degree] = temptypedegreenumber;

tempchapterscore[chapterindex] = chaptermainscore;

typemain[i][j] = exammain;//儲存題幹

}//endregion

//endregion

}//endregion

//region 將取題結果存入試卷中

//將取題結果存入試卷中

for (int j = 0; j < typemodellist.get(i).getquestiontypenum(); j++)

//endregion

}//將題幹設定到試卷

exam*****model.set*****questiontypelist(typemodellist);

//返回試卷

return exam*****model;

}return null;

}

1、在這次優化中,我首先對可用題數小於試卷上要求題數的情況做了處理,記錄到日誌,並返回null。

2、刪除了不必要的迴圈賦值,初始化陣列後,有些陣列沒有必要進行初始化賦值如int陣列,初始化後預設為0,不用迴圈賦值為0

3、去重集合set的宣告位置應在迴圈外,這樣才能保證set中記錄所有所需要的隨機數(位置問題要考慮周到)

4、新增了遍歷題庫中所有題後仍然不能抽到滿足要求的題目後的判斷退出,避免陷入死迴圈。

Sqoop 抽資料 優化

sqoop作為乙個跨平台抽取和輸出資料的工具,在關係型資料庫 oralce,mysql等 和大資料平台之間常用。而目前的專案使用的hadoop平台,上游資料庫是oracle。作為etl的一環,載入作業的效能也是需要關注和優化的。如果使用sqoop命令,則可以從以下幾點進行優化 1.允許並行抽數 m ...

考試系統 二 抽題

這次真的說抽題了 上次我們了解了 要做什麼才能考試 當考試 考場 學生 試卷或模板配好繫結之後 學生就能考試了 學生經過資訊的認證 進入考試頁面時就會進行抽題 今天我們就說下抽題的詳細步驟。抽題需要資料 查詢考試詳情 根據學號和當前資料庫時間 查詢出當前考試是按照模板還是試卷抽題 查詢出亂序方式 有...

PHP實現類似題庫抽題效果

php實現類似題庫抽題效果 現在來說說我的思路,希望各位大佬不吝賜教。首先要實現這個功能,首先我需要三個頁面,乙個是使用者輸入頁面input.html,乙個是後台處理頁面select.php,還有乙個是錯誤警告頁面error.html 如果使用者輸入為空,或者輸入的抽題數量超過了題庫的數量那麼就報錯...