xAPI
xAPI又名为Experience API,是一种描述学习内容和学习行为的软件数据标准,通过xAPI不同的学习行为存储系统之间可以进行相互通讯。LRS (Learning Record Store)又称为学习行为数据存储系统,LRS通过其他社交网站如微博、微课平台、社区论坛等收集用户的学习行为,并按照xAPI的数据格式要求进行存储。
下面是一段示例xAPI的代码:
{
"id": "863948CA-7014-444B-B026-E362D15BE010",
"actor": {
"mbox": "mailto:hjkun@buaa.edu.cn",
"name": "黄锦康",
"objectType": "Agent"
},
"verb": {
"id": "http://www.mooc.buaa.edu.cn/expapi/verbs/pause",
"display": {
"en-US": "pause"
}
},
"object": {
"definition": {
"type": "type:video",
"name": {
"zh-CN": "一年级数学第一讲"
},
"description": {
"en-US": "A video about equation."
},
"extensions":{
" http://mooc.buaa.edu.cn/test_video1": {
"name": "一年级数学第一讲",
"subject": "数学",
"grade": "一年级",
"time": "2400s",
"about": "equation"
}
}
},
"id": "http://mooc.buaa.edu.cn/test_video1",
"objectType": "Activity"
},
"timestamp": "2016-03-09T13:41:24.741805+00:00",
"stored": "2016-03-09T13:41:24.741805+00:00",
"authority": {
"mbox": "mailto:zhouxuan@nlsde.buaa.edu.cn",
"objectType": "Agent"
},
"version": "1.0.0"
}
当一项活动需要被记录下来时,xAPI 就会送出以”主词,动词,受词” (Noun,Verb,Object) 或者 “我做了这件事” (I did this) 格式的报告到学习记录储存区 (LRS,Learning Record Store)。XAPI官方提供了各种语言的demo版本,但是有一些文档解释的并不是很清楚,下面我对以java和python的语言写了两个demo,希望大家有兴趣的可以看一下:
java版本:
运行java版本需要先在https://github.com/RusticiSoftware/TinCanJava该地址下载java的库。然后运行mvn install生成jar包。但是在运行mvn的过程中,有RemoteLrs.java这个文件我一直跑不过,所以jar包无法生成。但是这个java文件是对lrs发送各种数据的测试行为的,所以我把它注释了,然后就可以顺利生成jar包了。
生成jar包之后,可以在项目中导入jar包,然后http://rusticisoftware.github.io/TinCanJava/doc/api/latest/参考这个网站的 接口说明进行数据传送。
这是我写的发送数据的demo:
package TincanJavaTest;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.joda.time.DateTime;
import com.fasterxml.jackson.databind.JsonNode;
import com.rusticisoftware.tincan.*;
import com.rusticisoftware.tincan.json.JSONBase;
import com.rusticisoftware.tincan.json.StringOfJSON;
import com.rusticisoftware.tincan.lrsresponses.StatementLRSResponse;
public class JavaTest {
public static void main(String args[]) throws URISyntaxException, IOException{
RemoteLRS lrs = new RemoteLRS();
lrs.setEndpoint("http://endpoint/xapi");
lrs.setVersion(TCAPIVersion.V100);
lrs.setUsername("nama");
lrs.setPassword("passwd");
Agent agent=new Agent();
agent.setOpenID("Beijing:123");
agent.setName("孙红雷");
Verb verb = new Verb("http://www.mooc.buaa.edu.cn/expapi/verbs/answer");
verb.setDisplay(new LanguageMap());
verb.getDisplay().put("en-US", "answer");
Map<String, String> map1 = new HashMap<String, String>();
map1.put("parent-id", "213");
map1.put("about", "123");
map1.put("subject", "math");
Extensions extensions=new Extensions();
extensions.put("http://sxtb7.mintelcn.com/MintelRev/servlet/MintelServlet?Pid=npart2", map1);
Activity activity = new Activity("341");
activity.setDefinition(new ActivityDefinition());
activity.getDefinition().setType(new URI("type:problem"));
activity.getDefinition().setMoreInfo(new URI("http://sxtb7.mintelcn.com/MintelRev/servlet/MintelServlet?Pid=npart2"));
activity.getDefinition().setName(new LanguageMap());
activity.getDefinition().getName().put("zh-CN", "基础练习");
activity.getDefinition().setDescription(new LanguageMap());
activity.getDefinition().getDescription().put("zh-CN", "第05章");
activity.getDefinition().setExtensions(extensions);
Score score=new Score();
score.setRaw(10.0);
score.setMax(10.0);
score.setMin(0.0);
Result result=new Result();
result.setResponse("0");
result.setScore(score);
Activity subContext=new Activity("http://www.mintelcn.com/");
Context context=new Context();
context.setRegistration(UUID.randomUUID());
context.setContextActivities(new ContextActivities());
context.getContextActivities().setGrouping(new ArrayList<Activity>());
context.getContextActivities().getGrouping().add(subContext);
DateTime dateTime=new DateTime(2016,5,15,0,0,0);
System.out.println(dateTime);
Statement st = new Statement();
st.setActor(agent);
st.setVerb(verb);
st.setObject(activity);
st.setResult(result);
st.setContext(context);
st.setTimestamp(new DateTime("2016-07-12T8:13:25.353Z"));
st.setAuthority(new Agent());
st.getAuthority().setMbox("mailto:mintelXapi@mintenglish.com");
st.getAuthority().setName("mintel");
StatementLRSResponse lrsRes = lrs.saveStatement(st);
if (lrsRes.getSuccess()) {
// success, use lrsRes.getContent() to get the statement back
System.out.println(lrsRes.getContent());
System.out.println("Success");
}
else {
// failure, error information is available in lrsRes.getErrMsg()
System.out.println(lrsRes.getErrMsg());
System.out.println("Failure");
}
}
}