AsmGrader 0.0.0
Loading...
Searching...
No Matches
grading_session.hpp
Go to the documentation of this file.
1
3#pragma once
4
5// TODO: Rename this file
6
12#include <asmgrader/version.hpp>
13
14#include <boost/config/workaround.hpp>
15#include <boost/preprocessor/stringize.hpp>
16#include <fmt/base.h>
17#include <gsl/util>
18#include <range/v3/algorithm/all_of.hpp>
19#include <range/v3/algorithm/count_if.hpp>
20#include <range/v3/algorithm/fold_left.hpp>
21#include <range/v3/view/transform.hpp>
22
23#include <chrono>
24#include <filesystem>
25#include <functional>
26#include <optional>
27#include <source_location>
28#include <string>
29#include <string_view>
30#include <vector>
31
32namespace asmgrader {
33
42
43static consteval CompilerInfo get_compiler_info() {
44 CompilerInfo compiler_info{};
45
46#if defined(__GNUC__) && !defined(__clang__)
47 compiler_info.kind = CompilerInfo::GCC;
48 compiler_info.major_version = __GNUC__;
49 compiler_info.minor_version = __GNUC_MINOR__;
50 compiler_info.patch_version = __GNUC_PATCHLEVEL__;
51#elif defined(__clang__)
52 compiler_info.kind = CompilerInfo::Clang;
53 compiler_info.major_version = __clang_major__;
54 compiler_info.minor_version = __clang_minor__;
55 compiler_info.patch_version = __clang_patchlevel__;
56#endif
57
58 return compiler_info;
59}
60
62{
65 std::string_view git_hash = BOOST_PP_STRINGIZE(ASMGRADER_VERSION_GIT_HASH);
66
67 std::chrono::time_point<std::chrono::system_clock> start_time = std::chrono::system_clock::now();
68
69 decltype(__cplusplus) cpp_standard = __cplusplus;
70
71 CompilerInfo compiler_info = get_compiler_info();
72};
73
75{
76 bool passed;
77 std::string description;
78
79 // these are only used when verbosity >= Extra
80 std::optional<exprs::ExpressionRepr> expression_repr;
81
82 struct DebugInfo
83 {
84 std::string_view msg; // stringified condition
85 std::source_location loc; // requirement execution point
86
87 static constexpr std::string_view DEFAULT_MSG = "<unknown>";
88
89 explicit DebugInfo(std::string_view message = DEFAULT_MSG,
90 std::source_location location = std::source_location::current())
91 : msg{message}
92 , loc{location} {}
93 };
94
96};
97
99{
100 std::string name;
101 std::vector<RequirementResult> requirement_results;
102
105 int weight{};
106
107 std::optional<ContextInternalError> error;
108
109 constexpr bool passed() const noexcept { return !error && num_failed() == 0; }
110
111 constexpr int num_failed() const noexcept { return num_total - num_passed; }
112
113 constexpr int total_weighted() const noexcept { return num_total * weight; }
114
115 constexpr int passed_weighted() const noexcept { return num_passed * weight; }
116};
117
119{
120 std::string name;
121 std::vector<TestResult> test_results;
123
124 double get_percentage() const noexcept {
125 using ranges::fold_left, ranges::views::transform;
126
127 auto total_weight = fold_left(test_results | transform(&TestResult::total_weighted), 0, std::plus{});
128
129 auto passed_weight = fold_left(test_results | transform(&TestResult::passed_weighted), 0, std::plus{});
130
131 if (total_weight == 0) {
132 return 0.0;
133 }
134
135 return static_cast<double>(passed_weight) / total_weight * 100;
136 }
137
138 bool all_passed() const noexcept { return ranges::all_of(test_results, &TestResult::passed); }
139
140 int num_tests_passed() const noexcept {
141 return gsl::narrow_cast<int>(ranges::count_if(test_results, &TestResult::passed));
142 }
143
144 int num_tests_failed() const noexcept { return gsl::narrow_cast<int>(test_results.size()) - num_tests_passed(); }
145
146 int num_requirements_failed() const noexcept {
147 auto failed_view = test_results | ranges::views::transform(&TestResult::num_failed);
148 return ranges::fold_left(failed_view, 0, std::plus<>{});
149 }
150
152};
153
154// PROFESSOR_VERSION only
155
157{
158 std::string first_name; // if names_known = false, this holds the inferred name for now
159 std::string last_name;
160 bool names_known; // whether the names are known (i.e., obtained from a database) or inferred based on filename
161
162 std::optional<std::filesystem::path> assignment_path;
163
164 // the regex matcher, with fields substituted; used to provide a more helpful diagnostic
166
167 // TODO: ids for students with the same names?
168};
169
175
177{
178 std::vector<StudentResult> results;
179};
180
181} // namespace asmgrader
182
183// I'm crying, please give me reflection :(
184FMT_SERIALIZE_CLASS(::asmgrader::CompilerInfo, kind, major_version, minor_version);
186FMT_SERIALIZE_CLASS(::asmgrader::RunMetadata, version, version_string, git_hash, start_time, cpp_standard,
187 compiler_info);
188FMT_SERIALIZE_CLASS(::asmgrader::RequirementResult, passed, description, expression_repr, debug_info);
190FMT_SERIALIZE_CLASS(::asmgrader::TestResult, name, requirement_results, num_passed, num_total, weight, error);
191FMT_SERIALIZE_CLASS(::asmgrader::AssignmentResult, name, test_results, num_requirements_total);
192FMT_SERIALIZE_CLASS(::asmgrader::StudentInfo, first_name, last_name, names_known, assignment_path, subst_regex_string);
#define FMT_SERIALIZE_CLASS(class_name,...)
Definition macros.hpp:24
#define FMT_SERIALIZE_ENUM(enum_name,...)
Definition macros.hpp:40
Definition asm_buffer.hpp:20
consteval unsigned int get_version()
Definition version.hpp:26
Definition grading_session.hpp:119
int num_requirements_passed() const noexcept
Definition grading_session.hpp:151
std::vector< TestResult > test_results
Definition grading_session.hpp:121
bool all_passed() const noexcept
Definition grading_session.hpp:138
double get_percentage() const noexcept
Definition grading_session.hpp:124
int num_requirements_total
Definition grading_session.hpp:122
int num_requirements_failed() const noexcept
Definition grading_session.hpp:146
std::string name
Definition grading_session.hpp:120
int num_tests_failed() const noexcept
Definition grading_session.hpp:144
int num_tests_passed() const noexcept
Definition grading_session.hpp:140
Definition grading_session.hpp:35
Vendor
Definition grading_session.hpp:36
@ Clang
Definition grading_session.hpp:36
@ GCC
Definition grading_session.hpp:36
@ Unknown
Definition grading_session.hpp:36
int major_version
Definition grading_session.hpp:38
enum asmgrader::CompilerInfo::Vendor kind
int minor_version
Definition grading_session.hpp:39
int patch_version
Definition grading_session.hpp:40
Definition grading_session.hpp:177
std::vector< StudentResult > results
Definition grading_session.hpp:178
Definition grading_session.hpp:83
std::source_location loc
Definition grading_session.hpp:85
static constexpr std::string_view DEFAULT_MSG
Definition grading_session.hpp:87
std::string_view msg
Definition grading_session.hpp:84
DebugInfo(std::string_view message=DEFAULT_MSG, std::source_location location=std::source_location::current())
Definition grading_session.hpp:89
Definition grading_session.hpp:75
DebugInfo debug_info
Definition grading_session.hpp:95
std::optional< exprs::ExpressionRepr > expression_repr
Definition grading_session.hpp:80
std::string description
Definition grading_session.hpp:77
bool passed
Definition grading_session.hpp:76
Definition grading_session.hpp:62
std::string_view git_hash
Definition grading_session.hpp:65
int version
Definition grading_session.hpp:63
CompilerInfo compiler_info
Definition grading_session.hpp:71
std::chrono::time_point< std::chrono::system_clock > start_time
Definition grading_session.hpp:67
std::string_view version_string
Definition grading_session.hpp:64
decltype(__cplusplus) cpp_standard
Definition grading_session.hpp:69
Definition grading_session.hpp:157
bool names_known
Definition grading_session.hpp:160
std::string last_name
Definition grading_session.hpp:159
std::string subst_regex_string
Definition grading_session.hpp:165
std::optional< std::filesystem::path > assignment_path
Definition grading_session.hpp:162
std::string first_name
Definition grading_session.hpp:158
Definition grading_session.hpp:171
StudentInfo info
Definition grading_session.hpp:172
AssignmentResult result
Definition grading_session.hpp:173
Definition grading_session.hpp:99
int weight
Definition grading_session.hpp:105
std::optional< ContextInternalError > error
Definition grading_session.hpp:107
std::string name
Definition grading_session.hpp:100
constexpr int total_weighted() const noexcept
Definition grading_session.hpp:113
constexpr int num_failed() const noexcept
Definition grading_session.hpp:111
constexpr bool passed() const noexcept
Definition grading_session.hpp:109
int num_passed
Definition grading_session.hpp:103
int num_total
Definition grading_session.hpp:104
constexpr int passed_weighted() const noexcept
Definition grading_session.hpp:115
std::vector< RequirementResult > requirement_results
Definition grading_session.hpp:101
#define ASMGRADER_VERSION_STRING
Definition version.hpp:20
#define ASMGRADER_VERSION_GIT_HASH
Definition version.hpp:17