Commit daf6849f authored by Abbassy's avatar Abbassy
Browse files

Initial commit: Moodle Assign Feedback DTA Plugin v1.0.0

- Automatic grade calculation based on DTA test results
- Grade display in DTA Feedback column
- Optional automatic grade application to Final grade
- Grade automatically checkbox functionality
- Support for competency-based grading
- Complete documentation and README
parent 411f28bb
# Assets Directory
This directory contains screenshots and images used in the plugin documentation.
## Screenshots
- `install_plugin.png` - Plugin installer page showing ZIP file upload
- `assignment_settings.png` - Assignment settings page with Feedback types section
- `submissions_table.png` - Submissions grading table showing DTA Feedback column
- `student_submission_view.png` - Student view of submission with feedback
## Usage
These images are referenced in the main README.md file using relative paths.
# Moodle plugin gitignore
*.zip
*.log
.env
full_output.log
tmp_*
moodle_env_runtime.sh
course_runtime.sh
script*.sh
run_pipeline_local.sh
deploy.sh
.gitlab-ci.yml
*.md
!README.md
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
# moodle-assignfeedback_dta # Moodle Assign Feedback Plugin - DTA (Dockerized Test Agent)
## Overview
The assignfeedback_dta plugin is part of the MoDTA (Moodle Dockerized Test Agent) system. It automatically calculates and displays grades for student submissions tested using the Dockerized Test Agent (DTA) system. When students submit code through the DTA submission plugin, the DTA backend runs automated tests and sends results back to Moodle. This feedback plugin takes those test results and automatically calculates a grade, displaying it in a dedicated feedback column.
## Getting started The MoDTA system comprises two key components:
To make it easy for you to get started with GitLab, here's a list of recommended next steps. • The MoDTA Moodle submission plugin (`assignsubmission_dta`), designed as an assignment submission tool.
• The MoDTA Moodle feedback plugin (`assignfeedback_dta`), designed to automatically calculate and display grades based on test results.
• The DTA backend web service, which interfaces with the Moodle plugins through REST and employs the JSON file format for communication.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! ## Goals
## Add your files MoDTA empowers teachers to provide programming Moodle assignments for their students, which are automatically corrected upon hand-in using teacher-provided tests. The feedback plugin extends this functionality by automatically calculating grades based on test results, providing immediate feedback to both students and teachers.
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files The feedback plugin optionally supports automatic grade calculation, allowing teachers to:
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - Automatically calculate grades based on test results
- Display grades in a dedicated feedback column
- Optionally apply grades to the "Final grade" column for automatic grading
- Or keep "Final grade" empty for manual grade entry
``` ## What is this plugin?
cd existing_repo
git remote add origin https://transfer.hft-stuttgart.de/gitlab/cota/moodle-assignfeedback_dta.git The assignfeedback_dta plugin automatically calculates and displays grades for student submissions tested using the Dockerized Test Agent (DTA) system. When students submit code, the DTA backend runs automated tests and sends results back to Moodle. This plugin takes those test results and automatically calculates a grade, displaying it in a dedicated feedback column.
git branch -M master
git push -uf origin master ## How does it work?
```
1. **Student submits code** - Uploads Java project files through the DTA submission plugin (`assignsubmission_dta`)
2. **Backend tests the code** - DTA backend automatically runs test cases
3. **Results come back** - Backend sends test results to Moodle, stored in `assignsubmission_dta_summary` and `assignsubmission_dta_result` tables
4. **Plugin calculates grade** - This feedback plugin reads the test results and calculates a grade based on:
- Test success rate (passed tests / total tests)
- Compilation errors (more than 1 error results in 0%)
- Optional competency scores (if available)
5. **Grade appears in feedback column** - Shows "80.00 / 100.00" in "Dockerized Test Agent Feedback" column
## The "Grade automatically" Button
In the assignment settings, you'll find a checkbox labeled **"Grade automatically"** in the Feedback types section. This button controls how the plugin handles grade calculation.
**When checked (Automatic Grading ON):**
- The plugin automatically calculates and displays grades based on test results
- Grades appear immediately in the DTA Feedback column after backend processing
- Grades are also automatically applied to the "Final grade" column
- You can still manually adjust grades in the "Final grade" column if needed
**When unchecked (Automatic Grading OFF):**
- The plugin shows test results and calculates a suggested grade
- The grade is displayed only in the DTA Feedback column
- No grade is automatically applied to "Final grade"
- You review each submission and manually enter grades in the "Final grade" column
## Scenarios
### Scenario 1: Automatic Grading Enabled
**Setup:** You enable the plugin and check "Grade automatically" in assignment settings.
**Student submits:** Code passes 8 out of 10 tests, no compilation errors.
**Result:** Plugin automatically calculates 80% and displays "80.00 / 100.00" in DTA Feedback column. The grade is also automatically applied to the "Final grade" column.
**Use case:** Perfect for large classes where you want quick automated grading with the option to manually adjust exceptional cases.
### Scenario 2: Automatic Grading Disabled
**Setup:** You enable the plugin but leave "Grade automatically" unchecked.
**Student submits:** Code passes 7 out of 10 tests.
**Result:** Plugin calculates suggested grade of 70% and displays it in DTA Feedback column. "Final grade" column remains empty. You review the code, notice good documentation and effort, and manually enter 85% in Final grade column.
**Use case:** Ideal when code quality, documentation, and subjective factors matter alongside test results.
### Scenario 3: Compilation Errors
**Setup:** Automatic grading enabled.
**Student submits:** Code has 2 compilation errors.
**Result:** Plugin automatically sets grade to 0% and displays "0.00 / 100.00". This ensures students fix critical errors first.
**Use case:** Helps identify submissions that need immediate attention before test cases can even run.
### Scenario 4: Perfect Submission
**Setup:** Automatic grading enabled.
**Student submits:** All 10 tests pass, no errors.
**Result:** Plugin calculates 100% and displays "100.00 / 100.00" immediately. Grade is automatically applied to "Final grade".
**Use case:** Instant feedback for students who submit correct code, encouraging early submissions.
## Integrate with your tools ### Scenario 5: Switching Modes Mid-Assignment
- [ ] [Set up project integrations](https://transfer.hft-stuttgart.de/gitlab/cota/moodle-assignfeedback_dta/-/settings/integrations) **Initial:** Automatic grading enabled, students submitting and getting grades automatically.
## Collaborate with your team **Change:** You uncheck "Grade automatically" after reviewing initial submissions.
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) **Result:** New submissions show suggested grades only in DTA Feedback column. "Final grade" remains empty. You manually review and enter final grades. Existing automatic grades remain visible for reference.
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy **Use case:** Flexibility to adapt grading strategy based on assignment progress and student performance patterns.
Use the built-in continuous integration in GitLab. ## Key features
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) - ✅ **Automatic grade calculation** based on test results
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) - ✅ **Grade display in DTA Feedback column** - Always shows calculated grade
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) - ✅ **Optional automatic grade application** - "Final grade" can be automatically set or left empty
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) - ✅ **Checkbox saving works** - "Grade automatically" setting is properly saved
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - ✅ **Batch testing support** - Works with batch testing functionality from submission plugin
- ✅ **Competency-based grading** - Supports competency scores if available from backend
*** ## Installation & Configuration
# Editing this README ### Prerequisites
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. The `assignsubmission_dta` plugin must be installed first, as the feedback plugin depends on it for test results. The feedback plugin reads from the database tables created by the submission plugin:
- `mdl_assignsubmission_dta_summary` - Summary of test results
- `mdl_assignsubmission_dta_result` - Individual test case results
## Suggestions for a good README ### Quick installation
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name 1. Download `assignfeedback_dta.zip`
Choose a self-explaining name for your project. 2. Go to **Site administration → Plugins → Install plugins**
3. Upload the ZIP file as shown in Fig. 1. ![Fig. 1: Plugin Installer](.assets/install_plugin.png)
4. Follow the installation wizard
## Description ### Manual installation
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges 1. Extract ZIP and copy `dta` folder to `/mod/assign/feedback/dta/`
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. 2. Set permissions: `chown -R www-data:www-data dta/`
3. Go to **Site administration → Notifications** to upgrade
4. Purge caches: **Site administration → Development → Purge all caches**
## Visuals ### Configuration
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation After installation, the plugin requires no additional configuration. It automatically reads test results from the submission plugin's database tables. However, ensure that:
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
- The DTA backend is properly configured (see submission plugin documentation)
- The submission plugin is installed and working
- HTTP Security settings allow communication with the backend (if needed)
## Usage ## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support With the MoDTA feedback plugin installed and the submission plugin configured:
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
### Teacher Setup
When creating or editing an assignment, a teacher can enable the DTA Feedback plugin in the **Feedback types** section as shown in Fig. 2. ![Fig. 2: Assignment Settings - Feedback Types](.assets/assignment_settings.png)
1. **Enable in assignment:**
- Edit assignment → **Feedback types** section
- Check **"Dockerized Test Agent Feedback"**
- Check **"Grade automatically"** (optional - controls automatic vs manual grading)
2. **Students submit code** via DTA submission plugin
3. **View grades:**
- Open assignment grading page as shown in Fig. 3. ![Fig. 3: Submissions Table with DTA Feedback](.assets/submissions_table.png)
- See grades in **"Dockerized Test Agent Feedback"** column
- Format: "85.50 / 100.00"
- If "Grade automatically" is enabled, grades also appear in **"Final grade"** column
- If disabled, **"Final grade"** column remains empty for manual entry
### Student View
Students see the calculated grade in the DTA Feedback column when viewing their submission status as shown in Fig. 4. ![Fig. 4: Student Submission View](.assets/student_submission_view.png) The grade is displayed in the format "XX.XX / 100.00" showing both the calculated grade and maximum possible grade.
## Grade calculation
The plugin uses a sophisticated calculation method:
- **Test Score:** Passed tests / Total tests (e.g., 8/10 = 80%)
- **With competencies:** (Test Score × 0.8) + (Competency Score × 0.2)
- **Without competencies:** Test Score × 1.0
- **Compilation errors (>1):** Grade = 0% (regardless of test results)
### Detailed Calculation Process
1. **Read test results** from `assignsubmission_dta_summary` and `assignsubmission_dta_result` tables
2. **Count successful tests** vs total tests
3. **Check compilation errors** - if more than 1, set grade to 0%
4. **Calculate test score** as percentage of passed tests
5. **Apply competency weighting** if competency data is available (80% test score, 20% competency score)
6. **Display grade** in DTA Feedback column
7. **Optionally apply grade** to "Final grade" if "Grade automatically" is enabled
## Technical Details
### Plugin Structure
The plugin follows Moodle's standard feedback plugin structure:
```
assignfeedback_dta/
├── version.php # Version information
├── locallib.php # Main plugin logic
├── lang/
│ └── en/
│ └── assignfeedback_dta.php # Language strings
├── classes/
│ └── local/
│ └── grading_service.php # Grade calculation engine
├── batchtestform.php # Batch test form
├── testuntestedform.php # Test untested form
└── styles.css # Stylesheet
```
### Database Tables Used
The plugin reads from tables created by the submission plugin:
- `mdl_assignsubmission_dta_summary` - Summary of test results (1:1 relation to submission)
- `mdl_assignsubmission_dta_result` - Individual test case results (1:n relation to summary)
### Configuration Storage
Plugin settings are stored in `mdl_assign_plugin_config`:
- `assignfeedback_dta_enabled` - Whether the plugin is enabled (0 or 1)
- `assignfeedback_dta_gradeautomatically` - Whether automatic grading is enabled (0 or 1)
### Key Methods
- `view_summary()` - Displays grade in feedback column, optionally applies grade
- `is_grade_automatically_enabled()` - Checks if automatic grading is enabled
- `get_settings()` / `save_settings()` - Manages plugin settings
- `grading_service->calculate_summary()` - Calculates grade from test results
- `grading_service->apply_grade()` - Applies calculated grade to Moodle gradebook
## Requirements
- Moodle 3.1 or higher
- PHP 7.4 or higher
- **`assignsubmission_dta` plugin must be installed first**
- DTA backend web service (configured via submission plugin)
## Troubleshooting
**Checkbox doesn't stay checked:** Fixed in version 1.0.0 - ensure you're using the latest version.
## Roadmap **No grade appears:**
If you have ideas for releases in the future, it is a good idea to list them in the README. - Check if "Grade automatically" is enabled (if you want automatic application)
- Wait for backend to process submission
- Ensure submission plugin is installed and working
- Verify test results exist in database tables
## Contributing **Grade in wrong column:**
State if you are open to contributions and what your requirements are for accepting them. - If "Grade automatically" is enabled: Grade appears in both DTA Feedback and "Final grade"
- If disabled: Grade appears only in DTA Feedback column
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. **Grade not calculated:**
- Ensure submission plugin has processed the submission
- Check that test results exist in `assignsubmission_dta_summary` table
- Verify backend is working correctly
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. ## Version
## Authors and acknowledgment - **Version:** 1.0.0
Show your appreciation to those who have contributed to the project. - **Status:** Stable
- **License:** GNU GPL v3 or later
- **Moodle Compatibility:** 3.1+
## License ## Related Documentation
For open source projects, say how it is licensed.
## Project status For more information about the MoDTA system:
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. - Submission Plugin: See `assignsubmission_dta` plugin documentation
- Backend: https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/dtabackend
- Test Runner: https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/dtatestrunner
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot . '/mod/assign/feedback/dta/locallib.php');
/**
* Assignment grading options form
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback_dta_batch_test_form extends moodleform {
/**
* Define this form - called by the parent constructor
*/
public function definition() {
global $COURSE, $USER;
$mform = $this->_form;
$params = $this->_customdata;
$mform->addElement('header', 'batchtestforusers',
get_string('batchtestforusers', 'assignfeedback_dta', count($params['users'])));
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assignfeedback_dta'), $params['usershtml']);
$mform->addElement('advcheckbox', 'forceretest', get_string('forceretest', 'assignfeedback_dta'));
$mform->setType('forceretest', PARAM_BOOL);
$mform->setDefault('forceretest', 0);
$mform->addElement('hidden', 'id', $params['cm']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action', 'viewpluginpage');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'pluginaction', 'batchtestaction');
$mform->setType('pluginaction', PARAM_ALPHA);
$mform->addElement('hidden', 'plugin', 'dta');
$mform->setType('plugin', PARAM_PLUGIN);
$mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
$mform->setType('pluginsubtype', PARAM_PLUGIN);
$mform->addElement('hidden', 'selectedusers', implode(',', $params['users']));
$mform->setType('selectedusers', PARAM_SEQUENCE);
$this->add_action_buttons(true, get_string('batchtestaction', 'assignfeedback_dta'));
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace assignfeedback_dta\local;
defined('MOODLE_INTERNAL') || die();
use assign_feedback_dta;
/**
* Service for calculating and applying grades based on DTA results.
*
* @package assignfeedback_dta
* @copyright 2025
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_service {
/** @var \assign */
private $assignment;
/**
* grading_service constructor.
*
* @param \assign $assignment
*/
public function __construct(\assign $assignment) {
$this->assignment = $assignment;
}
/**
* Calculate the grading summary for a submission.
*
* @param \stdClass|null $submission
* @param \stdClass|null $dtasubmission
* @return array
*/
public function calculate_summary(?\stdClass $submission, ?\stdClass $dtasubmission): array {
global $DB;
$summary = array(
'hasdata' => false,
'totaltests' => 0,
'successcount' => 0,
'failurecount' => 0,
'compilationerrors' => 0,
'test_score' => 0.0,
'competency_percent' => 0.0,
'has_competencies' => false,
'ratio' => 0.0,
'maxgrade' => $this->assignment->get_instance()->grade,
'finalgrade' => 0.0,
'gradable' => false,
);
if (empty($submission) || empty($dtasubmission)) {
return $summary;
}
$summary['hasdata'] = true;
$manager = $DB->get_manager();
if (!$manager->table_exists(assign_feedback_dta::TABLE_DTA_RESULTS)) {
return $summary;
}
$params = array(
'assignment_id' => $submission->assignment,
'submission_id' => $submission->id
);
$summary['totaltests'] = (int)$DB->count_records(assign_feedback_dta::TABLE_DTA_RESULTS, $params);
$summary['successcount'] = (int)$DB->count_records_select(assign_feedback_dta::TABLE_DTA_RESULTS,
'assignment_id = :assignment_id AND submission_id = :submission_id AND state = 1', $params);
$summary['failurecount'] = (int)$DB->count_records_select(assign_feedback_dta::TABLE_DTA_RESULTS,
'assignment_id = :assignment_id AND submission_id = :submission_id AND state = 2', $params);
$summary['compilationerrors'] = (int)$DB->count_records_select(assign_feedback_dta::TABLE_DTA_RESULTS,
'assignment_id = :assignment_id AND submission_id = :submission_id AND state = 3', $params);
// Only set grade to 0 if there are more than 1 compilation errors.
if ($summary['compilationerrors'] > 1) {
$summary['ratio'] = 0.0;
$summary['test_score'] = 0.0;
$summary['finalgrade'] = 0.0;
$summary['gradable'] = true;
return $summary;
}
// Calculate test score (0-100%).
if ($summary['totaltests'] > 0) {
$summary['test_score'] = ($summary['successcount'] / $summary['totaltests']) * 100.0;
$summary['ratio'] = $summary['successcount'] / $summary['totaltests'];
} else {
$summary['test_score'] = 0.0;
$summary['ratio'] = 0.0;
}
// Calculate competency score from competency strings.
$summary['competency_percent'] = $this->calculate_competency_percent($dtasubmission);
$summary['has_competencies'] = ($summary['competency_percent'] > 0);
// Calculate combined final score: 80% test score + 20% competency score.
// If no competencies available, use test score only (weight 1.0).
$test_weight = $summary['has_competencies'] ? 0.8 : 1.0;
$competency_weight = $summary['has_competencies'] ? 0.2 : 0.0;
$final_percent = ($test_weight * $summary['test_score']) + ($competency_weight * $summary['competency_percent']);
if ($summary['maxgrade'] > 0) {
$summary['finalgrade'] = round(($final_percent / 100.0) * $summary['maxgrade'], 5);
$summary['finalgrade'] = min(max($summary['finalgrade'], 0), $summary['maxgrade']);
$summary['gradable'] = true;
}
return $summary;
}
/**
* Calculate competency percentage from competency strings.
*
* Parses successful_competencies and tested_competencies strings (semicolon-separated)
* and calculates the average percentage for each competency block.
*
* @param \stdClass|null $dtasubmission Summary record with competency fields
* @return float Competency percentage (0-100)
*/
private function calculate_competency_percent(?\stdClass $dtasubmission): float {
if (empty($dtasubmission)) {
return 0.0;
}
$successful = $dtasubmission->successful_competencies ?? '';
$tested = $dtasubmission->tested_competencies ?? '';
if (empty($successful) || empty($tested)) {
return 0.0;
}
// Parse semicolon-separated values.
$successful_array = array_filter(array_map('trim', explode(';', $successful)), function($v) {
return $v !== '' && is_numeric($v);
});
$tested_array = array_filter(array_map('trim', explode(';', $tested)), function($v) {
return $v !== '' && is_numeric($v);
});
if (empty($successful_array) || empty($tested_array) || count($successful_array) !== count($tested_array)) {
return 0.0;
}
// Calculate percentage for each competency block.
$percentages = array();
for ($i = 0; $i < count($successful_array); $i++) {
$successful_val = (float)$successful_array[$i];
$tested_val = (float)$tested_array[$i];
if ($tested_val > 0) {
$percentages[] = ($successful_val / $tested_val) * 100.0;
}
}
if (empty($percentages)) {
return 0.0;
}
// Return average of all competency percentages.
return round(array_sum($percentages) / count($percentages), 2);
}
/**
* Check if the current user is a student (not teacher/admin).
*
* @return bool True if current user is a student
*/
private function is_current_user_student(): bool {
global $USER;
// Check if user has grading capability - if yes, they are teacher/admin.
$context = $this->assignment->get_context();
if (has_capability('mod/assign:grade', $context)) {
return false; // Teacher or admin
}
// Check if user has student role in this course.
$roles = get_user_roles($context, $USER->id, false);
foreach ($roles as $role) {
$rolename = $role->shortname;
// If user has teacher, editingteacher, manager, or admin role, they are not a student.
if (in_array($rolename, array('teacher', 'editingteacher', 'manager', 'administrator'))) {
return false;
}
}
// Default: assume student if no teacher/admin role found.
return true;
}
/**
* Apply the calculated grade to the Moodle assignment (Grade column, not Final grade).
* Applies grades for all users (admin, teacher, student) when "Grade automatically" is enabled.
*
* IMPORTANT: If the grade was manually modified by a teacher, it will NOT be overwritten.
* However, automatically set grades will be updated if test results change.
*
* @param int $userid The user ID whose grade is being set
* @param array $summary
* @param \stdClass|null $dtasubmission The DTA submission record (contains test timestamp)
* @return void
*/
public function apply_grade(int $userid, array $summary, ?\stdClass $dtasubmission = null): void {
if (empty($summary['gradable'])) {
return;
}
if ($summary['maxgrade'] <= 0) {
// Assignment uses a scale or no grade field – skip automatic grading.
return;
}
global $DB, $USER;
// Get the grade record for this user to get attemptnumber.
$grade = $this->assignment->get_user_grade($userid, true);
$assignmentid = $this->assignment->get_instance()->id;
// Get the grade_item for grade_grades table operations.
$gradeitem = \grade_item::fetch(array(
'itemtype' => 'mod',
'itemmodule' => 'assign',
'iteminstance' => $assignmentid,
'courseid' => $this->assignment->get_course()->id
));
// Check current grades
$currentgrade = null;
$gradetimemodified = null;
if (!empty($grade) && isset($grade->grade) && $grade->grade !== null) {
$currentgrade = (float)$grade->grade;
$gradetimemodified = isset($grade->timemodified) ? (int)$grade->timemodified : null;
}
$currentfinalgrade = null;
$finalgradetimemodified = null;
if ($gradeitem) {
$gradegrade = $DB->get_record('grade_grades', array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
if ($gradegrade) {
if ($gradegrade->finalgrade !== null) {
$currentfinalgrade = (float)$gradegrade->finalgrade;
}
$finalgradetimemodified = isset($gradegrade->timemodified) ? (int)$gradegrade->timemodified : null;
}
}
$calculatedgrade = (float)$summary['finalgrade'];
$tolerance = 0.01; // Allow small rounding differences
// Determine which grade to check (prefer finalgrade if available, otherwise grade)
$gradeToCheck = ($currentfinalgrade !== null) ? $currentfinalgrade : $currentgrade;
$gradeTimeToCheck = ($finalgradetimemodified !== null) ? $finalgradetimemodified : $gradetimemodified;
// Check if grade was manually modified
if ($gradeToCheck !== null) {
$gradeDifference = abs($gradeToCheck - $calculatedgrade);
// If grade matches calculated grade (within tolerance), it's automatically set - allow overwrite
if ($gradeDifference <= $tolerance) {
// Grade matches calculated grade - automatically set, can be overwritten
// Continue to apply grade
} else {
// Grade differs from calculated grade - might be manually modified
// Check if grade was modified AFTER tests were run (indicates manual change)
$testTimestamp = null;
if ($dtasubmission && isset($dtasubmission->timestamp) && $dtasubmission->timestamp > 0) {
$testTimestamp = (int)$dtasubmission->timestamp;
}
if ($testTimestamp !== null && $gradeTimeToCheck !== null) {
// If grade was modified AFTER tests were run, it was manually changed
if ($gradeTimeToCheck > $testTimestamp) {
// Grade was modified after tests - manual change, don't overwrite
return;
}
// If grade was modified BEFORE or AT test time, it's an old automatic grade
// Allow overwrite to update with new test results
} else {
// Can't determine timing - if grade differs significantly, assume manual change
// Only skip if difference is very large (more than 1 point)
if ($gradeDifference > 1.0) {
// Large difference - likely manual change, don't overwrite
return;
}
// Small difference - might be rounding or old automatic grade, allow overwrite
}
}
}
// IMPORTANT: Moodle's grade display logic:
// - Assignment grading table "Grade" column = displayed from assign_grades.grade OR grade_grades.rawgrade
// - Assignment grading table "Final grade" column = displayed from grade_grades.finalgrade
// - User Report "Assignment Grade" = displayed from grade_grades.finalgrade (if set) OR grade_grades.rawgrade
//
// To ensure the grade appears in Assignment Grade (User Report) but NOT in "Final grade" column:
// We need to set finalgrade to the same value as rawgrade, BUT ensure it's not displayed in "Final grade" column.
// Actually, Moodle uses finalgrade for the User Report, so we MUST set it.
// However, the "Final grade" column in grading table should stay empty - this is handled by Moodle's display logic.
//
// Strategy:
// 1. Set assign_grades.grade (for "Grade" column in grading table)
// 2. Set grade_grades.rawgrade (for grade calculation)
// 3. Set grade_grades.finalgrade (for User Report Assignment Grade display)
// Note: The "Final grade" column in grading table may show the value, but that's acceptable for User Report functionality.
// Step 1: Set grade in assign_grades table (for "Grade" column in grading table).
$DB->set_field('assign_grades', 'grade', $summary['finalgrade'], array(
'assignment' => $assignmentid,
'userid' => $userid,
'attemptnumber' => $grade->attemptnumber
));
// Update timemodified to reflect the change.
$DB->set_field('assign_grades', 'timemodified', time(), array(
'assignment' => $assignmentid,
'userid' => $userid,
'attemptnumber' => $grade->attemptnumber
));
// Step 2 & 3: Set rawgrade and finalgrade so grade appears in Assignment Grade (User Report).
// IMPORTANT: User Report displays Assignment Grade from grade_grades.finalgrade.
// We need to set finalgrade so the grade appears in the User Report.
if ($gradeitem) {
// Get or create grade_grades record.
$gradegrade = $DB->get_record('grade_grades', array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
if (!$gradegrade) {
// Create new grade_grades record with both rawgrade and finalgrade set.
$gradegrade = new \stdClass();
$gradegrade->itemid = $gradeitem->id;
$gradegrade->userid = $userid;
$gradegrade->rawgrade = $summary['finalgrade'];
$gradegrade->rawgrademax = $summary['maxgrade'];
$gradegrade->finalgrade = $summary['finalgrade']; // Set so it appears in User Report Assignment Grade
$gradegrade->timecreated = time();
$gradegrade->timemodified = time();
$gradegrade->usermodified = $USER->id ?? null;
$DB->insert_record('grade_grades', $gradegrade);
} else {
// Update existing record: set both rawgrade and finalgrade.
$DB->set_field('grade_grades', 'rawgrade', $summary['finalgrade'], array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
$DB->set_field('grade_grades', 'rawgrademax', $summary['maxgrade'], array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
$DB->set_field('grade_grades', 'finalgrade', $summary['finalgrade'], array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
$DB->set_field('grade_grades', 'timemodified', time(), array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
$DB->set_field('grade_grades', 'usermodified', $USER->id ?? null, array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
}
}
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'assignfeedback_dta', language 'en'
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string["dta"] = "Dockerized Test Agent";
$string["pluginname"] = "Dockerized Test Agent Feedback";
$string["enabled"] = "Enabled";
$string["enabled_help"] = "If enabled, the Dockerized Test Agent feedback plugin will be available for assignments.";
$string["testuntestedaction"] = "Test untested submissions";
$string["batchtestforusers"] = "Test submissions for {\$a} selected user(s).";
$string["batchtest"] = "Test submissions for multiple users";
$string["testuntestedforusers"] = "Test untested submissions for {\$a} user(s).";
$string["testuntested"] = "Test submissions for multiple users";
$string["selectedusers"] = "Selected users";
$string["batchtestaction"] = "Test selected submissions";
$string["batchoperationconfirmbatchtestaction"] = "Test selected submissions?";
$string["wsbase_not_set"] = "The Dockerized Test Agent web service base URL is not configured.";
$string["skippedexistingresults"] = "Skipped {\$a} submission(s) because existing test results were found.";
$string["forceretest"] = "Force re-test even if previous results exist";
$string["dta_tables_missing"] = "DTA submission data tables are not available.";
$string["grade_automatically"] = "Grade automatically";
$string["grade_automatically_help"] = "If enabled, the plugin will automatically calculate and apply grades based on test results. If disabled, the plugin will only display test results as feedback, and the teacher must manually assign grades.";
$string["suggested_grade"] = "Suggested grade";
$string["status_pass"] = "PASS";
$string["status_fail"] = "FAIL";
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the definition for the library class for dta feedback plugin
*
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use assignfeedback_dta\local\grading_service;
use assignsubmission_dta\dta_backend_utils;
use assignsubmission_dta\dta_db_utils;
use assignsubmission_dta\models\dta_recommendation;
use assignsubmission_dta\models\dta_result_summary;
/**
* Library class for dta feedback plugin extending feedback plugin base class.
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_feedback_dta extends assign_feedback_plugin {
// Database table names.
const TABLE_DTA_SUMMARY = "assignsubmission_dta_summary";
const TABLE_DTA_RESULTS = "assignsubmission_dta_result";
const COMPONENT_NAME = "assignfeedback_dta";
/**
* Get dta submission information from the database
*
* @param int $assignmentid
* @param int $submissionid
* @return mixed
*/
private function get_dta_submission($assignmentid, $submissionid) {
global $DB;
if (!$this->are_dta_tables_available()) {
return null;
}
$record = $DB->get_record(self::TABLE_DTA_SUMMARY,
array("assignment_id" => $assignmentid, "submission_id" => $submissionid));
// Convert false to null for type safety (get_record returns false if not found)
return $record ? $record : null;
}
/**
* Get the name of the dta feedback plugin.
* This name is displayed as the title of the feedback block in the Feedback section.
*
* @return string
*/
public function get_name() {
return get_string("pluginname", self::COMPONENT_NAME);
}
/**
* Check if this plugin is enabled.
* Returns true if the plugin is enabled in the assignment settings.
* This controls whether the feedback column is shown in the grading table.
*
* @return bool
*/
public function is_enabled() {
// Check if this plugin is enabled in the assignment settings.
// Moodle stores this in the assignment instance configuration.
// The parent class method checks if the plugin is enabled for this assignment.
return parent::is_enabled();
}
/**
* Check if the feedback is empty.
*
* This method determines if the feedback column should show content.
* We return false to always show the column (even if empty) so that
* the automatic grading functionality can work via view_summary().
*
* @param stdClass $grade The grade object
* @return bool True if feedback is empty, false if feedback exists
*/
public function is_empty(stdClass $grade) {
// Return false to always show the column, even if empty.
// This allows view_summary() to be called and automatic grading to work.
return false;
}
/**
* Check if this plugin has a summary to display.
* Always return true to ensure the column is always shown.
*
* @param stdClass $grade
* @return bool
*/
public function has_summary(stdClass $grade) {
return true;
}
/**
* Add elements to the settings form for this plugin.
*
* @param MoodleQuickForm $mform The form to add elements to
* @return void
*/
public function get_settings(MoodleQuickForm $mform) {
// Always add the checkbox - we'll hide it if this plugin (dta/Dockerized Test Agent) is not enabled.
// The plugin name is "dta", so the enabled checkbox is: assignfeedback_dta_enabled
$pluginelementname = 'assignfeedback_dta_enabled';
// Add the checkbox element.
// Description text is removed - only show help via the help button (blue question mark).
$mform->addElement('advcheckbox', 'assignfeedback_dta_gradeautomatically',
get_string('grade_automatically', self::COMPONENT_NAME),
null, // No description text - help only via help button
null, array(0, 1));
$mform->addHelpButton('assignfeedback_dta_gradeautomatically', 'grade_automatically', self::COMPONENT_NAME);
// Set default value from saved config, or 1 if not set yet.
// get_config() returns false if not set, so we need to handle that case.
$savedvalue = $this->get_config('gradeautomatically');
if ($savedvalue === false) {
// Value not set yet - use default of 1 (enabled)
$defaultvalue = 1;
} else {
// Value exists - use it (will be 0 or 1)
$defaultvalue = (int)$savedvalue;
}
$mform->setDefault('assignfeedback_dta_gradeautomatically', $defaultvalue);
$mform->setType('assignfeedback_dta_gradeautomatically', PARAM_BOOL);
// Hide the checkbox if this feedback plugin (Dockerized Test Agent) is not enabled.
// Use 'notchecked' condition like other Moodle plugins do (e.g. assignfeedback_comments).
// This creates a form dependency that reacts to the current form state.
$mform->hideIf('assignfeedback_dta_gradeautomatically', $pluginelementname, 'notchecked');
}
/**
* Save the settings for this plugin.
*
* @param stdClass $data The form data
* @return bool
*/
public function save_settings(stdClass $data) {
// Check if the checkbox value exists in the form data.
// The checkbox is only present in the form if the plugin is enabled.
// advcheckbox sends the value directly (0 or 1) when checked/unchecked.
if (property_exists($data, 'assignfeedback_dta_gradeautomatically')) {
// Get the old value before saving.
$oldvalue = $this->get_config('gradeautomatically');
if ($oldvalue === false) {
$oldvalue = 1; // Default to enabled if not set
} else {
$oldvalue = (int)$oldvalue;
}
// Get the new value from form data (will be 0 or 1).
$value = (int)$data->assignfeedback_dta_gradeautomatically;
// Save the value.
$this->set_config('gradeautomatically', $value);
// If the setting was changed from enabled (1) to disabled (0),
// remove all automatically set grades for this assignment.
if ($oldvalue == 1 && $value == 0) {
$this->clear_automatic_grades();
}
}
// If the checkbox is not in the form data, it means the plugin is not enabled,
// so we don't change the existing value (it stays as is).
return true;
}
/**
* Clear all automatically set grades for this assignment.
* Called when "Grade automatically" is disabled.
*
* @return void
*/
private function clear_automatic_grades(): void {
global $DB;
$assignmentid = $this->assignment->get_instance()->id;
// Clear grade field in assign_grades table for all users in this assignment.
$DB->set_field('assign_grades', 'grade', null, array(
'assignment' => $assignmentid
));
// Also clear finalgrade in grade_grades table.
$gradeitem = \grade_item::fetch(array(
'itemtype' => 'mod',
'itemmodule' => 'assign',
'iteminstance' => $assignmentid,
'courseid' => $this->assignment->get_course()->id
));
if ($gradeitem) {
// Delete all grade_grades records for this assignment to clear "Final grade" column.
$DB->delete_records('grade_grades', array(
'itemid' => $gradeitem->id
));
}
}
/**
* Clear only the "Final grade" column for a specific user.
* This keeps the grade displayed in DTA Feedback column but removes it from "Final grade".
*
* @param int $userid The user ID
* @return void
*/
private function clear_user_final_grade(int $userid): void {
global $DB;
$assignmentid = $this->assignment->get_instance()->id;
// Get the grade_item for grade_grades table operations.
$gradeitem = \grade_item::fetch(array(
'itemtype' => 'mod',
'itemmodule' => 'assign',
'iteminstance' => $assignmentid,
'courseid' => $this->assignment->get_course()->id
));
if ($gradeitem) {
// Set finalgrade to NULL to clear "Final grade" column, but keep the record.
$DB->set_field('grade_grades', 'finalgrade', null, array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
// Also clear rawgrade to ensure nothing is displayed in "Final grade".
$DB->set_field('grade_grades', 'rawgrade', null, array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
}
}
/**
* Clear automatically set grade for a specific user.
* Called when "Grade automatically" is disabled and view_summary() is called.
*
* @param int $userid The user ID
* @return void
*/
private function clear_user_automatic_grade(int $userid): void {
global $DB;
$assignmentid = $this->assignment->get_instance()->id;
// Get the grade record to get attemptnumber.
$grade = $this->assignment->get_user_grade($userid, true);
if (!$grade) {
return;
}
// Clear grade field in assign_grades table for this user.
$DB->set_field('assign_grades', 'grade', null, array(
'assignment' => $assignmentid,
'userid' => $userid,
'attemptnumber' => $grade->attemptnumber
));
// Delete grade_grades record for this user to clear "Final grade" column.
$gradeitem = \grade_item::fetch(array(
'itemtype' => 'mod',
'itemmodule' => 'assign',
'iteminstance' => $assignmentid,
'courseid' => $this->assignment->get_course()->id
));
if ($gradeitem) {
$DB->delete_records('grade_grades', array(
'itemid' => $gradeitem->id,
'userid' => $userid
));
}
}
/**
* Get the setting value for automatic grading.
*
* @return bool True if automatic grading is enabled
*/
public function is_grade_automatically_enabled() {
// get_config() returns false if not set, so we need to handle that case.
$value = $this->get_config('gradeautomatically');
if ($value === false) {
// Value not set yet - default to enabled (1)
return true;
}
return (bool)$value;
}
/**
* Called by the assignment module when someone chooses something from the
* grading navigation or batch operations list.
*
* @param string $action - The page to view
* @return string - The html response
*/
public function view_page($action) {
if ($action == "batchtestaction") {
$users = required_param("selectedusers", PARAM_SEQUENCE);
return $this->view_batch_test(explode(",", $users));
} else if ($action == "testuntestedaction") {
$users = $this->get_students_without_test_results();
return $this->view_resend_untested($users);
}
return "";
}
/**
* Return a list of the batch grading operations supported by this plugin.
* This plugins supports batch resend of the task files to the backend web service.
*
* @return array - An array of action and description strings.
* The action will be passed to grading_batch_operation.
*/
public function get_grading_batch_operations() {
return array("batchtestaction" => get_string("batchtestaction", self::COMPONENT_NAME));
}
/**
* Return a list of the grading actions performed by this plugin.
*
* @return array The list of grading actions
*/
public function get_grading_actions() {
return array(
"testuntestedaction" => get_string("testuntestedaction", self::COMPONENT_NAME)
);
}
/**
* User has chosen a custom grading batch operation and selected some users.
*
* @param string $action - The chosen action
* @param array $users - An array of user ids
* @return string - The response html
*/
public function grading_batch_operation($action, $users) {
if ($action == 'batchtestaction') {
return $this->view_batch_test($users);
}
return '';
}
private function get_students_without_test_results() {
global $DB;
$assignment = $this->assignment;
$currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
$users = array_keys($assignment->list_participants($currentgroup, true));
if (count($users) == 0) {
// Insert a record that will never match to the sql is still valid.
$users[] = -1;
}
$sql = "SELECT DISTINCT s.userid
FROM {dta_testresult} t, {assignsubmission_dta} m, {assign_submission} s
WHERE s.id=m.submission_id
AND t.dta_id = m.id
AND m.assignment_id = :assignmentid";
$params = array("assignmentid" => $assignment->get_instance()->id);
$records = $DB->get_fieldset_sql($sql, $params);
$result = array_diff($users, $records);
return $result;
}
/**
* Determine if there are existing test results for a dta submission.
*
* @param int $dtasubmissionid
* @return bool
*/
private function has_existing_results($assignmentid, $submissionid) {
global $DB;
if (empty($assignmentid) || empty($submissionid)) {
return false;
}
if (!$this->are_dta_tables_available()) {
return false;
}
$conditions = array('assignment_id' => $assignmentid, 'submission_id' => $submissionid);
return $DB->record_exists(self::TABLE_DTA_RESULTS, $conditions);
}
private function view_resend_untested($users) {
global $DB, $CFG;
require_once($CFG->dirroot . '/mod/assign/feedback/dta/testuntestedform.php');
require_once($CFG->dirroot . '/mod/assign/renderable.php');
$formparams = array('cm' => $this->assignment->get_course_module()->id,
'users' => $users,
'context' => $this->assignment->get_context());
$usershtml = '';
$usercount = 0;
foreach ($users as $userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$usersummary = new assign_user_summary($user,
$this->assignment->get_course()->id,
has_capability('moodle/site:viewfullnames',
$this->assignment->get_course_context()),
$this->assignment->is_blind_marking(),
$this->assignment->get_uniqueid_for_user($user->id),
get_extra_user_fields($this->assignment->get_context()));
$usershtml .= $this->assignment->get_renderer()->render($usersummary);
$usercount += 1;
}
$formparams['usershtml'] = $usershtml;
$mform = new assignfeedback_dta_test_untested_form(null, $formparams);
if ($mform->is_cancelled()) {
redirect(new moodle_url('view.php',
array('id' => $this->assignment->get_course_module()->id,
'action' => 'grading')));
return "";
} else if ($data = $mform->get_data()) {
if (!$this->are_dta_tables_available()) {
\core\notification::error(get_string('dta_tables_missing', self::COMPONENT_NAME));
return "";
}
$fs = get_file_storage();
$assignmentid = $this->assignment->get_instance()->id;
$forceretest = !empty($data->forceretest);
$skippedusers = array();
foreach ($users as $userid) {
$submission = $this->assignment->get_user_submission($userid, false, -1);
if (empty($submission)) {
continue;
}
$hasresults = $this->has_existing_results($assignmentid, $submission->id);
if (!$forceretest && $hasresults) {
$skippedusers[] = $userid;
continue;
}
if ($forceretest && $hasresults) {
$this->delete_dta_data($assignmentid, $submission->id);
}
$files = $fs->get_area_files(
$this->assignment->get_context()->id,
'assignsubmission_dta',
'submissions_dta',
$submission->id,
'id',
false
);
if (empty($files)) {
continue;
}
$file = reset($files);
$response = dta_backend_utils::assignsubmission_dta_send_submission_to_backend(
$this->assignment,
$submission->id,
$file
);
if (empty($response)) {
continue;
}
$summary = dta_result_summary::assignsubmission_dta_decode_json($response);
$recommendations = dta_recommendation::assignsubmission_dta_decode_json_recommendations($response);
dta_db_utils::assignsubmission_dta_store_result_summary_to_database(
$assignmentid,
$submission->id,
$summary
);
dta_db_utils::assignsubmission_dta_store_recommendations_to_database(
$assignmentid,
$submission->id,
$recommendations
);
}
if (!$forceretest && !empty($skippedusers)) {
\core\notification::info(get_string('skippedexistingresults',
self::COMPONENT_NAME, count($skippedusers)));
}
redirect(new moodle_url('view.php',
array('id' => $this->assignment->get_course_module()->id,
'action' => 'grading')));
return "";
} else {
$header = new \mod_assign\output\assign_header($this->assignment->get_instance(),
$this->assignment->get_context(),
false,
$this->assignment->get_course_module()->id,
get_string('testuntested', 'assignfeedback_dta'));
$o = '';
$o .= $this->assignment->get_renderer()->render($header);
$o .= $this->assignment->get_renderer()->render(new assign_form('testuntested', $mform));
$o .= $this->assignment->get_renderer()->render_footer();
}
return $o;
}
private function view_batch_test($users) {
global $DB, $CFG;
require_once($CFG->dirroot . '/mod/assign/feedback/dta/batchtestform.php');
require_once($CFG->dirroot . '/mod/assign/renderable.php');
$formparams = array('cm' => $this->assignment->get_course_module()->id,
'users' => $users,
'context' => $this->assignment->get_context());
$usershtml = '';
$usercount = 0;
foreach ($users as $userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$usersummary = new assign_user_summary($user,
$this->assignment->get_course()->id,
has_capability('moodle/site:viewfullnames',
$this->assignment->get_course_context()),
$this->assignment->is_blind_marking(),
$this->assignment->get_uniqueid_for_user($user->id),
get_extra_user_fields($this->assignment->get_context()));
$usershtml .= $this->assignment->get_renderer()->render($usersummary);
$usercount += 1;
}
$formparams['usershtml'] = $usershtml;
$mform = new assignfeedback_dta_batch_test_form(null, $formparams);
if ($mform->is_cancelled()) {
redirect(new moodle_url('view.php',
array('id' => $this->assignment->get_course_module()->id,
'action' => 'grading')));
return "";
} else if ($data = $mform->get_data()) {
if (!$this->are_dta_tables_available()) {
\core\notification::error(get_string('dta_tables_missing', self::COMPONENT_NAME));
return "";
}
$fs = get_file_storage();
$assignmentid = $this->assignment->get_instance()->id;
$forceretest = !empty($data->forceretest);
$skippedusers = array();
foreach ($users as $userid) {
$submission = $this->assignment->get_user_submission($userid, false, -1);
if (empty($submission)) {
continue;
}
$hasresults = $this->has_existing_results($assignmentid, $submission->id);
if (!$forceretest && $hasresults) {
$skippedusers[] = $userid;
continue;
}
if ($forceretest && $hasresults) {
$this->delete_dta_data($assignmentid, $submission->id);
}
$files = $fs->get_area_files(
$this->assignment->get_context()->id,
'assignsubmission_dta',
'submissions_dta',
$submission->id,
'id',
false
);
if (empty($files)) {
continue;
}
$file = reset($files);
$response = dta_backend_utils::assignsubmission_dta_send_submission_to_backend(
$this->assignment,
$submission->id,
$file
);
if (empty($response)) {
continue;
}
$summary = dta_result_summary::assignsubmission_dta_decode_json($response);
$recommendations = dta_recommendation::assignsubmission_dta_decode_json_recommendations($response);
dta_db_utils::assignsubmission_dta_store_result_summary_to_database(
$assignmentid,
$submission->id,
$summary
);
dta_db_utils::assignsubmission_dta_store_recommendations_to_database(
$assignmentid,
$submission->id,
$recommendations
);
}
if (!$forceretest && !empty($skippedusers)) {
\core\notification::info(get_string('skippedexistingresults',
self::COMPONENT_NAME, count($skippedusers)));
}
redirect(new moodle_url('view.php',
array('id' => $this->assignment->get_course_module()->id,
'action' => 'grading')));
return "";
} else {
$header = new \mod_assign\output\assign_header($this->assignment->get_instance(),
$this->assignment->get_context(),
false,
$this->assignment->get_course_module()->id,
get_string('batchtest', 'assignfeedback_dta'));
$o = '';
$o .= $this->assignment->get_renderer()->render($header);
$o .= $this->assignment->get_renderer()->render(new assign_form('batchtest', $mform));
$o .= $this->assignment->get_renderer()->render_footer();
}
return $o;
}
/**
* Display the feedback on the student view page (Feedback section).
* This method is called by Moodle to render feedback in the Feedback table.
*
* @param stdClass $grade The grade object
* @return string HTML output
*/
public function view(stdClass $grade) {
// Return empty string - no feedback button needed
return '';
}
/**
* Provide a summary column output in the grading table.
*
* @param stdClass $grade
* @param boolean $showviewlink
* @return string
*/
public function view_summary(stdClass $grade, &$showviewlink) {
$showviewlink = false;
// Get submission for grading calculations
$submission = null;
$dtasubmission = null;
if (!empty($grade) && isset($grade->userid) && !empty($grade->userid)) {
$submission = $this->assignment->get_user_submission($grade->userid, false, -1);
if (!empty($submission) && $this->are_dta_tables_available()) {
$dtasubmission = $this->get_dta_submission($this->assignment->get_instance()->id, $submission->id);
}
}
// Calculate grade if submission exists
$output = '';
if ($this->are_dta_tables_available() && !empty($submission) && !empty($grade) && isset($grade->userid) && !empty($grade->userid)) {
$gradingservice = new grading_service($this->assignment);
$gradesummary = $gradingservice->calculate_summary($submission, $dtasubmission);
// Display the grade in the DTA Feedback column
if ($gradesummary['gradable'] && $gradesummary['hasdata']) {
$maxgrade = $gradesummary['maxgrade'];
$finalgrade = $gradesummary['finalgrade'];
// Format: "42.36 / 100.00"
$output = html_writer::tag('div',
format_float($finalgrade, 2) . ' / ' . format_float($maxgrade, 2),
array('class' => 'dta-feedback-grade')
);
}
// Apply automatic grading if enabled
if ($this->is_grade_automatically_enabled()) {
// Apply the grade to both assign_grades and grade_grades (Final grade column)
if ($gradesummary['gradable'] && $gradesummary['hasdata']) {
$gradingservice->apply_grade($grade->userid, $gradesummary, $dtasubmission);
// Note: apply_grade() sets both assign_grades.grade and grade_grades.finalgrade
// So the grade appears in both "Grade" column and "Final grade" column
}
} else {
// If automatic grading is disabled, only show grade in DTA Feedback column
// Clear any automatically set grades so "Final grade" stays empty
$this->clear_user_automatic_grade($grade->userid);
}
}
return $output;
}
/**
* Called when a submission is deleted.
* This hook is called by Moodle when a submission is removed.
*
* @param stdClass $submission The submission record being deleted
* @return void
*/
public function ondelete(stdClass $submission) {
global $DB;
if (empty($submission) || empty($submission->id) || empty($submission->assignment)) {
return;
}
// Delete DTA data when submission is deleted
$this->delete_dta_data($submission->assignment, $submission->id);
// Also clear any automatically set grades for this user
if (!empty($submission->userid)) {
$this->clear_user_automatic_grade($submission->userid);
}
}
/**
* Called when a grade is deleted.
* This hook is called by Moodle when a grade is removed.
* We use this to also clean up DTA data if the submission was deleted.
*
* @param stdClass $grade The grade record being deleted
* @return void
*/
public function ongrade_delete(stdClass $grade) {
global $DB;
if (empty($grade) || empty($grade->userid)) {
return;
}
// Get the assignment ID
$assignmentid = $this->assignment->get_instance()->id;
// Check if submission still exists for this user
$submission = $this->assignment->get_user_submission($grade->userid, false, -1);
// If no submission exists, delete all DTA data for this user/assignment combination
if (empty($submission)) {
// Delete all DTA data for this assignment and user (by finding all submission IDs that might have existed)
// We need to find all submission IDs that might have DTA data for this user
if ($this->are_dta_tables_available()) {
// Get all submission IDs that have DTA data for this assignment
$dta_summaries = $DB->get_records(self::TABLE_DTA_SUMMARY,
array('assignment_id' => $assignmentid), '', 'DISTINCT submission_id');
// For each submission ID, check if submission still exists
foreach ($dta_summaries as $summary) {
$submission_exists = $DB->record_exists('assign_submission',
array('id' => $summary->submission_id, 'assignment' => $assignmentid));
// If submission doesn't exist, delete DTA data
if (!$submission_exists) {
$this->delete_dta_data($assignmentid, $summary->submission_id);
}
}
}
}
// Clear any automatically set grades for this user
$this->clear_user_automatic_grade($grade->userid);
}
/**
* Delete stored DTA data for a submission.
*
* @param int $assignmentid
* @param int $submissionid
* @return void
*/
private function delete_dta_data($assignmentid, $submissionid) {
global $DB;
if (!$this->are_dta_tables_available()) {
return;
}
$conditions = array('assignment_id' => $assignmentid, 'submission_id' => $submissionid);
$DB->delete_records(self::TABLE_DTA_RESULTS, $conditions);
$DB->delete_records(self::TABLE_DTA_SUMMARY, $conditions);
}
/**
* Ensure dta tables exist before querying.
*
* @return bool
*/
private function are_dta_tables_available() {
global $DB;
$manager = $DB->get_manager();
return $manager->table_exists(self::TABLE_DTA_SUMMARY) &&
$manager->table_exists(self::TABLE_DTA_RESULTS);
}
}
/* Frame around entire feedback table container - parallel to submission status table */
.feedbacktable,
div.feedbacktable,
.boxaligncenter.feedbacktable {
border: 1px solid #dee2e6 !important;
border-radius: 3px !important;
padding: 8px !important;
background-color: #ffffff !important;
margin: 0 !important;
}
/* Test Result Labels (same as submission plugin) */
.dtaTestLabel {
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
margin-right: 8px;
margin-bottom: 4px;
}
.dtaTestLabelSuccess {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.dtaTestLabelError {
background-color: #fff3cd;
color: #856404;
border: 1px solid #ffeaa7;
}
.dtaTestLabelFailure {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
/* Test Results Container (same as submission plugin) */
.dtaTestResults {
margin-top: 6px;
line-height: 1.4;
display: block;
padding-top: 0;
}
.dtaTestResults br {
margin-bottom: 4px;
}
/* Container for button and labels alignment (same as submission plugin) */
.dtaSubmissionSummary {
white-space: nowrap;
vertical-align: top;
padding-top: 0;
margin-top: 0;
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot . '/mod/assign/feedback/dta/locallib.php');
/**
* Assignment grading options form
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback_dta_test_untested_form extends moodleform {
/**
* Define this form - called by the parent constructor
*/
public function definition() {
global $COURSE, $USER;
$mform = $this->_form;
$params = $this->_customdata;
$mform->addElement('header', 'testuntestedforusers',
get_string('testuntestedforusers', 'assignfeedback_dta', count($params['users'])));
$mform->addElement('static', 'userslist', get_string('selectedusers', 'assignfeedback_dta'), $params['usershtml']);
$mform->addElement('advcheckbox', 'forceretest', get_string('forceretest', 'assignfeedback_dta'));
$mform->setType('forceretest', PARAM_BOOL);
$mform->setDefault('forceretest', 0);
$mform->addElement('hidden', 'id', $params['cm']);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'action', 'viewpluginpage');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'pluginaction', 'testuntestedaction');
$mform->setType('pluginaction', PARAM_ALPHA);
$mform->addElement('hidden', 'plugin', 'dta');
$mform->setType('plugin', PARAM_PLUGIN);
$mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
$mform->setType('pluginsubtype', PARAM_PLUGIN);
$mform->addElement('hidden', 'selectedusers', implode(',', $params['users']));
$mform->setType('selectedusers', PARAM_SEQUENCE);
$this->add_action_buttons(true, get_string('testuntestedaction', 'assignfeedback_dta'));
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the version information for the onlinetext dta plugin
*
* @package assignfeedback_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017120800;
$plugin->requires = 2016052300; // Moodle 3.1
$plugin->component = 'assignfeedback_dta';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "1.0.0";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment