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
9#include <asmgrader/version.hpp>
10
11#include <boost/config/workaround.hpp>
12#include <boost/preprocessor/stringize.hpp>
13#include <fmt/base.h>
14#include <gsl/util>
15#include <range/v3/algorithm/all_of.hpp>
16#include <range/v3/algorithm/count_if.hpp>
17#include <range/v3/algorithm/fold_left.hpp>
18#include <range/v3/view/transform.hpp>
19
20#include <chrono>
21#include <filesystem>
22#include <functional>
23#include <optional>
24#include <source_location>
25#include <string>
26#include <string_view>
27#include <vector>
28
29namespace asmgrader {
30
39
40static consteval CompilerInfo get_compiler_info() {
41 CompilerInfo compiler_info{};
42
43#if defined(__GNUC__) && !defined(__clang__)
44 compiler_info.kind = CompilerInfo::GCC;
45 compiler_info.major_version = __GNUC__;
46 compiler_info.minor_version = __GNUC_MINOR__;
47 compiler_info.patch_version = __GNUC_PATCHLEVEL__;
48#elif defined(__clang__)
49 compiler_info.kind = CompilerInfo::Clang;
50 compiler_info.major_version = __clang_major__;
51 compiler_info.minor_version = __clang_minor__;
52 compiler_info.patch_version = __clang_patchlevel__;
53#endif
54
55 return compiler_info;
56}
57
59{
60 int version = get_version();
61 std::string_view version_string = ASMGRADER_VERSION_STRING;
62 std::string_view git_hash = BOOST_PP_STRINGIZE(ASMGRADER_VERSION_GIT_HASH);
63
64 std::chrono::time_point<std::chrono::system_clock> start_time = std::chrono::system_clock::now();
65
66 decltype(__cplusplus) cpp_standard = __cplusplus;
67
68 CompilerInfo compiler_info = get_compiler_info();
69};
70
72{
73 bool passed;
74 std::string msg;
75
76 struct DebugInfo
77 {
78 std::string_view msg; // stringified condition
79 std::source_location loc; // requirement execution point
80
81 static constexpr std::string_view DEFAULT_MSG = "<unknown>";
82
83 explicit DebugInfo(std::string_view message = DEFAULT_MSG,
84 std::source_location location = std::source_location::current())
85 : msg{message}
86 , loc{location} {}
87 };
88
90};
91
93{
94 std::string name;
95 std::vector<RequirementResult> requirement_results;
96
98 int num_total{};
99 int weight{};
100
101 std::optional<ContextInternalError> error;
102
103 constexpr bool passed() const noexcept { return !error && num_failed() == 0; }
104
105 constexpr int num_failed() const noexcept { return num_total - num_passed; }
106
107 constexpr int total_weighted() const noexcept { return num_total * weight; }
108
109 constexpr int passed_weighted() const noexcept { return num_passed * weight; }
110};
111
113{
114 std::string name;
115 std::vector<TestResult> test_results;
117
118 double get_percentage() const noexcept {
119 using ranges::fold_left_first, ranges::views::transform;
120
121 auto total_weight = ranges::fold_left(test_results | transform(&TestResult::total_weighted), 0, std::plus{});
122
123 auto passed_weight = ranges::fold_left(test_results | transform(&TestResult::passed_weighted), 0, std::plus{});
124
125 if (total_weight == 0) {
126 return 0.0;
127 }
128
129 return static_cast<double>(passed_weight) / total_weight * 100;
130 }
131
132 bool all_passed() const noexcept { return ranges::all_of(test_results, &TestResult::passed); }
133
134 int num_tests_passed() const noexcept {
135 return gsl::narrow_cast<int>(ranges::count_if(test_results, &TestResult::passed));
136 }
137
138 int num_tests_failed() const noexcept { return gsl::narrow_cast<int>(test_results.size()) - num_tests_passed(); }
139
140 int num_requirements_failed() const noexcept {
141 auto failed_view = test_results | ranges::views::transform(&TestResult::num_failed);
142 return ranges::fold_left(failed_view, 0, std::plus<>{});
143 }
144
146};
147
148// PROFESSOR_VERSION only
149
151{
152 std::string first_name; // if names_known = false, this holds the inferred name for now
153 std::string last_name;
154 bool names_known; // whether the names are known (i.e., obtained from a database) or inferred based on filename
155
156 std::optional<std::filesystem::path> assignment_path;
157
158 // the regex matcher, with fields substituted; used to provide a more helpful diagnostic
160
161 // TODO: ids for students with the same names?
162};
163
169
171{
172 std::vector<StudentResult> results;
173};
174
175} // namespace asmgrader
176
177template <>
179{
180 constexpr auto format(const ::asmgrader::RequirementResult::DebugInfo& from, fmt::format_context& ctx) const {
181 // Explicitly called "DebugInfo", so fmt to an empty string if not debug mode
182 if (!is_debug_format) {
183 return ctx.out();
184 }
185
186 return fmt::format_to(ctx.out(), "{{{} at {}}}", from.msg, from.loc);
187 }
188};
Definition asm_buffer.hpp:19
Definition grading_session.hpp:113
int num_requirements_passed() const noexcept
Definition grading_session.hpp:145
std::vector< TestResult > test_results
Definition grading_session.hpp:115
bool all_passed() const noexcept
Definition grading_session.hpp:132
double get_percentage() const noexcept
Definition grading_session.hpp:118
int num_requirements_total
Definition grading_session.hpp:116
int num_requirements_failed() const noexcept
Definition grading_session.hpp:140
std::string name
Definition grading_session.hpp:114
int num_tests_failed() const noexcept
Definition grading_session.hpp:138
int num_tests_passed() const noexcept
Definition grading_session.hpp:134
Definition grading_session.hpp:32
int major_version
Definition grading_session.hpp:35
@ Clang
Definition grading_session.hpp:33
@ GCC
Definition grading_session.hpp:33
@ Unknown
Definition grading_session.hpp:33
int minor_version
Definition grading_session.hpp:36
enum asmgrader::CompilerInfo::@1 kind
int patch_version
Definition grading_session.hpp:37
Definition debug.hpp:9
Definition grading_session.hpp:171
std::vector< StudentResult > results
Definition grading_session.hpp:172
Definition grading_session.hpp:77
std::source_location loc
Definition grading_session.hpp:79
static constexpr std::string_view DEFAULT_MSG
Definition grading_session.hpp:81
std::string_view msg
Definition grading_session.hpp:78
DebugInfo(std::string_view message=DEFAULT_MSG, std::source_location location=std::source_location::current())
Definition grading_session.hpp:83
Definition grading_session.hpp:72
std::string msg
Definition grading_session.hpp:74
DebugInfo debug_info
Definition grading_session.hpp:89
bool passed
Definition grading_session.hpp:73
Definition grading_session.hpp:59
std::string_view git_hash
Definition grading_session.hpp:62
int version
Definition grading_session.hpp:60
CompilerInfo compiler_info
Definition grading_session.hpp:68
std::chrono::time_point< std::chrono::system_clock > start_time
Definition grading_session.hpp:64
std::string_view version_string
Definition grading_session.hpp:61
decltype(__cplusplus) cpp_standard
Definition grading_session.hpp:66
Definition grading_session.hpp:151
bool names_known
Definition grading_session.hpp:154
std::string last_name
Definition grading_session.hpp:153
std::string subst_regex_string
Definition grading_session.hpp:159
std::optional< std::filesystem::path > assignment_path
Definition grading_session.hpp:156
std::string first_name
Definition grading_session.hpp:152
Definition grading_session.hpp:165
StudentInfo info
Definition grading_session.hpp:166
AssignmentResult result
Definition grading_session.hpp:167
Definition grading_session.hpp:93
int weight
Definition grading_session.hpp:99
std::optional< ContextInternalError > error
Definition grading_session.hpp:101
std::string name
Definition grading_session.hpp:94
constexpr int total_weighted() const noexcept
Definition grading_session.hpp:107
constexpr int num_failed() const noexcept
Definition grading_session.hpp:105
constexpr bool passed() const noexcept
Definition grading_session.hpp:103
int num_passed
Definition grading_session.hpp:97
int num_total
Definition grading_session.hpp:98
constexpr int passed_weighted() const noexcept
Definition grading_session.hpp:109
std::vector< RequirementResult > requirement_results
Definition grading_session.hpp:95
constexpr auto format(const ::asmgrader::RequirementResult::DebugInfo &from, fmt::format_context &ctx) const
Definition grading_session.hpp:180