|
38 | 38 |
|
39 | 39 | class Competition(object):
|
40 | 40 |
|
41 |
| - def __init__(self, init_dict): |
42 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
43 |
| - self.__dict__.update(parsed_dict) |
44 |
| - self.tags = [Tag(t) for t in self.tags] |
| 41 | + def __init__(self, init_dict): |
| 42 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 43 | + self.__dict__.update(parsed_dict) |
| 44 | + self.tags = [Tag(t) for t in self.tags] |
45 | 45 |
|
46 |
| - def __repr__(self): |
47 |
| - return self.ref |
| 46 | + def __repr__(self): |
| 47 | + return self.ref |
48 | 48 |
|
49 | 49 |
|
50 | 50 | class SubmitResult(object):
|
51 | 51 |
|
52 |
| - def __init__(self, init_dict): |
53 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
54 |
| - self.__dict__.update(parsed_dict) |
| 52 | + def __init__(self, init_dict): |
| 53 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 54 | + self.__dict__.update(parsed_dict) |
55 | 55 |
|
56 |
| - def __repr__(self): |
57 |
| - return self.message |
| 56 | + def __repr__(self): |
| 57 | + return self.message |
58 | 58 |
|
59 | 59 |
|
60 | 60 | class Submission(object):
|
61 | 61 |
|
62 |
| - def __init__(self, init_dict): |
63 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
64 |
| - self.__dict__.update(parsed_dict) |
65 |
| - if self.totalBytes is None: |
66 |
| - self.size = None |
67 |
| - else: |
68 |
| - self.size = File.get_size(self.totalBytes) |
| 62 | + def __init__(self, init_dict): |
| 63 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 64 | + self.__dict__.update(parsed_dict) |
| 65 | + if self.totalBytes is None: |
| 66 | + self.size = None |
| 67 | + else: |
| 68 | + self.size = File.get_size(self.totalBytes) |
69 | 69 |
|
70 |
| - def __repr__(self): |
71 |
| - return str(self.ref) |
| 70 | + def __repr__(self): |
| 71 | + return str(self.ref) |
72 | 72 |
|
73 | 73 |
|
74 | 74 | class LeaderboardEntry(object):
|
75 | 75 |
|
76 |
| - def __init__(self, init_dict): |
77 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
78 |
| - self.__dict__.update(parsed_dict) |
| 76 | + def __init__(self, init_dict): |
| 77 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 78 | + self.__dict__.update(parsed_dict) |
79 | 79 |
|
80 |
| - def __repr__(self): |
81 |
| - return self.teamId |
| 80 | + def __repr__(self): |
| 81 | + return self.teamId |
82 | 82 |
|
83 | 83 |
|
84 | 84 | class Dataset(object):
|
85 | 85 |
|
86 |
| - def __init__(self, init_dict): |
87 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
88 |
| - self.__dict__.update(parsed_dict) |
89 |
| - self.tags = [Tag(t) for t in self.tags] |
90 |
| - self.files = [File(f) for f in self.files] |
91 |
| - self.versions = [DatasetVersion(v) for v in self.versions] |
92 |
| - self.size = File.get_size(self.totalBytes) |
| 86 | + def __init__(self, init_dict): |
| 87 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 88 | + self.__dict__.update(parsed_dict) |
| 89 | + self.tags = [Tag(t) for t in self.tags] |
| 90 | + self.files = [File(f) for f in self.files] |
| 91 | + self.versions = [DatasetVersion(v) for v in self.versions] |
| 92 | + self.size = File.get_size(self.totalBytes) |
93 | 93 |
|
94 |
| - def __repr__(self): |
95 |
| - return self.ref |
| 94 | + def __repr__(self): |
| 95 | + return self.ref |
96 | 96 |
|
97 | 97 |
|
98 | 98 | class Model(object):
|
99 | 99 |
|
100 |
| - def __init__(self, init_dict): |
101 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
102 |
| - self.__dict__.update(parsed_dict) |
| 100 | + def __init__(self, init_dict): |
| 101 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 102 | + self.__dict__.update(parsed_dict) |
103 | 103 |
|
104 |
| - def __repr__(self): |
105 |
| - return self.ref |
| 104 | + def __repr__(self): |
| 105 | + return self.ref |
106 | 106 |
|
107 | 107 |
|
108 | 108 | class Metadata(object):
|
109 | 109 |
|
110 |
| - def __init__(self, init_info): |
111 |
| - parsed_info = {k: parse(v) for k, v in init_info.items()} |
112 |
| - # backwards compatibility |
113 |
| - self.id = parsed_info["ownerUser"] + "/" + parsed_info['datasetSlug'] |
114 |
| - self.id_no = parsed_info['datasetId'] |
115 |
| - self.__dict__.update(parsed_info) |
| 110 | + def __init__(self, init_info): |
| 111 | + parsed_info = {k: parse(v) for k, v in init_info.items()} |
| 112 | + # backwards compatibility |
| 113 | + self.id = parsed_info["ownerUser"] + "/" + parsed_info['datasetSlug'] |
| 114 | + self.id_no = parsed_info['datasetId'] |
| 115 | + self.__dict__.update(parsed_info) |
116 | 116 |
|
117 |
| - def __repr__(self): |
118 |
| - return str(self.datasetId) |
| 117 | + def __repr__(self): |
| 118 | + return str(self.datasetId) |
119 | 119 |
|
120 | 120 |
|
121 | 121 | class DatasetVersion(object):
|
122 | 122 |
|
123 |
| - def __init__(self, init_dict): |
124 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
125 |
| - self.__dict__.update(parsed_dict) |
| 123 | + def __init__(self, init_dict): |
| 124 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 125 | + self.__dict__.update(parsed_dict) |
126 | 126 |
|
127 |
| - def __repr__(self): |
128 |
| - return str(self.versionNumber) |
| 127 | + def __repr__(self): |
| 128 | + return str(self.versionNumber) |
129 | 129 |
|
130 | 130 |
|
131 | 131 | class File(object):
|
132 | 132 |
|
133 |
| - def __init__(self, init_dict): |
134 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
135 |
| - self.__dict__.update(parsed_dict) |
136 |
| - self.size = File.get_size(self.totalBytes) |
| 133 | + def __init__(self, init_dict): |
| 134 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 135 | + self.__dict__.update(parsed_dict) |
| 136 | + self.size = File.get_size(self.totalBytes) |
137 | 137 |
|
138 |
| - def __repr__(self): |
139 |
| - return self.name |
| 138 | + def __repr__(self): |
| 139 | + return self.name |
140 | 140 |
|
141 |
| - @staticmethod |
142 |
| - def get_size(size, precision=0): |
143 |
| - suffixes = ['B', 'KB', 'MB', 'GB', 'TB'] |
144 |
| - suffix_index = 0 |
145 |
| - while size >= 1024 and suffix_index < 4: |
146 |
| - suffix_index += 1 |
147 |
| - size /= 1024.0 |
148 |
| - return '%.*f%s' % (precision, size, suffixes[suffix_index]) |
| 141 | + @staticmethod |
| 142 | + def get_size(size, precision=0): |
| 143 | + suffixes = ['B', 'KB', 'MB', 'GB', 'TB'] |
| 144 | + suffix_index = 0 |
| 145 | + while size >= 1024 and suffix_index < 4: |
| 146 | + suffix_index += 1 |
| 147 | + size /= 1024.0 |
| 148 | + return '%.*f%s' % (precision, size, suffixes[suffix_index]) |
149 | 149 |
|
150 | 150 |
|
151 | 151 | class Tag(object):
|
152 | 152 |
|
153 |
| - def __init__(self, init_dict): |
154 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
155 |
| - self.__dict__.update(parsed_dict) |
| 153 | + def __init__(self, init_dict): |
| 154 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 155 | + self.__dict__.update(parsed_dict) |
156 | 156 |
|
157 |
| - def __repr__(self): |
158 |
| - return self.ref |
| 157 | + def __repr__(self): |
| 158 | + return self.ref |
159 | 159 |
|
160 | 160 |
|
161 | 161 | class DatasetNewVersionResponse(object):
|
162 | 162 |
|
163 |
| - def __init__(self, init_dict): |
164 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
165 |
| - self.__dict__.update(parsed_dict) |
| 163 | + def __init__(self, init_dict): |
| 164 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 165 | + self.__dict__.update(parsed_dict) |
166 | 166 |
|
167 |
| - def __repr__(self): |
168 |
| - return self.url |
| 167 | + def __repr__(self): |
| 168 | + return self.url |
169 | 169 |
|
170 | 170 |
|
171 | 171 | class DatasetNewResponse(object):
|
172 | 172 |
|
173 |
| - def __init__(self, init_dict): |
174 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
175 |
| - self.__dict__.update(parsed_dict) |
| 173 | + def __init__(self, init_dict): |
| 174 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 175 | + self.__dict__.update(parsed_dict) |
176 | 176 |
|
177 |
| - def __repr__(self): |
178 |
| - return self.url |
| 177 | + def __repr__(self): |
| 178 | + return self.url |
179 | 179 |
|
180 | 180 |
|
181 | 181 | class ListFilesResult(object):
|
182 | 182 |
|
183 |
| - def __init__(self, init_dict): |
184 |
| - self.error_message = init_dict['errorMessage'] |
185 |
| - files = init_dict['datasetFiles'] |
186 |
| - if files: |
187 |
| - self.files = [File(f) for f in files] |
188 |
| - else: |
189 |
| - self.files = {} |
190 |
| - token = init_dict['nextPageToken'] |
191 |
| - if token: |
192 |
| - self.nextPageToken = token |
193 |
| - else: |
194 |
| - self.nextPageToken = "" |
| 183 | + def __init__(self, init_dict): |
| 184 | + self.error_message = init_dict['errorMessage'] |
| 185 | + files = init_dict['datasetFiles'] |
| 186 | + if files: |
| 187 | + self.files = [File(f) for f in files] |
| 188 | + else: |
| 189 | + self.files = {} |
| 190 | + token = init_dict['nextPageToken'] |
| 191 | + if token: |
| 192 | + self.nextPageToken = token |
| 193 | + else: |
| 194 | + self.nextPageToken = "" |
195 | 195 |
|
196 |
| - def __repr__(self): |
197 |
| - return self.error_message |
| 196 | + def __repr__(self): |
| 197 | + return self.error_message |
198 | 198 |
|
199 | 199 |
|
200 | 200 | class Kernel:
|
201 | 201 |
|
202 |
| - def __init__(self, init_dict): |
203 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
204 |
| - self.__dict__.update(parsed_dict) |
| 202 | + def __init__(self, init_dict): |
| 203 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 204 | + self.__dict__.update(parsed_dict) |
205 | 205 |
|
206 |
| - def __repr__(self): |
207 |
| - return self.title |
| 206 | + def __repr__(self): |
| 207 | + return self.title |
208 | 208 |
|
209 | 209 |
|
210 | 210 | class KernelPushResponse(object):
|
211 | 211 |
|
212 |
| - def __init__(self, init_dict): |
213 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
214 |
| - self.__dict__.update(parsed_dict) |
| 212 | + def __init__(self, init_dict): |
| 213 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 214 | + self.__dict__.update(parsed_dict) |
215 | 215 |
|
216 |
| - def __repr__(self): |
217 |
| - return self.newUrl |
| 216 | + def __repr__(self): |
| 217 | + return self.newUrl |
218 | 218 |
|
219 | 219 |
|
220 | 220 | class ModelNewResponse(object):
|
221 | 221 |
|
222 |
| - def __init__(self, init_dict): |
223 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
224 |
| - self.__dict__.update(parsed_dict) |
| 222 | + def __init__(self, init_dict): |
| 223 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 224 | + self.__dict__.update(parsed_dict) |
225 | 225 |
|
226 |
| - def __repr__(self): |
227 |
| - return self.url |
| 226 | + def __repr__(self): |
| 227 | + return self.url |
228 | 228 |
|
229 | 229 |
|
230 | 230 | class ModelDeleteResponse(object):
|
231 | 231 |
|
232 |
| - def __init__(self, init_dict): |
233 |
| - parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
234 |
| - self.__dict__.update(parsed_dict) |
| 232 | + def __init__(self, init_dict): |
| 233 | + parsed_dict = {k: parse(v) for k, v in init_dict.items()} |
| 234 | + self.__dict__.update(parsed_dict) |
235 | 235 |
|
236 |
| - def __repr__(self): |
237 |
| - return self.error |
| 236 | + def __repr__(self): |
| 237 | + return self.error |
238 | 238 |
|
239 | 239 |
|
240 | 240 | def parse(string):
|
241 |
| - time_formats = [ |
242 |
| - '%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S.%f', |
243 |
| - '%Y-%m-%dT%H:%M:%S.%fZ' |
244 |
| - ] |
245 |
| - for t in time_formats: |
246 |
| - try: |
247 |
| - result = datetime.strptime(string[:26], t).replace(microsecond=0) |
248 |
| - return result |
249 |
| - except: |
250 |
| - pass |
251 |
| - return string |
| 241 | + time_formats = [ |
| 242 | + '%Y-%m-%dT%H:%M:%S', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S.%f', |
| 243 | + '%Y-%m-%dT%H:%M:%S.%fZ' |
| 244 | + ] |
| 245 | + for t in time_formats: |
| 246 | + try: |
| 247 | + result = datetime.strptime(string[:26], t).replace(microsecond=0) |
| 248 | + return result |
| 249 | + except: |
| 250 | + pass |
| 251 | + return string |
252 | 252 |
|
253 | 253 |
|
254 | 254 | class ResumableUploadResult(object):
|
255 |
| - # Upload was complete, i.e., all bytes were received by the server. |
256 |
| - COMPLETE = 1 |
| 255 | + # Upload was complete, i.e., all bytes were received by the server. |
| 256 | + COMPLETE = 1 |
257 | 257 |
|
258 |
| - # There was a non-transient error during the upload or the upload expired. |
259 |
| - # The upload cannot be resumed so it should be restarted from scratch |
260 |
| - # (i.e., call /api/v1/files/upload to initiate the upload and get the |
261 |
| - # create/upload url and token). |
262 |
| - FAILED = 2 |
| 258 | + # There was a non-transient error during the upload or the upload expired. |
| 259 | + # The upload cannot be resumed so it should be restarted from scratch |
| 260 | + # (i.e., call /api/v1/files/upload to initiate the upload and get the |
| 261 | + # create/upload url and token). |
| 262 | + FAILED = 2 |
263 | 263 |
|
264 |
| - # Upload was interrupted due to some (transient) failure but it can be |
265 |
| - # safely resumed. |
266 |
| - INCOMPLETE = 3 |
| 264 | + # Upload was interrupted due to some (transient) failure but it can be |
| 265 | + # safely resumed. |
| 266 | + INCOMPLETE = 3 |
267 | 267 |
|
268 |
| - def __init__(self, result, bytes_uploaded=None): |
269 |
| - self.result = result |
270 |
| - self.bytes_uploaded = bytes_uploaded |
271 |
| - self.start_at = 0 if bytes_uploaded is None else bytes_uploaded + 1 |
| 268 | + def __init__(self, result, bytes_uploaded=None): |
| 269 | + self.result = result |
| 270 | + self.bytes_uploaded = bytes_uploaded |
| 271 | + self.start_at = 0 if bytes_uploaded is None else bytes_uploaded + 1 |
272 | 272 |
|
273 |
| - def Complete(): |
274 |
| - return ResumableUploadResult(ResumableUploadResult.COMPLETE) |
| 273 | + def Complete(): |
| 274 | + return ResumableUploadResult(ResumableUploadResult.COMPLETE) |
275 | 275 |
|
276 |
| - def Failed(): |
277 |
| - return ResumableUploadResult(ResumableUploadResult.FAILED) |
| 276 | + def Failed(): |
| 277 | + return ResumableUploadResult(ResumableUploadResult.FAILED) |
278 | 278 |
|
279 |
| - def Incomplete(bytes_uploaded=None): |
280 |
| - return ResumableUploadResult(ResumableUploadResult.INCOMPLETE, |
281 |
| - bytes_uploaded) |
| 279 | + def Incomplete(bytes_uploaded=None): |
| 280 | + return ResumableUploadResult(ResumableUploadResult.INCOMPLETE, |
| 281 | + bytes_uploaded) |
0 commit comments