-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfields.ts
368 lines (365 loc) · 10.8 KB
/
fields.ts
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import { aggregationTypeEnum } from './gds-types';
import { Converters } from './helpers';
import { fieldTypeEnum } from './gds-types';
/**
* To keep things clean and help with type checking, I'm maintaining a list of fields separately from getFields that will be used on both ends - prepping the fields and parsing return data
*/
export interface fieldMapping {
id: string;
name: string;
description?: string;
formula?: string;
togglMapping?: {
fields: {
[index: string]: Array<string> | undefined;
TogglDetailedEntry?: Array<string>;
TogglWeeklyProjectGroupedEntry?: Array<string>;
TogglWeeklyUserGroupedEntry?: Array<string>;
TogglSummaryEntry?: Array<string>;
};
formatter?: Function;
};
semantics: {
conceptType: 'DIMENSION' | 'METRIC';
semanticType: GoogleAppsScript.Data_Studio.FieldType;
semanticGroup?: GoogleAppsScript.Data_Studio.FieldType;
aggregationType?: GoogleAppsScript.Data_Studio.AggregationType;
isReaggregatable?: boolean;
};
}
export const myFields: { [index: string]: fieldMapping } = {
// Default date/time dimensions
day: {
id: 'day',
name: 'Date',
togglMapping: {
fields: {
TogglDetailedEntry: ['start']
},
formatter: (date: string) => {
return Converters.formatDateForGds(date, fieldTypeEnum.YEAR_MONTH_DAY);
}
},
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.YEAR_MONTH_DAY
}
},
startedAtHour: {
id: 'startedAtHour',
name: 'Started At - Hour',
description: 'The hour / time at which the time entry was started at',
togglMapping: {
fields: {
TogglDetailedEntry: ['start']
},
formatter: (date: string) => {
return Converters.formatDateForGds(date, fieldTypeEnum.YEAR_MONTH_DAY_HOUR);
}
},
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.YEAR_MONTH_DAY_HOUR
}
},
endedAtHour: {
id: 'endedAtHour',
name: 'Ended At - Hour',
description: 'The hour / time at which the time entry ended',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.YEAR_MONTH_DAY_HOUR
},
togglMapping: {
fields: {
TogglDetailedEntry: ['end']
},
formatter: (date: string) => {
return Converters.formatDateForGds(date, fieldTypeEnum.YEAR_MONTH_DAY_HOUR);
}
}
},
// Main Time Entry stuff (title, id, etc.)
entryId: {
id: 'entryId',
name: 'Entry ID',
description: 'Numerical ID auto-generated by Toggl per entry',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.NUMBER,
isReaggregatable: false
},
togglMapping: {
fields: {
TogglDetailedEntry: ['id']
}
}
},
entryCount: {
id: 'entryCount',
name: 'Entry Count',
description: 'Sum of all (unique) time entries',
formula: 'COUNT_DISTINCT($entryId)',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.NUMBER
}
},
entryDescription: {
id: 'entryDescription',
name: 'Entry Description / Title',
description: 'Entry Description / Title. Not required by Toggl',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.TEXT
},
togglMapping: {
fields: {
TogglDetailedEntry: ['description']
}
}
},
// Task Entry
taskId: {
id: 'taskId',
name: 'Task ID',
description: 'Task ID, only available on paid accounts',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.NUMBER
},
togglMapping: {
fields: {
TogglDetailedEntry: ['tid']
}
}
},
// Projects
projectId: {
id: 'projectId',
name: 'Project ID',
description: 'Numerical ID generated by Toggl for each project',
togglMapping: {
fields: {
TogglDetailedEntry: ['pid'],
TogglWeeklyProjectGroupedEntry: ['pid'],
TogglWeeklyUserGroupedEntry: ['details.pid'],
TogglSummaryEntry: ['pid']
}
},
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.NUMBER
}
},
projectCount: {
id: 'projectCount',
name: 'Project Count',
description: 'Count of Unique Projects',
formula: 'COUNT_DISTINCT($projectId)',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.NUMBER
}
},
projectName: {
id: 'projectName',
name: 'Project Name',
description: 'Your project name',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.TEXT
},
togglMapping: {
fields: {
TogglDetailedEntry: ['project'],
TogglWeeklyProjectGroupedEntry: ['title.project'],
TogglSummaryEntry: ['title.project']
}
}
},
// Clients
clientId: {
id: 'clientId',
name: 'Client ID',
description: 'Numerical ID generated by Toggl for each client',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.NUMBER
},
togglMapping: {
fields: {
// Client ID is only returned in reports explicitly grouped by client - e.g. summary
TogglSummaryEntry: ['cid']
}
}
},
clientName: {
id: 'clientName',
name: 'Client Name',
description: 'Client Name',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.TEXT
},
togglMapping: {
fields: {
TogglDetailedEntry: ['client'],
TogglWeeklyProjectGroupedEntry: ['title.client'],
TogglSummaryEntry: ['title.client']
}
}
},
// Billing Info
billableMoneyTotal: {
id: 'billableMoneyTotal',
name: 'Total Billable Amount',
description: 'Total Billable Amount in Configured Currency',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.CURRENCY_USD
},
togglMapping: {
fields: {
TogglDetailedEntry: ['billable'],
TogglSummaryEntry: ['totalBillingSum']
},
formatter: Converters.formatCurrencyForGds
}
},
billableTimeTotal: {
id: 'billableTimeTotal',
name: 'Total Billable Hours',
description: 'Total Billable Time, as configured in Toggl',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.DURATION
},
togglMapping: {
fields: {
TogglDetailedEntry: ['billableTime'],
TogglSummaryEntry: ['totalBillingTime']
},
formatter: (duration: number) => {
return Converters.togglDurationToGdsDuration(duration);
}
}
},
isBillable: {
id: 'isBillable',
name: 'Is Billable',
description: 'Whether given entry was marked as billable',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.BOOLEAN
},
togglMapping: {
fields: {
TogglDetailedEntry: ['is_billable']
},
formatter: Converters.forceBoolean
}
},
billingRate: {
id: 'billingRate',
name: 'Billing Rate',
description: 'Billing Rate',
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.CURRENCY_USD,
isReaggregatable: true,
aggregationType: aggregationTypeEnum.AVG
},
togglMapping: {
fields: {
TogglSummaryEntry: ['avgBillingRate']
},
formatter: Converters.formatCurrencyForGds
}
},
// !!! - Time Field - !!!
time: {
id: 'time',
name: 'Time',
description: 'Logged Time',
togglMapping: {
fields: {
TogglDetailedEntry: ['dur'],
TogglSummaryEntry: ['time']
},
formatter: (duration: number) => {
return Converters.togglDurationToGdsDuration(duration);
}
},
semantics: {
conceptType: 'METRIC',
semanticType: fieldTypeEnum.DURATION
}
},
// User Info
userId: {
id: 'userId',
name: 'User ID',
description: 'Numerical User ID, autogenerated by Toggl',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.NUMBER,
isReaggregatable: false
},
togglMapping: {
fields: {
TogglDetailedEntry: ['uid']
}
}
},
userName: {
id: 'userName',
name: 'User Name',
description: 'Your Toggl User Name',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.TEXT,
isReaggregatable: false
},
togglMapping: {
fields: {
TogglDetailedEntry: ['user']
}
}
},
// Meta info
updatedAt: {
id: 'updatedAt',
name: 'Updated At - Hour',
description: 'When the time entry was last edited',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.YEAR_MONTH_DAY_HOUR,
isReaggregatable: false
},
togglMapping: {
fields: {
TogglDetailedEntry: ['updated']
},
formatter: (date: string) => {
return Converters.formatDateForGds(date, fieldTypeEnum.YEAR_MONTH_DAY_HOUR);
}
}
},
useStop: {
id: 'useStop',
name: 'Use Stop',
description: 'If the stop time is saved on the entry',
semantics: {
conceptType: 'DIMENSION',
semanticType: fieldTypeEnum.BOOLEAN,
isReaggregatable: false
},
togglMapping: {
fields: {
TogglDetailedEntry: ['use_stop']
}
}
}
// @TODO - Add "tags"
};