-
Notifications
You must be signed in to change notification settings - Fork 0
/
stave-monitoring.C
190 lines (166 loc) · 7.53 KB
/
stave-monitoring.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//
// MAIN
//
bool stavemonitoring(){
//Output file
ofstream outfl("staveresults.dat");
//Black list: HSs that are in the DB but have some problems: missing HIC QT, missing attachments (added manually below)
string blacklist = "T-OL-Stave-027, T-OL-Stave-28, A-OL-Stave-020, B-ML-Stave-004, B-ML-Stave-038, B-ML-Stave-014, A-OL-Stave-023, T-OL-Stave-003, R-OL-Stave-004, B-ML-Stave-039, T-OL-Stave-002, D-OL-Stave-008, T-OL-Stave-006, B-ML-Stave-011, A-OL-Stave-001, A-OL-Stave-002, A-OL-Stave-003, A-OL-Stave-007, A-OL-Stave-011, F-OL-Stave-001";
//Add old HS, HS without attachments by hand (from excel)
const int nManual = 19;
string shsmanual[nManual] = {
"D-OL-Stave-008 D-OL-HS-U-008 D-OL-HS-L-008 98 84 17/5/2019 20",
"B-ML-Stave-011 B-ML-HS-U-011 B-ML-HS-L-011 56 56 12/11/2018 46",
"B-ML-Stave-014 B-ML-HS-U-014 B-ML-HS-L-014 56 56 3/11/2018 44",
"B-ML-Stave-039 B-ML-HS-U-039 B-ML-HS-L-039 56 54 14/5/2019 20",
"B-ML-Stave-038 B-ML-HS-U-038 B-ML-HS-L-038 49 56 2/5/2019 18",
"B-ML-Stave-004 B-ML-HS-U-004 B-ML-HS-L-004 35 56 11/10/2018 41",
"A-OL-Stave-001 A-OL-HS-U-001 A-OL-HS-L-001 96 84 7/9/2018 36",
"A-OL-Stave-002 A-OL-HS-U-002 A-OL-HS-L-002 91 49 7/9/2018 36",
"A-OL-Stave-003 A-OL-HS-U-003 A-OL-HS-L-003 98 70 7/9/2018 36",
"A-OL-Stave-007 A-OL-HS-U-007 A-OL-HS-L-008 98 98 3/12/2018 49",
"A-OL-Stave-011 A-OL-HS-U-013 A-OL-HS-L-014 96 98 1/4/2019 14",
//"F-OL-Stave-001 F-OL-HS-U-001 F-OL-HS-L-001 55 84 14/9/2018 37",
"F-OL-Stave-002 F-OL-HS-U-002 F-OL-HS-L-002 95 95 6/6/2018 23",
"T-OL-Stave-006 T-OL-HS-U-006 T-OL-HS-L-006 98 98 23/7/2018 30",
"T-OL-Stave-003 T-OL-HS-U-003 T-OL-HS-L-003 92 96 11/7/2018 28",
"R-OL-Stave-004 A-OL-HS-U-003 A-OL-HS-L-103 98 98 19/7/2019 29",
"A-OL-Stave-023 A-OL-HS-U-023 A-OL-HS-L-024 98 98 3/10/2019 40",
"T-OL-Stave-027 T-OL-HS-U-027 T-OL-HS-L-027 77 98 28/2/2019 9",
"T-OL-Stave-028 T-OL-HS-U-028 T-OL-HS-L-028 77 98 7/3/2019 10",
"A-OL-Stave-020 A-OL-HS-U-120 A-OL-HS-L-021 98 98 19/7/2019 29"
};
for(int i=0; i<nManual; i++)
outfl<<shsmanual[i]<<endl;
//Read file extracting the number of working chips HS by HS
ifstream infl("stavefiles.dat");
string fpath, activityname, hsid, hicid, staveidold, date;
std::vector<string> staveid, qualdate;
int nchipsokHSL = 0, nchipsokHSU = 0, nchipsmaskedHSU = 0, nchipsmaskedHSL = 0, nchipsokHIC = 0;
int count = 0, countU = 0, countL = 0, countUmiss = 0, countLmiss = 0;
int dayMax = -1, monthMax = -1, yearMax=-1;
bool isMissingparamU = false, isMissingparamL = false;
string hslid, hsuid;
while(infl>>activityname>>date>>nchipsokHIC){
staveid.push_back(ReadStaveID(activityname));
hsid = ReadHSID(activityname);
hicid = ReadHICID(activityname);
if(blacklist.find(staveid.back()) != string::npos) {staveid.pop_back(); continue;} //exclude HS that are added manually for DB issues
//Qualification date
qualdate.push_back(date);
//Take the most recent data in case of multiple information
/*string nextpath;
if(fpath.find("---------")==string::npos){//if not at the end of the file
int nrep = GetRepetitions("stavefiles.dat", hicid);
for(int irep=0; irep<nrep-1; irep++)
infl>>nextpath;
if(nrep>1)
fpath=nextpath;
}
count++;
if(count==1){
staveidold=staveid;
}*/
if(staveid[staveid.size()-1] != staveid[staveid.size()>1 ? staveid.size()-2 : staveid.size()-1]){
//Get most recent qualification date
for(int i=qualdate.size()-2; i>=(int)qualdate.size()-countL-countU-1; i--){
int day = GetDay(qualdate[i]);
int month = GetMonth(qualdate[i]);
int year = GetYear(qualdate[i]);
if(i==(int)qualdate.size()-2){
dayMax=day;
monthMax=month;
yearMax=year;
}
else{
if(year==yearMax){
if(month>monthMax){
dayMax=day;
monthMax=month;
yearMax=year;
}
else if(month==monthMax){
if(day>dayMax){
dayMax=day;
monthMax=month;
yearMax=year;
}
}
}
else if(year>yearMax){
dayMax=day;
monthMax=month;
yearMax=year;
}
}
/*if(day>dayMax || month>monthMax || year>yearMax){//Get most recent date
dayMax = day;
monthMax = month;
yearMax=year;
}*/
}
int week = GetWeek(dayMax, monthMax, yearMax);//week (most recent)
string stavewrite = staveid[staveid.size()-2];
bool isWritableOL = kTRUE;
bool isWritableML = kTRUE;
if(stavewrite.substr(0,1) != "B" && (countL==7 && countU==7)) isWritableOL=kTRUE;
if(stavewrite.substr(0,1) != "B" && ((countL<7 || countU<7) || (countL>7 || countU>7))) isWritableOL = kFALSE;
if(stavewrite.substr(0,1) == "B" && (countL==4 && countU==4)) isWritableML=kTRUE;
if(stavewrite.substr(0,1) == "B" && ((countL<4 || countU<4) || (countL>4 || countU>4))) isWritableML=kFALSE;
if(!isWritableML){
if(countL<4) errormsg(stavewrite.c_str(),Form(": %d missing HIC(s) for HS-Lower (not written) %s", 4-countL, isMissingparamL ? Form("--> No parameter for %d HIC(s)",countLmiss): "--> Missing info in DB" ));
if(countL>4) errormsg(stavewrite.c_str(),Form(": %d HIC(s) for HS-Lower (not written)", countL));
if(countU<4) errormsg(stavewrite.c_str(),Form(": %d missing HIC(s) for HS-Upper (not written) %s", 4-countU, isMissingparamU ? Form("--> No parameter for %d HIC(s)",countUmiss): "--> Missing info in DB" ));
if(countU>4) errormsg(stavewrite.c_str(),Form(": %d HIC(s) for HS-Upper (not written)", countU));
}
if(!isWritableOL){
if(countL<7) errormsg(stavewrite.c_str(),Form(": %d missing HIC(s) for HS-Lower (not written) %s",7-countL, isMissingparamL ? Form("--> No parameter for %d HIC(s)",countLmiss): "--> Missing info in DB" ));
if(countL>7) errormsg(stavewrite.c_str(),Form(": %d HIC(s) for HS-Lower (not written)", countL));
if(countU<7) errormsg(stavewrite.c_str(),Form(": %d missing HIC(s) for HS-Upper (not written) %s", 7-countU, isMissingparamU ? Form("--> No parameter for %d HIC(s)",countUmiss): "--> Missing info in DB" ));
if(countU>7) errormsg(stavewrite.c_str(),Form(": %d HIC(s) for HS-Upper (not written)", countU));
}
if(isWritableML && isWritableOL) //the two HSs must exist in the DB (both!)
outfl<<stavewrite<<" "<<hsuid<<" "<<hslid<<" "<<nchipsokHSU+nchipsmaskedHSU<<" "<<nchipsokHSL+nchipsmaskedHSL<<" "<<dayMax<<"/"<<monthMax<<"/"<<yearMax<<" "<<week<<endl; //write to file: <hsid> <#work chip> <qual date> <#week>
count=0;
countU = 0;
countL = 0;
nchipsokHSU = 0;
nchipsokHSL = 0;
nchipsmaskedHSL = 0;
nchipsmaskedHSU = 0;
dayMax = -1;
monthMax = -1;
yearMax=-1;
countUmiss=0;
countLmiss=0;
isMissingparamL=false;
isMissingparamU=false;
}
//int nchipsokHIC = ReadThresholdFile(fpath);
if(hsid.find("-U-")!=string::npos){//hs upper
hsuid=hsid;
if(nchipsokHIC<0){
countU--;
isMissingparamU=true;
countUmiss++;
}
nchipsokHSU+=nchipsokHIC;
countU++;
if(countU==20) nchipsmaskedHSU = GetMaskedFromConfig(fpath.substr(0, fpath.find("Threshold")-1),"Config_HS.cfg");//NOTE: no config file read out
}
else{//hs lower
hslid=hsid;
if(nchipsokHIC<0){
countL--;
isMissingparamL=true;
countLmiss++;
}
nchipsokHSL+=nchipsokHIC;
countL++;
if(countL==20) nchipsmaskedHSL = GetMaskedFromConfig(fpath.substr(0, fpath.find("Threshold")-1),"Config_HS.cfg");//NOTE: no config file read out
}
}
outfl.close();
infl.close();
return 1;
}