Skip to content

Commit

Permalink
Merge pull request #131 from FherStk/dmoj
Browse files Browse the repository at this point in the history
  • Loading branch information
FherStk authored Feb 11, 2023
2 parents f548dc3 + 15c19ac commit 036fe1c
Show file tree
Hide file tree
Showing 363 changed files with 5,366 additions and 1,676 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[//]: # (WARNING: DO NOT EDIT README.md file because it's a copy of docs/index.md auto-generated during on build.)
# Current versions:
**AutoCheck.Test:** v2.23.0 | **AutoCheck.Docs:** v2.23.0 | **AutoCheck.Core:** v2.23.1 | **AutoCheck.Cli:** v2.5.0 | **AutoCheck.Web:** v1.5.1
**AutoCheck.Test:** v2.24.0 | **AutoCheck.Docs:** v2.24.0 | **AutoCheck.Core:** v2.24.0 | **AutoCheck.Cli:** v2.5.0 | **AutoCheck.Web:** v1.5.1
# AutoCheck
Multipurpose and extensible automated assignment validator, designed for academic purposes only, which has been developed using C# over .NET 6.0.
It has been created in order to automatically check the correctness of a set of students assignments including a score suggestion, but manual supervision is still needed.
Expand Down
2 changes: 1 addition & 1 deletion cli/Run.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
60 changes: 30 additions & 30 deletions core/AutoCheck.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net6.0</TargetFramework>
<Authors>Fernando Porrino Serrano</Authors>
<Product>AutoCheck.Core</Product>
<Copyright>Copyright © 2022</Copyright>
<VersionPrefix>2.23.1</VersionPrefix>
<Copyright>Copyright © 2023</Copyright>
<VersionPrefix>2.24.0</VersionPrefix>
<VersionSuffix>stable</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<AssemblyFileVersion>$(AssemblyVersion)</AssemblyFileVersion>
Expand All @@ -19,27 +19,27 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dein.ToolBox" Version="1.7.1"/>
<PackageReference Include="HtmlAgilityPack" Version="1.11.38"/>
<PackageReference Include="ExCSS" Version="4.1.1"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
<PackageReference Include="Npgsql" Version="6.0.0"/>
<PackageReference Include="System.Text.Json" Version="6.0.0"/>
<PackageReference Include="SharpZipLib" Version="1.3.3"/>
<PackageReference Include="dein.ToolBox" Version="1.7.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.38" />
<PackageReference Include="ExCSS" Version="4.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Npgsql" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="docfx.console" Version="2.58.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SSH.NET" Version="2020.0.2"/>
<PackageReference Include="Google.Apis.Drive.v3" Version="1.55.0.2502"/>
<PackageReference Include="Google.Apis.Storage.v1" Version="1.55.0.2482"/>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0"/>
<PackageReference Include="XPath2" Version="1.1.2"/>
<PackageReference Include="YamlDotNet" Version="11.2.1"/>
<PackageReference Include="NCalc2" Version="2.1.0"/>
<PackageReference Include="SharpCompress" Version="0.30.1"/>
<PackageReference Include="SSH.NET" Version="2020.0.2" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.55.0.2502" />
<PackageReference Include="Google.Apis.Storage.v1" Version="1.55.0.2482" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="XPath2" Version="1.1.2" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="NCalc2" Version="2.1.0" />
<PackageReference Include="SharpCompress" Version="0.30.1" />
</ItemGroup>

<Target Name="Versions" AfterTargets="Build">
Expand All @@ -63,35 +63,35 @@
<VersionText>**AutoCheck.Test:** v@(TestVersion) | **AutoCheck.Docs:** v@(DocsVersion) | **AutoCheck.Core:** v$(VersionPrefix) | **AutoCheck.Cli:** v@(CliVersion) | **AutoCheck.Web:** v@(WebVersion)</VersionText>
</PropertyGroup>

<WriteLinesToFile File="..\versions.tmp" Lines="# Current versions:" Overwrite="true"/>
<WriteLinesToFile File="..\versions.tmp" Lines="$(VersionText)" Overwrite="false"/>
<WriteLinesToFile File="..\versions.tmp" Lines="# Current versions:" Overwrite="true" />
<WriteLinesToFile File="..\versions.tmp" Lines="$(VersionText)" Overwrite="false" />
</Target>

<Target Name="GitHubReadme" AfterTargets="Build">
<ItemGroup>
<ConcatFiles Include="..\docs\github\warning.md; ..\versions.tmp; ..\docs\index.md"/>
<ConcatFiles Include="..\docs\github\warning.md; ..\versions.tmp; ..\docs\index.md" />
</ItemGroup>
<ItemGroup>
<FileContents Include="$([System.IO.File]::ReadAllText(%(ConcatFiles.Identity)))"/>
<FileContents Include="$([System.IO.File]::ReadAllText(%(ConcatFiles.Identity)))" />
</ItemGroup>
<WriteLinesToFile File="..\README.md" Lines="@(FileContents)" Overwrite="true"/>
<WriteLinesToFile File="..\README.md" Lines="@(FileContents)" Overwrite="true" />
</Target>

<Target Name="BuildDocumentation" BeforeTargets="DocGenerateMetadata">
<Message Importance="High" Text="Generating README.md for GitHub..."/>
<Message Importance="High" Text="Generating documentation..."/>
<CallTarget Targets="GitHubReadme"/>
<Copy SourceFiles="..\docs\patch\docfx.console.targets" DestinationFiles="$(PkgDocfx_console)\build\docfx.console.targets"/>
<Message Importance="High" Text="Generating README.md for GitHub..." />
<Message Importance="High" Text="Generating documentation..." />
<CallTarget Targets="GitHubReadme" />
<Copy SourceFiles="..\docs\patch\docfx.console.targets" DestinationFiles="$(PkgDocfx_console)\build\docfx.console.targets" />
</Target>

<Target Name="ObliterateAfterClean" AfterTargets="Clean">
<RemoveDir Directories="bin"/>
<RemoveDir Directories="..\docs\obj"/>
<RemoveDir Directories="$(BaseIntermediateOutputPath)"/>
<RemoveDir Directories="bin" />
<RemoveDir Directories="..\docs\obj" />
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>

<Target Name="ObliterateAfterClean" AfterTargets="Build">
<RemoveDir Directories="bin\Debug\net6.0\temp"/>
<RemoveDir Directories="bin\Debug\net6.0\temp" />
<Delete Files="..\versions.tmp" />
</Target>
</Project>
1 change: 1 addition & 0 deletions core/config/dmoj_token.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAAAAcsIYAC1jPFKWlFo2qAzQEomogs5bN1uXKBAXlrpa49h
2 changes: 1 addition & 1 deletion core/connectors/Atom.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Base.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Compressed.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Css.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Csv.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
144 changes: 144 additions & 0 deletions core/connectors/Dmoj.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
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/>.
*/

using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using AutoCheck.Core.Exceptions;

//NOTA: en función del directorio de batch y del file puesto en el script, se invoca a este método con el folder y el file que se ha encontrado por cada iteración.
// en este caso eso no es necesario, porque se trata de cargar desde un servicio.
// habria que definir el destino del batch como un "service" que habría que inventárselo. En ese service habría que definir lo necesario para la conexión, en este caso al DMOJ.
// se podria lanzar excepción si se intenta hacer cualquier cosa dentro de un "service" que no sea el copy_detector
// en un futuro podría interesar conectarse a un servicio remoto, descargar todo lo descargable de allí en local y empezar a lanzar un batch (como Moodle por ejemplo).

//ALT: como alternativa, se puede usar el INIT para descargar todas las entregas del DMOJ de un concurso.
// luego, basta con pasarle el anticopia de código fuente a esas carpetas generadas con el modo batch tradicional.
// esta opción parece más sencilla y factible.

namespace AutoCheck.Core.Connectors{

/// <summary>
/// Allows in/out operations and/or data validations with the DMOJ service.
/// </summary>
public class Dmoj: Base{
/// <summary>
/// DMOJ instance's host address.
/// </summary>
/// <value></value>
public string Host {get; private set;}


private string ApiToken{
get{
string fileName = "dmoj_token.txt";
string filePath = Utils.ConfigFile(fileName);

if(!File.Exists(filePath)) throw new ConfigFileMissingException($"Unable to load the DMOJ's API token from the config file '{filePath}'");
return File.ReadAllText(filePath);
}
}

/// <summary>
/// Creates a new connector instance.
/// </summary>
/// <param name="host">DMOJ's host address.</param>
public Dmoj(string host){
if(string.IsNullOrEmpty(host)) throw new ArgumentNullException("The 'host' cannot be null or empty");
this.Host = host;
}

/// <summary>
/// Disposes the object releasing its unmanaged properties.
/// </summary>
public override void Dispose(){
}

/// <summary>
/// Downloads all contest submissions, generating a a folder for each participant.
/// </summary>
/// <param name="contestCode">The contest code to download.</param>
/// <param name="outputPath">The contest code to download.</param>
public void DownloadContestSubmissions(string contestCode, string outputPath = ""){
if(string.IsNullOrEmpty(contestCode)) throw new ArgumentNullException("The 'contestCode' cannot be null or empty");
if(string.IsNullOrEmpty(outputPath)) outputPath = Path.Combine(Utils.TempFolder, "DMOJ", contestCode);

//Documentation: https://docs.dmoj.ca/#/site/api
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiToken);

var contest = DmojApiCall(httpClient, $"https://{Host}/api/v2/contest/{contestCode}");
var problems = contest["data"]["object"]["problems"];

int i=0;
string[] problemCodes = new string[problems.Count()];
foreach(var problem in problems){
problemCodes[i++] = problem["code"].ToString();
}

if(string.IsNullOrEmpty(outputPath)) outputPath = Utils.TempFolder;
var rankings = contest["data"]["object"]["rankings"];
foreach(var ranking in rankings){
var user = ranking["user"].ToString();
var userPath = Path.Combine(outputPath, user);

if(Directory.Exists(userPath)) Directory.Delete(userPath, true);
Directory.CreateDirectory(userPath);

i=0;
foreach(var submit in ranking["solutions"]){
if(submit.HasValues){
var submissions = DmojApiCall(httpClient, $"https://{Host}/api/v2/submissions?user={user}&problem={problemCodes[i]}");
var submitAC = submissions["data"]["objects"].Where(x => x["result"].ToString().Equals("AC")).FirstOrDefault();

if(submitAC != null){
var submitID = submitAC["id"].ToString();

var sourceCode = DmojSrcCall(httpClient, $"https://{Host}/src/{submitID}/raw");

var problemFile = Path.Combine(userPath, $"{problemCodes[i]}.java");
File.WriteAllText(problemFile, sourceCode);
}
}

i++;
}
}
}

private JObject DmojApiCall(HttpClient httpClient, string uri){
return JObject.Parse(DmojSrcCall(httpClient, uri));
}

private string DmojSrcCall(HttpClient httpClient, string uri){
var asyncGet = httpClient.GetAsync(uri);
asyncGet.Wait();
asyncGet.Result.EnsureSuccessStatusCode();

var asyncRead = asyncGet.Result.Content.ReadAsStringAsync();
asyncRead.Wait();

return asyncRead.Result;
}
}
}
2 changes: 1 addition & 1 deletion core/connectors/GDrive.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Html.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Math.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Odoo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/PlainText.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Postgres.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Rss.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Shell.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/TextStream.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/connectors/Xml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/copy/Base.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/copy/Css.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
2 changes: 1 addition & 1 deletion core/copy/Html.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Fernando Porrino Serrano
Copyright © 2023 Fernando Porrino Serrano
Third party software licenses can be found at /docs/credits/credits.md
This file is part of AutoCheck.
Expand Down
Loading

0 comments on commit 036fe1c

Please sign in to comment.