Skip to content

Commit

Permalink
Merge pull request #102 from COS301-SE-2024/feature/walkthrough
Browse files Browse the repository at this point in the history
Feature/walkthrough
  • Loading branch information
Yeshlen authored Jul 19, 2024
2 parents 33e3755 + 184d644 commit 3aa1e57
Show file tree
Hide file tree
Showing 24 changed files with 2,466 additions and 250 deletions.
Binary file added backend/Receiver/NCEWD1.docx
Binary file not shown.
Binary file added backend/Receiver/NCEX1.xlsx
Binary file not shown.
9 changes: 5 additions & 4 deletions gnd-app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "700kb", // Increased from 500kb
"maximumError": "1.5mb" // Increased from 1mb
"maximumWarning": "700kb",
"maximumError": "1.5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "3kb", // Increased from 2kb
"maximumError": "5kb" // Increased from 4kb
"maximumWarning": "3kb",
"maximumError": "5kb"
}
],
"outputHashing": "all"
Expand Down Expand Up @@ -89,6 +89,7 @@
],
"styles": [
"@angular/material/prebuilt-themes/azure-blue.css",
"node_modules/intro.js/introjs.css",
"src/styles.css"
],
"scripts": []
Expand Down
69 changes: 43 additions & 26 deletions gnd-app/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { app, BrowserWindow } = require('electron')
const { spawn } = require('child_process');
const http = require('http');
const axios = require('axios');
const path_ = require('path');
const path = require('path');
const fs = require('fs');

function createWindow () {
Expand All @@ -11,45 +10,53 @@ function createWindow () {
height: 600,
minWidth: 700,
minHeight: 600,
icon: path.join(__dirname, 'src/assets/logo.ico'),
webPreferences: {
nodeIntegration: true,
}
})

win.loadFile('dist/gnd-app/index.html')
win.setMenu(null);
win.loadFile(path.join(__dirname, 'dist', 'gnd-app', 'index.html'))
}

app.whenReady().then(() => {
startAPI();
createWindow();
setTimeout(setupWatcher, 1);
setTimeout(setupWatcher, 1000); // Increased delay to ensure API is ready
});

function startAPI() {
const api = spawn('uvicorn', ['api:app', '--reload'], {cwd: '../backend'});
const apiPath = path.join(__dirname, '..', 'backend');
const api = spawn('uvicorn', ['api:app', '--reload'], {cwd: apiPath});

api.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
console.log(`API stdout: ${data}`);
});

api.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
console.error(`API stderr: ${data}`);
});

api.on('error', (error) => {
console.error(`Failed to start API: ${error}`);
});

api.on('close', (code) => {
console.log(`child process exited with code ${code}`);
console.log(`API process exited with code ${code}`);
});
}

function setupWatcher() {
const watcher = spawn('python', ['../backend/File_monitor/file_watcher.py', '../backend/Receiver', 'pdf,docx,xlsx,xls']);
const watcherPath = path.join(__dirname, '..', 'backend', 'File_monitor', 'file_watcher.py');
const receiverPath = path.join(__dirname, '..', 'backend', 'Receiver');
const watcher = spawn('python', [watcherPath, receiverPath, 'pdf,docx,xlsx,xls']);

watcher.stdout.on('data', (data) => {
let output = data.toString().trim();
console.log(`stdout: ${output}`);
console.log(`Watcher stdout: ${output}`);
const postData = { path: output };

const path = data.toString().trim();
const segments = path.split('/');
const segments = output.split(path.sep);
const fileNameWithExtension = segments[segments.length - 1];
const parts = fileNameWithExtension.split('.');
const name = parts[0] + '_report.txt';
Expand All @@ -61,17 +68,27 @@ function setupWatcher() {
'Content-Type': 'application/json',
},
})
.then((res) => {
// console.log(`STATUS: ${res.status}`);
// console.log(`BODY: ${JSON.stringify(res.data)}`);
output = JSON.stringify(res.data);
// console.log(output)
console.log("Report successfully created")
const outputDir = path_.join('../backend/Reports', newFileName);
fs.writeFileSync(outputDir, output, 'utf8');
})
.catch((error) => {
console.error(`problem with request: ${error.message}`);
});
.then((res) => {
console.log("Report successfully created");
const outputDir = path.join(__dirname, '..', 'backend', 'Reports', newFileName);
fs.writeFile(outputDir, JSON.stringify(res.data), 'utf8', (err) => {
if (err) console.error(`Failed to write report: ${err}`);
});
})
.catch((error) => {
console.error(`Problem with request: ${error.message}`);
});
});

watcher.stderr.on('data', (data) => {
console.error(`Watcher stderr: ${data}`);
});

watcher.on('error', (error) => {
console.error(`Failed to start watcher: ${error}`);
});
}

watcher.on('close', (code) => {
console.log(`Watcher process exited with code ${code}`);
});
}
Loading

0 comments on commit 3aa1e57

Please sign in to comment.