| author | wenzelm |
| Mon, 15 Sep 2025 22:36:04 +0200 | |
| changeset 83158 | 7e94f31b6d6c |
| parent 83157 | dc54c60492c3 |
| child 83160 | bc86832bd2fd |
| permissions | -rw-r--r-- |
| 68758 | 1 |
/* Title: Pure/PIDE/document_status.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Document status based on markup information. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 75393 | 10 |
object Document_Status {
|
| 68758 | 11 |
/* command status */ |
12 |
||
| 75393 | 13 |
object Command_Status {
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
14 |
object Theory_Status extends Enumeration {
|
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
15 |
val NONE, INITIALIZED, CONSOLIDATING, CONSOLIDATED = Value |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
16 |
|
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
17 |
def initialized(t: Value): Boolean = t >= INITIALIZED |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
18 |
def consolidating(t: Value): Boolean = t >= CONSOLIDATING |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
19 |
def consolidated(t: Value): Boolean = t >= CONSOLIDATED |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
20 |
|
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
21 |
def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2 |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
22 |
} |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
23 |
|
| 68758 | 24 |
val proper_elements: Markup.Elements = |
25 |
Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
26 |
Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
| 68758 | 27 |
|
28 |
val liberal_elements: Markup.Elements = |
|
29 |
proper_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR |
|
30 |
||
| 83157 | 31 |
def make( |
32 |
markups: Iterable[Markup], |
|
33 |
warned: Boolean = false, |
|
34 |
failed: Boolean = false |
|
35 |
): Command_Status = {
|
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
36 |
var theory_status = Theory_Status.NONE |
| 68758 | 37 |
var touched = false |
38 |
var accepted = false |
|
| 83157 | 39 |
var warned1 = warned |
40 |
var failed1 = failed |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
41 |
var canceled = false |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
42 |
var finalized = false |
| 68758 | 43 |
var forks = 0 |
44 |
var runs = 0 |
|
| 83155 | 45 |
for (markup <- markups) {
|
| 68758 | 46 |
markup.name match {
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
47 |
case Markup.INITIALIZED => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
48 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
49 |
case Markup.CONSOLIDATING => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
50 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
51 |
case Markup.CONSOLIDATED => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
52 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED) |
| 68758 | 53 |
case Markup.ACCEPTED => accepted = true |
54 |
case Markup.FORKED => touched = true; forks += 1 |
|
55 |
case Markup.JOINED => forks -= 1 |
|
56 |
case Markup.RUNNING => touched = true; runs += 1 |
|
57 |
case Markup.FINISHED => runs -= 1 |
|
| 83157 | 58 |
case Markup.WARNING | Markup.LEGACY => warned1 = true |
59 |
case Markup.FAILED | Markup.ERROR => failed1 = true |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
60 |
case Markup.CANCELED => canceled = true |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
61 |
case Markup.FINALIZED => finalized = true |
| 68758 | 62 |
case _ => |
63 |
} |
|
64 |
} |
|
| 83155 | 65 |
new Command_Status( |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
66 |
theory_status = theory_status, |
| 68887 | 67 |
touched = touched, |
68 |
accepted = accepted, |
|
| 83157 | 69 |
warned = warned1, |
70 |
failed = failed1, |
|
| 68887 | 71 |
canceled = canceled, |
72 |
finalized = finalized, |
|
73 |
forks = forks, |
|
74 |
runs = runs) |
|
| 68758 | 75 |
} |
76 |
||
| 83155 | 77 |
val empty: Command_Status = make(Nil) |
| 68758 | 78 |
|
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
79 |
def merge(args: IterableOnce[Command_Status]): Command_Status = |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
80 |
args.iterator.foldLeft(empty)(_ + _) |
| 68758 | 81 |
} |
82 |
||
| 83155 | 83 |
final class Command_Status private( |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
84 |
private val theory_status: Command_Status.Theory_Status.Value, |
| 68758 | 85 |
private val touched: Boolean, |
86 |
private val accepted: Boolean, |
|
87 |
private val warned: Boolean, |
|
88 |
private val failed: Boolean, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
89 |
private val canceled: Boolean, |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
90 |
private val finalized: Boolean, |
| 83155 | 91 |
val forks: Int, |
92 |
val runs: Int |
|
| 75393 | 93 |
) {
|
| 83155 | 94 |
override def toString: String = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
95 |
if (is_empty) "Command_Status.empty" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
96 |
else if (failed) "Command_Status(failed)" |
| 83155 | 97 |
else if (warned) "Command_Status(warned)" |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
98 |
else "Command_Status(...)" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
99 |
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
100 |
def is_empty: Boolean = |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
101 |
!Command_Status.Theory_Status.initialized(theory_status) && |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
102 |
!touched && !accepted && !warned && !failed && !canceled && !finalized && |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
103 |
forks == 0 && runs == 0 |
| 83155 | 104 |
|
| 68758 | 105 |
def + (that: Command_Status): Command_Status = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
106 |
if (is_empty) that |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
107 |
else if (that.is_empty) this |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
108 |
else {
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
109 |
new Command_Status( |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
110 |
theory_status = Command_Status.Theory_Status.merge(theory_status, that.theory_status), |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
111 |
touched = touched || that.touched, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
112 |
accepted = accepted || that.accepted, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
113 |
warned = warned || that.warned, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
114 |
failed = failed || that.failed, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
115 |
canceled = canceled || that.canceled, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
116 |
finalized = finalized || that.finalized, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
117 |
forks = forks + that.forks, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
118 |
runs = runs + that.runs) |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
119 |
} |
| 68758 | 120 |
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
121 |
def initialized: Boolean = Command_Status.Theory_Status.initialized(theory_status) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
122 |
def consolidating: Boolean = Command_Status.Theory_Status.consolidating(theory_status) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
123 |
def consolidated: Boolean = Command_Status.Theory_Status.consolidated(theory_status) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
124 |
def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0 |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
125 |
|
| 68758 | 126 |
def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
127 |
def is_running: Boolean = runs != 0 |
|
128 |
def is_warned: Boolean = warned |
|
129 |
def is_failed: Boolean = failed |
|
130 |
def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
131 |
def is_canceled: Boolean = canceled |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
132 |
def is_finalized: Boolean = finalized |
| 68881 | 133 |
def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0 |
| 68758 | 134 |
} |
135 |
||
136 |
||
137 |
/* node status */ |
|
138 |
||
| 75393 | 139 |
object Node_Status {
|
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
140 |
val empty: Node_Status = |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
141 |
Node_Status( |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
142 |
is_suppressed = false, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
143 |
unprocessed = 0, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
144 |
running = 0, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
145 |
warned = 0, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
146 |
failed = 0, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
147 |
finished = 0, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
148 |
canceled = false, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
149 |
terminated = false, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
150 |
initialized = false, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
151 |
finalized = false, |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
152 |
consolidated = false) |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
153 |
|
| 68758 | 154 |
def make( |
155 |
state: Document.State, |
|
156 |
version: Document.Version, |
|
| 76714 | 157 |
name: Document.Node.Name |
158 |
): Node_Status = {
|
|
| 68758 | 159 |
val node = version.nodes(name) |
160 |
||
161 |
var unprocessed = 0 |
|
162 |
var running = 0 |
|
163 |
var warned = 0 |
|
164 |
var failed = 0 |
|
165 |
var finished = 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
166 |
var canceled = false |
| 68892 | 167 |
var terminated = true |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
168 |
var finalized = false |
| 68758 | 169 |
for (command <- node.commands.iterator) {
|
170 |
val states = state.command_states(version, command) |
|
171 |
val status = Command_Status.merge(states.iterator.map(_.document_status)) |
|
172 |
||
173 |
if (status.is_running) running += 1 |
|
174 |
else if (status.is_failed) failed += 1 |
|
175 |
else if (status.is_warned) warned += 1 |
|
176 |
else if (status.is_finished) finished += 1 |
|
177 |
else unprocessed += 1 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
178 |
|
|
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
179 |
if (status.is_canceled) canceled = true |
| 68892 | 180 |
if (!status.is_terminated) terminated = false |
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
181 |
if (status.is_finalized) finalized = true |
| 68758 | 182 |
} |
183 |
val initialized = state.node_initialized(version, name) |
|
184 |
val consolidated = state.node_consolidated(version, name) |
|
185 |
||
| 68887 | 186 |
Node_Status( |
|
69818
60d0ee8f2ddb
more robust: avoid potentially unrelated snapshot for the sake of is_suppressed;
wenzelm
parents:
69817
diff
changeset
|
187 |
is_suppressed = version.nodes.is_suppressed(name), |
| 68887 | 188 |
unprocessed = unprocessed, |
189 |
running = running, |
|
190 |
warned = warned, |
|
191 |
failed = failed, |
|
192 |
finished = finished, |
|
193 |
canceled = canceled, |
|
194 |
terminated = terminated, |
|
| 68889 | 195 |
initialized = initialized, |
| 68887 | 196 |
finalized = finalized, |
197 |
consolidated = consolidated) |
|
| 68758 | 198 |
} |
199 |
} |
|
200 |
||
201 |
sealed case class Node_Status( |
|
|
69818
60d0ee8f2ddb
more robust: avoid potentially unrelated snapshot for the sake of is_suppressed;
wenzelm
parents:
69817
diff
changeset
|
202 |
is_suppressed: Boolean, |
| 68887 | 203 |
unprocessed: Int, |
204 |
running: Int, |
|
205 |
warned: Int, |
|
206 |
failed: Int, |
|
207 |
finished: Int, |
|
208 |
canceled: Boolean, |
|
209 |
terminated: Boolean, |
|
| 68889 | 210 |
initialized: Boolean, |
| 68887 | 211 |
finalized: Boolean, |
| 75393 | 212 |
consolidated: Boolean |
213 |
) {
|
|
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
214 |
def is_empty: Boolean = this == Node_Status.empty |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
215 |
|
| 68758 | 216 |
def ok: Boolean = failed == 0 |
217 |
def total: Int = unprocessed + running + warned + failed + finished |
|
218 |
||
|
69844
b21ddfa7042b
clarified quasi_consolidated status after 5f160df596c1 -- relevant for headless PIDE session (e.g. "isabelle dump");
wenzelm
parents:
69818
diff
changeset
|
219 |
def quasi_consolidated: Boolean = !is_suppressed && !finalized && terminated |
| 68897 | 220 |
|
| 68898 | 221 |
def percentage: Int = |
222 |
if (consolidated) 100 |
|
223 |
else if (total == 0) 0 |
|
224 |
else (((total - unprocessed).toDouble / total) * 100).toInt min 99 |
|
225 |
||
| 68758 | 226 |
def json: JSON.Object.T = |
227 |
JSON.Object("ok" -> ok, "total" -> total, "unprocessed" -> unprocessed,
|
|
228 |
"running" -> running, "warned" -> warned, "failed" -> failed, "finished" -> finished, |
|
| 68898 | 229 |
"canceled" -> canceled, "consolidated" -> consolidated, |
230 |
"percentage" -> percentage) |
|
| 68758 | 231 |
} |
232 |
||
233 |
||
| 69863 | 234 |
/* overall timing */ |
| 68758 | 235 |
|
| 75393 | 236 |
object Overall_Timing {
|
| 83154 | 237 |
val empty: Overall_Timing = Overall_Timing() |
| 68758 | 238 |
|
239 |
def make( |
|
240 |
state: Document.State, |
|
241 |
version: Document.Version, |
|
| 69863 | 242 |
commands: Iterable[Command], |
| 75393 | 243 |
threshold: Double = 0.0 |
244 |
): Overall_Timing = {
|
|
| 68758 | 245 |
var total = 0.0 |
| 69863 | 246 |
var command_timings = Map.empty[Command, Double] |
| 68758 | 247 |
for {
|
| 69863 | 248 |
command <- commands.iterator |
| 68758 | 249 |
st <- state.command_states(version, command) |
250 |
} {
|
|
251 |
val command_timing = |
|
| 73359 | 252 |
st.status.foldLeft(0.0) {
|
| 68758 | 253 |
case (timing, Markup.Timing(t)) => timing + t.elapsed.seconds |
254 |
case (timing, _) => timing |
|
| 73359 | 255 |
} |
| 68758 | 256 |
total += command_timing |
| 69864 | 257 |
if (command_timing > 0.0 && command_timing >= threshold) {
|
258 |
command_timings += (command -> command_timing) |
|
259 |
} |
|
| 68758 | 260 |
} |
| 83154 | 261 |
Overall_Timing(total = total, command_timings = command_timings) |
| 68758 | 262 |
} |
263 |
} |
|
264 |
||
| 83154 | 265 |
sealed case class Overall_Timing( |
266 |
total: Double = 0.0, |
|
267 |
command_timings: Map[Command, Double] = Map.empty |
|
268 |
) {
|
|
| 69864 | 269 |
def command_timing(command: Command): Double = |
270 |
command_timings.getOrElse(command, 0.0) |
|
271 |
} |
|
| 68759 | 272 |
|
273 |
||
274 |
/* nodes status */ |
|
275 |
||
| 78600 | 276 |
enum Overall_Node_Status { case ok, failed, pending }
|
| 68759 | 277 |
|
| 75393 | 278 |
object Nodes_Status {
|
| 68903 | 279 |
val empty: Nodes_Status = new Nodes_Status(Map.empty, Document.Nodes.empty) |
| 68759 | 280 |
} |
281 |
||
| 68903 | 282 |
final class Nodes_Status private( |
283 |
private val rep: Map[Document.Node.Name, Node_Status], |
|
| 75393 | 284 |
nodes: Document.Nodes |
285 |
) {
|
|
|
68770
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68769
diff
changeset
|
286 |
def is_empty: Boolean = rep.isEmpty |
|
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68769
diff
changeset
|
287 |
def apply(name: Document.Node.Name): Node_Status = rep(name) |
| 68759 | 288 |
def get(name: Document.Node.Name): Option[Node_Status] = rep.get(name) |
289 |
||
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
290 |
def present( |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
291 |
domain: Option[List[Document.Node.Name]] = None |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
292 |
): List[(Document.Node.Name, Node_Status)] = {
|
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
293 |
for (name <- domain.getOrElse(nodes.topological_order)) |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
294 |
yield name -> get(name).getOrElse(Node_Status.empty) |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
295 |
} |
| 68903 | 296 |
|
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
297 |
def quasi_consolidated(name: Document.Node.Name): Boolean = |
|
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
298 |
rep.get(name) match {
|
| 68897 | 299 |
case Some(st) => st.quasi_consolidated |
|
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
300 |
case None => false |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
301 |
} |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
302 |
|
| 78600 | 303 |
def overall_node_status(name: Document.Node.Name): Overall_Node_Status = |
| 68759 | 304 |
rep.get(name) match {
|
305 |
case Some(st) if st.consolidated => |
|
306 |
if (st.ok) Overall_Node_Status.ok else Overall_Node_Status.failed |
|
307 |
case _ => Overall_Node_Status.pending |
|
308 |
} |
|
309 |
||
| 68763 | 310 |
def update( |
|
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68904
diff
changeset
|
311 |
resources: Resources, |
| 68763 | 312 |
state: Document.State, |
313 |
version: Document.Version, |
|
| 68769 | 314 |
domain: Option[Set[Document.Node.Name]] = None, |
| 75393 | 315 |
trim: Boolean = false |
316 |
): (Boolean, Nodes_Status) = {
|
|
| 68903 | 317 |
val nodes1 = version.nodes |
| 68763 | 318 |
val update_iterator = |
319 |
for {
|
|
| 68903 | 320 |
name <- domain.getOrElse(nodes1.domain).iterator |
| 82918 | 321 |
if !Resources.hidden_node(name) && !resources.loaded_theory(name) |
| 68763 | 322 |
st = Document_Status.Node_Status.make(state, version, name) |
323 |
if !rep.isDefinedAt(name) || rep(name) != st |
|
324 |
} yield (name -> st) |
|
325 |
val rep1 = rep ++ update_iterator |
|
| 68903 | 326 |
val rep2 = if (trim) rep1 -- rep1.keysIterator.filterNot(nodes1.domain) else rep1 |
| 68764 | 327 |
|
| 68903 | 328 |
(rep != rep2, new Nodes_Status(rep2, nodes1)) |
| 68763 | 329 |
} |
| 68761 | 330 |
|
| 68759 | 331 |
override def hashCode: Int = rep.hashCode |
332 |
override def equals(that: Any): Boolean = |
|
333 |
that match {
|
|
334 |
case other: Nodes_Status => rep == other.rep |
|
335 |
case _ => false |
|
336 |
} |
|
| 68765 | 337 |
|
| 75393 | 338 |
override def toString: String = {
|
| 68765 | 339 |
var ok = 0 |
340 |
var failed = 0 |
|
341 |
var pending = 0 |
|
| 68873 | 342 |
var canceled = 0 |
| 68765 | 343 |
for (name <- rep.keysIterator) {
|
344 |
overall_node_status(name) match {
|
|
345 |
case Overall_Node_Status.ok => ok += 1 |
|
346 |
case Overall_Node_Status.failed => failed += 1 |
|
347 |
case Overall_Node_Status.pending => pending += 1 |
|
348 |
} |
|
| 68873 | 349 |
if (apply(name).canceled) canceled += 1 |
| 68765 | 350 |
} |
| 68873 | 351 |
"Nodes_Status(ok = " + ok + ", failed = " + failed + ", pending = " + pending + |
352 |
", canceled = " + canceled + ")" |
|
| 68765 | 353 |
} |
| 68759 | 354 |
} |
| 68758 | 355 |
} |