ndmspc 0.20250128.0
Loading...
Searching...
No Matches
GitlabEvent.cxx
1#include <fstream>
2#include <sstream>
3#include <TString.h>
4#include <TRandom.h>
5#include "GitlabEvent.h"
6
10
11namespace Ndmspc {
12namespace Gitlab {
13
14Event::Event() : TObject(), fID(0), fNIssues(0), fNMergeRequests(0), fIssues(0), fMergeRequests(0)
15{
19}
20
21Event::Event(Long64_t id) : TObject(), fID(id), fNIssues(0), fNMergeRequests(0), fIssues(0), fMergeRequests(0)
22{
26 fIssues = new TClonesArray("Ndmspc::Gitlab::Track");
27 fMergeRequests = new TClonesArray("Ndmspc::Gitlab::Track");
28 fAuthors = new TH1S("authors", "Authors", 0, 0, 0);
29 fProjects = new TH1S("projects", "Projects", 0, 0, 0);
30 fMilestones = new TH1S("milestones", "Milestones", 0, 0, 0);
31 fMilestones->GetXaxis()->FindBin("none");
32 gRandom->SetSeed(0);
33}
34
36{
40
41 SafeDelete(fIssues);
42 SafeDelete(fMergeRequests);
43 SafeDelete(fAuthors);
44 SafeDelete(fProjects);
45 SafeDelete(fMilestones);
46}
47
49{
53 return (Track *)fIssues->ConstructedAt(fNIssues++);
54}
55
57{
61 return (Track *)fMergeRequests->ConstructedAt(fNMergeRequests++);
62}
63
64bool Event::FillGitlabFromJson(std::string issues, std::string mergrerequests)
65{
69
70 json iss, mrs;
71 // Json::String errs;
72 std::string errs;
73
74 if (!issues.empty()) {
75 Printf("Processing '%s' ...", issues.data());
76 std::ifstream fileIssues(issues.data());
77 if (!fileIssues.is_open()) {
78 Printf("Error: Unable to open file '%s' !!!", issues.data());
79 return false;
80 }
81
82 iss = json::parse(fileIssues);
84 }
85
86 if (!mergrerequests.empty()) {
87 Printf("Processing '%s' ...", mergrerequests.data());
88 std::ifstream fileMRs(mergrerequests);
89 if (!fileMRs.is_open()) {
90 Printf("Error: Unable to open file '%s' !!!", mergrerequests.data());
91 return false;
92 }
93
94 mrs = json::parse(fileMRs);
96 }
97 return true;
98}
99bool Event::FillIssuesFromJson(const json root)
100{
104
105 for (const auto & jv : root) {
106 Track * t = AddIssue();
107 t->SetState(jv["state"].get<std::string>());
108 t->SetProjectID(jv["project_id"].get<int>());
109 t->SetAuthorID(jv["author"]["id"].get<int>());
110 t->SetProject(ParseProjectName(jv["references"]["full"].get<std::string>(), '#'));
111 t->SetAuthor(jv["author"]["username"].get<std::string>());
112 if (!jv["milestone"].is_null()) {
113 t->SetMilestoneID(jv["milestone"]["id"].get<int>());
114 t->SetMilestone(jv["milestone"]["title"].get<std::string>());
115 }
116 else {
117 t->SetMilestoneID(-1);
118 t->SetMilestone("none");
119 }
120 fAuthors->GetXaxis()->FindBin(t->GetAuthor().c_str());
121 fProjects->GetXaxis()->FindBin(t->GetProject().c_str());
122 fMilestones->GetXaxis()->FindBin(t->GetMilestone().c_str());
123 Printf("Issue %d project [%s] author [%s] state [%s]", jv["iid"].get<int>(), t->GetProject().data(),
124 t->GetAuthor().data(), t->GetState().c_str());
125 }
126
127 return true;
128}
130{
134
135 for (const auto & jv : root) {
136 Track * t = AddMergeRequest();
137 t->SetState(jv["state"].get<std::string>());
138 t->SetProjectID(jv["project_id"].get<int>());
139 t->SetAuthorID(jv["author"]["id"].get<int>());
140 t->SetProject(ParseProjectName(jv["references"]["full"].get<std::string>(), '!'));
141 t->SetAuthor(jv["author"]["username"].get<std::string>());
142 if (!jv["milestone"].is_null()) {
143 t->SetMilestoneID(jv["milestone"]["id"].get<int>());
144 t->SetMilestone(jv["milestone"]["title"].get<std::string>());
145 }
146 else {
147 t->SetMilestoneID(-1);
148 t->SetMilestone("none");
149 }
150 fAuthors->GetXaxis()->FindBin(t->GetAuthor().c_str());
151 fProjects->GetXaxis()->FindBin(t->GetProject().c_str());
152 fMilestones->GetXaxis()->FindBin(t->GetMilestone().c_str());
153 Printf("MR %d project [%s] author [%s] state [%s]", jv["iid"].get<int>(), t->GetProject().data(),
154 t->GetAuthor().data(), t->GetState().c_str());
155 }
156
157 return true;
158}
159
160void Event::Print(Option_t * option) const
161{
165 Printf("id=%lld nIssues=%d nMergeRequests=%d", fID, fNIssues, fNMergeRequests);
166
167 // if (!fTracks) return;
168
169 // TString str(option);
170 // str.ToLower();
171 // if (str.Contains("all")) {
172 // Track * t;
173 // for (Int_t i = 0; i < fTracks->GetEntries(); i++) {
174 // t = (Track *)fTracks->At(i);
175 // t->Print();
176 // }
177 // }
178}
180{
184 ShrinkHistogram("autors", fAuthors, verbose);
185 ShrinkHistogram("projects", fProjects, verbose);
186 ShrinkHistogram("milestoness", fMilestones, verbose);
187}
188
189void Event::Clear(Option_t *)
190{
194 fID = 0;
195 // fDateTime.Reset();
196
197 fNIssues = 0;
198 fIssues->Clear("C");
199 fNMergeRequests = 0;
200 fMergeRequests->Clear("C");
201}
202
203void Event::SetTimeDate(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
204{
208 fDateTime.Set(year, month, day, hour, min, sec);
209}
210
211std::string Event::ParseProjectName(std::string in, char d) const
212{
216 std::string s;
217 std::stringstream ss(in);
218 std::getline(ss, s, d);
219
220 return std::move(s);
221}
222void Event::ShrinkHistogram(const char * name, TH1 * h, bool verbose)
223{
224
225 if (!h) return;
226 if (h->GetXaxis()->GetNbins() <= 0) return;
227 int count = 0;
228 std::string s;
229 for (int i = 1; i < h->GetXaxis()->GetNbins(); i++) {
230 s = h->GetXaxis()->GetBinLabel(i);
231 if (!s.empty()) {
232 count++;
233 Printf("%s label [%d] : %s", name, count, h->GetXaxis()->GetBinLabel(i));
234 }
235 else {
236 break;
237 }
238 }
239 h->GetXaxis()->Set(count, 0, count);
240}
241} // namespace Gitlab
242
243} // namespace Ndmspc
virtual void Print(Option_t *option="") const
bool FillIssuesFromJson(const json root)
void SetTimeDate(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
bool FillMergeRequestsFromJson(const json root)
Int_t fNIssues
Number of Issues.
TDatime fDateTime
Time of event.
Long64_t fID
ID of event.
std::string ParseProjectName(std::string in, char d='!') const
not implemented
TClonesArray * fIssues
Array with all issues.
virtual void Clear(Option_t *option="")
void ShrinkMappingHistograms(bool verbose=true)
Int_t fNMergeRequests
Number of MergeRequests.
bool FillGitlabFromJson(std::string issues, std::string mergrerequests)
TH1S * fProjects
! List of authors in current event
TH1S * fMilestones
! List of projects in current event
TClonesArray * fMergeRequests
Array with all merge requests.
std::string GetAuthor() const
Returns author.
Definition GitlabTrack.h:81
void SetAuthor(std::string name)
Definition GitlabTrack.h:82
void SetState(std::string t)
Definition GitlabTrack.h:78
std::string GetMilestone() const
Returns Milestone.
Definition GitlabTrack.h:89
void SetProjectID(Int_t id)
Definition GitlabTrack.h:84
void SetAuthorID(Int_t id)
Definition GitlabTrack.h:80
void SetProject(std::string name)
Definition GitlabTrack.h:86
std::string GetProject() const
Returns Project.
Definition GitlabTrack.h:85
void SetMilestoneID(Int_t id)
Definition GitlabTrack.h:88
std::string GetState() const
Returns state.
Definition GitlabTrack.h:77
void SetMilestone(std::string name)
Definition GitlabTrack.h:90