Skip to content

Commit

Permalink
added loggs
Browse files Browse the repository at this point in the history
  • Loading branch information
sijumoncy committed Jan 19, 2023
1 parent cc9d46e commit 36de8f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
3 changes: 3 additions & 0 deletions renderer/src/components/EditorPage/Reference/OBS/ObsTn.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ function ObsTnCard({
const projectName = `${offlineResource.data?.value?.meta?.name}_${offlineResource.data?.value?.meta?.owner}_${offlineResource.data?.value?.meta?.release?.tag_name}`;
if (fs.existsSync(path.join(folder, projectName))) {
if (offlineResource.data?.value?.dublin_core?.format?.toLowerCase() === 'text/tsv') {
logger.debug('inside OBS TN offline TSV resource');
const tsvFileName = offlineResource.data?.value?.projects[0]?.path;
const obsTsvData = await fs.readFileSync(path.join(folder, projectName, tsvFileName), 'utf8');
const obsTsvJson = obsTsvData && await tsvJSON(obsTsvData);
logger.debug('inside OBS TN offline TSV resource : created TSV JSON');
await ObsTsvToChapterLevelMd(obsTsvJson, chapter).then((chapterTsvData) => {
logger.debug('inside OBS TN offline TSV resource : generated chapter Md level occurencenot Array');
setItems(chapterTsvData);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
// filter current chapter data from whole TSV JSON and generate array of notes of md content
// based on reference of tsv
import * as logger from '../../../../logger';

export default async function ObsTsvToChapterLevelMd(tsvJSON, chapter) {
return new Promise((resolve) => {
logger.debug('in ObsTsvToChapterLevel.js : in promise');
const filteredData = tsvJSON.filter((data) => data.Reference.split(':')[0].toString() === chapter.toString());
const chapterTsvData = [];
const notesObj = {};
filteredData.forEach((tsvObj) => {
let mdstring = '';
mdstring += `# ${ tsvObj.Quote }\n\n${ tsvObj.Note }\n`;
if (tsvObj.Reference.split(':')[1] in notesObj) {
notesObj[tsvObj.Reference.split(':')[1]].OccurrenceNote += mdstring;
} else {
notesObj[tsvObj.Reference.split(':')[1]] = { OccurrenceNote: mdstring };
const chapterTsvData = [];
const notesObj = {};
filteredData.forEach((tsvObj) => {
let mdstring = '';
mdstring += `# ${ tsvObj.Quote }\n\n${ tsvObj.Note }\n`;
if (tsvObj.Reference.split(':')[1] in notesObj) {
notesObj[tsvObj.Reference.split(':')[1]].OccurrenceNote += mdstring;
} else {
notesObj[tsvObj.Reference.split(':')[1]] = { OccurrenceNote: mdstring };
}
});
Object.values(notesObj).forEach((value) => {
chapterTsvData.push(value);
});
if (chapterTsvData?.length > 0) {
logger.debug('in ObsTsvToChapterLevel.js : finished tsv md array resolved');
resolve(chapterTsvData);
}
});
Object.values(notesObj).forEach((value) => {
chapterTsvData.push(value);
});
if (chapterTsvData?.length > 0) {
resolve(chapterTsvData);
}
});
}
7 changes: 5 additions & 2 deletions renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// convert TSV to line by line json
import * as logger from '../../../../logger';

export default async function tsvJSON(tsv) {
const lines = tsv.split('\n');

logger.debug('in TsvToJson.js : in convert function');
const result = [];

const headers = lines[0].split('\t');
Expand All @@ -15,6 +18,6 @@ export default async function tsvJSON(tsv) {

result.push(obj);
}

logger.debug('in TsvToJson.js : in convert function , Finished');
return result;
}

0 comments on commit 36de8f3

Please sign in to comment.