Advertisement
Fahim_7861

Untitled

Jul 1st, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1.  
  2. const [open,setOpen] = useState(false);
  3.  
  4. const classes = useStyles();
  5.  
  6. const theme = useTheme();
  7.  
  8. const isWeb = useMediaQuery(theme.breakpoints.up("sm"));
  9.  
  10. const testValue = 0;
  11.  
  12. const { id, page, from } = useParams();
  13.  
  14. const [currentPage, setCurrentPage] = useState(useParams().page);
  15.  
  16. const initData = useSelector((state) => state.initData);
  17.  
  18. let resultinitData,allExams=[];
  19.  
  20.  
  21. const AllresultinitData = useSelector((state) => state.initData.results);
  22.  
  23. if(AllresultinitData!==undefined){
  24. resultinitData = AllresultinitData[id];
  25. }
  26.  
  27. const resultresponse = useSelector((state) => state.submitAnsResponse);
  28.  
  29. let inittialAllExam =useSelector((state) => state.initData.exams);
  30.  
  31. if(inittialAllExam!==undefined)
  32. allExams=inittialAllExam;
  33.  
  34. let archievedExam = useSelector((state) => state.archievedData.exams);
  35.  
  36. if (archievedExam !== undefined) {
  37. allExams = [...allExams, ...archievedExam];
  38. }
  39.  
  40.  
  41. const history = useHistory();
  42.  
  43. const pageChange = (Page) => {
  44. setCurrentPage(Page);
  45.  
  46. history.push(resultDetails(id, Page, from));
  47. };
  48.  
  49. let result,
  50. statistics = {},
  51. passed_examinees = 0,
  52. total_examinees = 0,
  53. cut_mark = 0.0,
  54. marks = 0.0,
  55. incorrect_answers = 0,
  56. correct_answers = 0,
  57. skippedCount = 0,
  58. total_marks = 1,
  59. total_questions=0,
  60.  
  61. title="";
  62.  
  63.  
  64.  
  65.  
  66. if (from == RESPONSE) {
  67. result = resultresponse;
  68. statistics = result.statistics;
  69. } else {
  70. result = resultinitData;
  71.  
  72. if (result == undefined) {
  73. const resultarray = allExams.filter((ex) => ex.id == id);
  74.  
  75. if (resultarray.length > 0) {
  76. result = resultarray[0];
  77.  
  78. statistics = result.statistics;
  79. }
  80. } else statistics = result.exam_data.statistics;
  81. }
  82.  
  83.  
  84.  
  85. if (isEmpty(result) || result == undefined) {
  86. return <LoaderComponent />;
  87. }
  88.  
  89. let standings = [];
  90.  
  91. if (from != RESPONSE) {
  92. if ( result.exam_data == undefined ||result.exam_data.statistics == undefined
  93. ) {
  94. standings = result.statistics.standings;
  95. } else standings = result.exam_data.statistics.standings;
  96.  
  97. passed_examinees = statistics.passed_examinees;
  98. total_examinees = statistics.total_examinees;
  99. if(statistics.cut_mark!=undefined)
  100. cut_mark = statistics.cut_mark.toFixed(1);
  101.  
  102. }
  103. else {
  104. if (result.exam_data != undefined) {
  105. standings = result.exam_data.statistics.standings;
  106.  
  107.  
  108. }
  109. }
  110.  
  111.  
  112.  
  113.  
  114. let currentQuestion = [];
  115.  
  116. if (from == RESPONSE) {
  117.  
  118. let AllcurrentQuestion = allExams.filter((ex) => ex.id == id)[0].questions;
  119.  
  120. if(AllcurrentQuestion!==undefined)
  121. {
  122. currentQuestion = AllcurrentQuestion;
  123. }
  124. } else {
  125. if (
  126. result.exam_data == undefined ||
  127. result.exam_data.questions == undefined
  128. ) {
  129. currentQuestion = result.questions;
  130. } else currentQuestion = result.exam_data.questions;
  131. }
  132.  
  133. if (result.answer_sheet != undefined) {
  134. let mp = {};
  135.  
  136. result.answer_sheet.forEach((ans) => {
  137. mp[ans.question] = ans.answers[0];
  138. });
  139.  
  140. // console.log(currentQuestion);
  141.  
  142. let newAnswerSheet = [];
  143.  
  144. if(currentQuestion!==undefined){
  145.  
  146. currentQuestion.forEach((que) => {
  147. if (mp[que] != undefined)
  148. newAnswerSheet.push({
  149. answers: [mp[que]],
  150. question: que,
  151. });
  152. else
  153. newAnswerSheet.push({
  154. answers: [],
  155. question: que,
  156. });
  157. });
  158.  
  159. }
  160.  
  161. result = { ...result, ["answer_sheet"]: newAnswerSheet };
  162. }
  163.  
  164. if (result != undefined && result.answer_sheet != undefined) {
  165. marks = result.statistics.marks.toFixed(1);
  166. incorrect_answers = result.statistics.incorrect_answers;
  167. correct_answers = result.statistics.correct_answers;
  168. skippedCount =
  169. result.answer_sheet.length - (incorrect_answers + correct_answers);
  170. }
  171.  
  172. const pageCheck = (newPage) => newPage === page;
  173.  
  174. const standingAvailable = () =>
  175. (standings != undefined && standings != null && standings.length > 0) ==
  176. true;
  177.  
  178.  
  179.  
  180. const checkPosition = () => {
  181. if (
  182. result == undefined ||
  183. result.statistics == undefined ||
  184. result.statistics.position == undefined ||
  185. result.statistics.position == "N/A"
  186. )
  187. return false;
  188.  
  189. return true;
  190. };
  191.  
  192. const PassFailRemark = () => {
  193. if (
  194. result == undefined ||
  195. result.statistics == undefined ||
  196. result.statistics.grade == undefined ||
  197. result.statistics.grade == "fail"
  198. )
  199. return "আপনি অনুত্তীর্ণ হয়েছেন";
  200. else return "আপনি উত্তীর্ণ হয়েছেন";
  201. };
  202.  
  203. const passFailBorderColor = () => {
  204. if (
  205. result == undefined ||
  206. result.statistics == undefined ||
  207. result.statistics.grade == undefined ||
  208. result.statistics.grade == "fail"
  209. )
  210. return { border: "2px solid red" };
  211.  
  212. return {};
  213. };
  214.  
  215. const PassOrFaillImage = () => {
  216. if (
  217. result == undefined ||
  218. result.statistics == undefined ||
  219. result.statistics.grade == undefined ||
  220. result.statistics.grade == "fail"
  221. )
  222. return <img className={classes.passFailImageSize} src={crossResult} alt=''></img>;
  223.  
  224. return <img style={classes.passFailImageSize} src={trophy} alt=''></img>;
  225. };
  226.  
  227.  
  228.  
  229. if(result!==undefined && result.exam_data!==undefined && result.exam_data.total_marks!=undefined )
  230. {
  231.  
  232. total_marks = result.exam_data.total_marks;
  233.  
  234.  
  235.  
  236.  
  237. }
  238. else if(result!=undefined && result.total_marks!=undefined)
  239. {
  240. total_marks = result.total_marks;
  241. }
  242.  
  243. // console.log('final ',result,result!==undefined, result.exam_data,result.exam_data.statistics);
  244.  
  245. if(from==RESPONSE && result!==undefined && result.exam_data!==undefined && result.exam_data.statistics!=undefined )
  246. {
  247. passed_examinees = result.exam_data.statistics.passed_examinees;
  248. total_examinees = result.exam_data.statistics.total_examinees;
  249. if(result.exam_data.statistics.cut_mark!=undefined)
  250. cut_mark = result.exam_data.statistics.cut_mark.toFixed(1);
  251.  
  252. }
  253.  
  254. if(result!==undefined && result.exam_data!==undefined)
  255. {
  256. title = result.exam_data.title;
  257.  
  258. }
  259.  
  260. if(result!==undefined && currentQuestion!==undefined)
  261. {
  262.  
  263. total_questions = currentQuestion.length;
  264. console.log(total_questions)
  265. }
  266.  
  267.  
  268.  
  269.  
  270.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement