forked from errorcodexero/standing_predictor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcat.cpp
More file actions
258 lines (219 loc) · 5.19 KB
/
Copy pathcat.cpp
File metadata and controls
258 lines (219 loc) · 5.19 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "cat.h"
#include<fstream>
#include "util.h"
#include "vector.h"
#include "vector_void.h"
#include "io.h"
#include "map.h"
#include "tba.h"
#include "query.h"
using namespace std;
struct Any{
auto operator<=>(Any const&)const=default;
};
std::ostream& operator<<(std::ostream& o,Any){
return o<<"*";
}
std::ostream& operator<<(std::ostream& o,Now const&){
return o<<"Now";
}
std::ostream& operator<<(std::ostream& o,Static const&){
return o<<"Static";
}
std::optional<Cat_result> cat(std::string const& url){
const string p="https://www.thebluealliance.com/api/v3/";
assert(prefix(url,p));
auto rest=url.substr(p.size(),url.size());
if(rest[0]=='/'){
rest=skip(1,rest);
}
auto sp=split(rest,'/');
if(sp.size()==2 && sp[0]=="districts"){
return Static{};
}
if(sp.size()==3 && sp[0]=="district" && sp[2]=="events"){
return Static{};
}
static const tba::Year current_year(2026);
if(sp.size()==3 && sp[0]=="event" && sp[2]=="matches"){
auto event=tba::Event_key(sp[1]);
if(year(event)<current_year){
return Static{};
}else{
return Now();
}
}
if(
sp.size()==3 &&
sp[0]=="event" &&
(
sp[2]=="alliances"
|| sp[2]=="rankings"
)
){
tba::Event_key event(sp[1]);
if(year(event)<current_year){
return Static{};
}else{
return Now();
}
}
if(sp.size()==4 && sp[0]=="event" && sp[2]=="teams" && sp[3]=="keys"){
return Static();
}
if(sp.size()==2 && sp[0]=="event"){
return Static();
}
if(sp.size()==4 && sp[0]=="district" && sp[2]=="events" && sp[3]=="keys"){
tba::Event_key event(sp[1]);
if(year(event)<current_year){
return Static();
}else{
return Now();
}
}
if(sp.size()==3 && sp[0]=="district" && sp[2]=="rankings"){
tba::District_key d(sp[1]);
if(year(d)<current_year){
return Static();
}else{
return Now();
}
}
if(sp.size()==3 && sp[0]=="event" && sp[2]=="awards"){
tba::Event_key event(sp[1]);
if(year(event)<current_year){
return Static();
}else{
return Now();
}
}
if(sp.size()==5 && sp[0]=="team" && sp[2]=="events" && sp[4]=="keys"){
return Static();
}
if(sp.size()==3 && sp[0]=="district" && sp[2]=="history"){
return Now();
}
if(sp.size()==1 && sp[0]=="status"){
//correct for the stuff we're doing, anyway
//for other uses, this would definitely be a problem.
return Static();
}
if(sp.size()==3 && sp[0]=="district" && sp[2]=="dcmp_history"){
return Now();
}
if(sp.size()==3 && sp[0]=="teams"){
return Static();
}
if(sp.size()==4 && sp[0]=="team" && sp[2]=="events"){
//1=team
tba::Year year(stoi(sp[3]));
if(year<current_year){
return Static();
}else{
return Static();
}
}
if(sp.size()==3 && sp[0]=="district" && sp[2]=="teams"){
return Static();
}
if(sp.size()==4 && sp[0]=="district" && sp[2]=="events" && sp[3]=="simple"){
return Static();
}
if(sp.size()==3 && sp[0]=="event" && sp[2]=="district_points"){
tba::Event_key event(sp[1]);
if(year(event)<current_year){
return Static();
}else{
return Now();
}
}
if(sp.size()==3 && sp[0]=="events" && sp[2]=="simple"){
return Static();
}
if(sp.size()==3 && sp[0]=="event" && sp[2]=="oprs"){
tba::Event_key event(sp[1]);
if(year(event)<current_year){
return Static();
}else{
return Now();
}
}
if(sp.size()==4 && sp[0]=="district" && sp[2]=="teams" && sp[3]=="keys"){
return Static();
}
if(sp.size()==2 && sp[0]=="events"){
return Static();
}
if(sp.size()==4 && sp[0]=="team" && sp[2]=="awards"){
tba::Year year(stoi(sp[3]));
if(year<current_year){
return Static();
}else{
return Now();
}
}
#if 0
PRINT(sp);
nyi
#else
return std::nullopt;
#endif
}
int cat_demo(){
ifstream f("url.txt");
string s;
std::vector<string> v;
while(getline(f,s)){
v|=s;
}
string p="https://www.thebluealliance.com/api/v3/";
auto m=to_set(mapf(
[=](auto x){
assert(prefix(x,p));
auto s=x.substr(p.size(),1000);
if(s[0]=='/'){
s=s.substr(1,1000);
}
return s;
},
v
));
auto m2=MAP([](auto x){ return split(x,'/'); },m);
auto g=GROUP(car,m2);
using Item=std::variant<std::string,Any>;
using Pattern=std::vector<Item>;
vector<Pattern> vp;
vp|=Pattern{"district",Any{},"advancement"};
vp|=Pattern{"district",Any{},"awards"};
vp|=Pattern{"district",Any{},"dcmp_history"};
vp|=Pattern{"district",Any{},"events"};
vp|=Pattern{"district",Any{},"events","keys"};
vp|=Pattern{"district",Any{},"events","simple"};
vp|=Pattern{"district",Any{},"history"};
vp|=Pattern{"district",Any{},"insights"};
vp|=Pattern{"district",Any{},"rankings"};
vp|=Pattern{"district",Any{},"teams"};
vp|=Pattern{"district",Any{},"teams","keys"};
vp|=Pattern{"district",Any{},"teams","simple"};
vp|=Pattern{"districts"};
vp|=Pattern{"event",Any{}};
for(auto x:{"alliances","awards","district_points","insights","matches"}){
(void)x;
nyi//vp|=Pattern("event",Any{},x);
}
//anyway, can put all the patterns in and pull the calls back out
//need to have a function of URL->expected update speed
//expected update categories: 1) annual 2) continuous
//and for some of the things it's going to be something like
for(auto [k,v]:g){
PRINT(k);
auto v2=to_set(mapf([](auto x){ return skip(2,x); },v));
if(v2.size()<20){
print_lines(v2);
}else{
nyi
}
}
return 0;
}