Skip to content

Commit

Permalink
Merge pull request #52 from Aar-if/newaltv1
Browse files Browse the repository at this point in the history
School and timespent changes aded
  • Loading branch information
Aar-if authored Mar 20, 2024
2 parents 4378e45 + 2a8034c commit d9e035a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 104 deletions.
17 changes: 10 additions & 7 deletions packages/admin/src/api/schoolBulkAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { schoolBulk } from "routes/links";
import axios from "axios";

const schoolBulkAPI = async (school) => {
const token = sessionStorage.getItem('token');
const token = sessionStorage.getItem("token");

const headers = {
"Accept-Language": "en-GB,en;q=0.9",
Expand All @@ -19,9 +19,12 @@ const schoolBulkAPI = async (school) => {
headers: headers,
})
.then((res) => {
const names = res.data.errors.map((error) => error.name).filter(Boolean);
if (res.data.errors && res.data.errors.length > 0) {
const firstError = res.data.errors[0];
console.log(res);
const names = res.data.data.errors
.map((error) => error.name)
.filter(Boolean);
if (res.data.data.errors && res.data.data.errors.length > 0) {
const firstError = res.data.data.errors[0];
if (firstError.schoolRes && firstError.schoolRes.errorMessage) {
const errorMessage = firstError.schoolRes.errorMessage;
localStorage.setItem("errorMessage", errorMessage);
Expand All @@ -32,11 +35,11 @@ const schoolBulkAPI = async (school) => {
console.log("No errors in the response data.");
}

localStorage.setItem("bulkErrors", res.data.errors.length - 1);
localStorage.setItem("bulkErrors", res.data.data.errors.length);
localStorage.setItem("bulkErrorsNames", names);
localStorage.setItem("successCount", res.data.successCount);
localStorage.setItem("successCount", res.data.data.successCount);

if (res.status === 201) {
if (res.status === 200) {
result = true;
} else {
result = false;
Expand Down
175 changes: 82 additions & 93 deletions packages/admin/src/components/SchoolCSV.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button } from "native-base";
import { H2 } from "@shiksha/common-lib";
import schoolBulkAPI from "api/schoolBulkAPI";
import { Progress, Space } from "antd";
import Papa from "papaparse";

function CSVImportForm() {
const [csvData, setCSVData] = useState([]);
Expand All @@ -30,39 +31,21 @@ function CSVImportForm() {

const handleFileChange = (e) => {
const file = e.target.files[0];
const reader = new FileReader();

reader.onload = (event) => {
const content = event.target.result;
const lines = content.split("\n");

let headers = [];

// Find the header row (row with the header names)
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() !== "") {
headers = lines[i].split(",");
break;
}
}

// Remove the trailing newline character from each line and then split into columns
const data = lines.slice(1).map((line) => {
const columns = line.replace(/\r$/, "").split(",");
const schoolObject = {};

// Map columns to header names dynamically
headers.forEach((header, index) => {
schoolObject[header] = columns[index] || "";
});

return schoolObject;
});

setCSVData(data);
};

reader.readAsText(file);
Papa.parse(file, {
header: true,
complete: (result) => {
const trimmedData = result.data.map((row) => ({
...row,
gender: row.gender ? row.gender.trim() : null,
}));

setCSVData(trimmedData);
console.log(trimmedData);
},
error: (error) => {
console.error("CSV Parsing Error:", error);
},
});
};

const sendBatch = async (startIndex, endIndex) => {
Expand All @@ -81,67 +64,73 @@ function CSVImportForm() {

for (let i = 0; i < csvData.length; i++) {
const schoolData = csvData[i];
const schoolObject = {
udiseCode: schoolData["School UDISE code"] || null,
name: schoolData["School Name"] || null,
location: schoolData["Location"] || null,
management: schoolData["School Management"] || null,
composition: schoolData["School Composition"] || null,
board: schoolData["Board"] || null,
mediumOfInstruction: [schoolData["Medium of Instruction"]] || [],
headmaster: schoolData["Head Master"] || null,
headmasterType: schoolData["Headmaster Type"] || null,
headmasterMobile: schoolData["Headmaster Mobile"] || null,
upperPrimaryTeachersSanctioned:
parseInt(
schoolData["Number of teachers sanctioned -Upper Primary"]
) || 0,
secondaryTeachersSanctioned:
parseInt(schoolData["Number of teachers sanctioned -Secondary"]) || 0,
libraryFunctional: schoolData["Library Functional"] || null,
computerLabFunctional: schoolData["Computer Lab functional"] || null,
totalFunctionalComputers:
parseInt(schoolData["Number of functional computers"]) || 0,
noOfBoysToilet: parseInt(schoolData["Number of Boys toilet"]) || 0,
noOfGirlsToilet: parseInt(schoolData["Number of Girls toilet"]) || 0,
smartBoardFunctionalClass6:
schoolData["Smart Board functional in Class 6"] || null,
smartBoardFunctionalClass7:
schoolData["Smart Board functional in Class 7"] || null,
smartBoardFunctionalClass8:
schoolData["Smart Board functional in Class 8"] || null,
smartBoardFunctionalClass9:
schoolData["Smart Board functional in Class 9"] || null,
smartBoardFunctionalClass10:
schoolData["Smart Board functional in Class 10"] || null,
state: schoolData["State"] || null,
district: schoolData["District"] || null,
block: schoolData["Block"] || null,
adequateRoomsForEveryClass:
schoolData["Adequate Rooms For EveryClass"] || false,
drinkingWaterSupply: schoolData["Drinking Water Supply"] || false,
seperateToiletForGirlsAndBoys:
schoolData["Separate Toilet For Girls And Boys"] || false,
whetherToiletBeingUsed:
schoolData["Whether Toilet Being Used"] || false,
playgroundAvailable: schoolData["Playground Available"] || false,
boundaryWallFence: schoolData["Boundary Wall Fence"] || false,
electricFittingsAreInsulated:
schoolData["Electric Fittings Are Insulated"] || false,
buildingIsResistantToEarthquakeFireFloodOtherCalamity:
schoolData[
"Building Is Resistant To Earthquake Fire Flood Other Calamity"
] || false,
buildingIsFreeFromInflammableAndToxicMaterials:
schoolData["Building Is Free From Inflammable And Toxic Materials"] ||
false,
roofAndWallsAreInGoodCondition:
schoolData["Roof And Walls Are In Good Condition"] || false,
};

requestData.schools.push(schoolObject);
if (
schoolData["School UDISE code"] &&
schoolData["School UDISE code"].trim() !== ""
) {
const schoolObject = {
udiseCode: schoolData["School UDISE code"] || null,
name: schoolData["School Name"] || null,
location: schoolData["Location"] || null,
management: schoolData["School Management"] || null,
composition: schoolData["School Composition"] || null,
board: schoolData["Board"] || null,
mediumOfInstruction: [schoolData["Medium of Instruction"]] || [],
headmaster: schoolData["Head Master"] || null,
headmasterType: schoolData["Headmaster Type"] || null,
headmasterMobile: schoolData["Headmaster Mobile"] || null,
upperPrimaryTeachersSanctioned:
parseInt(
schoolData["Number of teachers sanctioned -Upper Primary"]
) || 0,
secondaryTeachersSanctioned:
parseInt(schoolData["Number of teachers sanctioned -Secondary"]) ||
0,
libraryFunctional: schoolData["Library Functional"] || null,
computerLabFunctional: schoolData["Computer Lab functional"] || null,
totalFunctionalComputers:
parseInt(schoolData["Number of functional computers"]) || 0,
noOfBoysToilet: parseInt(schoolData["Number of Boys toilet"]) || 0,
noOfGirlsToilet: parseInt(schoolData["Number of Girls toilet"]) || 0,
smartBoardFunctionalClass6:
schoolData["Smart Board functional in Class 6"] || null,
smartBoardFunctionalClass7:
schoolData["Smart Board functional in Class 7"] || null,
smartBoardFunctionalClass8:
schoolData["Smart Board functional in Class 8"] || null,
smartBoardFunctionalClass9:
schoolData["Smart Board functional in Class 9"] || null,
smartBoardFunctionalClass10:
schoolData["Smart Board functional in Class 10"] || null,
state: schoolData["State"] || null,
district: schoolData["District"] || null,
block: schoolData["Block"] || null,
adequateRoomsForEveryClass:
schoolData["Adequate Rooms For EveryClass"] || false,
drinkingWaterSupply: schoolData["Drinking Water Supply"] || false,
seperateToiletForGirlsAndBoys:
schoolData["Separate Toilet For Girls And Boys"] || false,
whetherToiletBeingUsed:
schoolData["Whether Toilet Being Used"] || false,
playgroundAvailable: schoolData["Playground Available"] || false,
boundaryWallFence: schoolData["Boundary Wall Fence"] || false,
electricFittingsAreInsulated:
schoolData["Electric Fittings Are Insulated"] || false,
buildingIsResistantToEarthquakeFireFloodOtherCalamity:
schoolData[
"Building Is Resistant To Earthquake Fire Flood Other Calamity"
] || false,
buildingIsFreeFromInflammableAndToxicMaterials:
schoolData[
"Building Is Free From Inflammable And Toxic Materials"
] || false,
roofAndWallsAreInGoodCondition:
schoolData["Roof And Walls Are In Good Condition"] || false,
};

requestData.schools.push(schoolObject);
}
}

try {
const result = await schoolBulkAPI(requestData);
if (result === true) {
Expand Down
14 changes: 10 additions & 4 deletions packages/studentprogram/src/pages/lessonList.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,17 @@ export default function LessonList({ footerLinks }) {
}, []);
scoreDetails = JSON.stringify(newFormatData);
const timeSpentString = localStorage.getItem("totalDuration");
const timeSpentInt = parseInt(timeSpentString, 10);
const formattedNumber =
timeSpentString.slice(0, -3) + "." + timeSpentString.slice(-3);
const timeSpentInt = parseFloat(formattedNumber);
const inSeconds = Math.ceil(timeSpentInt);
data = {
courseId: id,
moduleId: id,
lessonId: id,
status: "completed",
contentType: localStorage.getItem("contentType"),
timeSpent: timeSpentInt,
timeSpent: inSeconds,
score: score,
scoreDetails: scoreDetails,
program: programData?.programId,
Expand All @@ -155,14 +158,17 @@ export default function LessonList({ footerLinks }) {
} else {
scoreDetails = JSON.stringify(props);
const timeSpentString = localStorage.getItem("totalDuration");
const timeSpentInt = parseInt(timeSpentString, 10);
const formattedNumber =
timeSpentString.slice(0, -3) + "." + timeSpentString.slice(-3);
const timeSpentInt = parseFloat(formattedNumber);
const inSeconds = Math.ceil(timeSpentInt);
data = {
courseId: id,
moduleId: lessonId?.parent,
lessonId: lessonId?.identifier,
status: "completed",
contentType: localStorage.getItem("contentType"),
timeSpent: timeSpentInt,
timeSpent: inSeconds,
score: score ? score : 0,
scoreDetails: scoreDetails,
program: programData?.programId,
Expand Down

0 comments on commit d9e035a

Please sign in to comment.