generated from CMU-17313Q/NodeBB-f23
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from CMU-17313Q/integration-python-microservi…
…ce-flask Integration python microservice flask
- Loading branch information
Showing
18 changed files
with
597 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict'; | ||
|
||
define('forum/career', [ | ||
'translator', 'jquery-form', | ||
], function (translator) { | ||
const Career = {}; | ||
let validationError = false; | ||
|
||
Career.init = function () { | ||
const student_id = $('#student_id'); | ||
const age = $('#age'); | ||
const gpa = $('#gpa'); | ||
const num_programming_languages = $('#num_programming_languages'); | ||
const num_past_internships = $('#num_past_internships'); | ||
const signup = $('#signup'); | ||
|
||
function validateForm(callback) { | ||
validationError = false; | ||
validateNonEmpty(student_id.val(), $('#student-id-notify')); | ||
validateRangedInt(age.val(), $('#age-notify'), 18, 25); | ||
validateRangedFloat(gpa.val(), $('#gpa-notify'), 0.0, 4.0); | ||
validateRangedInt(num_programming_languages.val(), $('#num-programming-languages-notify'), 1, 5); | ||
validateRangedInt(num_past_internships.val(), $('#num-past-internships-notify'), 0, 4); | ||
callback(); | ||
} | ||
|
||
signup.on('click', function (e) { | ||
const registerBtn = $(this); | ||
const errorEl = $('#career-error-notify'); | ||
errorEl.addClass('hidden'); | ||
e.preventDefault(); | ||
validateForm(function () { | ||
if (validationError) { | ||
return; | ||
} | ||
|
||
registerBtn.addClass('disabled'); | ||
|
||
registerBtn.parents('form').ajaxSubmit({ | ||
headers: { | ||
'x-csrf-token': config.csrf_token, | ||
}, | ||
success: function () { | ||
location.reload(); | ||
}, | ||
error: function (data) { | ||
translator.translate(data.responseText, config.defaultLang, function (translated) { | ||
if (data.status === 403 && data.responseText === 'Forbidden') { | ||
window.location.href = config.relative_path + '/career?error=csrf-invalid'; | ||
} else { | ||
errorEl.find('p').text(translated); | ||
errorEl.removeClass('hidden'); | ||
registerBtn.removeClass('disabled'); | ||
} | ||
}); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
function validateNonEmpty(value, value_notify) { | ||
if (!value || value.length === 0) { | ||
showError(value_notify, 'Must be non-empty'); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function validateRangedInt(value, value_notify, min_val, max_val) { | ||
if (!value || isNaN(value)) { | ||
showError(value_notify, `Must be a valid integer`); | ||
} else if (parseInt(value, 10) < min_val || parseInt(value, 10) > max_val) { | ||
showError(value_notify, `Must be within the range [${min_val}, ${max_val}]`); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function validateRangedFloat(value, value_notify, min_val, max_val) { | ||
if (!value || isNaN(value)) { | ||
showError(value_notify, `Must be a valid floating point value`); | ||
} else if (parseFloat(value) < min_val || parseFloat(value) > max_val) { | ||
showError(value_notify, `Must be within the range [${min_val}, ${max_val}]`); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function showError(element, msg) { | ||
translator.translate(msg, function (msg) { | ||
element.html(msg); | ||
element.parent() | ||
.removeClass('register-success') | ||
.addClass('register-danger'); | ||
element.show(); | ||
}); | ||
validationError = true; | ||
} | ||
|
||
function showSuccess(element, msg) { | ||
translator.translate(msg, function (msg) { | ||
element.html(msg); | ||
element.parent() | ||
.removeClass('register-danger') | ||
.addClass('register-success'); | ||
element.show(); | ||
}); | ||
} | ||
|
||
return Career; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const user = require('../user'); | ||
const helpers = require('./helpers'); | ||
|
||
const careerController = module.exports; | ||
|
||
careerController.get = async function (req, res) { | ||
const userData = await user.getUserFields(req.uid, ['accounttype']); | ||
|
||
const accountType = userData.accounttype; | ||
let careerData = {}; | ||
|
||
if (accountType === 'recruiter') { | ||
careerData.allData = await user.getAllCareerData(); | ||
} else { | ||
const userCareerData = await user.getCareerData(req.uid); | ||
if (userCareerData) { | ||
careerData = userCareerData; | ||
} else { | ||
careerData.newAccount = true; | ||
} | ||
} | ||
|
||
careerData.accountType = accountType; | ||
careerData.breadcrumbs = helpers.buildBreadcrumbs([{ text: 'Career', url: '/career' }]); | ||
res.render('career', careerData); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const helpers = require('../helpers'); | ||
const user = require('../../user'); | ||
const db = require('../../database'); | ||
|
||
const Career = module.exports; | ||
Career.register = async function (req, res) { | ||
const userData = req.query; | ||
try { | ||
// Forward the request to the Flask application | ||
// console.log(userData.student_id); | ||
const flaskResponse = await fetch('http://127.0.0.1:5000/predict', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
// Include any other necessary headers | ||
}, | ||
body: JSON.stringify({ | ||
student_id: userData.student_id, | ||
major: userData.major, | ||
age: userData.age, | ||
gender: userData.gender, | ||
gpa: userData.gpa, | ||
extra_curricular: userData.extra_curricular, | ||
num_programming_languages: userData.num_programming_languages, | ||
num_past_internships: userData.num_past_internships, | ||
}), | ||
}); | ||
|
||
const userCareerData = { | ||
student_id: userData.student_id, | ||
major: userData.major, | ||
age: userData.age, | ||
gender: userData.gender, | ||
gpa: userData.gpa, | ||
extra_curricular: userData.extra_curricular, | ||
num_programming_languages: userData.num_programming_languages, | ||
num_past_internships: userData.num_past_internships, | ||
}; | ||
if (!flaskResponse.ok) { | ||
throw new Error('Failed to get prediction from Flask app.'); | ||
} | ||
const predictionResult = await flaskResponse.json(); | ||
console.log(predictionResult); | ||
userCareerData.prediction = predictionResult.good_employee; | ||
await user.setCareerData(req.uid, userCareerData); | ||
db.sortedSetAdd('users:career', req.uid, req.uid); | ||
res.json({}); | ||
} catch (err) { | ||
console.log(err); | ||
helpers.noScriptErrors(req, res, err.message, 400); | ||
} | ||
}; |
Oops, something went wrong.