Device wise Usage Statistics of a Skill in SUSI.AI
The device wise usage distribution in SUSI.AI helps in understanding what kind of skills are used more on which type of devices, so that the skill creator can harness the core features of that device to enhance the skills or make the user experience smoother. For example, music playing skill may be used mostly on Smart Speakers whereas Android devices may have higher usage of alarm setting skill.
Sending the device type (ex, web client)
- Send the device type parameter as “Web Client” along with the query while fetching reply from SUSI server in chat.json API. The parameter is device_type.
// Add the type of device in the query { url += '&device_type=Web Client'; }
Storage of Device Wise Skill Usage Data on SUSI Server
- Create a deviceWiseSkillUsage.json file to store the device wise skill usage stats and make a JSONTray object for that in src/ai/susi/DAO.java file. The JSON file contains the device type and the usage count on that type of device (like Android, iOS, Web Client, Smart Speaker and others).
- Modify the src/ai/susi/server/api/susi/SusiService.java file to fetch device_type from the query parameters and pass them SusiCognition constructor.
public ServiceResponse serviceImpl(Query post, HttpServletResponse response, Authorization user, final JsonObjectWithDefault permissions) throws APIException { ... String deviceType = post.get("device_type", "Others"); ... SusiCognition cognition = new SusiCognition(q, timezoneOffset, latitude, longitude, countryCode, countryName, language, deviceType, count, user.getIdentity(), minds.toArray(new SusiMind[minds.size()])); ... }
- Modify the src/ai/susi/mind/SusiCognition.java file to accept the deviceType in the constructor parameters. Check which skill is being currently used for the response and update the skill’s usage stats for the current device in deviceWiseSkillUsage.json. Call the function updateDeviceWiseUsageData() to update the skill usage data.
List<String> skills = dispute.get(0).getSkills(); for (String skill : skills) { updateDeviceWiseUsageData(skill, deviceType); }
The updateDeviceWiseUsageData() function accepts the skill path and type of device. It parses the skill path to get the skill metadata like its model name, group name, language etc. The function then checks if the device already exists in the JSON file or not. If it exists then it increments the usage count by 1 else it creates an entry for the device in the JSON file and initializes it with the usage count 1.
for (int i = 0; i < deviceWiseUsageData.length(); i++) { deviceUsage = deviceWiseUsageData.getJSONObject(i); if (deviceUsage.get("device_type").equals(deviceType)) { deviceUsage.put("count", deviceUsage.getInt("count") + 1); deviceWiseUsageData.put(i,deviceUsage); } }
API to access the Device Wise Skill Usage Data
- Create GetDeviceWiseSkillUsageService.java file to return the usage stats stored in deviceWiseSkillUsage.json
public ServiceResponse serviceImpl(Query call, HttpServletResponse response, Authorization rights, final JsonObjectWithDefault permissions) { ... // Fetch the query parameters JSONArray deviceWiseSkillUsage = languageName.getJSONArray(skill_name); result.put("skill_name", skill_name); result.put("skill_usage", deviceWiseSkillUsage); result.put("accepted", true); result.put("message", "Device wise skill usage fetched"); return new ServiceResponse(result); }
- Add the API file to src/ai/susi/server/api/susi/SusiServer.java
services = new Class[]{ ... //Skill usage data GetDeviceWiseSkillUsageService.class ... }
Endpoint : /cms/getDeviceWiseSkillUsage.json
Parameters
- model
- group
- language
- Skill
Sample query: /cms/getDeviceWiseSkillUsage.json?model=general&group=Knowledge&language=en&skill=aboutsusi
Sample response:
{ "skill_usage":[ { "device_type": "Web Client", "count": 1 }, { "device_type": "Android", "count": 4 }, { "device_type": "iOS", "count": 2 }, { "device_type": "Smart Speaker", "count": 1 }, { "device_type": "Others", "count": 2 } ], "session":{ "identity":{ "type":"host", "name":"162.158.154.147_81c88a10", "anonymous":true } }, "skill_name":"ceo", "accepted":true, "message":"Device wise skill usage fetched" }
Resources
- How to make piechart using react and d3 – https://dzone.com/articles/how-to-make-a-piechart-using-react-and-d3
- Github (making doughnut type charts) – https://github.com/jerairrest/react-chartjs-2