forked from rosewbw/KGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
100 changed files
with
2,683 additions
and
25,666 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-dbVIfZGuN1Yq7/1Ocstc1lUEm+AT+/rCkibIcC/OmWo5f0EA48Vf8CytHzGrSwbQ" crossorigin="anonymous"> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-2BKqo+exmr9su6dir+qCw08N2ZKRucY4PrGQPPWU1A7FtlCGjmEGFqXCv5nyM5Ij" crossorigin="anonymous"></script> | ||
<title>众智化教学平台</title> | ||
</head> | ||
<body> | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
const knowledgePoints = require('./knowledgePoints'); | ||
const service = require('./service'); | ||
|
||
module.exports = { | ||
knowledgePoints, | ||
service, | ||
}; |
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,104 @@ | ||
const { createInModel, findInModel, findOneInModel } = require('../../../database/model-operations'); | ||
const { pyRequest } = require('../../utils/pyRequest'); | ||
const { getUserInfoFromReq } = require('../../utils/token'); | ||
|
||
async function get(req, res, next) { | ||
const { courseId, knowledgeId } = req.params; | ||
if (!courseId || !knowledgeId) { | ||
return res.sendStatus(400); | ||
} | ||
|
||
try { | ||
const NecessaryInfo = [getUserInfoFromReq(req), findOneInModel('tProject', {_id: courseId})]; | ||
const [user, course] = await Promise.all(NecessaryInfo); | ||
if (course.publishStatus !== 'publish' && course.userId !== user._id) { | ||
return res.sendStatus(401); | ||
} | ||
|
||
if (!Array.isArray(course.data)) return res.sendStatus(500); | ||
let knowledgePoint = course.data.filter(k => k._id === knowledgeId)[0]; | ||
knowledgePoint.course = { | ||
_id: course._id, | ||
title: course.projectName, | ||
}; | ||
|
||
return res.json({ | ||
status: 'success', | ||
data: knowledgePoint, | ||
}); | ||
} catch (error) { | ||
res.sendStatus(500).send({message: error}); | ||
} | ||
} | ||
|
||
async function _getLearningActivities(userId, courseId) { | ||
const docs = await findInModel('tUserActivity', { | ||
userId, | ||
'activity.action': 'answer-question', | ||
}); | ||
return docs.map(doc => doc.activity).filter(activity => activity.courseId === courseId); | ||
} | ||
|
||
async function _insertLearningActivity(userId, courseId, knowledgeId, correct) { | ||
return createInModel('tUserActivity', { | ||
userId, | ||
activity: { | ||
action: 'answer-question', | ||
courseId, | ||
knowledgeId, | ||
correct, | ||
}, | ||
}); | ||
} | ||
|
||
async function answer(req, res, next) { | ||
const { courseId, knowledgeId } = req.params; | ||
let recommendedKnowledge = null; | ||
|
||
try { | ||
const { correct } = req.body.currentLearning; | ||
const [course, user] = await Promise.all([ | ||
findOneInModel('tProject', { _id: courseId }), | ||
getUserInfoFromReq(req), | ||
]); | ||
|
||
await _insertLearningActivity(user._id, courseId, knowledgeId, correct); | ||
const activities = await _getLearningActivities(user._id, courseId); | ||
const learningHistory = activities.map(activity => ({ | ||
name: course.data.filter(knowledge => knowledge._id === activity.knowledgeId)[0].title, | ||
correct: activity.correct, | ||
})); | ||
|
||
const recommendedKnowledgeTitle = await pyRequest('/learning-path-recommendation', { | ||
body: { | ||
learningHistory, | ||
course: course.projectName, | ||
} | ||
}, 'POST'); | ||
recommendedKnowledge = course.data.filter(knowledge => knowledge.title === recommendedKnowledgeTitle)[0]; | ||
|
||
if (!recommendedKnowledge) { | ||
return res.status(500).json({ | ||
status: 'error', | ||
message: '找不到推荐知识点!', | ||
}) | ||
} | ||
} catch(err) { | ||
return res.status(500).json({ | ||
status: 'error', | ||
message: err, | ||
}) | ||
} | ||
|
||
return res.json({ | ||
status: 'success', | ||
data: { | ||
recommendedKnowledge, | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
get, | ||
answer, | ||
}; |
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,62 @@ | ||
const { getUserInfoFromReq } = require('../../utils/token'); | ||
const { createInModel, findInModel, findOneInModel } = require('../../../database/model-operations'); | ||
const { pyRequest } = require('../../utils/pyRequest'); | ||
|
||
|
||
async function _getLearningActivities(userId, courseId) { | ||
const docs = await findInModel('tUserActivity', { | ||
userId, | ||
'activity.action': 'answer-question', | ||
}); | ||
return docs.map(doc => doc.activity).filter(activity => activity.courseId === courseId); | ||
} | ||
|
||
async function learningPathRecommendation(req, res, next) { | ||
const { courseId } = req.params; | ||
let recommendedKnowledge = null; | ||
|
||
try { | ||
const [course, user] = await Promise.all([ | ||
findOneInModel('tProject', { _id: courseId }), | ||
getUserInfoFromReq(req), | ||
]); | ||
|
||
const activities = await _getLearningActivities(user._id, courseId); | ||
const learningHistory = activities.map(activity => ({ | ||
name: course.data.filter(knowledge => knowledge._id === activity.knowledgeId)[0].title, | ||
correct: activity.correct, | ||
})); | ||
|
||
const recommendedKnowledgeTitle = await pyRequest('/learning-path-recommendation', { | ||
body: { | ||
learningHistory, | ||
course: course.projectName, | ||
} | ||
}, 'POST'); | ||
recommendedKnowledge = course.data.filter(knowledge => knowledge.title === recommendedKnowledgeTitle)[0]; | ||
|
||
if (!recommendedKnowledge) { | ||
return res.status(500).json({ | ||
status: 'error', | ||
message: '找不到推荐知识点!', | ||
}) | ||
} | ||
} catch(err) { | ||
return res.status(500).json({ | ||
status: 'error', | ||
message: err, | ||
}) | ||
} | ||
|
||
|
||
return res.json({ | ||
status: 'success', | ||
data: { | ||
recommendedKnowledge, | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
learningPathRecommendation, | ||
}; |
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
Oops, something went wrong.