comparison scid/page-index.c @ 57:bc617784ec97

scid: many fixes in pages
author David Demelier <markand@malikania.fr>
date Wed, 17 Aug 2022 18:26:27 +0200
parents 3cf148705724
children b0d1166de7d3
comparison
equal deleted inserted replaced
56:308aa1086702 57:bc617784ec97
24 #include "scid.h" 24 #include "scid.h"
25 #include "theme.h" 25 #include "theme.h"
26 #include "util.h" 26 #include "util.h"
27 27
28 static void 28 static void
29 set_job_status(json_t *project, json_t *job, json_t *jobresults) 29 set_job_status(json_t *project, json_t *job, json_t *jobresults, size_t *ns, size_t *nf)
30 { 30 {
31 json_t *iter; 31 json_t *iter, *status;
32 int exitcode, sigcode; 32 int exitcode, sigcode;
33 size_t i, ns = 0, nf = 0; 33 size_t i;
34 34
35 /* Compute number of failures and number of success. */ 35 /* Compute number of failures and number of success. */
36 json_array_foreach(jobresults, i, iter) { 36 json_array_foreach(jobresults, i, iter) {
37 json_unpack(iter, "{si si}", "exitcode", &exitcode, "sigcode", &sigcode); 37 json_unpack(iter, "{si si}", "exitcode", &exitcode, "sigcode", &sigcode);
38 38
39 if (exitcode == 0 && sigcode == 0) 39 if (exitcode == 0 && sigcode == 0)
40 ns++; 40 (*ns)++;
41 else 41 else
42 nf++; 42 (*nf)++;
43
44 /* Also add exitcode and sigcode to the job object. */
45 json_object_set_new(job, "exitcode", json_integer(exitcode));
46 json_object_set_new(job, "sigcode", json_integer(sigcode));
47 } 43 }
48 44
49 json_object_set_new(project, "n-failed", json_integer(nf)); 45 /* At least one failed, set status to false. */
50 json_object_set_new(project, "n-success", json_integer(ns)); 46 json_object_set_new(job, "status", json_boolean(nf));
51 } 47 }
52 48
53 static void 49 static void
54 set_project_jobs(json_t *project, json_t *jobs) 50 set_project_jobs(json_t *project, json_t *jobs)
55 { 51 {
56 json_t *iter, *jobresults; 52 json_t *iter, *jobresults;
57 json_int_t job_id; 53 json_int_t job_id;
58 size_t i; 54 size_t i, ns = 0, nf = 0;
59 55
60 json_array_foreach(jobs, i, iter) { 56 json_array_foreach(jobs, i, iter) {
61 /* Don't populate too much. */ 57 /* Don't populate too much. */
62 if (i + 1 >= 10) 58 if (i + 1 >= 10)
63 break; 59 break;
72 json_unpack(iter, "{sI}", "id", &job_id); 68 json_unpack(iter, "{sI}", "id", &job_id);
73 69
74 if (!(jobresults = db_jobresult_list_by_job_group(job_id))) 70 if (!(jobresults = db_jobresult_list_by_job_group(job_id)))
75 continue; 71 continue;
76 72
77 set_job_status(project, iter, jobresults); 73 set_job_status(project, iter, jobresults, &ns, &nf);
78 json_decref(jobresults); 74 json_decref(jobresults);
79 } 75 }
80 76
81 json_object_set_new(project, "jobs", jobs); 77 json_object_set_new(project, "jobs", jobs);
78 json_object_set_new(project, "n-failed", json_integer(nf));
79 json_object_set_new(project, "n-success", json_integer(ns));
82 } 80 }
83 81
84 /* 82 /*
85 * For every projects, find their jobs and add them as 'jobs' property. 83 * For every projects, find their jobs and add them as 'jobs' property.
86 */ 84 */