Skip to content

Commit

Permalink
Add button to download student usage csv
Browse files Browse the repository at this point in the history
  • Loading branch information
allomanta committed Oct 10, 2024
1 parent 352f308 commit 6dad8ae
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
12 changes: 12 additions & 0 deletions IguideME.Web/Controllers/Apps/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,17 @@ public ActionResult GetNotificationDates()

return allDates != null ? Json(allDates) : NotFound();
}

[Authorize(Policy = "IsInstructor")]
[Route("/app/usage")]
[HttpGet]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetUsage()
{
return Json(DatabaseManager.Instance.GetUsage(GetCourseID()));
}

}
}
1 change: 0 additions & 1 deletion IguideME.Web/Services/CanvasSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ await _computationJobStatus
.UpdateJobProgressInformationAsync(jobId, $"tasks.students", 0)
.ConfigureAwait(false);

DatabaseManager.Instance.GetUsage(courseID, timestamp);

new QuizWorker(courseID, timestamp, _lmsHandler, _logger).Start();
await _computationJobStatus
Expand Down
6 changes: 4 additions & 2 deletions IguideME.Web/Services/Constants/DatabaseQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,10 @@ ORDER BY `end_timestamp` DESC
ORDER BY `name` ASC;";

public const string QUERY_USAGE =
@"SELECT `user_tracker`.`user_id`,
count(`user_tracker`.`user_id`)
@"SELECT `user_tracker`.`id`,
`user_tracker`.`time`,
`user_tracker`.`user_id`,
`user_tracker`.`action`,
FROM `user_tracker`
INNER JOIN `canvas_users`
ON `canvas_users`.`user_id`=`user_tracker`.`user_id`
Expand Down
8 changes: 5 additions & 3 deletions IguideME.Web/Services/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,22 +625,24 @@ public void RegisterDiscussionReply(AppDiscussion reply)
);
}

public void GetUsage(int courseID, string hash)
public string GetUsage(int courseID)
{
_logger.LogInformation("userID: #actions");
string csv = "";
using (
SQLiteDataReader r = Query(
DatabaseQueries.QUERY_USAGE,
new SQLiteParameter("courseID", courseID),
new SQLiteParameter("hash", hash)
new SQLiteParameter("hash", this.GetCurrentHash(courseID))
)
)
{
while (r.Read())
{
_logger.LogInformation("{}: {}", r.GetValue(0).ToString(), r.GetInt32(1));
csv += $"{r.GetInt32(0)}, {r.GetValue(1)}, {r.GetValue(2)}, {r.GetValue(3)}\r\n";
}
}
return csv;
}

public List<User> GetUsers(int courseID, string role = "%", string hash = null)
Expand Down
7 changes: 7 additions & 0 deletions IguideME.Web/wwwroot/src/api/controllers/datamart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export default class DataMartController extends Controller {
).then(response => response.data);
}

static getUsage(): Promise<string> {

return this.client.post(
'app/usage',
).then(response => response.data);
}

static startNewSync() {
// when in debug mode always accept the handshake
if (debug()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from "react";
import Admin from "../../index";
import {Divider, Space} from "antd";
import {Button, Divider, Space} from "antd";
import RequireConsent from "../../../../components/settings/RequireConsent";
import AcceptList from "../../../../components/settings/AcceptList";
import PeerGroups from "../../../../components/settings/PeerGroups";
Expand All @@ -18,6 +18,24 @@ export default class Settings extends Component {
<Divider />

<Space direction={"vertical"} style={{width: '100%'}}>
<Button onClick={() => {
let data1 = DataMartController.getUsage().then((data) => {

console.log("data", data)

const csvData = new Blob([data], { type: 'text/csv' });

const csvURL = URL.createObjectURL(csvData);
const link = document.createElement('a');
link.href = csvURL;
link.download = `usage.csv`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
console.log("data1", data1)
}}>
Download Usage Data</Button>
<RequireConsent />
<AcceptList />
<PeerGroups />
Expand Down
4 changes: 2 additions & 2 deletions charts/iguideme/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: iguideme
description: IguideME
type: application
version: 0.2.94
appVersion: "0.2.94"
version: 0.2.95
appVersion: "0.2.95"

0 comments on commit 6dad8ae

Please sign in to comment.