TeachingController.php 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/8/13
  6. * Time: 10:48
  7. */
  8. require_once 'pData.class.php';
  9. require_once 'pDraw.class.php';
  10. require_once 'pImage.class.php';
  11. require_once 'pScatter.class.php';
  12. require_once 'IspMongo.php';
  13. class TeachingController extends Controller
  14. {
  15. public $subjectId;
  16. private $typeName;
  17. private $logicTypeName;
  18. private $imgArr = array();
  19. private $isThird = 0;
  20. // private $domainUrl = '';
  21. public function __construct()
  22. {
  23. $this->typeName = array('1' => '选择题', '11' => '不定项选择题', '5' => '填空题', '7' => '解答题', '17' => '选做解答题');
  24. }
  25. /**
  26. * 第三方教学宝
  27. * @throws CException
  28. */
  29. public function actionIndex()
  30. {
  31. set_time_limit(300);
  32. ini_set('memory_limit', '300M');
  33. $classId = Req::get("classId");
  34. $examId = (string)Req::get("examId");
  35. $force = (int)Req::get('force');
  36. $viewHtml = (int)Req::get('viewHtml');
  37. $subjectId = $this->subjectId;
  38. if ($viewHtml) {
  39. $force = 1;
  40. }
  41. if (!$examId || !is_numeric($examId)) {
  42. echo json_encode(array("status" => 1, "error" => "考试ID参数不正确!"));
  43. }
  44. $examObj = new Exam();
  45. $examInfo = $examObj->getTeachingInfo($examId);
  46. if (!$examInfo) {
  47. echo json_encode(array("status" => 1, "error" => "没有考试信息!"));
  48. exit;
  49. }
  50. if ($examInfo['subject_id']) {
  51. $this->subjectId = $examInfo['subject_id'];
  52. }
  53. $subjectId = $this->subjectId;
  54. $this->logicTypeName = getSubjectTopicType($subjectId);
  55. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path'];
  56. $pdfurl = $examInfo['academicr_pdf_path'];
  57. $res = array();//生成pdf命令结果
  58. if (strpos($examInfo['academicr_pdf_path'], 'http') !== false) {
  59. if (!file_get_contents($examInfo['academicr_pdf_path'])) {
  60. $force = 1;
  61. }
  62. } else {
  63. $force = 1;
  64. }
  65. //英语兼容新老标注
  66. $getTopicTypeRelate = $this->getTopicTypeRelate();
  67. $batch_subject_id = $subjectId;
  68. if ($batch_subject_id == 8 && $examInfo['qxk_paper_id']) {
  69. $batch_subject_id = 0;
  70. }
  71. if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || $force) {
  72. // if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath) || $force) {
  73. //domain 域名
  74. // if ($subjectId == 8) {
  75. // if (isset($_SESSION['myDatebase'])) {
  76. // $groupId = $_SESSION['myDatebase']->group_id;
  77. // }else{
  78. // $groupId = 0;
  79. // }
  80. //
  81. // $groupServer = new BGroupServer();
  82. // $this->domainUrl = $groupServer->getDomainUrl($groupId);
  83. // }
  84. $paperObj = new SPaper();
  85. $ptrObj = new SPaperTopicRelation();
  86. $ptlObj = new SPaperTopicLarge();
  87. $sprObj = new SStudentPaperRelation();
  88. $sptRsObj = new SStudentPaperTopicRs();
  89. $tmt = new SThirdMultiTemplate();
  90. $examGroupId = $examInfo['exam_group_id'];
  91. $arr = $tmt->getStatusByExamGroupId($examGroupId);
  92. if ($subjectId == 8 && $examInfo['is_third'] == 1 && !$examInfo['qxk_paper_id']) {
  93. $isUpload = 0;
  94. if ($arr) {
  95. foreach ($arr as $k => $v) {
  96. if ($k == 1 && $v['topic_upload'] == 1) {
  97. $isUpload++;
  98. } elseif ($k == 2 && $v['answer_upload'] == 1) {
  99. $isUpload++;
  100. }
  101. }
  102. }
  103. //精品试卷不用上传试题和答案,第三方需要
  104. if ($examInfo['is_fine_paper'] <= 0 && $isUpload != 2) {
  105. echo json_encode(array("status" => 1, "error" => "试卷试题或答案没上传!"));
  106. exit();
  107. }
  108. }
  109. $examIds = $examObj->getExamIds($examGroupId);
  110. $examGroupObj = new SExamGroup();
  111. $isThird = $examGroupObj->getExamIsTird($examGroupId, $examId);
  112. $this->isThird = $isThird;
  113. //去除没有上传成绩的学生
  114. $ptrInfo = $stuIdsArr = array();
  115. if ($examIds) {
  116. $stuIdsArr = $sptRsObj->getHasScoreStu($examIds);
  117. $ptrInfo = $sprObj->getStudentExamInfo($examIds);
  118. }
  119. if (!$ptrInfo) {
  120. echo json_encode(array("status" => 1, "error" => "考试没有数据!"));
  121. exit();
  122. }
  123. $paperIds = array();
  124. foreach ($ptrInfo as $value) {
  125. $paperIds[$value['exam_id']] = $value['paper_id'];
  126. }
  127. //试卷总分
  128. $paperScore = $paperObj->getPaperScore($paperIds);
  129. if (!$paperScore) {
  130. echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
  131. exit();
  132. }
  133. /**************************** 一、班级情况分析 ***********************************/
  134. //获取当前考试的上一次考试数据
  135. $cepObj = new SClassExamPrinter();
  136. $preInfo = $cepObj->getPreExamId($examId, $examInfo['subject_id'], $examInfo['class_id']);
  137. $preExamId = isset($preInfo['exam_id']) ? $preInfo['exam_id'] : '';
  138. $preExamGroupId = isset($preInfo['exam_group_id']) ? $preInfo['exam_group_id'] : '';
  139. $prePaperScore = 0;
  140. $preStuIdsArr = array();
  141. if ($preExamId) {
  142. $preExamIds = $examObj->getExamIds($preExamGroupId);
  143. //去除没有上传成绩的学生
  144. $prePtrInfo = array();
  145. if ($preExamIds) {
  146. $preStuIdsArr = $sptRsObj->getHasScoreStu($preExamIds);
  147. $prePtrInfo = $sprObj->getStudentExamInfo($preExamIds);
  148. }
  149. $prePaperIds = array();
  150. foreach ($prePtrInfo as $value) {
  151. $prePaperIds[$value['exam_id']] = $value['paper_id'];
  152. }
  153. if ($prePaperIds) {
  154. $prePaperScore = $paperObj->getPaperScore($prePaperIds);
  155. }
  156. } else {
  157. $prePtrInfo = array();
  158. }
  159. if (!$prePaperScore && $prePtrInfo) {
  160. echo json_encode(array("status" => 1, "error" => "试卷总分不正确!"));
  161. exit();
  162. }
  163. if (isset($paperIds[$examId])) {
  164. $paperId = $paperIds[$examId];
  165. } else {
  166. echo json_encode(array("status" => 1, "error" => "试卷id没有考试信息!"));
  167. exit();
  168. }
  169. //班级排名得分率人数等数据
  170. $classAnalyData = $this->getClassAnalyse($examId, $ptrInfo, $paperScore, $preExamId, $prePtrInfo, $prePaperScore, $stuIdsArr, $preStuIdsArr);
  171. //大幅进步,大幅退步,前5名和后5名
  172. $largeOrderData = $this->getLargeOrder($examId, $ptrInfo, $preExamId, $prePtrInfo, $stuIdsArr, $preStuIdsArr);
  173. $sutName = isset($largeOrderData['stu_name']) ? $largeOrderData['stu_name'] : array();
  174. $sutOrder = isset($largeOrderData['stu_order']) ? $largeOrderData['stu_order'] : array();
  175. unset($ptrInfo);
  176. unset($prePtrInfo);
  177. /**************************** 二、考试情况分析 ***********************************/
  178. //试卷题对应的题号,分数
  179. list($largeTopicType, $largeTopicMethod) = $ptlObj->getPaperLargeTopicInfo($paperId);
  180. list($smallTopicScore, $smallTopicNo, $topicScore, $topicNo, $topicType, $topicLogicType, $topicRelLarge, $topicRelMethod, $topicTypeRelNo, $topicRelTopicCount) = $ptrObj->getPaperTopicInfo2($paperId, $largeTopicType, $subjectId, $examInfo);
  181. if (!$topicScore) {
  182. echo json_encode(array("status" => 1, "error" => "没有试卷题数据!"));
  183. exit();
  184. }
  185. // // 学生得分
  186. $stuRs = $sptRsObj->getStudentRs($paperIds);
  187. if (!$stuRs) {
  188. echo json_encode(array("status" => 1, "error" => "没有学生做题数据!"));
  189. exit();
  190. }
  191. // $examAnalyData = $this->getExamAnalyse($stuRs,$topicScore,$topicNo,$paperId,$topicRelLarge);
  192. $typeMasterData = $this->getTopicTypeAnaly($stuRs, $topicScore, $topicNo, $paperId, $topicLogicType, $topicRelLarge, $smallTopicNo);
  193. //英语全学科判断
  194. if ($subjectId == 8 && $examInfo['qxk_paper_id']) {
  195. $newTopicTypeRelNo = array();
  196. foreach ($topicTypeRelNo as $topic_type => $topic_data) {
  197. if (isset($getTopicTypeRelate[$topic_type])) {
  198. $newTopicTypeRelNo[$getTopicTypeRelate[$topic_type]] = $topic_data;
  199. } else {
  200. $newTopicTypeRelNo[$topic_type] = $topic_data;
  201. }
  202. }
  203. $topicTypeRelNo = $newTopicTypeRelNo;
  204. }
  205. //班级高频错题 统计班级得分率小于50%的题目
  206. $high_rate_wrong_topic = array();
  207. if ($typeMasterData['type_name_arr']) {
  208. foreach ($typeMasterData['type_name_arr'] as $large_type => $type_name) {
  209. if (isset($topicTypeRelNo[$large_type])) {
  210. $high_rate_wrong_topic[$large_type] = array(array(), array(), array(), array(), array());
  211. foreach ($topicTypeRelNo[$large_type] as $topic_id => $topic_no) {
  212. $topic_class_rate = isset($typeMasterData['topic_class_rate'][$topic_id]) ? $typeMasterData['topic_class_rate'][$topic_id] : 0;
  213. if ($topic_class_rate <= 10) {
  214. $high_rate_wrong_topic[$large_type][0][] = $smallTopicNo[$topic_id];
  215. } elseif ($topic_class_rate > 10 && ($topic_class_rate <= 20)) {
  216. $high_rate_wrong_topic[$large_type][1][] = $smallTopicNo[$topic_id];
  217. } elseif ($topic_class_rate > 20 && ($topic_class_rate <= 30)) {
  218. $high_rate_wrong_topic[$large_type][2][] = $smallTopicNo[$topic_id];
  219. } elseif ($topic_class_rate > 30 && ($topic_class_rate <= 40)) {
  220. $high_rate_wrong_topic[$large_type][3][] = $smallTopicNo[$topic_id];
  221. } elseif ($topic_class_rate > 40 && ($topic_class_rate <= 50)) {
  222. $high_rate_wrong_topic[$large_type][4][] = $smallTopicNo[$topic_id];
  223. }
  224. }
  225. }
  226. }
  227. }
  228. $typeMasterData['high_rate_wrong_topic'] = $high_rate_wrong_topic;
  229. $typeRateImgUrl = array();
  230. // if($subjectId == 8){
  231. // //题型得分率图片
  232. // $typeRateImgUrl = $this->getTopicTypeRateImg($typeMasterData,$examId,$paperId);
  233. // if(!$typeRateImgUrl){
  234. // echo json_encode(array("status" => 1, "error" => "题型得分率图片未生成!"));
  235. // exit();
  236. // }
  237. // }
  238. /**************************** 三、考点掌握情况 ***********************************/
  239. // 15,3,5,2,6,18,13
  240. // $topicNo = array(
  241. // '10001190' => 4,
  242. // '10000151' => 6,
  243. // '10000917' => 7,
  244. // '10000166' => 8,
  245. // '10001228' => 9,
  246. // '10000405' => 10,
  247. // '10001172' => 11,
  248. // '10001174' => 12,
  249. // '10048797' => 14,
  250. // '10096054' => 16,
  251. // '10095990' => 17,
  252. // '10017696' => 18,
  253. // '10017824' => 19,
  254. // '10096052' => 20,
  255. // );
  256. //题信息
  257. $topicIds = array_keys($topicNo);
  258. $tplData = array();
  259. if ($examInfo['tpl_data']) {
  260. $tplData = $examInfo['tpl_data'];
  261. if ($tplData && !is_array($tplData)) {
  262. $tplData = json_decode($tplData, true);
  263. }
  264. }
  265. $isNewEnglish = (isset($tplData['isNewEnglish']) && $tplData['isNewEnglish'] == 1) ? 1 : 0;
  266. $_params = array('isFormat' => $subjectId == 8 ? 0 : 1, 'isTird' => $isThird, 'isNewEnglish' => $isNewEnglish, 'isNoReplaceLable' => 1);
  267. $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topicIds, 'subjectId' => $batch_subject_id, 'params' => $_params), 25, true);
  268. unset($tplData);
  269. // unset($examInfo['tpl_data']);
  270. // if(($this->subjectId == 8 && !$isThird) || (isset($tplData['isNewEnglish']) && $tplData['isNewEnglish'] == 1 && $isThird)){
  271. // $topicDetails = $this->getEnglishTopic($topicIds);
  272. //// $topicDetails = $this->getEnglishTopic(array(20001740));
  273. // }else{
  274. // $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicIds));
  275. // }
  276. //获取考点名称
  277. // $methodName = $this->getMethodName($topicDetails);
  278. $methodName = array();
  279. $largeTopicScore = array();
  280. if (!$topicDetails) {
  281. echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
  282. exit();
  283. } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
  284. echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
  285. exit();
  286. } else {
  287. if ($subjectId == 8) {
  288. $tempDetials = array();
  289. if ($examInfo['qxk_paper_id']) {
  290. $topicDetails = $this->quanTopicDetail($topicDetails);
  291. }
  292. foreach ($topicDetails as $detail) {
  293. //范文
  294. // $fineArticle = $this->getFineArticle($examId,$topicLogicType);
  295. //语篇
  296. $keyWords = array();
  297. if (isset($getTopicTypeRelate[$detail['type_id']])) {
  298. $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']];
  299. }
  300. if (in_array($detail['type_id'], array(2, 3, 4, 5))) {
  301. $wordsIds = array();
  302. $wordInfoArr = array();
  303. if (isset($detail['key_words_levels']) && $detail['key_words_levels']) {
  304. $key_words_level = $detail['key_words_levels'];
  305. $class = array();
  306. foreach ($key_words_level as $val) {
  307. $class[] = $val['level'];
  308. }
  309. array_multisort($class, SORT_DESC, $key_words_level);
  310. $_new_key_words = $key_words_level;
  311. $word_content = array();
  312. foreach ($_new_key_words as $item) {
  313. $word_content[] = '"' . $item['name'] . '"';
  314. }
  315. if ($word_content) {
  316. $wordInfoArr = $this->getWord(array('content' => $word_content, 'type_id' => array(1, 2), 'core_words' => 1, 'status' => 1));
  317. $topic_word_level = array();
  318. foreach ($wordInfoArr as $word_id => $word_info) {
  319. $level = isset($word_info['levels']) ? $word_info['levels'] : 0;
  320. $topic_word_level[$word_id] = $level;
  321. }
  322. arsort($topic_word_level);
  323. foreach ($topic_word_level as $word_id => $level) {
  324. if (count($wordsIds) <= 10) {
  325. $wordsIds[] = $word_id;
  326. }
  327. }
  328. }
  329. }
  330. if ($wordsIds) {
  331. foreach ($wordsIds as $w_id) {
  332. if (isset($wordInfoArr[$w_id])) {
  333. $keyWords[] = $wordInfoArr[$w_id];
  334. }
  335. }
  336. $keyWords = $this->handleWordClass($keyWords);
  337. }
  338. unset($wordInfoArr);
  339. }
  340. $detail['key_words'] = $keyWords;
  341. if ($examInfo['qxk_paper_id']) {
  342. $detail['key_words'] = isset($detail['new_key_words']) ? $detail['new_key_words'] : array();
  343. }
  344. //替换序号
  345. // if (in_array($detail['type_id'], array(2,4,5,6,9, 10, 11, 12, 14))) {
  346. // $this->replaceTitle($detail['title'],$detail['id'],$topicRelLarge,$smallTopicNo);
  347. // }
  348. $detail['title'] = str_replace('&nbsp;', ' ', $detail['title']);
  349. $tempDetials[(string)$detail['id']] = $detail;
  350. }
  351. $topicDetails = $tempDetials;
  352. unset($tempDetials);
  353. //大题分数
  354. foreach ($topicRelLarge as $small_id => $large_id) {
  355. if (!isset($largeTopicScore[$large_id])) {
  356. $largeTopicScore[$large_id] = 0;
  357. }
  358. $largeTopicScore[$large_id] += $topicScore[$small_id];
  359. }
  360. }
  361. }
  362. $diff_id_arr = array_diff($topicIds, array_keys($topicDetails));
  363. if ($diff_id_arr) {
  364. //todo 发送消息到补提
  365. echo json_encode(array("status" => 1, "error" => "没有试题内容!(" . implode(',', $diff_id_arr) . ")"));
  366. exit;
  367. }
  368. //1.薄弱考点统计
  369. //2.薄弱考点掌握较差学生名单
  370. //3.班级排名后25%学生的薄弱考点
  371. $pramas = array($smallTopicScore, $smallTopicNo, $paperId, $topicType, $topicLogicType, $topicRelLarge, $topicRelMethod, $largeTopicMethod, $sutName, $sutOrder, $methodName);
  372. // $methodCount = $this->getMethodCount($stuRs,$pramas);
  373. $methodCount = array();
  374. //4.考点掌握情况变化趋势
  375. //生成图片
  376. // if($subjectId == 8){
  377. if (false) {
  378. $_classRate = array();
  379. $thirdExam = $cepObj->getTirdExamIds($examId, $examInfo['subject_id'], $examInfo['class_id']);
  380. if (count($thirdExam) > 3) {
  381. $thirdExamIds = array();
  382. $examTime = array();
  383. foreach ($thirdExam as $value) {
  384. $thirdExamIds[] = $value['exam_id'];
  385. $examTime[$value['exam_id']] = $value['add_time'];
  386. }
  387. list($paperRelExam, $exmaRelPaper) = $paperObj->getPaperIdsByExamIds($thirdExamIds);
  388. $_topicScore = array();
  389. $_topicMethod = array();
  390. $_stuRs = array();
  391. if ($paperRelExam) {
  392. $thirdPaperInfo = $ptrObj->getPaperInfos($paperRelExam);
  393. foreach ($thirdPaperInfo as $item) {
  394. $_topicScore[$item['topic_id']] = $item['score'];
  395. $_topicMethod[$item['topic_id']] = explode(',', $item['method_ids']);
  396. }
  397. $_stuRs = $sptRsObj->getStudentRs($paperRelExam);
  398. }
  399. $_scoring = $_score = array();
  400. foreach ($_stuRs as $stuId => $stuR) {
  401. foreach ($stuR as $tId => $item) {
  402. $pId = $item['paper_id'];
  403. $eId = isset($exmaRelPaper[$pId]) ? $exmaRelPaper[$pId] : 0;
  404. $eTime = isset($examTime[$eId]) ? $examTime[$eId] : 0;
  405. if (!$eTime) continue;
  406. $_tScore = isset($_topicScore[$tId]) ? $_topicScore[$tId] : 0;
  407. if (isset($_topicMethod[$tId]) && $_topicMethod[$tId]) {
  408. foreach ($_topicMethod[$tId] as $mId) {
  409. if (!$mId) {
  410. continue;
  411. }
  412. if (!isset($_scoring[$eTime])) {
  413. $_scoring[$eTime] = array();
  414. }
  415. if (!isset($_scoring[$eTime][$mId])) {
  416. $_scoring[$eTime][$mId] = 0;
  417. }
  418. $_scoring[$eTime][$mId] += $item['scoring'];
  419. if (!isset($_score[$eTime])) {
  420. $_score[$eTime] = array();
  421. }
  422. if (!isset($_score[$eTime][$mId])) {
  423. $_score[$eTime][$mId] = 0;
  424. }
  425. $_score[$eTime][$mId] += $_tScore;
  426. }
  427. }
  428. }
  429. }
  430. foreach ($_scoring as $eTime => $scorings) {
  431. if (!isset($_classRate[$eTime])) {
  432. $_classRate[$eTime] = array();
  433. }
  434. foreach ($scorings as $mId => $scoring) {
  435. if (isset($_score[$eTime]) && isset($_score[$eTime][$mId]) && $_score[$eTime][$mId]) {
  436. $_classRate[$eTime][$mId] = round($scoring / $_score[$eTime][$mId], 4) * 100;
  437. } else {
  438. $_classRate[$eTime][$mId] = 0;
  439. }
  440. }
  441. }
  442. }
  443. ksort($_classRate);
  444. //三次考试同一考点的得分率
  445. $timeMethodRate = array();
  446. foreach ($_classRate as $time => $rates) {
  447. foreach ($rates as $mId => $rate) {
  448. if (!isset($timeMethodRate[$mId])) {
  449. $timeMethodRate[$mId] = array();
  450. }
  451. $timeMethodRate[$mId][] = $rate;
  452. $timeMethodRate[$mId][] = $rate;
  453. $timeMethodRate[$mId][] = $rate;
  454. }
  455. }
  456. //取出符合规则的三个考点
  457. $rateCompare = array();
  458. foreach ($timeMethodRate as $mId => $rates) {
  459. $rate_1 = $rates[2] - $rates[1];
  460. $rate_2 = $rates[1] - $rates[0];
  461. $rateCompare[$mId] = $rate_1 - $rate_2;
  462. }
  463. arsort($rateCompare);
  464. $rateCompare = array_slice($rateCompare, 0, 3, true);
  465. $timeMethodRate = array();
  466. foreach ($_classRate as $time => $rates) {
  467. foreach ($rates as $mId => $rate) {
  468. if (isset($rateCompare[$mId])) {
  469. if (!isset($timeMethodRate[$mId])) {
  470. $timeMethodRate[$mId] = array();
  471. }
  472. $timeMethodRate[$mId][] = $rate;
  473. }
  474. }
  475. }
  476. $imgPath = str_replace("protected", "", Yii::app()->basePath) . 'assets/temp_img/';
  477. $urlPath = Yii::app()->request->hostInfo . '/assets/temp_img/';
  478. $methodRatePath = $imgPath . $examId . "_rate.png";
  479. $methodRateUrl = $urlPath . $examId . "_rate.png";
  480. $this->imgArr[] = $methodRatePath;
  481. if (count($timeMethodRate) >= 3) {
  482. $this->getImage($methodRatePath, $timeMethodRate);
  483. }
  484. if (!file_exists($methodRatePath)) {
  485. // echo json_encode(array("status" => 1, "error" => "考点得分率图片未生成!"));
  486. // exit();
  487. $methodRateUrl = '';
  488. }
  489. } else {
  490. $methodRateUrl = '';
  491. }
  492. /**************************** 四、试卷讲评 ***********************************/
  493. //选择题
  494. $choinceIds = $this->getChoiceIds($topicType, $topicLogicType, $subjectId, $examInfo['tpl_index']);
  495. //试题年级和班级得分率,答对和答错人数
  496. $topicRateStu = $this->getTopicRateWrongPerson($stuRs, $topicScore, $paperId, $stuIdsArr, $topicRelLarge, $choinceIds, $sutName, $topicLogicType);
  497. $common_practice = array();
  498. $commonTopicDetail = array();
  499. if ($subjectId == 8) {
  500. $commonCheck = SProductSetting::model()->getCommonSetting($classId, $subjectId, 6);
  501. if ($commonCheck) {
  502. if ($examInfo['academicr_common_practice']) {
  503. $common_push_all_topics = array();
  504. $common_practice = json_decode($examInfo['academicr_common_practice'], true);
  505. foreach ($common_practice as $type => $cp_info) {
  506. if ($type == 'min_rate_text' || $type == 'common_extra') {
  507. $t_ids = _array_column($cp_info, 'topic_id');
  508. $common_push_all_topics = array_merge($common_push_all_topics, $t_ids);
  509. } else {
  510. foreach ($cp_info as $topic_type => $t_info) {
  511. $t_ids = _array_column($t_info, 'topic_id');
  512. $common_push_all_topics = array_merge($common_push_all_topics, $t_ids);
  513. }
  514. }
  515. }
  516. } else {
  517. //20211221新逻辑:学生提分宝不生成共性问题的话 教师讲案直接不生成
  518. echo json_encode(array("status" => 1, "error" => "共性题未生成!"));
  519. exit;
  520. $common_wrong_topic = $this->getCommonPractice($topicDetails, $topicRateStu['large_topic_score'], $stuRs, $largeTopicType, $topicRateStu['large_contain_score']);
  521. list($common_practice, $common_push_all_topics) = $common_wrong_topic;
  522. $sql = "update exam set academicr_common_practice = '" . json_encode($common_practice) . "' where exam_id={$examId}";
  523. $dbConn = Exam::model()->getDbConnection();
  524. $dbConn->createCommand($sql)->execute();
  525. }
  526. if ($common_push_all_topics) {
  527. $commonTopicDetail = $this->apiBrainPost('/topic/batchAll', array('topicIds' => array_values($common_push_all_topics), 'subjectId' => $batch_subject_id, 'params' => array('isNoReplaceLable' => 1)), 25, true);
  528. if (!$commonTopicDetail) {
  529. echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
  530. exit();
  531. } elseif (isset($commonTopicDetail['status']) && $commonTopicDetail['status'] == 0) {
  532. echo json_encode(array("status" => 1, "error" => $commonTopicDetail['error'][0]));
  533. exit();
  534. } else {
  535. $tempDetials = array();
  536. if ($examInfo['qxk_paper_id']) {
  537. $commonTopicDetail = $this->quanTopicDetail($commonTopicDetail);
  538. }
  539. foreach ($commonTopicDetail as $detail) {
  540. if (isset($getTopicTypeRelate[$detail['type_id']])) {
  541. $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']];
  542. }
  543. $tempDetials[(string)$detail['id']] = $detail;
  544. }
  545. $commonTopicDetail = $tempDetials;
  546. }
  547. }
  548. }
  549. }
  550. //echo 111;exit;
  551. $topicTypeScore = array();
  552. if ($subjectId == 8) {
  553. //题型重新按照组卷顺序排序
  554. $new_type_name_arr = array();
  555. $new_high_rate_wrong_topic = array();
  556. $new_class_rate = array();
  557. $new_type_order = array_keys($topicTypeRelNo);
  558. if ($new_type_order) {
  559. foreach ($new_type_order as $new_type) {
  560. if (isset($this->logicTypeName) && isset($this->logicTypeName[$new_type]) && $this->logicTypeName[$new_type]) {
  561. $new_type_name_arr[$new_type] = $this->logicTypeName[$new_type];
  562. } else {
  563. $new_type_name_arr[$new_type] = '';
  564. }
  565. if (isset($typeMasterData['high_rate_wrong_topic']) && $typeMasterData['high_rate_wrong_topic'] && isset($typeMasterData['high_rate_wrong_topic'][$new_type])) {
  566. $new_high_rate_wrong_topic[$new_type] = $typeMasterData['high_rate_wrong_topic'][$new_type];
  567. }
  568. if (isset($typeMasterData['class_rate']) && $typeMasterData['class_rate'] && isset($typeMasterData['class_rate'][$new_type])) {
  569. $new_class_rate[$new_type] = $typeMasterData['class_rate'][$new_type];
  570. }
  571. }
  572. }
  573. if ($new_type_name_arr) {
  574. $typeMasterData['type_name_arr'] = $new_type_name_arr;
  575. }
  576. if ($new_high_rate_wrong_topic) {
  577. $typeMasterData['high_rate_wrong_topic'] = $new_high_rate_wrong_topic;
  578. }
  579. if ($new_class_rate) {
  580. $typeMasterData['class_rate'] = $new_class_rate;
  581. }
  582. //获取题型对应题目关系
  583. $typeToTopicIds = array();
  584. if ($topicDetails) {
  585. foreach ($topicDetails as $topicIdTemp => $topicDetailTemp) {
  586. if (isset($topicDetailTemp['type_id']) && $topicDetailTemp['type_id']) {
  587. $typeToTopicIds[$topicDetailTemp['type_id']][] = (string)$topicIdTemp;
  588. }
  589. }
  590. }
  591. //增加班级题型得分表
  592. if ($topicTypeRelNo) {
  593. foreach ($topicTypeRelNo as $typeTemp => $topicNoDataTemp) {
  594. if ($topicNoDataTemp) {
  595. $topicTypeScore[$typeTemp]['score'] = 0;
  596. $topicTypeScore[$typeTemp]['class_score'] = 0;
  597. $topicTypeScore[$typeTemp]['grade_score'] = 0;
  598. $topicTypeScore[$typeTemp]['diff_score'] = 0;
  599. $topicTypeScore[$typeTemp]['no'] = '';
  600. $tempClassScore = $tempGradeScore = $tempClassCount = $tempGradeCount = 0;
  601. $tempClassStuIds = $tempGradeStuIds = array();
  602. if (isset($topicRateStu) && $topicRateStu && isset($topicRateStu['large_topic_score']) && $topicRateStu['large_topic_score']) {
  603. foreach ($topicRateStu['large_topic_score'] as $stuIdTemp => $stuScoreTemp) {
  604. foreach ($stuScoreTemp as $tempTopicIdK => $tempTopicIdV) {
  605. if (isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp] && in_array((string)$tempTopicIdK, $typeToTopicIds[$typeTemp], true)) {
  606. if (isset($sutName[$stuIdTemp])) {//本班
  607. $tempClassScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring'] : 0;
  608. // $tempClassCount ++;
  609. $tempClassStuIds[] = (string)$stuIdTemp;
  610. }
  611. $tempGradeScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring'] : 0;
  612. // $tempGradeCount ++;
  613. $tempGradeStuIds[] = (string)$stuIdTemp;
  614. }
  615. }
  616. }
  617. }
  618. if ($tempClassStuIds) {
  619. $tempClassCount = count(array_unique($tempClassStuIds));
  620. $topicTypeScore[$typeTemp]['class_score'] = round($tempClassScore / $tempClassCount, 1);
  621. }
  622. if ($tempGradeStuIds) {
  623. $tempGradeCount = count(array_unique($tempGradeStuIds));
  624. $topicTypeScore[$typeTemp]['grade_score'] = round($tempGradeScore / $tempGradeCount, 1);
  625. }
  626. $topicTypeScore[$typeTemp]['diff_score'] = round($topicTypeScore[$typeTemp]['class_score'] - $topicTypeScore[$typeTemp]['grade_score'], 1);
  627. if (isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp]) {
  628. foreach ($typeToTopicIds[$typeTemp] as $bigTopicTemp) {
  629. if (isset($largeTopicScore[$bigTopicTemp]) && $largeTopicScore[$bigTopicTemp]) {
  630. $topicTypeScore[$typeTemp]['score'] += $largeTopicScore[$bigTopicTemp];
  631. }
  632. }
  633. }
  634. $topicNoValue = array_values($topicNoDataTemp);
  635. if (count($topicNoValue) == 1) {
  636. $topicTypeScore[$typeTemp]['no'] = $topicNoValue[0];
  637. } else {
  638. $topicTypeScore[$typeTemp]['no'] = min($topicNoValue) . '-' . max($topicNoValue);
  639. }
  640. }
  641. }
  642. }
  643. }
  644. $data = array();
  645. $data['examInfo'] = $examInfo;
  646. $data['classAnalyData'] = $classAnalyData;
  647. $data['largeOrderData'] = $largeOrderData;
  648. // $data['examAnalyData'] = $examAnalyData;
  649. $data['typeMasterData'] = $typeMasterData;
  650. $data['typeRateImg'] = $typeRateImgUrl;
  651. $data['methodCount'] = $methodCount;
  652. $data['topicDetails'] = $topicDetails;
  653. $data['paperTopicNo'] = $topicNo;
  654. $data['smallTopicNo'] = $smallTopicNo;
  655. $data['topicTypeRelNo'] = $topicTypeRelNo;
  656. $data['topicRateStu'] = $topicRateStu;
  657. $data['methodRateUrl'] = $methodRateUrl;
  658. $data['subjectId'] = $subjectId;
  659. $data['isThird'] = $isThird;
  660. $data['sutName'] = $sutName;
  661. $data['methodName'] = $methodName;
  662. $data['logicTypeName'] = $this->logicTypeName;
  663. $data['topic_score'] = $largeTopicScore;
  664. $data['topic_rel_topic_count'] = $topicRelTopicCount;
  665. $data['common_practice'] = $common_practice;
  666. $data['common_topic_detail'] = $commonTopicDetail;
  667. $data['topicTypeScore'] = $topicTypeScore;
  668. //echo json_encode($data);exit;
  669. if ($subjectId == 8) {
  670. $html_name = 'en_teach';
  671. } else {
  672. $html_name = 'teach';
  673. }
  674. if ($viewHtml) {
  675. $this->renderPartial("teaching/{$html_name}", $data);
  676. exit();
  677. } else {
  678. $html = $this->renderPartial("teaching/{$html_name}", $data, true);
  679. }
  680. unset($data);
  681. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径
  682. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $this->schoolId . "/"; //存放生成的PDF路径
  683. $pdfurl = '/upload/tmpDir/academicr/' . $this->schoolId . "/";
  684. if (!is_dir($htmlpath)) {
  685. if (!mkdir($htmlpath, 0777, true)) {
  686. exit('Create directory fail: ' . $htmlpath);
  687. }
  688. }
  689. if (!is_dir($pdfpath)) {
  690. if (!mkdir($pdfpath, 0777, true)) {
  691. exit('Create directory fail1: ' . $pdfpath);
  692. }
  693. }
  694. $htmlpath .= $examId . ".html";
  695. $f = fopen($htmlpath, "w");
  696. fwrite($f, $html);
  697. fclose($f);
  698. $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
  699. if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
  700. $htmlurl = " http://local.zsyas2teaching.com" . '/' . $examId . '.html';
  701. $pdffname = $classId . "-" . $examId . ".pdf";
  702. $pdfpath = $pdfpath . $pdffname;
  703. $pdfurl = $pdfurl . $pdffname;
  704. $commond = Yii::app()->params['phantomjs'] . " "
  705. . Yii::app()->params['html2pdf'] . " "
  706. . " {$htmlurl}"
  707. . " {$pdfpath}"
  708. . " 176mm*250mm ''";
  709. } else {
  710. $server = Yii::app()->params['phantomjs_server'];
  711. $js = 'html2pdf.js';
  712. if ($subjectId == 8) {
  713. $server = Yii::app()->params['phantomjs_server_en'];
  714. $js = 'html2pdf_en.js';
  715. }
  716. $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  717. $pdffname = $classId . "-" . $examId . ".pdf";
  718. $pdfpath = $pdfpath . $pdffname;
  719. $pdfurl = $pdfurl . $pdffname;
  720. $commond = $server . " "
  721. . Yii::app()->basePath . '/../js/' . $js . " "
  722. . " {$htmlurl}"
  723. . " {$pdfpath}"
  724. . " 176mm*250mm ''";
  725. }
  726. exec($commond, $res, $code);
  727. //删除生成的图片
  728. $this->delCreateImgs();
  729. $ucloud = new Qcloud();
  730. //上传html
  731. $rehtml = $examId . ".html";
  732. $rehtmlname = 'zsyas2/math_academicr/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
  733. $uploadHtmlInfo = $ucloud->putFile($rehtmlname, $htmlpath);
  734. if ($uploadHtmlInfo['status'] == 0) {
  735. $html_url = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  736. } else {
  737. $html_url = $uploadHtmlInfo['url'];
  738. @unlink($htmlpath);
  739. }
  740. $this->sConn->createCommand()->update("exam", array("academicr_html_path" => $html_url), "exam_id = '{$examId}'");
  741. if (isset($res[0])) {
  742. $isBool = false;
  743. foreach ($res as $msg) {
  744. if (strpos($msg, 'succeed') !== false) {
  745. $isBool = true;
  746. }
  747. }
  748. if ($isBool) {//命令返回成功
  749. if (file_exists($pdfpath)) {
  750. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  751. $repdf = $examId . ".pdf";
  752. $rename = 'zsyas2/academicr/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
  753. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  754. if ($uploadInfo['status'] == 0) {
  755. $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
  756. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  757. // if($uploadInfo['msg']){
  758. // exit(json_encode(array("status" => 0, "error" => $uploadInfo['msg'])));
  759. // }else{
  760. // exit(json_encode(array("status" => 0, "error" => 'PDF文件上传失败')));
  761. // }
  762. //throw new CException("PDF文件上传失败");
  763. } else {
  764. $pdfurl = $uploadInfo['url'];
  765. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
  766. @unlink($pdfpath);
  767. }
  768. @unlink($htmlpath);
  769. } else {
  770. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  771. @unlink($htmlpath);
  772. echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
  773. exit;
  774. }
  775. } else {
  776. @unlink($htmlpath);
  777. echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
  778. exit;
  779. }
  780. } else {
  781. Curl::post(Yii::app()->params['handle_log_api'], array(
  782. "exam_group_id" => (string)$examGroupId,
  783. "operate_project" => 'zsyas2',
  784. "school_id" => $this->schoolId,
  785. "title" => '下载教师讲案',
  786. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  787. "operate_method" => $this->action,
  788. "operate_url" => $this->getRoute(),
  789. "operate_sql" => '',
  790. "operate_param" => json_encode(array('post' => array("examId" => $examId, "pdf" => array("commond" => $commond, "res" => $res, "code" => $code), "htmlurl" => $htmlurl))),
  791. ));
  792. echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
  793. exit;
  794. }
  795. }
  796. if (fileGetContents($pdfurl)) {
  797. // if ($this->check_pdf($pdfpath)) {
  798. echo json_encode(array("status" => 0, "error" => "", "is_create" => 1, 'exec_rs' => json_encode($res)));
  799. exit;
  800. } else {
  801. echo json_encode(array("status" => 1, "error" => "文件尚未生成!!", 'exec_rs' => json_encode($res)));
  802. exit;
  803. }
  804. }
  805. //替换序号
  806. private function replaceTitle(&$title, $topicId, $topicRelLarge, $smallTopicNo)
  807. {
  808. // $str = '<img src="http://zsytk2.zhixinhuixue.com/static/images/4.gif" _src="http://zsytk2.zhixinhuixue.com/static/images/4.gif" class="tiankong" data-num="3">';
  809. $topicNoArr = array();
  810. foreach ($topicRelLarge as $small_id => $large_id) {
  811. if ($topicId == $large_id && isset($smallTopicNo[$small_id])) {
  812. $topicNoArr[] = $smallTopicNo[$small_id];
  813. }
  814. }
  815. $imgArr = array();
  816. $pattern = "/<img[\s\S]*?src\s*=\s*[\"|\'](.*?)[\"|\'][\s\S]*?>/";
  817. preg_match_all($pattern, $title, $match);
  818. if (isset($match[0]) && $match[0]) {
  819. foreach ($match[0] as $img) {
  820. $pattern = "/data-num=[\"|\'](\d{0,2})[\"|\']/";
  821. preg_match_all($pattern, $img, $match);
  822. if (isset($match[0]) && isset($match[1]) && isset($match[1][0])) {
  823. $imgArr[$match[1][0]] = $img;
  824. }
  825. }
  826. }
  827. if (count($imgArr) == count($topicNoArr)) {
  828. asort($topicNoArr);
  829. $searchArr = $replaceArr = array();
  830. foreach ($topicNoArr as $key => $no) {
  831. $searchArr[] = isset($imgArr[$key]) ? $imgArr[$key] : '';
  832. $replaceArr[] = ' (' . $no . ') ';
  833. }
  834. $title = str_replace($searchArr, $replaceArr, $title);
  835. }
  836. }
  837. /**
  838. * 精品范文
  839. * @return array
  840. */
  841. public function getFineArticle($examId, $topicLogicType)
  842. {
  843. $fineArticle = array();
  844. $studentModelEssay = new SStudentModelEssay();
  845. $stuRsIds = $studentModelEssay->getStuRsId($examId);
  846. if (!$stuRsIds) {
  847. return $fineArticle;
  848. }
  849. $sptr = new SStudentPaperTopicRs();
  850. $rsInfo = $sptr->getStuRsByIds($stuRsIds);
  851. if ($rsInfo) {
  852. foreach ($rsInfo as $v) {
  853. $id = $v['id'];
  854. $ansUrl = $v['answer_trace'];
  855. $topic_id = $v['topic_id'];
  856. $type = isset($topicLogicType[$topic_id]) ? $topicLogicType[$topic_id] : 0;
  857. if (!$ansUrl) {
  858. $ansUrl = $v['simplify_answer_url'];
  859. }
  860. if (!$ansUrl) {
  861. $ansUrl = $v['answer_url'];
  862. }
  863. $ansUrl = answer_process($this->domainUrl, $ansUrl);
  864. if (!isset($fineArticle[$type])) {
  865. $fineArticle[$type] = array();
  866. }
  867. if ($v['answer_url']) {
  868. $fineArticle[$type][$id] = $ansUrl;
  869. } else {
  870. $fineArticle[$type][$id] = '';
  871. }
  872. }
  873. }
  874. return $fineArticle;
  875. }
  876. //获取词汇
  877. private function getWord($condition)
  878. {
  879. $wordsInfo = array();
  880. // $params = array(
  881. // '_id' => array('$in' => array_values($word_ids))
  882. // );
  883. //
  884. // return IspMongo::selectMongo('english_single',$params);
  885. $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition' => $condition, 'table' => 'en_single_word', 'isAll' => 1), 25, true);
  886. if (isset($rs['status']) && $rs['status'] == 1 && isset($rs['data']) && $rs['data']) {
  887. foreach ($rs['data'] as $v) {
  888. $wordsInfo[$v['single_word_id']] = $v;
  889. }
  890. }
  891. return $wordsInfo;
  892. }
  893. private function check_pdf($pdf_path)
  894. {
  895. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  896. if (file_exists($pdf_path)) {
  897. return true;
  898. }
  899. }
  900. return false;
  901. }
  902. /**
  903. * 班级排名得分率人数等数据
  904. * @param $examId
  905. * @param $ptrInfo
  906. * @param $paperScore
  907. * @param $preExamId
  908. * @param $prePtrInfo
  909. * @param $prePaperScore
  910. * @return array
  911. */
  912. private function getClassAnalyse($examId, &$ptrInfo, $paperScore, $preExamId, &$prePtrInfo, $prePaperScore, &$stuIdsArr, &$preStuIdsArr)
  913. {
  914. $result = array();
  915. $gradePerson = $classPerson = 0;//参考人数
  916. $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数
  917. $gradeOrder = $classOrder = 0; //排名
  918. $gradeAvgScore = $classAvgScore = 0; //平均分
  919. $gradeScoreRate = $classScoreRate = 0; //得分率
  920. $gradeFineRate = $classFineRate = 0; //优秀率 80%
  921. $gradePassRate = $classPassRate = 0; //合格率 60%
  922. $gradeLowRate = $classLowRate = 0; //低分率 30%
  923. $angData = array(
  924. 'class_num' => 0,//班级数量
  925. 'order' => 0,
  926. 'absent_person' => 0,
  927. 'exam_person' => 0,
  928. 'avg_score' => 0,
  929. 'score_rate' => 0,
  930. 'fine_rate' => 0,
  931. 'pass_rate' => 0,
  932. 'low_rate' => 0,
  933. );
  934. $result['grade'] = $result['class'] = $angData;
  935. $gradeScoring = $classScoring = array();
  936. $gradeScoringSum = array();//年级中每个考试的得分和
  937. // $classScoringSum = 0;//考试得分和
  938. $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率
  939. foreach ($ptrInfo as $value) {
  940. $stuIds = isset($stuIdsArr[$value['exam_id']]) ? $stuIdsArr[$value['exam_id']] : array();
  941. if (!isset($gradeScoringSum[$value['exam_id']])) {
  942. $gradeScoringSum[$value['exam_id']] = 0;
  943. }
  944. if (inArray($value['student_id'], $stuIds)) {
  945. $gradeScoringSum[$value['exam_id']] += $value['scoring'];
  946. $gradeScoring[] = $value['scoring'];
  947. $gradeStuScoringRate[] = round($value['scoring'] / $paperScore, 4) * 100;
  948. $gradePerson++;
  949. }
  950. if (!inArray($value['student_id'], $stuIds)) {
  951. $gradeAbsentPerson++;
  952. }
  953. // if($examId == $value['exam_id']){
  954. if (strcmp($examId, $value['exam_id']) == 0) {
  955. if (inArray($value['student_id'], $stuIds)) {
  956. // $classScoringSum += $value['scoring'];
  957. $classScoring[] = $value['scoring'];
  958. $classStuScoringRate[] = round($value['scoring'] / $paperScore, 4) * 100;
  959. $classPerson++;
  960. }
  961. if (!inArray($value['student_id'], $stuIds)) {
  962. $classAbsentPerson++;
  963. }
  964. }
  965. }
  966. unset($ptrInfo);
  967. $result['class']['class_num'] = count($gradeScoringSum);
  968. $result['grade']['exam_person'] = $gradePerson;
  969. $result['grade']['absent_person'] = $gradeAbsentPerson;
  970. $result['class']['exam_person'] = $classPerson;
  971. $result['class']['absent_person'] = $classAbsentPerson;
  972. //排名
  973. if ($gradeScoringSum) {
  974. $scoringArr = array();
  975. foreach ($gradeScoringSum as $eId => $scoring) {
  976. $stuCount = isset($stuIdsArr[$eId]) ? count($stuIdsArr[$eId]) : 0;
  977. if ($stuCount) {
  978. $scoringArr[$eId] = round($scoring / $stuCount, 2);
  979. }
  980. }
  981. if (isset($scoringArr[$examId])) {
  982. $classOrder = $this->getOrder($scoringArr[$examId], $scoringArr);
  983. } else {
  984. $classOrder = 0;
  985. }
  986. }
  987. $result['class']['order'] = $classOrder;
  988. //平均分,得分率
  989. $count = count($gradeScoring);
  990. if ($count > 0) {
  991. $gradeAvgScore = round(array_sum($gradeScoring) / $count, 2);//平均分
  992. $gradeScoreRate = round(array_sum($gradeScoring) / ($paperScore * $count), 4) * 100;//得分率
  993. } else {
  994. $gradeAvgScore = 0;
  995. $gradeScoreRate = 0;
  996. }
  997. $result['grade']['avg_score'] = $gradeAvgScore;
  998. $result['grade']['score_rate'] = $gradeScoreRate;
  999. $count = count($classScoring);
  1000. if ($count > 0) {
  1001. $classAvgScore = round(array_sum($classScoring) / $count, 2);
  1002. $classScoreRate = round(array_sum($classScoring) / ($paperScore * $count), 4) * 100;//得分率
  1003. } else {
  1004. $classAvgScore = 0;
  1005. $classScoreRate = 0;
  1006. }
  1007. $result['class']['avg_score'] = $classAvgScore;
  1008. $result['class']['score_rate'] = $classScoreRate;
  1009. //优秀率,合格率,低分率
  1010. // $gradeFineRate = $classFineRate = 0; //优秀率 85%
  1011. // $gradePassRate = $classPassRate = 0; //合格率 60%
  1012. // $gradeLowRate = $classLowRate = 0; //低分率 30%
  1013. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  1014. $rateCount = count($gradeStuScoringRate);
  1015. foreach ($gradeStuScoringRate as $scoringRate) {
  1016. if ($scoringRate >= 85) {
  1017. $tempFineNum++;
  1018. }
  1019. if ($scoringRate >= 60) {
  1020. $tempPassNum++;
  1021. }
  1022. if ($scoringRate <= 30) {
  1023. $tempLowNum++;
  1024. }
  1025. }
  1026. $gradeFineRate = round($tempFineNum / $rateCount, 4) * 100;
  1027. $gradePassRate = round($tempPassNum / $rateCount, 4) * 100;
  1028. $gradeLowRate = round($tempLowNum / $rateCount, 4) * 100;
  1029. $result['grade']['fine_rate'] = $gradeFineRate;
  1030. $result['grade']['pass_rate'] = $gradePassRate;
  1031. $result['grade']['low_rate'] = $gradeLowRate;
  1032. $tempFineNum = $tempPassNum = $tempLowNum = 0;
  1033. $rateCount = count($classStuScoringRate);
  1034. foreach ($classStuScoringRate as $scoringRate) {
  1035. if ($scoringRate >= 85) {
  1036. $tempFineNum++;
  1037. }
  1038. if ($scoringRate >= 60) {
  1039. $tempPassNum++;
  1040. }
  1041. if ($scoringRate <= 30) {
  1042. $tempLowNum++;
  1043. }
  1044. }
  1045. if ($rateCount) {
  1046. $classFineRate = round($tempFineNum / $rateCount, 4) * 100;
  1047. $classPassRate = round($tempPassNum / $rateCount, 4) * 100;
  1048. $classLowRate = round($tempLowNum / $rateCount, 4) * 100;
  1049. } else {
  1050. $classFineRate = 0;
  1051. $classPassRate = 0;
  1052. $classLowRate = 0;
  1053. }
  1054. $result['class']['fine_rate'] = $classFineRate;
  1055. $result['class']['pass_rate'] = $classPassRate;
  1056. $result['class']['low_rate'] = $classLowRate;
  1057. /**************** 提升数据 ******************/
  1058. $result['class']['order_increase'] = 0;
  1059. $result['class']['rate_increase'] = 0;
  1060. $result['class']['fine_rate_increase'] = 0;
  1061. if ($prePtrInfo) {
  1062. $preClassStuScoringRate = array();
  1063. $preGradeScoringSum = array();
  1064. $preClassScoringSum = 0;
  1065. $preClassScoring = array();
  1066. if ($prePtrInfo) {
  1067. foreach ($prePtrInfo as $value) {
  1068. $stuIds = isset($preStuIdsArr[$value['exam_id']]) ? $preStuIdsArr[$value['exam_id']] : array();
  1069. if (!isset($preGradeScoringSum[$value['exam_id']])) {
  1070. $preGradeScoringSum[$value['exam_id']] = 0;
  1071. }
  1072. if (inArray($value['student_id'], $stuIds)) {
  1073. $preGradeScoringSum[$value['exam_id']] += $value['scoring'];
  1074. }
  1075. // if($preExamId == $value['exam_id']){
  1076. if (strcmp($preExamId, $value['exam_id']) == 0) {
  1077. if (inArray($value['student_id'], $stuIds)) {
  1078. $preClassScoringSum += $value['scoring'];
  1079. $preClassScoring[] = $value['scoring'];
  1080. $preClassStuScoringRate[] = round($value['scoring'] / $prePaperScore, 4) * 100;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. //上一次考试排名
  1086. if ($gradeScoringSum) {
  1087. $scoringArr = array();
  1088. foreach ($preGradeScoringSum as $eId => $scoring) {
  1089. $stuCount = isset($preStuIdsArr[$eId]) ? count($preStuIdsArr[$eId]) : 0;
  1090. if ($stuCount) {
  1091. $scoringArr[$eId] = round($scoring / $stuCount, 2);
  1092. }
  1093. }
  1094. if (isset($scoringArr[$preExamId])) {
  1095. $preClassOrder = $this->getOrder($scoringArr[$preExamId], $scoringArr);
  1096. } else {
  1097. $preClassOrder = 0;
  1098. }
  1099. $result['class']['order_increase'] = -($classOrder - $preClassOrder);
  1100. }
  1101. $count = count($preClassScoring);
  1102. if ($count > 0) {
  1103. $preClassScoreRate = round(array_sum($preClassScoring) / ($prePaperScore * $count), 4) * 100;//得分率
  1104. $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate;
  1105. }
  1106. $tempFineNum = 0;
  1107. $rateCount = count($preClassStuScoringRate);
  1108. foreach ($preClassStuScoringRate as $scoringRate) {
  1109. if ($scoringRate >= 85) {
  1110. $tempFineNum++;
  1111. }
  1112. }
  1113. if ($rateCount) {
  1114. $preClassFineRate = round($tempFineNum / $rateCount, 4) * 100;
  1115. } else {
  1116. $preClassFineRate = 0;
  1117. }
  1118. $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate;
  1119. }
  1120. return $result;
  1121. }
  1122. /**
  1123. * 大幅进步,大幅退步,前5名和后5名
  1124. * @param $examId
  1125. * @param $ptrInfo
  1126. * @param $paperScore
  1127. * @param $preExamId
  1128. * @param $prePtrInfo
  1129. * @param $prePaperScore
  1130. */
  1131. private function getLargeOrder($examId, &$ptrInfo, $preExamId, &$prePtrInfo, &$stuIdsArr, &$preStuIdsArr)
  1132. {
  1133. $result = array();
  1134. $stuOrderArr = $this->getStudentOrder($examId, $ptrInfo, $stuIdsArr);
  1135. $diffNum = ceil(count($stuOrderArr) * 0.2);
  1136. if ($prePtrInfo) {
  1137. $preStuOrderArr = $this->getStudentOrder($preExamId, $prePtrInfo, $preStuIdsArr);
  1138. } else {
  1139. $preStuOrderArr = array();
  1140. }
  1141. if ($preStuOrderArr) {
  1142. $interOrderArr = array_intersect_key($stuOrderArr, $preStuOrderArr);
  1143. if (!$interOrderArr) {
  1144. $interOrderArr = $stuOrderArr;
  1145. }
  1146. } else {
  1147. $interOrderArr = array();
  1148. }
  1149. //大幅进步,退步
  1150. $increaseArr = $reduceArr = array();
  1151. $stuDiffOrder = array();
  1152. if ($interOrderArr) {
  1153. foreach ($stuOrderArr as $stuId => $order) {
  1154. if (isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])) {
  1155. $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]);
  1156. } else {
  1157. $stuDiffOrder[$stuId] = 0;
  1158. }
  1159. }
  1160. arsort($stuDiffOrder);
  1161. foreach ($stuDiffOrder as $stuId => $num) {
  1162. if ($num >= $diffNum) {
  1163. $increaseArr[] = $stuId;
  1164. }
  1165. }
  1166. $increaseArr = array_slice($increaseArr, 0, 5, true);
  1167. asort($stuDiffOrder);
  1168. foreach ($stuDiffOrder as $stuId => $num) {
  1169. if ($num <= -$diffNum) {
  1170. $reduceArr[] = $stuId;
  1171. }
  1172. }
  1173. $reduceArr = array_slice($reduceArr, 0, 5, true);
  1174. } else {
  1175. $increaseArr = array_slice($stuOrderArr, 0, 5, true);
  1176. $reduceArr = array();
  1177. }
  1178. $result['stu_diff_order'] = $stuDiffOrder;
  1179. $result['stu_order'] = $stuOrderArr;
  1180. $result['increase_stu'] = $increaseArr;
  1181. $result['reduce_stu'] = $reduceArr;
  1182. //前5名和后5名
  1183. $font5 = $back5 = array();
  1184. $i = 1;
  1185. $fonrt5_order = array();
  1186. foreach ($stuOrderArr as $stuId => $order) {
  1187. if ($i <= 5) {
  1188. $font5[] = $stuId;
  1189. $fonrt5_order[] = $order;
  1190. } else {
  1191. break;
  1192. }
  1193. $i++;
  1194. }
  1195. $result['font_five'] = $font5;
  1196. $i = 1;
  1197. //删除前5排名
  1198. $_stuOrderArr = $stuOrderArr;
  1199. foreach ($_stuOrderArr as $k => $order) {
  1200. if (in_array($order, $fonrt5_order)) {
  1201. unset($_stuOrderArr[$k]);
  1202. }
  1203. }
  1204. arsort($_stuOrderArr);
  1205. foreach ($_stuOrderArr as $stuId => $order) {
  1206. if ($i <= 5) {
  1207. $back5[] = $stuId;
  1208. } else {
  1209. break;
  1210. }
  1211. $i++;
  1212. }
  1213. $result['back_five'] = $back5;
  1214. //学生名称
  1215. $stuInfoObj = new SStudentInfo();
  1216. $stuName = $stuInfoObj->getStudentNames(array_keys($stuOrderArr));
  1217. $result['stu_name'] = $stuName;
  1218. unset($stuOrderArr);
  1219. return $result;
  1220. }
  1221. /**
  1222. * 考试情况分析
  1223. * @param $stuRs
  1224. * @param $topicScore
  1225. * @param $topicNo
  1226. * @return array
  1227. */
  1228. private function getExamAnalyse(&$stuRs, $paperTopicScore, $topicNo, $paperId, $topicRelLarge)
  1229. {
  1230. $result = array();
  1231. $stuTopicWrong = array();//题答错人数
  1232. $topicScoreRate = array();//题得分率
  1233. $topicScoring = array();//题得分
  1234. $topicScore = array();//题分
  1235. foreach ($stuRs as $stuId => $rs) {
  1236. foreach ($rs as $v) {
  1237. // if($paperId == $v['paper_id']){
  1238. if (strcmp($paperId, $v['paper_id']) == 0) {
  1239. if (isset($topicRelLarge[$v['topic_id']]) && $topicRelLarge[$v['topic_id']] > 0) {
  1240. $t_id = $topicRelLarge[$v['topic_id']];
  1241. } else {
  1242. $t_id = $v['topic_id'];
  1243. }
  1244. $t_score = isset($paperTopicScore[$t_id]) ? $paperTopicScore[$t_id] : 0;
  1245. if (!isset($topicScoring[$t_id])) {
  1246. $topicScoring[$t_id] = 0;
  1247. }
  1248. $topicScoring[$t_id] += $v['scoring'];
  1249. if (!isset($topicScore[$t_id])) {
  1250. $topicScore[$t_id] = 0;
  1251. }
  1252. $topicScore[$t_id] += $t_score;
  1253. if (!isset($stuTopicWrong[$t_id])) {
  1254. $stuTopicWrong[$t_id] = array();
  1255. }
  1256. if ($t_score != $v['scoring']) {
  1257. $stuTopicWrong[$t_id][] = $stuId;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. //题得分率
  1263. foreach ($topicScoring as $topicId => $scoring) {
  1264. if (isset($topicScore[$topicId]) && $topicScore[$topicId] > 0) {
  1265. $topicScoreRate[$topicId] = round($scoring / $topicScore[$topicId], 4) * 100;
  1266. } else {
  1267. $topicScoreRate[$topicId] = 0;
  1268. }
  1269. }
  1270. unset($topicScoring);
  1271. //答错人数
  1272. if ($stuTopicWrong) {
  1273. foreach ($stuTopicWrong as $key => $stuIds) {
  1274. $stuIds = array_unique($stuIds);
  1275. $stuTopicWrong[$key] = count($stuIds);
  1276. }
  1277. }
  1278. $result['stu_topic_wrong'] = $stuTopicWrong;
  1279. $result['topic_score_rate'] = $topicScoreRate;
  1280. $result['topic_no'] = $topicNo;
  1281. unset($stuTopicWrong);
  1282. unset($topicScoreRate);
  1283. unset($topicNo);
  1284. unset($topicScore);
  1285. return $result;
  1286. }
  1287. //题类型掌握情况
  1288. private function getTopicTypeAnaly(&$stuRs, $topicScore, $topicNo, $paperId, $topicLogicType, $topicRelLarge, $smallTopicNo)
  1289. {
  1290. $result = array();
  1291. $getTopicTypeRelate = $this->getTopicTypeRelate();
  1292. $gradeRate = $classRate = array();//班级和年级得分率
  1293. $stuTypeWrong = array();//题型答错人数
  1294. $typeTopicNo = array();//题型对应的题号
  1295. $typeMasterDegree = array();//题型掌握水平
  1296. $typeName = $this->typeName;
  1297. $logicTypeName = $this->logicTypeName;
  1298. $gradeScoreArr = $classScoreArr = array();
  1299. $gradeScoring = $classScoring = array();
  1300. $_gradeScore = $_classScore = array();
  1301. $_gradeScoring = $_classScoring = array();
  1302. $typeNameArr = array();
  1303. $allClassScore = $allClassScoring = array();
  1304. $paperScoreSum = array();
  1305. //优化strcmp($paperId ,$value['paper_id']) == 0
  1306. $paperIndexArr = array();
  1307. foreach ($stuRs as $stuId => $rs) {
  1308. foreach ($rs as $value) {
  1309. $paperIndexArr[$value['paper_id']] = 0;
  1310. }
  1311. }
  1312. if ($paperIndexArr) {
  1313. $paperIndexArr = array_keys($paperIndexArr);
  1314. $paperIndexArr = array_flip($paperIndexArr);
  1315. }
  1316. //当前paper_id的索引
  1317. $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false;
  1318. foreach ($stuRs as $stuId => $rs) {
  1319. foreach ($rs as $k => $value) {
  1320. $tId = $value['topic_id'];
  1321. $t_score = isset($topicScore[$value['topic_id']]) ? $topicScore[$value['topic_id']] : 0;
  1322. if (isset($topicLogicType[$value['topic_id']]) && $topicLogicType[$value['topic_id']] > 0) {
  1323. $type = $topicLogicType[$value['topic_id']];
  1324. if ($this->subjectId == 9) {
  1325. $typeArr = explode('_', $type);
  1326. if (count($typeArr) > 1) {
  1327. $type = $typeArr[0];
  1328. }
  1329. }
  1330. if ($this->subjectId == 8) {
  1331. if (isset($getTopicTypeRelate[$type])) {
  1332. $type = $getTopicTypeRelate[$type];
  1333. }
  1334. }
  1335. $typeNameArr[$type] = isset($logicTypeName[$type]) ? $logicTypeName[$type] : '';
  1336. } else {
  1337. $type = $value['type'];
  1338. $typeNameArr[$type] = isset($typeName[$type]) ? $typeName[$type] : '';
  1339. }
  1340. if (!isset($gradeScoring[$type])) {
  1341. $gradeScoring[$type] = array();
  1342. }
  1343. $gradeScoring[$type][] = $value['scoring'];
  1344. if (!isset($gradeScoreArr[$type])) {
  1345. $gradeScoreArr[$type] = 0;
  1346. }
  1347. $gradeScoreArr[$type] += $t_score;
  1348. if (!isset($_gradeScoring[$tId])) {
  1349. $_gradeScoring[$tId] = 0;
  1350. }
  1351. $_gradeScoring[$tId] += $value['scoring'];
  1352. if (!isset($_gradeScore[$tId])) {
  1353. $_gradeScore[$tId] = 0;
  1354. }
  1355. $_gradeScore[$tId] += $t_score;
  1356. //当前班级
  1357. // if(strcmp($paperId ,$value['paper_id']) == 0){
  1358. if (isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex) {
  1359. if (!isset($classScoring[$type])) {
  1360. $classScoring[$type] = 0;
  1361. }
  1362. $classScoring[$type] += $value['scoring'];
  1363. if (!isset($classScoreArr[$type])) {
  1364. $classScoreArr[$type] = 0;
  1365. }
  1366. $classScoreArr[$type] += $t_score;
  1367. if (!isset($stuTypeWrong[$type])) {
  1368. $stuTypeWrong[$type] = array();
  1369. }
  1370. if (!isset($stuTypeWrong[$type][$stuId])) {
  1371. $stuTypeWrong[$type][$stuId] = array(
  1372. 'scoring' => 0,
  1373. 'score' => 0,
  1374. );
  1375. }
  1376. $stuTypeWrong[$type][$stuId]['scoring'] += $value['scoring'];
  1377. $stuTypeWrong[$type][$stuId]['score'] += $t_score;
  1378. if (!isset($typeTopicNo[$type])) {
  1379. $typeTopicNo[$type] = array();
  1380. }
  1381. //小题得分率
  1382. if (!isset($_classScoring[$tId])) {
  1383. $_classScoring[$tId] = 0;
  1384. }
  1385. $_classScoring[$tId] += $value['scoring'];
  1386. if (!isset($_classScore[$tId])) {
  1387. $_classScore[$tId] = 0;
  1388. }
  1389. $_classScore[$tId] += $t_score;
  1390. if (!isset($typeTopicNo[$type])) {
  1391. $typeTopicNo[$type] = array();
  1392. }
  1393. // if(isset($topicNo[$value['topic_id']])){
  1394. // $typeTopicNo[$type][] = $topicNo[$value['topic_id']];
  1395. // }
  1396. }
  1397. //所以班级
  1398. $pId = $value['paper_id'];
  1399. if (!isset($allClassScoring[$pId])) {
  1400. $allClassScoring[$pId] = array();
  1401. }
  1402. if (!isset($allClassScoring[$pId][$type])) {
  1403. $allClassScoring[$pId][$type] = 0;
  1404. }
  1405. $allClassScoring[$pId][$type] += $value['scoring'];
  1406. if (!isset($allClassScore[$pId])) {
  1407. $allClassScore[$pId] = array();
  1408. }
  1409. if (!isset($allClassScore[$pId][$type])) {
  1410. $allClassScore[$pId][$type] = 0;
  1411. }
  1412. $allClassScore[$pId][$type] += $t_score;
  1413. if (!isset($paperScoreSum[$pId])) {
  1414. $paperScoreSum[$pId] = 0;
  1415. }
  1416. $paperScoreSum[$pId] += $t_score;
  1417. }
  1418. }
  1419. //年级得分率
  1420. foreach ($gradeScoring as $type => $scorings) {
  1421. if (isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]) {
  1422. $gradeRate[$type] = round(array_sum($scorings) / $gradeScoreArr[$type], 2) * 100;
  1423. } else {
  1424. $gradeRate[$type] = 0;
  1425. }
  1426. }
  1427. //班级得分率
  1428. foreach ($classScoring as $type => $scoring) {
  1429. if (isset($classScoreArr[$type]) && $classScoreArr[$type] > 0) {
  1430. $classRate[$type] = round($scoring / $classScoreArr[$type], 2) * 100;
  1431. } else {
  1432. $classRate[$type] = 0;
  1433. }
  1434. }
  1435. //小题
  1436. //年级得分率
  1437. $_gradeRate = array();
  1438. foreach ($_gradeScoring as $tId => $scoring) {
  1439. if (isset($_gradeScore[$tId]) && $_gradeScore[$tId]) {
  1440. $_gradeRate[$tId] = round($scoring / $_gradeScore[$tId], 2) * 100;
  1441. } else {
  1442. $_gradeRate[$tId] = 0;
  1443. }
  1444. }
  1445. //班级得分率
  1446. $_classRate = array();
  1447. foreach ($_classScoring as $tId => $scoring) {
  1448. if (isset($_classScore[$tId]) && $_classScore[$tId] > 0) {
  1449. $_classRate[$tId] = round($scoring / $_classScore[$tId], 2) * 100;
  1450. } else {
  1451. $_classRate[$tId] = 0;
  1452. }
  1453. }
  1454. //题型对应题号排序
  1455. foreach ($typeTopicNo as $type => $nos) {
  1456. asort($nos);
  1457. $typeTopicNo[$type] = array_unique($nos);
  1458. }
  1459. //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。
  1460. foreach ($classRate as $type => $rate) {
  1461. if ($rate >= 85) {
  1462. $typeMasterDegree[$type] = 5;
  1463. } elseif ($rate < 85 && $rate >= 75) {
  1464. $typeMasterDegree[$type] = 4;
  1465. } elseif ($rate < 75 && $rate >= 65) {
  1466. $typeMasterDegree[$type] = 3;
  1467. } elseif ($rate < 65 && $rate >= 55) {
  1468. $typeMasterDegree[$type] = 2;
  1469. } else {
  1470. $typeMasterDegree[$type] = 1;
  1471. }
  1472. }
  1473. //所有班级得分率
  1474. $allClassRate = array();
  1475. foreach ($allClassScoring as $pId => $scoringArr) {
  1476. foreach ($scoringArr as $type => $scoring) {
  1477. if (isset($allClassScore[$pId]) && isset($allClassScore[$pId][$type]) && $allClassScore[$pId][$type] > 0) {
  1478. $allClassRate[$pId][$type] = round($scoring / $allClassScore[$pId][$type], 4) * 100;
  1479. } else {
  1480. $allClassRate[$pId][$type] = 0;
  1481. }
  1482. }
  1483. }
  1484. //班级题型/试卷总分
  1485. $typePaperRate = array();
  1486. foreach ($allClassScoring as $pId => $scoringArr) {
  1487. foreach ($scoringArr as $type => $scoring) {
  1488. $paperScore = isset($paperScoreSum[$pId]) ? $paperScoreSum[$pId] : 0;
  1489. if ($paperScore > 0) {
  1490. $typePaperRate[$pId][$type] = round($scoring / $paperScore, 4) * 100;
  1491. } else {
  1492. $typePaperRate[$pId][$type] = 0;
  1493. }
  1494. }
  1495. }
  1496. //题型答错人数
  1497. foreach ($stuTypeWrong as $type => $stuScore) {
  1498. $wrongNum = 0;
  1499. foreach ($stuScore as $stuId => $score) {
  1500. if ($score['score'] != $score['scoring']) {
  1501. $wrongNum++;
  1502. }
  1503. }
  1504. $stuTypeWrong[$type] = $wrongNum;
  1505. }
  1506. $result['class_rate'] = $classRate;
  1507. $result['grade_rate'] = $gradeRate;
  1508. $result['all_class_rate'] = $allClassRate;
  1509. $result['type_paper_rate'] = $typePaperRate;
  1510. $result['stu_type_wrong'] = $stuTypeWrong;
  1511. $result['type_topic_no'] = $typeTopicNo;
  1512. $result['type_master_degree'] = $typeMasterDegree;
  1513. $result['type_name_arr'] = $typeNameArr;
  1514. $result['topic_grade_rate'] = $_gradeRate;
  1515. $result['topic_class_rate'] = $_classRate;
  1516. return $result;
  1517. }
  1518. /**
  1519. * 试题年级和班级得分率,答对和答错人数
  1520. * @param $stuRs
  1521. * @param $topicScore
  1522. * @param $paperId
  1523. * @return array
  1524. */
  1525. public function getTopicRateWrongPerson(&$stuRs, $topicScore, $paperId, &$stuIdsArr, $topicRelLarge, $choinceIds, $sutName, $topicLogicType)
  1526. {
  1527. $gradeRate = $classRate = array();//班级和年级得分率
  1528. $wrongStu = $rightStu = array();//答对答错人数
  1529. $isChoiceTopic = array();
  1530. $stuNormalIds = array();
  1531. foreach ($stuIdsArr as $stuIds) {
  1532. foreach ($stuIds as $stuId) {
  1533. $stuNormalIds[$stuId] = 0;
  1534. }
  1535. }
  1536. $gradeScoring = $classScoring = array();
  1537. $gradeScore = $classScore = array();
  1538. $doneTopicNum = array();//每题做题总人数
  1539. $stuScoring = $stuScore = array();
  1540. $classTopicScoring = array();//班级题得分
  1541. $choiceTopicWrong = array();//单选题答错统计
  1542. $stuLargeTopicScore = array();//学生大题得分统计
  1543. $largeContainScore = array();
  1544. $readingTopicIds = array();
  1545. $readingWrongStu = array();
  1546. //优化strcmp($paperId ,$value['paper_id']) == 0
  1547. $paperIndexArr = array();
  1548. foreach ($stuRs as $stuId => $rs) {
  1549. foreach ($rs as $value) {
  1550. $paperIndexArr[$value['paper_id']] = 0;
  1551. }
  1552. }
  1553. if ($paperIndexArr) {
  1554. $paperIndexArr = array_keys($paperIndexArr);
  1555. $paperIndexArr = array_flip($paperIndexArr);
  1556. }
  1557. //当前paper_id的索引
  1558. $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false;
  1559. //阅读理解选项显示答错学生姓名
  1560. foreach ($topicLogicType as $tId => $logicType) {
  1561. if ($logicType == 3 || $logicType == 42) {
  1562. $readingTopicIds[] = $tId;
  1563. }
  1564. }
  1565. foreach ($stuRs as $stuId => $rs) {
  1566. if (!isset($stuNormalIds[$stuId])) {
  1567. continue;
  1568. }
  1569. foreach ($rs as $k => $value) {
  1570. if (isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0) {
  1571. $t_id = $topicRelLarge[$value['topic_id']];
  1572. } else {
  1573. $t_id = $value['topic_id'];
  1574. }
  1575. if (!isset($largeContainScore[$t_id])) {
  1576. $largeContainScore[$t_id] = array();
  1577. }
  1578. $largeContainScore[$t_id][$value['topic_id']] = $topicScore[$value['topic_id']];
  1579. if (!isset($stuLargeTopicScore[$stuId][$t_id])) {
  1580. $stuLargeTopicScore[$stuId][$t_id] = array('scoring' => 0, 'score' => 0);
  1581. }
  1582. $stuLargeTopicScore[$stuId][$t_id]['scoring'] += $value['scoring'];
  1583. $stuLargeTopicScore[$stuId][$t_id]['score'] += $topicScore[$value['topic_id']];
  1584. $t_score = isset($topicScore[$value['topic_id']]) ? $topicScore[$value['topic_id']] : 0;
  1585. if (!isset($gradeScoring[$t_id])) {
  1586. $gradeScoring[$t_id] = 0;
  1587. }
  1588. $gradeScoring[$t_id] += $value['scoring'];
  1589. if (!isset($gradeScore[$t_id])) {
  1590. $gradeScore[$t_id] = 0;
  1591. }
  1592. $gradeScore[$t_id] += $t_score;
  1593. // if(strcmp($paperId,$value['paper_id']) == 0){
  1594. if (isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex) {
  1595. if (!isset($classScoring[$t_id])) {
  1596. $classScoring[$t_id] = 0;
  1597. }
  1598. $classScoring[$t_id] += $value['scoring'];
  1599. if (!isset($classScore[$t_id])) {
  1600. $classScore[$t_id] = 0;
  1601. }
  1602. $classScore[$t_id] += $t_score;
  1603. if (!isset($wrongStu[$t_id])) {
  1604. $wrongStu[$t_id] = array();
  1605. }
  1606. // if($t_score != $value['scoring']){
  1607. // $wrongStu[$t_id][] = $stuId;
  1608. // }
  1609. if (!isset($doneTopicNum[$t_id])) {
  1610. $doneTopicNum[$t_id] = array();
  1611. }
  1612. $doneTopicNum[$t_id][] = $stuId;
  1613. //学生得分率
  1614. if (!isset($stuScoring[$stuId])) {
  1615. $stuScoring[$stuId] = array();
  1616. }
  1617. if (!isset($stuScoring[$stuId][$t_id])) {
  1618. $stuScoring[$stuId][$t_id] = 0;
  1619. }
  1620. $stuScoring[$stuId][$t_id] += $value['scoring'];
  1621. if (!isset($stuScore[$stuId])) {
  1622. $stuScore[$stuId] = array();
  1623. }
  1624. if (!isset($stuScore[$stuId][$t_id])) {
  1625. $stuScore[$stuId][$t_id] = 0;
  1626. }
  1627. $stuScore[$stuId][$t_id] += $t_score;
  1628. //班级平均得分
  1629. if (!isset($classTopicScoring[$t_id])) {
  1630. $classTopicScoring[$t_id] = array();
  1631. }
  1632. $classTopicScoring[$t_id][] = $value['scoring'];
  1633. //统计单选题答错人数
  1634. if (isset($topicLogicType[$t_id]) && $topicLogicType[$t_id] == 1) {
  1635. if ($value['is_right'] != 1 && in_array($value['answer'], array('A', 'B', 'C', 'D', 'E'))) {
  1636. if (!isset($choiceTopicWrong[$t_id])) {
  1637. $choiceTopicWrong[$t_id] = array();
  1638. }
  1639. if (!isset($choiceTopicWrong[$t_id][$value['answer']])) {
  1640. $choiceTopicWrong[$t_id][$value['answer']] = 0;
  1641. }
  1642. $choiceTopicWrong[$t_id][$value['answer']]++;
  1643. }
  1644. }
  1645. }
  1646. if (in_array($value['topic_id'], $readingTopicIds)) {
  1647. if (empty($value['is_right']) && $value['answer']) {
  1648. if (!isset($readingWrongStu[$value['topic_id']])) {
  1649. $readingWrongStu[$value['topic_id']][$value['answer']] = array();
  1650. }
  1651. if (isset($sutName[$stuId])) {
  1652. $readingWrongStu[$value['topic_id']][$value['answer']][] = $sutName[$stuId];
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. //年级得分率
  1659. foreach ($gradeScoring as $tId => $scorings) {
  1660. if (isset($gradeScore[$tId]) && $gradeScore[$tId] > 0) {
  1661. $gradeRate[$tId] = round($scorings / $gradeScore[$tId], 4) * 100;
  1662. } else {
  1663. $gradeRate[$tId] = 0;
  1664. }
  1665. }
  1666. //班级得分率
  1667. foreach ($classScoring as $tId => $scoring) {
  1668. if (isset($classScore[$tId]) && $classScore[$tId] > 0) {
  1669. $classRate[$tId] = round($scoring / $classScore[$tId], 4) * 100;
  1670. } else {
  1671. $classRate[$tId] = 0;
  1672. }
  1673. }
  1674. //答错人数
  1675. foreach ($stuScore as $stuId => $tScores) {
  1676. if (isset($stuScoring[$stuId])) {
  1677. foreach ($tScores as $tId => $score) {
  1678. $_scoring = isset($stuScoring[$stuId][$tId]) ? $stuScoring[$stuId][$tId] : 0;
  1679. if ($score != $_scoring) {
  1680. $wrongStu[$tId][] = $stuId;
  1681. }
  1682. }
  1683. }
  1684. }
  1685. if ($wrongStu) {
  1686. foreach ($wrongStu as $key => $stuIds) {
  1687. $stuIds = array_unique($stuIds);
  1688. $wrongStu[$key] = count($stuIds);
  1689. if (isset($doneTopicNum[$key])) {
  1690. $_stuIds = array_unique($doneTopicNum[$key]);
  1691. $rightStu[$key] = count($_stuIds) - $wrongStu[$key];
  1692. }
  1693. }
  1694. }
  1695. //题得分率低于70%的学
  1696. $rateLess70 = array();
  1697. if ($stuScoring) {
  1698. foreach ($stuScoring as $stuId => $tScoring) {
  1699. $stuScoreArr = isset($stuScore[$stuId]) ? $stuScore[$stuId] : array();
  1700. foreach ($tScoring as $tId => $scoring) {
  1701. if (!isset($rateLess70[$tId])) {
  1702. $rateLess70[$tId] = array();
  1703. }
  1704. if (isset($stuScoreArr[$tId]) && $stuScoreArr[$tId] > 0) {
  1705. $tempRate = round($scoring / $stuScoreArr[$tId], 4) * 100;
  1706. } else {
  1707. $tempRate = 0;
  1708. }
  1709. if (inArray($tId, $choinceIds)) {
  1710. if ($tempRate < 100 && !inArray($stuId, $rateLess70[$tId])) {
  1711. $rateLess70[$tId][] = $stuId;
  1712. }
  1713. $isChoiceTopic[] = $tId;
  1714. } else {
  1715. if ($tempRate < 70 && !inArray($stuId, $rateLess70[$tId])) {
  1716. $rateLess70[$tId][] = $stuId;
  1717. }
  1718. }
  1719. }
  1720. }
  1721. }
  1722. foreach ($rateLess70 as $tId => $stuIds) {
  1723. $nameArr = array();
  1724. foreach ($stuIds as $stuId) {
  1725. $nameArr[] = isset($sutName[$stuId]) ? $sutName[$stuId] : '';
  1726. }
  1727. $rateLess70[$tId] = implode('、', $nameArr);
  1728. }
  1729. //大题对应的小题个数
  1730. $large_rel_count = array();
  1731. foreach ($topicRelLarge as $tId => $ltId) {
  1732. if (!isset($large_rel_count[$ltId])) {
  1733. $large_rel_count[$ltId] = 0;
  1734. }
  1735. $large_rel_count[$ltId]++;
  1736. }
  1737. //班级平均分
  1738. $classTopicAvg = array();
  1739. foreach ($classTopicScoring as $tId => $scorings) {
  1740. if ($scorings) {
  1741. $classTopicAvg[$tId] = round(array_sum($scorings) / (count($scorings) / $large_rel_count[$tId]), 2);
  1742. } else {
  1743. $classTopicAvg[$tId] = 0;
  1744. }
  1745. }
  1746. unset($classTopicScoring);
  1747. //低于班级平均分
  1748. $rateLessAvg = array();
  1749. if ($stuScoring) {
  1750. foreach ($stuScoring as $stuId => $tScoring) {
  1751. foreach ($tScoring as $tId => $scoring) {
  1752. if (!isset($rateLessAvg[$tId])) {
  1753. $rateLessAvg[$tId] = array();
  1754. }
  1755. if (isset($classTopicAvg[$tId]) && $scoring < $classTopicAvg[$tId]) {
  1756. $rateLessAvg[$tId][$stuId] = $scoring;
  1757. }
  1758. }
  1759. }
  1760. }
  1761. foreach ($rateLessAvg as $tId => $stuScoring) {
  1762. if ($stuScoring) {
  1763. asort($stuScoring);
  1764. $nameArr = array();
  1765. foreach ($stuScoring as $stuId => $scoring) {
  1766. $nameArr[] = isset($sutName[$stuId]) ? $sutName[$stuId] : '';
  1767. }
  1768. $rateLessAvg[$tId] = implode('、', $nameArr);
  1769. } else {
  1770. $rateLessAvg[$tId] = '';
  1771. }
  1772. }
  1773. foreach ($readingWrongStu as $tId => $val) {
  1774. foreach ($val as $option => $stuArr) {
  1775. $readingWrongStu[$tId][$option] = implode('、', $stuArr);
  1776. }
  1777. }
  1778. $result = array();
  1779. $result['grade_rate'] = $gradeRate;
  1780. $result['class_rate'] = $classRate;
  1781. $result['wrong_stu'] = $wrongStu;
  1782. $result['right_stu'] = $rightStu;
  1783. $result['rate_less_70'] = $rateLess70;
  1784. $result['rate_less_avg'] = $rateLessAvg;
  1785. $result['is_choice_topic'] = $isChoiceTopic;
  1786. $result['choice_topic_wrong'] = $choiceTopicWrong;
  1787. $result['large_topic_score'] = $stuLargeTopicScore;
  1788. $result['large_contain_score'] = $largeContainScore;
  1789. $result['reading_wrong_stu'] = $readingWrongStu;
  1790. $gradeScoring = $classScoring = array();
  1791. $gradeScore = $classScore = array();
  1792. $doneTopicNum = array();//每题做题总人数
  1793. unset($gradeScoring);
  1794. unset($classScoring);
  1795. unset($gradeScore);
  1796. unset($classScore);
  1797. unset($doneTopicNum);
  1798. unset($stuScoring);
  1799. unset($stuScore);
  1800. return $result;
  1801. }
  1802. /**
  1803. * 获取学生排名
  1804. * @param $examId
  1805. * @param $ptrInfo
  1806. * @return array
  1807. */
  1808. private function getStudentOrder($examId, &$ptrInfo, &$stuIdsArr)
  1809. {
  1810. $stuOrderArr = array();
  1811. $stuScoring = array();
  1812. foreach ($ptrInfo as $value) {
  1813. // if($examId == $value['exam_id']){
  1814. if (strcmp($examId, $value['exam_id']) == 0) {
  1815. $stuIds = isset($stuIdsArr[$value['exam_id']]) ? $stuIdsArr[$value['exam_id']] : array();
  1816. if (inArray($value['student_id'], $stuIds)) {
  1817. $stuScoring[$value['student_id']] = $value['scoring'];
  1818. }
  1819. }
  1820. }
  1821. $scoringArr = array_values($stuScoring);
  1822. foreach ($stuScoring as $stuId => $scoring) {
  1823. $stuOrderArr[$stuId] = $this->getOrder($scoring, $scoringArr);
  1824. }
  1825. if ($stuOrderArr) {
  1826. asort($stuOrderArr);
  1827. }
  1828. return $stuOrderArr;
  1829. }
  1830. /**
  1831. * 获取排名
  1832. * @param $ele
  1833. * @param $arr
  1834. * @return false|int|string
  1835. */
  1836. private function getOrder($ele, $arr)
  1837. {
  1838. $orderRs = 0;
  1839. if ($arr) {
  1840. arsort($arr);
  1841. $arr = array_values($arr);
  1842. $index = array_search($ele, $arr);
  1843. $orderRs = $index + 1;
  1844. }
  1845. return $orderRs;
  1846. }
  1847. /**
  1848. * 整理题详情
  1849. * @param $allApiInfo
  1850. * @return mixed
  1851. * @throws CException
  1852. */
  1853. public function getTopicDetail($topicBatches)
  1854. {
  1855. $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
  1856. $topicDetails = array();
  1857. foreach ($topicBatches AS $topic) {
  1858. $topic = (object)$topic;
  1859. $type = $topic->type_id;
  1860. 6 == $type && $type = 5; //6表示多空题,多空题也是5
  1861. $topic->id = (string)$topic->id;
  1862. $topicDetails[$topic->id] = array();
  1863. $topicDetails[$topic->id]['is_large_topic'] = isset($topic->is_large_topic) ? $topic->is_large_topic : 0;
  1864. $topicDetails[$topic->id]['type'] = $type;
  1865. $topicDetails[$topic->id]['subject_id'] = $topic->subject_id;
  1866. $topicDetails[$topic->id]['methods'] = '';//考点
  1867. $topicDetails[$topic->id]['method_id_arr'] = '';//考点id数组
  1868. $topicDetails[$topic->id]['kps'] = '';//知识点
  1869. $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title);//题目详情
  1870. $topicDetails[$topic->id]['options'] = '';
  1871. $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : '';
  1872. $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案
  1873. $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content);//答题解析
  1874. $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips);//名师点评
  1875. $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null;
  1876. $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
  1877. $_methods = array();
  1878. $_method_id_arr = array();
  1879. $_method_names = array();
  1880. if ($topic->specials) {
  1881. foreach ($topic->specials AS $_method) {
  1882. $_method = (object)$_method;
  1883. if ($_method->method_name) {
  1884. $_methods[] = $_method->method_name;
  1885. }
  1886. if (isset($_method->method_id)) {
  1887. $_method_id_arr[] = $_method->method_id;
  1888. }
  1889. if (isset($_method->method_id) && isset($_method->method_name)) {
  1890. $_method_names[$_method->method_id] = $_method->method_name;
  1891. }
  1892. }
  1893. $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods));//考点
  1894. $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
  1895. $topicDetails[$topic->id]['method_names'] = $_method_names;
  1896. }
  1897. $_kps = array();
  1898. if (isset($topic->kps) && $topic->kps) {
  1899. foreach ($topic->kps as $_kp) {
  1900. $_kp = (object)$_kp;
  1901. if ($_kp->kp_name) {
  1902. $_kps[$_kp->kp_id] = $_kp->kp_name;
  1903. }
  1904. }
  1905. $topicDetails[$topic->id]['kps'] = $_kps;//考点
  1906. }
  1907. if ($topic->type_id == 1 || $topic->type_id == 11) { //选择题有选项
  1908. if ($topic->items) {
  1909. if (isset($topic->items[0])) {
  1910. $topic->items[0] = (object)$topic->items[0];
  1911. if (isset($topic->items[0]->options)) {
  1912. $options = $topic->items[0]->options;
  1913. if ($options) {
  1914. $_tmp_options = array();
  1915. $correct_answer_arr = array();
  1916. foreach ($options AS $_optionIndex => $_option) {
  1917. $_option = (object)$_option;
  1918. $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
  1919. if ($_option->option_correct) {
  1920. $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex], true);
  1921. // $topicDetails[$topic->id]['answer']=topicProcess($optionIndex[$_optionIndex]);
  1922. }
  1923. }
  1924. $topicDetails[$topic->id]['answer'] = implode(',', $correct_answer_arr);
  1925. $_list_type = (int)$topic->items[0]->list_type;
  1926. $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type);
  1927. }
  1928. }
  1929. }
  1930. }
  1931. } else {
  1932. if ($topic->items) {
  1933. if (isset($topic->items[0])) {
  1934. $topic->items[0] = (object)$topic->items[0];
  1935. if (isset($topic->items[0]->options)) {
  1936. $options = $topic->items[0]->options;
  1937. if ($options) {
  1938. $_answer = '';
  1939. foreach ($options as $v) {
  1940. $_option = (object)$v;
  1941. if (trim($_answer) != '') {
  1942. $_answer .= ' ; ';
  1943. }
  1944. $_answer .= $_option->option_content;
  1945. }
  1946. $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer, true);
  1947. }
  1948. }
  1949. }
  1950. }
  1951. }
  1952. //大题的小题
  1953. $topicDetails[$topic->id]['slave'] = array();
  1954. if (isset($topic->slave) && $topic->slave) {
  1955. $topicDetails[$topic->id]['answer'] = array();
  1956. foreach ($topic->slave as $slave) {
  1957. $slave = (object)$slave;
  1958. $_slave = array();
  1959. $_slave['topic_slave_id'] = (string)$slave->topic_slave_id;
  1960. $_slave['type'] = $slave->topic_type;
  1961. $_slave['methods'] = '';//考点
  1962. $_slave['method_id_arr'] = '';//考点id数组
  1963. $_slave['kps'] = '';//知识点
  1964. $_slave['queBody'] = $this->topicProcess($slave->title);//题目详情
  1965. $_slave['options'] = '';
  1966. $_slave['answer'] = ''; //每题的正确答案
  1967. // $_slave['analysis']=topicProcess($slave->parse_content);//答题解析
  1968. // $_slave['teacher_tips']=topicProcess($slave->teacher_tips);//名师点评
  1969. $_slave['difficulty_degree'] = isset($slave->difficulty_degree) ? $slave->difficulty_degree : null;
  1970. $_slave['difficulty'] = $slave->difficulty;
  1971. if ($slave->topic_type == 1 || $slave->topic_type == 11) { //选择题有选项
  1972. if ($slave->items) {
  1973. if (isset($slave->items)) {
  1974. $slave->items = (object)$slave->items;
  1975. if (isset($slave->items->options)) {
  1976. $options = (object)$slave->items->options;
  1977. if ($options) {
  1978. $_tmp_options = array();
  1979. $correct_answer_arr = array();
  1980. foreach ($options AS $_optionIndex => $_option) {
  1981. $_option = (object)$_option;
  1982. $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
  1983. if ($_option->option_correct) {
  1984. if (isset($_option->content_is_answer) && $_option->content_is_answer == 1) {
  1985. $correct_answer_arr[] = $_option->option_content;
  1986. } else {
  1987. $correct_answer_arr[] = $this->topicProcess($optionIndex[$_optionIndex]);
  1988. }
  1989. }
  1990. }
  1991. $_slave['answer'] = implode(',', $correct_answer_arr);
  1992. $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
  1993. $_list_type = (int)$slave->items->list_type;
  1994. $_slave['options'] = $this->option_process($_tmp_options, $_list_type);
  1995. }
  1996. }
  1997. }
  1998. }
  1999. } else {
  2000. if ($slave->items) {
  2001. if (isset($slave->items)) {
  2002. $slave->items = (object)$slave->items;
  2003. if (isset($slave->items->options)) {
  2004. $options = (object)$slave->items->options;
  2005. if ($options) {
  2006. $_answer = '';
  2007. foreach ($options as $v) {
  2008. $_option = (object)$v;
  2009. if (trim($_answer) != '') {
  2010. $_answer .= ' ; ';
  2011. }
  2012. $_answer .= $_option->option_content;
  2013. }
  2014. $_slave['answer'] = $this->topicProcess($_answer, true);
  2015. $topicDetails[$topic->id]['answer'][(string)$slave->topic_slave_id] = $_slave['answer'];
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. $topicDetails[$topic->id]['slave'][] = $_slave;
  2022. }
  2023. }
  2024. }
  2025. return $topicDetails;
  2026. }
  2027. /**
  2028. *对选项的处理
  2029. * @param $options
  2030. * @param $list_type
  2031. * @return string
  2032. */
  2033. public function option_process($options, $list_type)
  2034. {
  2035. $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
  2036. if ($list_type == 0) { //纵向排列,即1行1个
  2037. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  2038. $option_str = "";
  2039. foreach ($options as $key => $option) {
  2040. if ($option) {
  2041. $option_str .= "<li style='width:100%;'>$option_index[$key].$option</li>";
  2042. }
  2043. }
  2044. // $option_str.="</ul>";
  2045. } elseif ($list_type == 1) { //横向排列,即1行4个
  2046. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  2047. $option_str = "";
  2048. foreach ($options as $key => $option) {
  2049. $option_str .= "<li class='fl'>$option_index[$key].$option</li>";
  2050. }
  2051. // $option_str.="</ul>";
  2052. } elseif ($list_type == 2) { //1行2个
  2053. // $option_str="<ul class='answer clearfix font8' style='margin-right:45px'>";
  2054. $option_str = "";
  2055. foreach ($options as $key => $option) {
  2056. if ($key % 2 == 0) {
  2057. $option1 = $options[$key];
  2058. $option_str2 = "<li class='fl' style='width:50%;'>$option_index[$key].$option1</li>";
  2059. $key1 = $key + 1;
  2060. if (isset($options[$key1])) {
  2061. $option2 = $options[$key1];
  2062. $option_str2 .= "<li class='fl' style='width:50%;'>$option_index[$key1].$option2</li>";
  2063. }
  2064. $option_str .= $option_str2;
  2065. } else {
  2066. continue;
  2067. }
  2068. }
  2069. // $option_str.="</ul>";
  2070. }
  2071. return $option_str;
  2072. }
  2073. public function topicProcess($html, $isAnswer = false)
  2074. {
  2075. if ($this->subjectId == 8 && !$this->isThird && !$isAnswer) {
  2076. $html = preg_replace('/<br\/*>/', '', $html);
  2077. return $html;
  2078. }
  2079. preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr);
  2080. foreach ($arr[0] as $v) {
  2081. $process_str = $this->img_process($v);;
  2082. $html = str_replace($v, $process_str, $html);
  2083. }
  2084. $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html);
  2085. $html = preg_replace('/<p\s*>/', '', $html);
  2086. $html = preg_replace('/<\/p>/', '', $html);
  2087. $html = preg_replace('/<br\/*>/', '', $html);
  2088. $html = preg_replace('/<big\s*>/', '', $html);
  2089. $html = preg_replace('/<\/big>/', '', $html);
  2090. $html = str_replace("&nbsp;", '', $html);
  2091. return $html;
  2092. }
  2093. public function img_process($img)
  2094. {
  2095. $widthArr = array();
  2096. $heightArr = array();
  2097. $width = '';
  2098. $height = '';
  2099. preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si', $img, $widthArr);
  2100. if ($widthArr) {
  2101. $width = $this->length_process($widthArr);
  2102. } else {
  2103. preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si', $img, $widthArr);
  2104. if ($widthArr) {
  2105. $width = $this->length_process($widthArr);
  2106. }
  2107. }
  2108. if ($width) {
  2109. $width = "width=" . $width;
  2110. }
  2111. preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si', $img, $heightArr);
  2112. if ($heightArr) {
  2113. $height = $this->length_process($heightArr);
  2114. } else {
  2115. preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si', $img, $heightArr);
  2116. if ($heightArr) {
  2117. $height = $this->length_process($heightArr);
  2118. }
  2119. }
  2120. if ($height) {
  2121. $height = "height=" . $height;
  2122. }
  2123. $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', "<img " . $width . " " . $height . " $1 />", $img);
  2124. return $return_img;
  2125. }
  2126. public function length_process($length_arr)
  2127. {
  2128. $units = array(
  2129. 'in' => 96,
  2130. 'cm' => 28,
  2131. 'mm' => 2.8,
  2132. 'pt' => 1.33,
  2133. 'pc' => 12,
  2134. );
  2135. $length = 0.6 * $length_arr[1];
  2136. $unit_keys = array_keys($units);
  2137. if (isset($length_arr[2])) {
  2138. //将直接连接单位改为 单位换算
  2139. if (in_array($length_arr[2], $unit_keys)) {
  2140. $length = $length * $units[$length_arr[2]];
  2141. } else {
  2142. $length .= $length_arr[2];
  2143. }
  2144. }
  2145. return $length;
  2146. }
  2147. protected function getTopicTypeRateImg(&$typeMasterData, $examId, $paperId)
  2148. {
  2149. $imgPath = str_replace("protected", "", Yii::app()->basePath) . 'assets/temp_img/';
  2150. $urlPath = Yii::app()->request->hostInfo . '/assets/temp_img/';
  2151. if (!is_dir($imgPath)) {
  2152. if (!mkdir($imgPath, 0777, true)) {
  2153. exit('Create directory fail: ' . $imgPath);
  2154. }
  2155. }
  2156. $data = array();
  2157. foreach ($typeMasterData['grade_rate'] as $type => $rate) {
  2158. if (!isset($data[$type])) {
  2159. $data[$type] = array();
  2160. }
  2161. $data[$type]['type_name'] = isset($typeMasterData['type_name_arr'][$type]) ? $typeMasterData['type_name_arr'][$type] : array();
  2162. $data[$type]['class_rate'] = isset($typeMasterData['class_rate'][$type]) ? $typeMasterData['class_rate'][$type] : array();
  2163. //当前班级得分率坐标
  2164. $data[$type]['all_class_rate'] = array();
  2165. foreach ($typeMasterData['all_class_rate'] as $pId => $rates) {
  2166. foreach ($rates as $ty => $_rate) {
  2167. if ($ty == $type) {
  2168. $data[$type]['all_class_rate'][] = $_rate;
  2169. // if($paperId == $pId){
  2170. if (strcmp($paperId, $pId) == 0) {
  2171. $data[$ty]['curr_rate_x'] = $_rate;
  2172. }
  2173. }
  2174. }
  2175. }
  2176. $data[$type]['type_paper_rate'] = array();
  2177. foreach ($typeMasterData['type_paper_rate'] as $pId => $rates) {
  2178. foreach ($rates as $ty => $_rate) {
  2179. if ($ty == $type) {
  2180. // if($paperId == $pId){
  2181. if (strcmp($paperId, $pId) == 0) {
  2182. $data[$ty]['curr_rate_y'] = $_rate;
  2183. }
  2184. $data[$type]['type_paper_rate'][] = $_rate;
  2185. }
  2186. }
  2187. }
  2188. }
  2189. //复制我班的数据
  2190. foreach ($data as $type => $rates) {
  2191. foreach ($rates['type_paper_rate'] as $rate) {
  2192. $data[$type]['my_class_rate'][] = $rates['curr_rate_x'];
  2193. }
  2194. }
  2195. $typeRateImgPath = array();
  2196. $typeRateImgUrl = array();
  2197. foreach ($data as $type => $value) {
  2198. $tempPath = $imgPath . $examId . "_" . $type . ".png";
  2199. $this->imgArr[] = $tempPath;
  2200. $bool = $this->getScatterImage($value, $tempPath);
  2201. if ($bool) {
  2202. $typeRateImgUrl[$type] = $urlPath . $examId . "_" . $type . ".png";
  2203. }
  2204. }
  2205. return $typeRateImgUrl;
  2206. }
  2207. protected function getScatterImage($data, $imgPath)
  2208. {
  2209. /* Create the pData object */
  2210. $myData = new pData();
  2211. /* Create the X axis and the binded series */
  2212. // for ($i=0;$i<=10;$i=$i+1) { $myData->addPoints(rand(1,20),"Probe 1"); }
  2213. // for ($i=0;$i<=10;$i=$i+1) { $myData->addPoints(rand(1,20),"Probe 2"); }
  2214. foreach ($data['all_class_rate'] as $v) {
  2215. $myData->addPoints($v, "Probe 1");
  2216. }
  2217. foreach ($data['my_class_rate'] as $v) {
  2218. $myData->addPoints($v, "Probe 2");
  2219. }
  2220. $myData->setAxisName(0, "总得分率");
  2221. $myData->setAxisXY(0, AXIS_X);
  2222. $myData->setAxisPosition(0, AXIS_POSITION_BOTTOM);
  2223. /* Create the Y axis and the binded series */
  2224. // for ($i=0;$i<=10;$i=$i+1) { $myData->addPoints(rand(1,20),"Probe 3"); }
  2225. foreach ($data['type_paper_rate'] as $v) {
  2226. $myData->addPoints($v, "Probe 3");
  2227. }
  2228. foreach ($data['type_paper_rate'] as $v) {
  2229. $myData->addPoints($data['curr_rate_y'], "Probe 4");
  2230. }
  2231. $myData->setSerieOnAxis("Probe 3", 1);
  2232. $myData->setAxisName(1, $data['type_name'] . "得分率");
  2233. $myData->setAxisXY(1, AXIS_Y);
  2234. $myData->setAxisPosition(1, AXIS_POSITION_LEFT);
  2235. /* Create the 1st scatter chart binding */
  2236. $myData->setScatterSerie("Probe 1", "Probe 3", 0);
  2237. $myData->setScatterSerieDescription(0, "其它班级");
  2238. $myData->setScatterSerieColor(0, array("R" => 0, "G" => 0, "B" => 0));
  2239. // $myData->setScatterSerieColor(0,array("R"=>255,"G"=>255,"B"=>255));
  2240. $myData->setScatterSerieShape(0, SERIE_SHAPE_TRIANGLE);
  2241. //========================================================
  2242. $myData->setSerieOnAxis("Probe 4", 1);
  2243. // $myData->setAxisName(1,$data['type_name']."得分率");
  2244. // $myData->setAxisXY(1,AXIS_Y);
  2245. // $myData->setAxisPosition(1,AXIS_POSITION_LEFT);
  2246. /* Create the 2nd scatter chart binding */
  2247. $myData->setScatterSerie("Probe 2", "Probe 4", 1);
  2248. $myData->setScatterSerieDescription(1, "我班");
  2249. $myData->setScatterSerieShape(1, SERIE_SHAPE_FILLEDTRIANGLE);
  2250. /* Create the pChart object */
  2251. $myPicture = new pImage(800, 400, $myData);
  2252. /* Turn of Anti-aliasing */
  2253. $myPicture->Antialias = FALSE;
  2254. /* Add a border to the picture */
  2255. // $myPicture->drawRectangle(0,0,399,399,array("R"=>0,"G"=>0,"B"=>0));
  2256. /* Set the default font */
  2257. $myPicture->setFontProperties(array("FontName" => str_replace("protected", "", Yii::app()->basePath) . "fonts/pChart/msyh.ttf", "FontSize" => 8));
  2258. /* Set the graph area */
  2259. $myPicture->setGraphArea(40, 20, 760, 360);
  2260. /* Create the Scatter chart object */
  2261. $myScatter = new pScatter($myPicture, $myData);
  2262. /* Draw the scale */
  2263. $scaleSettings = array("XMargin" => 15, "YMargin" => 15, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
  2264. $myScatter->drawScatterScale($scaleSettings);
  2265. /* Draw the legend */
  2266. $myScatter->drawScatterLegend(650, 388, array("Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER));
  2267. $myPicture->drawText(100, 20, "总分与{$data['type_name']}成绩", array("FontSize" => 10, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2268. $myPicture->drawText(80, 50, "总分低,", array("FontSize" => 8, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2269. $myPicture->drawText(80, 60, "{$data['type_name']}高", array("FontSize" => 8, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2270. $myPicture->drawText(720, 340, "总分高,", array("FontSize" => 8, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2271. $myPicture->drawText(720, 350, "{$data['type_name']}低", array("FontSize" => 8, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2272. //用例图标
  2273. // $myPicture->drawRectangle(250,385,256,391,array("R"=>0,"G"=>0,"B"=>0));
  2274. $xNum = 91;
  2275. $yNum = 315;
  2276. // $myPicture->drawFilledRectangle($xNum,$yNum,$xNum + 6,$yNum + 6,array("R"=>0,"G"=>0,"B"=>0));
  2277. // $myPicture->drawFilledCircle($data['curr_rate_x'] + $xNum,$yNum - $data['curr_rate_x'],3,array("R"=>0,"G"=>0,"B"=>0));
  2278. //画线
  2279. arsort($data['all_class_rate']);
  2280. $maxAllRate = round(current($data['all_class_rate']));
  2281. arsort($data['type_paper_rate']);
  2282. $maxTypePaper = round(current($data['type_paper_rate']));
  2283. // $myPicture->drawLine($xNum + $maxAllRate,15,$xNum + $maxAllRate,315,array("R"=>0,"G"=>0,"B"=>0));
  2284. $myPicture->drawLine($xNum + $maxAllRate + 5, 35, $xNum + $maxAllRate + 5, 345, array("R" => 0, "G" => 0, "B" => 0));
  2285. $myPicture->drawLine($xNum + $maxAllRate - 5, 35, $xNum + $maxAllRate - 5, 345, array("R" => 0, "G" => 0, "B" => 0));
  2286. $myPicture->drawLine(55, ($yNum - $maxTypePaper) + 5, 745, ($yNum - $maxTypePaper) + 5, array("R" => 0, "G" => 0, "B" => 0));
  2287. $myPicture->drawLine(55, ($yNum - $maxTypePaper) - 5, 745, ($yNum - $maxTypePaper) - 5, array("R" => 0, "G" => 0, "B" => 0));
  2288. /* Draw a scatter plot chart */
  2289. $myPicture->Antialias = TRUE;
  2290. $myScatter->drawScatterPlotChart();
  2291. /* Render the picture (choose the best way) */
  2292. // $myPicture->autoOutput("pictures/example.example.drawScatterShape.png");
  2293. $myPicture->render($imgPath);
  2294. // $myPicture->autoOutput($imgPath);die;
  2295. return $imgPath;
  2296. }
  2297. //考点掌握情况
  2298. protected function getMethodCount(&$stuRs, &$pramas)
  2299. {
  2300. list($smallTopicScore, $smallTopicNo, $paperId, $topicType, $topicLogicType, $topicRelLarge, $topicRelMethod, $largeTopicMethod, $sutName, $sutOrder, $methodName) = $pramas;
  2301. $gradeScoring = $gradeScore = array();
  2302. $classScoring = $classScore = array();
  2303. $rightNum = $wrongNum = array();
  2304. $methodRelNo = array();
  2305. $diffStu = array();//考点较差学生
  2306. $classDiffStu = array();//班级排名后25%学生的薄弱考点
  2307. $methodRelType = array();//考点对应的题型
  2308. $typeNameArr = array();//考点对应的题型
  2309. $back25Rate = array();
  2310. $reStuOrder = $sutOrder;
  2311. $stuCount = count($reStuOrder);
  2312. $stuCount = ceil($stuCount * 0.25);
  2313. arsort($reStuOrder);
  2314. $reStuOrder = array_slice($reStuOrder, 0, $stuCount);
  2315. $typeName = $this->typeName;
  2316. $logicTypeName = $this->logicTypeName;
  2317. foreach ($stuRs as $sId => $value) {
  2318. foreach ($value as $tId => $v) {
  2319. if (isset($topicRelMethod[$tId]) && $topicRelMethod[$tId]) {
  2320. foreach ($topicRelMethod[$tId] as $methodId) {
  2321. if (!$methodId) continue;
  2322. if (isset($topicLogicType[$tId]) && $topicLogicType[$tId] > 0) {
  2323. $type = (int)$topicLogicType[$tId];
  2324. $typeNameArr[$type] = isset($logicTypeName[$type]) ? $logicTypeName[$type] : '';
  2325. } else {
  2326. $type = $v['type'];
  2327. $typeNameArr[$type] = isset($typeName[$type]) ? $typeName[$type] : '';
  2328. }
  2329. $methodRelType[$methodId] = $type;
  2330. $tScore = isset($smallTopicScore[$tId]) ? $smallTopicScore[$tId] : 0;
  2331. if ($tScore) {
  2332. $stuRate = round($v['scoring'] / $tScore, 4) * 100;
  2333. } else {
  2334. $stuRate = 0;
  2335. }
  2336. //年级
  2337. if (!isset($gradeScoring[$methodId])) {
  2338. $gradeScoring[$methodId] = 0;
  2339. }
  2340. $gradeScoring[$methodId] += $v['scoring'];
  2341. if (!isset($gradeScore[$methodId])) {
  2342. $gradeScore[$methodId] = 0;
  2343. }
  2344. $gradeScore[$methodId] += $tScore;
  2345. //班级
  2346. // if($paperId == $v['paper_id']){
  2347. if (strcmp($paperId, $v['paper_id']) == 0) {
  2348. if (!isset($classScoring[$methodId])) {
  2349. $classScoring[$methodId] = 0;
  2350. }
  2351. $classScoring[$methodId] += $v['scoring'];
  2352. if (!isset($classScore[$methodId])) {
  2353. $classScore[$methodId] = 0;
  2354. }
  2355. $classScore[$methodId] += $tScore;
  2356. //对错人数
  2357. if ($v['is_right'] == 1) {
  2358. if (!isset($rightNum[$methodId])) {
  2359. $rightNum[$methodId] = array();
  2360. }
  2361. $rightNum[$methodId][] = $sId;
  2362. } else {
  2363. if (!isset($wrongNum[$methodId])) {
  2364. $wrongNum[$methodId] = array();
  2365. }
  2366. $wrongNum[$methodId][] = $sId;
  2367. }
  2368. //薄弱考点掌握较差学生
  2369. if (!isset($diffStu[$methodId])) {
  2370. $diffStu[$methodId] = array();
  2371. }
  2372. if ($stuRate <= 40) {
  2373. if (!inArray($sId, $diffStu[$methodId])) {
  2374. $diffStu[$methodId][] = $sId;
  2375. }
  2376. }
  2377. }
  2378. //班级排名后25%学生的薄弱考点
  2379. if (isset($reStuOrder[$sId])) {
  2380. if (!isset($classDiffStu[$sId])) {
  2381. $classDiffStu[$sId] = array();
  2382. }
  2383. if ($stuRate <= 40) {
  2384. if (!inArray($methodId, $classDiffStu[$sId])) {
  2385. $classDiffStu[$sId][] = $methodId;
  2386. }
  2387. }
  2388. }
  2389. }
  2390. }
  2391. }
  2392. }
  2393. //年级得分率
  2394. $gradeRate = array();
  2395. if ($gradeScoring) {
  2396. foreach ($gradeScoring as $mId => $scoring) {
  2397. if (isset($gradeScore[$mId]) && $gradeScore[$mId]) {
  2398. $gradeRate[$mId] = round($scoring / $gradeScore[$mId], 4) * 100;
  2399. } else {
  2400. $gradeRate[$mId] = 0;
  2401. }
  2402. }
  2403. }
  2404. //年级得分率
  2405. $classRate = array();
  2406. if ($classScoring) {
  2407. foreach ($classScoring as $mId => $scoring) {
  2408. if (isset($classScore[$mId]) && $classScore[$mId]) {
  2409. $classRate[$mId] = round($scoring / $classScore[$mId], 4) * 100;
  2410. } else {
  2411. $classRate[$mId] = 0;
  2412. }
  2413. }
  2414. }
  2415. //对错人数
  2416. foreach ($rightNum as $mId => $stuIds) {
  2417. $rightNum[$mId] = count(array_unique($stuIds));
  2418. }
  2419. foreach ($wrongNum as $mId => $stuIds) {
  2420. $wrongNum[$mId] = count(array_unique($stuIds));
  2421. }
  2422. //考点对应题号
  2423. foreach ($topicRelMethod as $tId => $mIds) {
  2424. if (isset($smallTopicNo[$tId]) && $smallTopicNo[$tId]) {
  2425. foreach ($mIds as $mId) {
  2426. if ($mId) {
  2427. if (!isset($methodRelNo[$mId])) {
  2428. $methodRelNo[$mId] = array();
  2429. }
  2430. $methodRelNo[$mId][] = $smallTopicNo[$tId];
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //题号数组转成字符串
  2436. foreach ($methodRelNo as $mId => $nos) {
  2437. asort($nos);
  2438. $methodRelNo[$mId] = $nos;
  2439. }
  2440. //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。
  2441. $masterDegree = array();
  2442. foreach ($classRate as $mId => $rate) {
  2443. if ($rate >= 85) {
  2444. $masterDegree[$mId] = 5;
  2445. } elseif ($rate < 85 && $rate >= 75) {
  2446. $masterDegree[$mId] = 4;
  2447. } elseif ($rate < 75 && $rate >= 65) {
  2448. $masterDegree[$mId] = 3;
  2449. } elseif ($rate < 65 && $rate >= 55) {
  2450. $masterDegree[$mId] = 2;
  2451. } else {
  2452. $masterDegree[$mId] = 1;
  2453. }
  2454. }
  2455. //薄弱考点掌握较差学生
  2456. foreach ($diffStu as $mId => $stuIds) {
  2457. $stuNameArr = array();
  2458. foreach ($stuIds as $stuId) {
  2459. $stuNameArr[$stuId] = isset($sutName[$stuId]) ? $sutName[$stuId] : '';
  2460. }
  2461. $diffStu[$mId] = implode(',', $stuNameArr);
  2462. }
  2463. //考点顺序按班级得分率升序进行。
  2464. asort($classRate);
  2465. $typeRelMethod = array();
  2466. foreach ($classRate as $mId => $rate) {
  2467. if (isset($methodRelType[$mId])) {
  2468. if (!isset($typeRelMethod[$methodRelType[$mId]])) {
  2469. $typeRelMethod[$methodRelType[$mId]] = array();
  2470. }
  2471. $typeRelMethod[$methodRelType[$mId]][] = $mId;
  2472. }
  2473. }
  2474. //班级排名后25%学生的薄弱考点
  2475. foreach ($classDiffStu as $stuId => $mIds) {
  2476. // asort($mIds);
  2477. $mName = array();
  2478. foreach ($mIds as $mId) {
  2479. if (isset($methodName[$mId]) && $methodName[$mId]) {
  2480. $mName[] = $methodName[$mId];
  2481. }
  2482. }
  2483. $classDiffStu[$stuId] = implode('、', $mName);
  2484. }
  2485. $result = array(
  2486. 'grade_rate' => $gradeRate,
  2487. 'class_rate' => $classRate,
  2488. 'method_rel_no' => $methodRelNo,
  2489. 'master_degree' => $masterDegree,
  2490. 'right_num' => $rightNum,
  2491. 'wrong_num' => $wrongNum,
  2492. 'diff_stu' => $diffStu,
  2493. 'class_diff_stu' => $classDiffStu,
  2494. 'type_rel_method' => $typeRelMethod,
  2495. 'type_name_arr' => $typeNameArr,
  2496. );
  2497. return $result;
  2498. }
  2499. protected function getImage($ratePath, $timeMethodRate)
  2500. {
  2501. /* Create and populate the pData object */
  2502. $MyData = new pData();
  2503. $i = 1;
  2504. foreach ($timeMethodRate as $arr) {
  2505. $MyData->addPoints($arr, "Probe {$i}");
  2506. $i++;
  2507. if ($i > 3) {
  2508. break;
  2509. }
  2510. }
  2511. // $MyData->addPoints(array(4,1,2,12,8,3),"Probe 1");
  2512. // $MyData->addPoints(array(3,12,15,8,5,5),"Probe 2");
  2513. // $MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
  2514. $MyData->setSerieTicks("Probe 2", 4);
  2515. $MyData->setSerieWeight("Probe 3", 2);
  2516. $MyData->setAxisName(0, "得分率");
  2517. $MyData->addPoints(array("上上次", "上次", "本次"), "Labels");
  2518. $MyData->setSerieDescription("Labels", "Months");
  2519. $MyData->setAbscissa("Labels");
  2520. $MyData->setSerieShape(0, SERIE_SHAPE_TRIANGLE);
  2521. /* Create the pChart object */
  2522. $myPicture = new pImage(700, 230, $MyData);
  2523. /* Turn of Antialiasing */
  2524. $myPicture->Antialias = FALSE;
  2525. /* Add a border to the picture */
  2526. $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
  2527. /* Write the chart title */
  2528. $myPicture->setFontProperties(array("FontName" => str_replace("protected", "", Yii::app()->basePath) . "fonts/pChart/msyh.ttf", "FontSize" => 11));
  2529. $myPicture->drawText(150, 35, "考点掌握情况变化趋势", array("FontSize" => 12, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
  2530. /* Set the default font */
  2531. $myPicture->setFontProperties(array("FontName" => str_replace("protected", "", Yii::app()->basePath) . "fonts/pChart/msyh.ttf", "FontSize" => 8));
  2532. /* Define the chart area */
  2533. $myPicture->setGraphArea(60, 40, 650, 200);
  2534. /* Draw the scale */
  2535. $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE);
  2536. $myPicture->drawScale($scaleSettings);
  2537. /* Turn on Antialiasing */
  2538. $myPicture->Antialias = false;
  2539. /* Draw the line chart */
  2540. // $myPicture->drawLineChart();
  2541. $myPicture->drawLineChart(array("ForceColor" => true, "ForceR" => 0, "ForceG" => 0, "ForceB" => 0, "ForceAlpha" => 80));
  2542. $myPicture->drawPlotChart(array("DisplayValues" => TRUE, "PlotBorder" => TRUE, "BorderSize" => 2, "Surrounding" => -60, "BorderAlpha" => 80));
  2543. /* Write the chart legend */
  2544. $myPicture->drawLegend(510, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
  2545. /* Render the picture (choose the best way) */
  2546. // $myPicture->autoOutput($ratePath);die;
  2547. $myPicture->render($ratePath);
  2548. }
  2549. /**
  2550. * 删除生成的图片
  2551. */
  2552. private function delCreateImgs()
  2553. {
  2554. if ($this->imgArr && is_array($this->imgArr)) {
  2555. foreach ($this->imgArr as $path) {
  2556. if (file_exists($path)) {
  2557. @unlink($path);
  2558. }
  2559. }
  2560. }
  2561. }
  2562. /**
  2563. * 获取试题内容参数
  2564. * @param $topicIds
  2565. * @return array
  2566. */
  2567. private function getEnglishTopic($topicIds)
  2568. {
  2569. $result = array('status' => 0, 'error' => array('无题'));
  2570. // $topicIds = array(1821);
  2571. // $topicIds = array(20001908);
  2572. $param = array(
  2573. 'size' => count($topicIds),
  2574. 'query' => array(
  2575. 'bool' => array(
  2576. 'must' => array(
  2577. array(
  2578. 'match' => array(
  2579. 'status' => array(
  2580. 'query' => 1,
  2581. 'type' => 'boolean'
  2582. )
  2583. )
  2584. ),
  2585. array(
  2586. 'terms' => array(
  2587. 'topicId' => $topicIds
  2588. )
  2589. )
  2590. )
  2591. )
  2592. )
  2593. );
  2594. $url = Yii::app()->params['english_topic_search_url'];
  2595. $rs = $this->aipostEng($url, $param);
  2596. if (!$rs) {
  2597. return false;
  2598. }
  2599. if (isset($rs['hits'])) {
  2600. if (isset($rs['hits']['hits'])) {
  2601. $topicInfos = array();
  2602. foreach ($rs['hits']['hits'] as $v) {
  2603. if (isset($v['_source']) && $v['_source']) {
  2604. $src = $v['_source'];
  2605. $temp_info = array(
  2606. 'id' => $src['topicId'],
  2607. 'is_large_topic' => isset($src['options']) && $src['options'] ? 0 : 1,
  2608. 'type_id' => $src['physicalTypeId'],
  2609. 'title' => $src['content'],
  2610. 'topic_type' => $src['physicalTypeId'],
  2611. 'school_id' => 0,
  2612. 'type_name' => '',
  2613. 'difficulty' => $src['difficulty'],
  2614. 'subject_id' => 8,
  2615. 'create_time' => time(),
  2616. 'update_time' => time(),
  2617. 'subject_name' => '英语',
  2618. 'teacher_tips' => '',
  2619. 'source' => '',
  2620. 'relation_topic' => 0,
  2621. 'teaching_quality' => 0,
  2622. 'source_title' => '',
  2623. 'parse_video' => null,
  2624. 'parse_content' => $src['parse'],
  2625. 'difficulty_degree' => 0.86,
  2626. // 'difficulty_degree' => 0.86,
  2627. 'kps' => array(),
  2628. 'specials' => array(),
  2629. 'uses' => array(),
  2630. 'total' => 0,
  2631. 'oneself' => 0,
  2632. 'items' => array(),
  2633. 'slave' => array(),
  2634. );
  2635. //考点
  2636. if (isset($src['methods']) && $src['methods']) {
  2637. $specials = array();
  2638. foreach ($src['methods'] as $method) {
  2639. if (isset($method['isLast']) && $method['isLast']) {
  2640. $_method = array(
  2641. "method_id" => $method['methodId'],
  2642. "method_name" => $method['methodName'],
  2643. );
  2644. $specials[] = $_method;
  2645. }
  2646. }
  2647. $temp_info['specials'] = $specials;
  2648. }
  2649. //小题
  2650. if (isset($src['slaves']) && $src['slaves']) {
  2651. foreach ($src['slaves'] as $slave) {
  2652. $_slave = array(
  2653. 'topic_slave_id' => $slave['topicId'],
  2654. 'topic_type' => $slave['physicalTypeId'],
  2655. 'type_name' => '',
  2656. 'difficulty_degree' => 0.86,
  2657. // 'difficulty_degree' => float 0.86
  2658. 'difficulty' => $slave['difficulty'],
  2659. 'title' => $slave['content'],
  2660. 'items' => array(),
  2661. 'kps' => array(),
  2662. 'specials' => array(),
  2663. );
  2664. $_items = array(
  2665. 'type_id' => 1,
  2666. 'type_name' => '',
  2667. 'list_type' => 1,
  2668. // 'list_type' => int 0
  2669. 'title' => $slave['content'],
  2670. 'options' => array(),
  2671. );
  2672. if (isset($slave['options']) && $slave['options']) {
  2673. $_option = array();
  2674. foreach ($slave['options'] as $option) {
  2675. $_temp_op = array(
  2676. 'option_id' => 0,
  2677. 'option_content' => $option['content'],
  2678. 'option_correct' => $option['isTrue'],
  2679. );
  2680. $_option[] = $_temp_op;
  2681. }
  2682. $_items['options'] = $_option;
  2683. } elseif (isset($slave['answer']) && $slave['answer']) {
  2684. $_option = array();
  2685. $_temp_op = array(
  2686. 'option_id' => 0,
  2687. 'option_content' => $slave['answer'],
  2688. 'option_correct' => 1,
  2689. );
  2690. if ($src['physicalTypeId'] == 11) {
  2691. $_temp_op['content_is_answer'] = 1;
  2692. }
  2693. $_option[] = $_temp_op;
  2694. $_items['options'] = $_option;
  2695. }
  2696. $_slave['items'] = $_items;
  2697. if (isset($slave['methods']) && $slave['methods']) {
  2698. $_specials = array();
  2699. foreach ($slave['methods'] as $method) {
  2700. if (isset($method['isLast']) && $method['isLast']) {
  2701. $__method = array(
  2702. "method_id" => $method['methodId'],
  2703. "method_name" => $method['methodName'],
  2704. );
  2705. $_specials[] = $__method;
  2706. }
  2707. }
  2708. $_slave['specials'] = $_specials;
  2709. }
  2710. $temp_info['slave'][] = $_slave;
  2711. }
  2712. } elseif (isset($src['options']) && $src['options']) {//大题单选选择
  2713. $temp_info['items'] = array();
  2714. $_option = array();
  2715. $_items = array(
  2716. 'type_id' => 1,
  2717. 'type_name' => '',
  2718. 'list_type' => 1,
  2719. // 'list_type' => int 0
  2720. 'title' => '',
  2721. 'options' => array(),
  2722. );
  2723. foreach ($src['options'] as $option) {
  2724. $_temp_op = array(
  2725. 'option_id' => 0,
  2726. 'option_content' => $option['content'],
  2727. 'option_correct' => $option['isTrue'],
  2728. );
  2729. $_option[] = $_temp_op;
  2730. }
  2731. $_items['options'] = $_option;
  2732. $temp_info['items'][] = $_items;
  2733. } elseif (isset($src['answer']) && $src['answer']) {//主题有答案的从题没有的,加一个从题
  2734. $_slave = array(
  2735. 'topic_slave_id' => $src['topicId'],
  2736. 'topic_type' => $src['physicalTypeId'],
  2737. 'type_name' => '',
  2738. 'difficulty_degree' => 0.86,
  2739. // 'difficulty_degree' => float 0.86
  2740. 'difficulty' => $src['difficulty'],
  2741. 'title' => '',
  2742. 'items' => array(),
  2743. 'kps' => array(),
  2744. 'specials' => array(),
  2745. );
  2746. $_items = array(
  2747. 'type_id' => 1,
  2748. 'type_name' => '',
  2749. 'list_type' => 1,
  2750. // 'list_type' => int 0
  2751. 'title' => '',
  2752. 'options' => array(),
  2753. );
  2754. $_option = array();
  2755. $_temp_op = array(
  2756. 'option_id' => 0,
  2757. 'option_content' => $src['answer'],
  2758. 'option_correct' => 1,
  2759. );
  2760. $_option[] = $_temp_op;
  2761. $_items['options'] = $_option;
  2762. $_slave['items'] = $_items;
  2763. $temp_info['slave'][] = $_slave;
  2764. }
  2765. $topicInfos[] = $temp_info;
  2766. }
  2767. }
  2768. if ($topicInfos) {
  2769. return $topicInfos;
  2770. } else {
  2771. return $result;
  2772. }
  2773. }
  2774. }
  2775. return $result;
  2776. }
  2777. /**
  2778. * 获取试卷选择题id
  2779. * @param $topic_type_arr
  2780. * @param $topic_logic_type_arr
  2781. * @param $is_has_large
  2782. */
  2783. protected function getChoiceIds($topic_type_arr, $topic_logic_type_arr, $subject_id, $paper_type)
  2784. {
  2785. $choice_ids = array();
  2786. $type_arr = array();
  2787. if (inArray($paper_type, array(0, 1, 2))) {
  2788. if ($subject_id == 12) {//物理
  2789. $type_arr = array(1, 4, 5, 8, 9);
  2790. } elseif ($subject_id == 13) {//化学
  2791. $type_arr = array(1);
  2792. } elseif ($subject_id == 14) {//生物
  2793. $type_arr = array(1, 3, 4);
  2794. } elseif ($subject_id == 15) {//政治
  2795. $type_arr = array(1, 3, 4, 6, 7);
  2796. } elseif ($subject_id == 16) {//历史
  2797. $type_arr = array(1);
  2798. } elseif ($subject_id == 17) {//地理
  2799. $type_arr = array(1, 3, 4);
  2800. }
  2801. } else {
  2802. $type_arr = array(1, 11);
  2803. }
  2804. foreach ($topic_logic_type_arr as $t_id => $type) {
  2805. if (inArray($type, $type_arr)) {
  2806. $choice_ids[] = $t_id;
  2807. }
  2808. }
  2809. //
  2810. $diff_topic = array_diff(array_keys($topic_logic_type_arr), $choice_ids);
  2811. if ($diff_topic) {
  2812. foreach ($topic_type_arr as $t_id => $item) {
  2813. if (inArray($t_id, $diff_topic) && inArray($item, array(1, 11))) {
  2814. $choice_ids[] = $t_id;
  2815. }
  2816. }
  2817. }
  2818. return $choice_ids;
  2819. }
  2820. /**
  2821. * 获取考点名称
  2822. * @param $topicDetails
  2823. * @return array
  2824. */
  2825. public function getMethodName(&$topicDetails)
  2826. {
  2827. $methodName = array();
  2828. if (is_array($topicDetails)) {
  2829. foreach ($topicDetails as $topicDetail) {
  2830. if (isset($topicDetail['specials']) && $topicDetail['specials']) {
  2831. foreach ($topicDetail['specials'] as $special) {
  2832. $methodName[$special['method_id']] = $special['method_name'];
  2833. }
  2834. }
  2835. if (isset($topicDetail['slave']) && $topicDetail['slave']) {
  2836. foreach ($topicDetail['slave'] as $slave) {
  2837. if (isset($slave['specials']) && $slave['specials']) {
  2838. foreach ($slave['specials'] as $spec) {
  2839. $methodName[$spec['method_id']] = $spec['method_name'];
  2840. }
  2841. }
  2842. }
  2843. }
  2844. }
  2845. }
  2846. return $methodName;
  2847. }
  2848. //共性问题变式训练
  2849. protected function getCommonPractice($paper_topic_detail, $stu_score_info, $stu_topic_rs, $large_topic_type_arr, $large_contain)
  2850. {
  2851. $class_wrong_topic = array();
  2852. $cls_grammar_topic = array();
  2853. $texturl_topic = array();
  2854. $common_push_topic = array();
  2855. $topic_method_arr = array();
  2856. $_push_all_topics = array();
  2857. $paper_topics = array_keys($large_topic_type_arr);
  2858. foreach ($paper_topic_detail as $topic_id => $detail) {
  2859. if (in_array($detail['type_id'], array(2, 3, 4, 5, 6, 7, 18, 19))) {
  2860. $topic_method_arr[$topic_id] = isset($detail['specials']) ? _array_column($detail['specials'], 'method_id') : array();
  2861. if (isset($detail['slave'])) {
  2862. foreach ($detail['slave'] as $slave) {
  2863. if (isset($slave['topic_slave_id'])) {
  2864. $topic_method_arr[$slave['topic_slave_id']] = isset($slave['method_names']) ? _array_column($slave['method_names'], 'method_id') : array();
  2865. }
  2866. }
  2867. }
  2868. }
  2869. }
  2870. foreach ($stu_score_info as $stu_id => $score_info) {
  2871. foreach ($score_info as $large_topic_id => $scoring) {
  2872. if (isset($large_topic_type_arr[$large_topic_id])) {
  2873. if (in_array($large_topic_type_arr[$large_topic_id], array(2, 3, 4, 5))) {
  2874. if (!isset($class_wrong_topic[$large_topic_id])) {
  2875. $class_wrong_topic[$large_topic_id] = array('scoring' => 0, 'score' => 0);
  2876. }
  2877. $_scoring = $class_wrong_topic[$large_topic_id]['scoring'];
  2878. $_score = $class_wrong_topic[$large_topic_id]['score'];
  2879. $class_wrong_topic[$large_topic_id] = array('scoring' => ($scoring['scoring'] + $_scoring), 'score' => ($scoring['score'] + $_score));
  2880. } elseif (in_array($large_topic_type_arr[$large_topic_id], array(18, 19))) {
  2881. $small_topic = $large_contain[$large_topic_id];
  2882. $stu_topic_info = isset($stu_topic_rs[$stu_id]) ? $stu_topic_rs[$stu_id] : array();
  2883. if ($stu_topic_info) {
  2884. foreach ($small_topic as $small_topic_id => $score) {
  2885. if (!isset($cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id])) {
  2886. $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring' => 0, 'score' => 0);
  2887. }
  2888. $stu_scoring = $stu_topic_info[$small_topic_id];
  2889. $_scoring = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['scoring'];
  2890. $_score = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['score'];
  2891. $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring' => ($stu_scoring['scoring'] + $_scoring), 'score' => ($score + $_score));
  2892. }
  2893. }
  2894. } elseif (in_array($large_topic_type_arr[$large_topic_id], array(6, 7))) {
  2895. $texturl_topic[] = $large_topic_id;
  2896. }
  2897. }
  2898. }
  2899. }
  2900. $class_score_rate = array();
  2901. foreach ($class_wrong_topic as $large_topic_id => $score_info) {
  2902. $score_rate = $this->scoreRate($score_info['scoring'], $score_info['score']);
  2903. $class_score_rate[$large_topic_id] = $score_rate;
  2904. }
  2905. if ($class_score_rate) {
  2906. asort($class_score_rate);
  2907. reset($class_score_rate);
  2908. $push_text_topic = key($class_score_rate);
  2909. $text_detail = $paper_topic_detail[$push_text_topic];
  2910. $kps = _array_column($text_detail['specials'], 'method_id');
  2911. $text_level = isset($text_detail['text_level']) ? $text_detail['text_level'] : 5;
  2912. $cloze_type = 0;
  2913. if ($text_detail['type_id'] == 2) {
  2914. $cloze_type = count($text_detail['slave']) == 15 ? 1 : 2;
  2915. }
  2916. $rules = array();
  2917. $rules[] = array(
  2918. 'type' => $text_detail['type_id'],
  2919. 'size' => 600,
  2920. 'cloze_type' => $cloze_type
  2921. );
  2922. $params_eng = array();
  2923. $params_eng['subjectId'] = 10;
  2924. $params_eng['rules'] = $rules;
  2925. $params_eng['inMethodIds'] = $kps;
  2926. $params_eng['isAudit'] = 2;
  2927. $params_eng['notInTopicIds'] = $paper_topics;
  2928. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng, 25, true);
  2929. if (isset($type_topic_arr[$text_detail['type_id']])) {
  2930. $all_topic = array();
  2931. $extract_topics = $type_topic_arr[$text_detail['type_id']];
  2932. while ($text_level > 0) {
  2933. if ($extract_topics[$text_level]) {
  2934. $all_topic = $extract_topics[$text_level];
  2935. break;
  2936. }
  2937. $text_level--;
  2938. }
  2939. if ($all_topic) {
  2940. $push_topic_key = array_rand($all_topic, 1);
  2941. $common_push_topic['min_rate_text'][$text_detail['type_id']] = array('topic_id' => $all_topic[$push_topic_key], 'topic_type' => $text_detail['type_id']);
  2942. $_push_all_topics[$all_topic[$push_topic_key]] = $all_topic[$push_topic_key];
  2943. }
  2944. }
  2945. }
  2946. $grammar_rules = array();
  2947. //班级错误率在50%及以上的
  2948. $grammar_score_rate = array();
  2949. $grammar_method = array();
  2950. foreach ($cls_grammar_topic as $type => $cgt_info) {
  2951. foreach ($cgt_info as $small_topic_id => $score_info) {
  2952. $score_rate = $this->scoreRate($score_info['scoring'], $score_info['score'], true);
  2953. if ($score_rate < 50) {
  2954. $grammar_score_rate[$type][$small_topic_id] = isset($topic_method_arr[$small_topic_id]) ? $topic_method_arr[$small_topic_id] : array();
  2955. }
  2956. }
  2957. }
  2958. $topic_count = array('19' => 10, '18' => 0);
  2959. foreach ($grammar_score_rate as $type => $gsr) {
  2960. if ($type == 6 || $type == 19) {
  2961. $type = 19;
  2962. }
  2963. $grammar_rules[$type] = array(
  2964. 'type' => 19,
  2965. 'size' => 600
  2966. );
  2967. if (!isset($grammar_method[$type])) {
  2968. $grammar_method[$type] = array();
  2969. }
  2970. foreach ($gsr as $item) {
  2971. if ($type == 18) {
  2972. $topic_count[18]++;
  2973. }
  2974. $grammar_method[$type] = array_merge($grammar_method[$type], $item);
  2975. }
  2976. }
  2977. //$read_base_obj = new ReadBase();
  2978. foreach ($grammar_rules as $type => $gr) {
  2979. $rules = array();
  2980. $rules[] = array(
  2981. 'type' => $type,
  2982. 'size' => 600
  2983. );
  2984. $params_eng = array();
  2985. $params_eng['subjectId'] = 10;
  2986. $params_eng['rules'] = $rules;
  2987. $params_eng['inMethodIds'] = isset($grammar_method[$type]) ? $grammar_method[$type] : array();
  2988. $params_eng['notInTopicIds'] = $paper_topics;
  2989. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng, 25, true);
  2990. if ($type_topic_arr) {
  2991. if (isset($type_topic_arr[$type]) && $type_topic_arr[$type]) {
  2992. $topics = reset($type_topic_arr[$type]);
  2993. $push_topic_key = array_rand($topics, $topic_count[$type]);
  2994. foreach ($push_topic_key as $key) {
  2995. $_push_all_topics[$topics[$key]] = $topics[$key];
  2996. $common_push_topic['common_grammar_topic'][$type][] = array('topic_id' => $topics[$key], 'topic_type' => $type);
  2997. }
  2998. }
  2999. }
  3000. }
  3001. $texturl_topic = array_unique($texturl_topic);
  3002. foreach ($texturl_topic as $t_id) {
  3003. $rules = array();
  3004. $rules[] = array(
  3005. 'type' => $paper_topic_detail[$t_id]['type_id'],
  3006. 'size' => 600
  3007. );
  3008. $params_eng = array();
  3009. $params_eng['subjectId'] = 10;
  3010. $params_eng['rules'] = $rules;
  3011. $params_eng['inMethodIds'] = isset($topic_method_arr[$t_id]) ? $topic_method_arr[$t_id] : array();
  3012. $params_eng['notInTopicIds'] = $paper_topics;
  3013. $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng, 25, true);
  3014. if ($type_topic_arr) {
  3015. if (isset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]) && $type_topic_arr[$paper_topic_detail[$t_id]['type_id']]) {
  3016. $topics = reset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]);
  3017. if ($topics) {
  3018. $push_topic_key = array_rand($topics, 1);
  3019. $_push_all_topics[$topics[$push_topic_key]] = $topics[$push_topic_key];
  3020. $common_push_topic['common_extra'][$paper_topic_detail[$t_id]['type_id']] = array('topic_id' => $topics[$push_topic_key], 'topic_type' => $paper_topic_detail[$t_id]['type_id']);
  3021. }
  3022. }
  3023. }
  3024. }
  3025. return array($common_push_topic, $_push_all_topics);
  3026. }
  3027. function scoreRate($scoring, $total_score, $is_per = false)
  3028. {
  3029. if ($total_score > 0) {
  3030. if ($is_per) {
  3031. $pre_rate = 100;
  3032. $decimal = 4;
  3033. } else {
  3034. $pre_rate = 1;
  3035. $decimal = 2;
  3036. }
  3037. return round($scoring / $total_score, $decimal) * $pre_rate;
  3038. } else {
  3039. return 0;
  3040. }
  3041. }
  3042. private function handleWordClass($keyWords)
  3043. {
  3044. $word_ids = _array_column($keyWords, 'single_word_id');
  3045. $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition' => array('single_word_id' => $word_ids), 'table' => 'en_single_word_label', 'isAll' => 1), 25, true);
  3046. if (isset($rs['status']) && $rs['status'] == 1 && isset($rs['data']) && $rs['data']) {
  3047. $label_ids = array();
  3048. $swm_ids = array();
  3049. foreach ($rs['data'] as $key => $v) {
  3050. if ($v['label_type_id'] == 3) {
  3051. unset($rs['data'][$key]);
  3052. }
  3053. if ($v['label_type_id'] == 7) {
  3054. $label_ids[] = $v['label_id'];
  3055. $swm_ids[] = $v['swm_id'];
  3056. }
  3057. }
  3058. $rel = array();
  3059. if ($label_ids) {
  3060. $label_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition' => array('label_id' => $label_ids), 'table' => 'en_label', 'isAll' => 1), 25, true);
  3061. if (isset($label_rs['status']) && $label_rs['status'] == 1 && isset($label_rs['data']) && $label_rs['data']) {
  3062. $rel = array();
  3063. foreach ($label_rs['data'] as $v) {
  3064. $rel[$v['label_id']] = $v['content'];
  3065. }
  3066. }
  3067. }
  3068. foreach ($rs['data'] as &$item) {
  3069. $item['content'] = isset($rel[$item['label_id']]) ? $rel[$item['label_id']] : '';
  3070. }
  3071. unset($item);
  3072. $new_swm_res = array();
  3073. if ($swm_ids) {
  3074. $swm_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition' => array('swm_id' => $swm_ids), 'table' => 'en_single_word_mean', 'isAll' => 1), 25, true);
  3075. if (isset($swm_rs['status']) && $swm_rs['status'] == 1 && isset($swm_rs['data']) && $swm_rs['data']) {
  3076. foreach ($swm_rs['data'] as $item) {
  3077. $new_swm_res[$item['swm_id']] = $item;
  3078. }
  3079. }
  3080. }
  3081. $new_res = array();
  3082. $res = $rs['data'];
  3083. foreach ($res as $res_val) {
  3084. $s_id = $res_val['single_word_id'];
  3085. if (!isset($new_res[$s_id])) {
  3086. $new_res[$s_id] = array('con_str' => '', 'swm_ids' => array(), 'single_word_id' => $s_id);
  3087. }
  3088. $new_res[$s_id]['con_str'] .= $res_val['content'];
  3089. $new_res[$s_id]['swm_ids'][] = $res_val['swm_id'];
  3090. if ($res_val['swm_id']) {
  3091. $new_res[$s_id]['swm_con'][$res_val['swm_id']] = $res_val['content'];
  3092. }
  3093. }
  3094. $_tmp_res = array();
  3095. foreach ($new_res as $tmp) {
  3096. $single_id = $tmp['single_word_id'];
  3097. $swm_ids = array_filter($tmp['swm_ids']);
  3098. if (!isset($_tmp_res[$single_id])) {
  3099. $_tmp_res[$single_id] = '';
  3100. }
  3101. if ($swm_ids) {
  3102. foreach ($swm_ids as $_id) {
  3103. if (isset($new_swm_res[$_id])) {
  3104. $_tmp_res[$single_id] .= ' ' . $tmp['swm_con'][$_id] . " {$new_swm_res[$_id]['mean']} ";
  3105. }
  3106. }
  3107. }
  3108. }
  3109. foreach ($keyWords as &$val) {
  3110. $val['word_class'] = isset($new_res[$val['single_word_id']]) ? $new_res[$val['single_word_id']]['con_str'] : '';
  3111. $val['new_mean'] = isset($_tmp_res[$val['single_word_id']]) ? $_tmp_res[$val['single_word_id']] : '';
  3112. }
  3113. }
  3114. return $keyWords;
  3115. }
  3116. /**
  3117. * 物理教师讲案
  3118. * @return array
  3119. */
  3120. public function actionPhysics()
  3121. {
  3122. set_time_limit(300);
  3123. ini_set('memory_limit', '300M');
  3124. $examId = (string)Req::get("examId");
  3125. $viewHtml = (int)Req::get('viewHtml');
  3126. $force = (int)Req::get('force');
  3127. require_once('TeachingPhysics.php');
  3128. $teachingPhysicsObj = new TeachingPhysics($this);
  3129. $result = $teachingPhysicsObj->getTeachingPdf($this->schoolId, $examId, $force, $viewHtml);
  3130. $result['pdf_path'] = '';
  3131. echo json_encode($result);
  3132. exit();
  3133. }
  3134. /**
  3135. * 英语题型新转老
  3136. */
  3137. public function getTopicTypeRelate()
  3138. {
  3139. return array(
  3140. '553' => '1',
  3141. '28' => '1',
  3142. '554' => '2',
  3143. '41' => '2',
  3144. '555' => '3',
  3145. '42' => '3',
  3146. '281' => '4',
  3147. '566' => '4',
  3148. '556' => '5',
  3149. '44' => '5',
  3150. '563' => '6',
  3151. '278' => '6',
  3152. '286' => '7',
  3153. '570' => '7',
  3154. '47' => '8',
  3155. '557' => '8',
  3156. '282' => '9',
  3157. '567' => '9',
  3158. '279' => '10',
  3159. '564' => '10',
  3160. '288' => '11',
  3161. '572' => '11',
  3162. '285' => '12',
  3163. '444' => '13',
  3164. '741' => '13',
  3165. '280' => '14',
  3166. '565' => '14',
  3167. '287' => '15',
  3168. '571' => '15',
  3169. '116' => '17',
  3170. '562' => '17',
  3171. '54' => '18',
  3172. '559' => '18',
  3173. '55' => '19',
  3174. '560' => '19',
  3175. '56' => '20',
  3176. '561' => '20',
  3177. '428' => '21',
  3178. '284' => '16'
  3179. );
  3180. }
  3181. //全学科试题详情兼容
  3182. public function quanTopicDetail($data)
  3183. {
  3184. $result = array();
  3185. $answer_arr = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
  3186. $getTopicTypeRelate = $this->getTopicTypeRelate();
  3187. if ($data) {
  3188. foreach ($data as $k => $v) {
  3189. $temp_basic_type_id = isset($v['basic_type_id']) ? $v['basic_type_id'] : 1;
  3190. $result[$k]['topic_id'] = $v['id'];
  3191. $result[$k]['id'] = $v['id'];
  3192. if (isset($v['bank_type']) && $v['bank_type']) {
  3193. $temp_type_id = $v['bank_type'];
  3194. } else {
  3195. $temp_type_id = $v['type_id'];
  3196. }
  3197. $result[$k]['type'] = $result[$k]['type_id'] = isset($getTopicTypeRelate[$temp_type_id]) ? $getTopicTypeRelate[$temp_type_id] : $temp_type_id;
  3198. $result[$k]['queBody'] = $v['title'];
  3199. $result[$k]['title'] = $v['title'];
  3200. $result[$k]['analysis'] = $v['parse_content'];
  3201. $result[$k]['parse_content'] = $v['parse_content'];
  3202. $result[$k]['slave'] = array();
  3203. $result[$k]['items'] = array();
  3204. $result[$k]['answer'] = '';
  3205. $result[$k]['answer_str'] = '';
  3206. $result[$k]['key_words_levels'] = array();
  3207. $result[$k]['key_words'] = array();
  3208. $result[$k]['isp_ids'] = array();
  3209. $result[$k]['text_level'] = 0;
  3210. $result[$k]['method_id_arr'] = array();
  3211. $result[$k]['sentences_analysis'] = '';
  3212. $result[$k]['topic_solution'] = '';
  3213. $result[$k]['model_essay_point'] = '';
  3214. $result[$k]['new_key_words'] = array();
  3215. if (isset($v['kps']) && $v['kps']) {
  3216. foreach ($v['kps'] as $kps) {
  3217. $result[$k]['method_id_arr'][] = $kps['kp_id'];
  3218. }
  3219. }
  3220. if (isset($v['affiliate']) && $v['affiliate']) {
  3221. foreach ($v['affiliate'] as $aff) {
  3222. if (isset($aff['field_key']) && $aff['field_key'] == 'tag_8_118') {
  3223. $result[$k]['text_level'] = isset($aff['field_value']) ? $aff['field_value'] : 0;
  3224. }
  3225. if (isset($aff['field_name']) && $aff['field_name'] == '长难句解析') {
  3226. $result[$k]['sentences_analysis'] = $aff['field_value'];
  3227. }
  3228. if (isset($aff['field_name']) && $aff['field_name'] == '审题思路') {
  3229. $result[$k]['topic_solution'] = $aff['field_value'];
  3230. }
  3231. if (isset($aff['field_name']) && $aff['field_name'] == '范文亮点') {
  3232. $result[$k]['model_essay_point'] = $aff['field_value'];
  3233. }
  3234. if (isset($aff['field_name']) && $aff['field_name'] == '词汇积累') {
  3235. if (isset($aff['field_value']) && $aff['field_value']) {
  3236. $temp_chjl = strip_tags($aff['field_value']);
  3237. $strPattern = "/(?<=\()[^\)]+/";
  3238. preg_match_all($strPattern, $temp_chjl, $result_words);
  3239. if (isset($result_words[0]) && $result_words[0]) {
  3240. $single_word_ids = $result_words[0];
  3241. $single_word_data = $this->apiBrainPost('/all_library/getSingleWords', array("single_word_id" => $single_word_ids), 25, true);
  3242. if ($single_word_data && $single_word_data['data']) {
  3243. $temp_single_word_data = $single_word_data['data'];
  3244. foreach ($temp_single_word_data as $temp_single_word_data_k => $temp_single_word_data_v) {
  3245. $result[$k]['new_key_words'][] = array(
  3246. "content" => isset($temp_single_word_data_v['content']) ? $temp_single_word_data_v['content'] : '',
  3247. "phonetic_symbol" => isset($temp_single_word_data_v['phonetic_symbol']) ? $temp_single_word_data_v['phonetic_symbol'] : '',
  3248. "new_mean" => isset($temp_single_word_data_v['mean']) ? $temp_single_word_data_v['mean'] : ''
  3249. );
  3250. }
  3251. }
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. if (isset($v['slave']) && $v['slave']) {
  3258. //七选五特殊处理
  3259. if ($result[$k]['type_id'] == 5) {
  3260. foreach ($v['slave'] as $slave_k => $slave_v) {
  3261. if (isset($slave_v['items']) && isset($slave_v['items']['options']) && $slave_v['items']['options']) {
  3262. foreach ($slave_v['items']['options'] as $option_k => $option_v) {
  3263. if ($option_v["option_correct"]) {
  3264. $v['slave'][$slave_k]['items']['options'][$option_k] = array("option_content" => isset($answer_arr[$option_k]) ? $answer_arr[$option_k] : '');
  3265. }
  3266. }
  3267. }
  3268. }
  3269. }
  3270. $result[$k]['slave'] = $v['slave'];
  3271. } else {
  3272. $result[$k]['items'] = $v['items'];
  3273. $options_arr = array();
  3274. if ($v['items'] && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  3275. $options_arr = $v['items'][0]['options'];
  3276. if ($v['items'][0]['options'] && count($v['items'][0]['options']) == 1) {
  3277. foreach ($v['items'][0]['options'] as $op_v) {
  3278. $result[$k]['answer'] = $op_v['option_content'];
  3279. }
  3280. }
  3281. }
  3282. $result[$k]['slave'][] = array('topic_slave_id' => $v['id'], 'items' => array('options' => $options_arr));
  3283. }
  3284. }
  3285. }
  3286. return $result;
  3287. }
  3288. }