Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-xapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quentin Pimont
moodle-xapi
Commits
5a551bd8
Commit
5a551bd8
authored
9 years ago
by
Jerrett Fowler
Browse files
Options
Downloads
Plain Diff
Merge pull request #44 from University-of-Strathclyde-LTE-Team/batch-sending
Send statements to LRS in batches
parents
da06d05f
11ef2933
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
classes/log/store.php
+27
-15
27 additions, 15 deletions
classes/log/store.php
lang/en/logstore_xapi.php
+4
-0
4 additions, 0 deletions
lang/en/logstore_xapi.php
settings.php
+4
-0
4 additions, 0 deletions
settings.php
tests/TestCase.php
+10
-8
10 additions, 8 deletions
tests/TestCase.php
with
45 additions
and
23 deletions
classes/log/store.php
+
27
−
15
View file @
5a551bd8
...
...
@@ -95,22 +95,34 @@ class store extends php_obj implements log_writer {
$translatorcontroller
=
new
translator_controller
();
// Emits events to other APIs.
foreach
(
$events
as
$event
)
{
$event
=
(
array
)
$event
;
$this
->
error_log
(
''
);
$this
->
error_log_value
(
'event'
,
$event
);
$moodleevent
=
$moodlecontroller
->
createEvent
(
$event
);
if
(
is_null
(
$moodleevent
))
{
continue
;
}
$this
->
error_log_value
(
'moodleevent'
,
$moodleevent
);
$translatorevents
=
$translatorcontroller
->
createEvents
(
$moodleevent
);
$this
->
error_log_value
(
'translatorevents'
,
$translatorevents
);
foreach
(
$translatorevents
as
$index
=>
$translatorevent
)
{
$xapievent
=
$xapicontroller
->
createEvent
(
$translatorevent
);
$this
->
error_log_value
(
'xapievent'
,
$xapievent
);
}
foreach
(
$events
as
$index
=>
$event
)
{
$events
[
$index
]
=
(
array
)
$event
;
}
$this
->
error_log
(
''
);
$this
->
error_log_value
(
'events'
,
$events
);
$moodleevents
=
$moodlecontroller
->
createEvents
(
$events
);
$this
->
error_log_value
(
'moodleevent'
,
$moodleevents
);
$translatorevents
=
$translatorcontroller
->
createEvents
(
$moodleevents
);
$this
->
error_log_value
(
'translatorevents'
,
$translatorevents
);
if
(
empty
(
$translatorevents
))
{
return
;
}
// Split statements into batches.
$eventbatches
=
array
(
$translatorevents
);
$maxbatchsize
=
get_config
(
'logstore_xapi'
,
'maxbatchsize'
);
if
(
!
empty
(
$maxbatchsize
)
&&
$maxbatchsize
<
count
(
$translatorevents
))
{
$eventbatches
=
array_chunk
(
$translatorevents
,
$maxbatchsize
);
}
foreach
(
$eventbatches
as
$translatoreventsbatch
)
{
$xapievents
=
$xapicontroller
->
createEvents
(
$translatoreventsbatch
);
$this
->
error_log_value
(
'xapievents'
,
$xapievents
);
}
}
private
function
error_log_value
(
$key
,
$value
)
{
...
...
This diff is collapsed.
Click to expand it.
lang/en/logstore_xapi.php
+
4
−
0
View file @
5a551bd8
...
...
@@ -39,4 +39,8 @@ $string['backgroundmode'] = 'Send statements by scheduled task?';
$string
[
'backgroundmode_desc'
]
=
'This will force Moodle to send the statements to the LRS in the background,
via a cron task. This will make the process less close to real time, but will help to prevent unpredictable
Moodle performance linked to the performance of the LRS.'
;
$string
[
'maxbatchsize'
]
=
'Maximum batch size'
;
$string
[
'maxbatchsize_desc'
]
=
'Statements are sent to the LRS in batches. This setting controls the maximum number of
statements that will be sent in a single operation. Setting this to zero will cause all available statements to
be sent at once, although this is not recommended.'
;
$string
[
'taskemit'
]
=
'Emit records to LRS'
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
settings.php
+
4
−
0
View file @
5a551bd8
...
...
@@ -41,4 +41,8 @@ if ($hassiteconfig) {
$settings
->
add
(
new
admin_setting_configcheckbox
(
'logstore_xapi/backgroundmode'
,
get_string
(
'backgroundmode'
,
'logstore_xapi'
),
get_string
(
'backgroundmode_desc'
,
'logstore_xapi'
),
0
));
$settings
->
add
(
new
admin_setting_configtext
(
'logstore_xapi/maxbatchsize'
,
get_string
(
'maxbatchsize'
,
'logstore_xapi'
),
get_string
(
'maxbatchsize_desc'
,
'logstore_xapi'
),
30
,
PARAM_INT
));
}
This diff is collapsed.
Click to expand it.
tests/TestCase.php
+
10
−
8
View file @
5a551bd8
...
...
@@ -29,20 +29,22 @@ abstract class TestCase extends PhpUnitTestCase {
public
function
testCreateEvent
()
{
$input
=
$this
->
constructInput
();
$moodle_event
=
$this
->
moodle_controller
->
createEvent
(
$input
);
$this
->
assert
True
(
$moodle_event
!=
null
,
'Check that the event exist
s
in the expander controller.'
);
$moodle_event
s
=
$this
->
moodle_controller
->
createEvent
s
([
$input
]
);
$this
->
assert
NotNull
(
$moodle_event
s
,
'Check that the event
s
exist in the expander controller.'
);
$translator_event
=
$this
->
translator_controller
->
createEvent
(
$moodle_event
);
$this
->
assert
True
(
$translator_event
!=
null
,
'Check that the event exist
s
in the translator controller.'
);
$translator_event
s
=
$this
->
translator_controller
->
createEvent
s
(
$moodle_event
s
);
$this
->
assert
NotNull
(
$translator_event
s
,
'Check that the event
s
exist in the translator controller.'
);
$xapi_event
=
$this
->
xapi_controller
->
createEvent
(
$translator_event
);
$this
->
assert
True
(
$xapi_event
!=
null
,
'Check that the event exist
s
in the emitter controller.'
);
$xapi_event
s
=
$this
->
xapi_controller
->
createEvent
s
(
$translator_event
s
);
$this
->
assert
NotNull
(
$xapi_event
s
,
'Check that the event
s
exist in the emitter controller.'
);
$this
->
assertOutput
(
$input
,
$xapi_event
);
$this
->
assertOutput
(
$input
,
$xapi_event
s
);
}
protected
function
assertOutput
(
$input
,
$output
)
{
$this
->
assertValidXapiStatement
((
new
TinCanStatement
(
$output
))
->
asVersion
(
'1.0.0'
));
foreach
(
$output
as
$outputpart
)
{
$this
->
assertValidXapiStatement
((
new
TinCanStatement
(
$outputpart
))
->
asVersion
(
'1.0.0'
));
}
}
protected
function
assertValidXapiStatement
(
$output
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment