Skip to content

Commit

Permalink
Dmoj script ready
Browse files Browse the repository at this point in the history
  • Loading branch information
FherStk committed Feb 11, 2023
1 parent fe4593f commit 0954617
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 29 deletions.
54 changes: 31 additions & 23 deletions core/main/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,39 +258,46 @@ public Log CloseLog(){
/// </summary>
public Log[] GetLog() {
List<Log> logs = new List<Log>();

//Getting info for each script log (head+setup+script+teardown)
foreach(var script in ScriptLog){
var log = new Log();
log.Content = log.Content.Concat(Trim(HeaderLog.Content)).ToList();

if(SetupLog.Content.Count > 0){
log.Content = log.Content.Concat(Trim(SetupLog.Content)).ToList();
log.Content.Add(new Space());
}

if(script.Content.Count > 0){
log.Content = log.Content.Concat(Trim(script.Content)).ToList();
log.Content.Add(new Space());
}

if(TeardownLog.Content.Count > 0){
log.Content = log.Content.Concat(Trim(TeardownLog.Content)).ToList();
}

logs.Add(log);
}

if(ScriptLog.Count == 0) AppendLogData(logs, null);
if(ScriptLog.Count > 0){
//Getting info for each script log (head+setup+script+teardown)
foreach(var scriptLog in ScriptLog){
AppendLogData(logs, scriptLog);
}
}

//Getting trailing log data
if(CurrentLog.Content.Count > 0){
var log = new Log();
log.Content.Add(new Space());
log.Content = log.Content.Concat(Trim(CurrentLog.Content)).ToList();
logs.Add(log);
}
}

return logs.ToArray();
}

private void AppendLogData(List<Log> allLogs, Log scriptLog){
var log = new Log();
log.Content = log.Content.Concat(Trim(HeaderLog.Content)).ToList();

if(SetupLog.Content.Count > 0){
log.Content = log.Content.Concat(Trim(SetupLog.Content)).ToList();
log.Content.Add(new Space());
}

if(scriptLog != null && scriptLog.Content.Count > 0){
log.Content = log.Content.Concat(Trim(scriptLog.Content)).ToList();
log.Content.Add(new Space());
}

if(TeardownLog.Content.Count > 0){
log.Content = log.Content.Concat(Trim(TeardownLog.Content)).ToList();
}

allLogs.Add(log);
}

/// <summary>
/// Returns the Output history as an string, using \r\n as breaklines.
Expand Down Expand Up @@ -414,6 +421,7 @@ private void WriteColor(string text, Style style, bool newLine){
Style = $"{style.ToString().ToLower()}-primary"
});
text = text.Substring(i+1);
IsNewLine = false; //otherwise another ~ trailed items produces an unwanted indent

i = (text.Contains("~") ? text.IndexOf("~") : text.Contains("...") ? text.IndexOf("...") : text.IndexOf(":"));
if(i == -1) i = text.Length;
Expand Down
31 changes: 31 additions & 0 deletions core/main/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ protected string AppConfigName {
}
}

/// <summary>
/// The current app's temporary folder path.
/// </summary>
protected string AppTempPath {
get{
return GetVar("app_temp_path", AutoComputeVarValues).ToString();
}

private set{
try{
//Read only
GetVar("app_temp_path", AutoComputeVarValues);
throw new NotSupportedException("Read only");
}
catch (ItemNotFoundException){
UpdateVar("app_temp_path", value);
UpdateVar("app_temp_name", Path.GetFileName(value) ?? string.Empty);
}
}
}

/// <summary>
/// The root app's temporary folder name.
/// </summary>
protected string AppTempName {
get{
return GetVar("app_temp_name", AutoComputeVarValues).ToString();
}
}

/// <summary>
/// The current app's utils folder path.
/// </summary>
Expand Down Expand Up @@ -710,6 +740,7 @@ private Script(){
AppFolderPath = Utils.AppFolder;
AppConfigPath = Utils.ConfigFolder;
AppUtilsPath = Utils.UtilsFolder;
AppTempPath = Utils.TempFolder;
ExecutionFolderPath = Utils.ExecutionFolder;

//Setup the remaining vars
Expand Down
34 changes: 28 additions & 6 deletions docs/tutorials/teacher.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ APP_CONFIG_NAME | text | The core app's configuration folder (just the folder na
APP_CONFIG_PATH | text | The core app's configuration folder (the entire path).
APP_UTILS_NAME | text | The core app's utils folder (just the folder name).
APP_UTILS_PATH | text | The core app's utils folder (the entire path).
APP_TEMP_NAME | text | The core app's temporary folder (just the folder name).
APP_TEMP_PATH | text | The core app's temporary folder (the entire path).

##### Script data:
Name | Type | Description
Expand Down Expand Up @@ -443,18 +445,18 @@ Name | Type | Mandatory | Description | Default
------------ | -------------
caption | text | no | Message to display before every batch execution. | `"Running on batch mode:"`
concurrent | integer | no | Maximum concurrent scripts execution (0 = MAX). | `0`
[init](#init) | sequence | no | The defined content will be executed once at the begining, before the caption| |
[init](#init) | sequence | no | The defined content will be executed once at the begining, before the caption. | |
[setup](#setup) | sequence | no | The defined content will be executed once per target, before the caption (and also before the copy_detectors begins). | |
[pre](#pre) | sequence | no | The defined content will be executed once per batch target just before each body. |
[post](#post) | sequence | no | The defined content will be executed once per batch target just after each body. |
[teardown](#teardown) | sequence | no | The defined content will be executed once per target, after the execution of all post. |
[end](#end) | sequence | no | The defined content will be executed once at the end of the script | |
[end](#end) | sequence | no | The defined content will be executed once at the end of the script. | |
[copy_detector](#copy_detector) | mapping | no | Enables the copy detection logic, which will be executed before any body and after all pre executions. |
[local](#local) | sequence | yes (if no `remote` has been defined) | Local batch target, so each script body will be executed once per local target. |
[remote](#remote) | sequence | yes (if no `local` has been defined) | Remote batch target, so each script body will be executed once per remote target |

### <a name="setup"></a> body
The defined content will be executed before the caption (once per target on batch mode).
### <a name="init"></a> init
The defined content will be executed once at the begining, before the caption.

Name | Type | Mandatory | Description
------------ | -------------
Expand All @@ -463,8 +465,8 @@ Name | Type | Mandatory | Description
[run](#run) | mapping | no | Runs a command.
echo | text | no | Displays a message.

### <a name="teardown"></a> body
The defined content will be executed at the end (once per target on batch mode).
### <a name="setup"></a> setup
The defined content will be executed before the caption (once per target on batch mode).

Name | Type | Mandatory | Description
------------ | -------------
Expand Down Expand Up @@ -493,6 +495,26 @@ Name | Type | Mandatory | Description
[run](#run) | mapping | no | Runs a command, it can be used wherever inside the body (usually inside a question's content).
echo | text | no | Displays a message.

### <a name="teardown"></a> teardown
The defined content will be executed at the end (once per target on batch mode).

Name | Type | Mandatory | Description
------------ | -------------
[vars](#vars) | mapping | no | Defines vars in the same way and with the same rules as the ones defined within root level, but as local-scope vars; useful to store command results or other stuff.
[connector](#connector) | mapping | no | Defines a connector to use, it can be defined wherever inside the body (usually inside a question's content).
[run](#run) | mapping | no | Runs a command.
echo | text | no | Displays a message.

### <a name="end"></a> end
The defined content will be executed once at the end of the script.

Name | Type | Mandatory | Description
------------ | -------------
[vars](#vars) | mapping | no | Defines vars in the same way and with the same rules as the ones defined within root level, but as local-scope vars; useful to store command results or other stuff.
[connector](#connector) | mapping | no | Defines a connector to use, it can be defined wherever inside the body (usually inside a question's content).
[run](#run) | mapping | no | Runs a command.
echo | text | no | Displays a message.

#### <a name="copy_detector"></a> copy_detector
Enables the copy detection logic, not supported for `host` targets (see avaliable copy detectors through API documentation). Just a single file per folder can be loaded into the copy detector engine, but this will be upgraded in a near future in order to allow multi-file support.

Expand Down
82 changes: 82 additions & 0 deletions scripts/targets/batch/dmoj_asix1p4curs22.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright © 2023 Fernando Porrino Serrano
# Third party software licenses can be found at /docs/credits/credits.md

# This file is part of AutoCheck.

# AutoCheck is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# AutoCheck 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with AutoCheck. If not, see <https://www.gnu.org/licenses/>.

vars:
contest: "asix1p4curs22"
output: "{$APP_TEMP_PATH}/DMOJ/{$CONTEST}"

batch:
- init:
- echo: "Downloading DMOJ contest ~{$CONTEST}~ into ~{$OUTPUT}:"

- connector:
type: "Dmoj"
arguments: "--host dmoj.elpuig.xeill.net"

- run:
connector: "Dmoj"
command: "DownloadContestSubmissions"
arguments: "--contestCode {$CONTEST} --outputPath {$OUTPUT}"
store: "ZIP_FILE"

- local:
- path: "{$APP_TEMP_PATH}/DMOJ/{$CONTEST}"

- caption: "Running on batch mode for ~{$CURRENT_FOLDER_NAME}:"

- copy_detector:
type: "SourceCode"
file: "quantitatdetalles.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "quantitatdivisibles.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "posiciovalormespetit.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "posiciovalormesgran.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "endrecarifiltrar.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "endrecareliminarrepe.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "fusiolleteresinums.java"
threshold: !!float 0.97

- copy_detector:
type: "SourceCode"
file: "separarlletresinums.java"
threshold: !!float 0.97


45 changes: 45 additions & 0 deletions test/main/Script.cs/Real/Dmoj.cs

Large diffs are not rendered by default.

0 comments on commit 0954617

Please sign in to comment.