-
Notifications
You must be signed in to change notification settings - Fork 0
/
appletConfig.ts
208 lines (171 loc) · 5.75 KB
/
appletConfig.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
import { AppletConfigInput, ConfigCulturalContext, ConfigMethod, ConfigResourceType, ConfigThreshold, Dimension, Range } from '@neighbourhoods/sensemaker-lite-types'
export const NH_APPLET_ID = "vf_timetracker"
// --------[ RANGES ] --------
const MAX_RUST_U32 = 4294967295
// define on/off toggle Range
const toggleRange: Range = {
"name": "1-scale",
"kind": { "Integer": { "min": 0, "max": 1 } }
}
// define numeric range for hourly pay rate
// (the currency this rate is relative to does not matter here)
const positiveNumberRange: Range = {
"name": "1-scale",
"kind": { "Float": { "min": 0, "max": MAX_RUST_U32 } }
}
// define output range to hold summary data of toggles
const summaryRange: Range = {
"name": "1-scale-total",
"kind": { "Integer": { "min": 0, "max": MAX_RUST_U32 } }
}
// --------[ METADATA INPUTS & OUTPUTS ] --------
// INPUT DATUM: verify work
// :TODO: how to validate this so that `EconomicEvent.provider` cannot log?
const verifyDimension: Dimension = {
"name": "verify",
"range": toggleRange,
"computed": false
}
// OUTPUT DATUM: order by verified work
const totalVerifications: Dimension = {
"name": "total_verify",
"range": summaryRange,
"computed": true
}
// INPUT DATUM: work entry marked for followup (whatever that may mean in your organisational context)
const followupDimension: Dimension = {
"name": "followup",
"range": toggleRange,
"computed": false
}
// OUTPUT DATUM: order by followups needed
const totalFollowupsNeeded: Dimension = {
"name": "total_followup",
"range": summaryRange,
"computed": true
}
// INPUT DATUM: hourly pay rate for work
// const payRateDimension: Dimension = {
// "name": "hourly_rate",
// "range": positiveNumberRange,
// "computed": false
// }
// INPUT DATUM: hours worked
// :TODO: Figure out how to programatically assign this from `EconomicEvent` fields in a generic way.
// Suspicion is the UI would pass this and it'd be a "non-computed" dim from the perspective of the Sensemaker.
// const hoursWorkedDimension: Dimension = {
// "name": "hours_worked",
// "range": positiveNumberRange,
// "computed": false
// }
// OUTPUT DATUM: order by followups needed
// const payAmount: Dimension = {
// "name": "pay_amount",
// "range": summaryRange,
// "computed": true
// }
// --------[ RESOURCE TYPES & BOUND ASSESSMENTS ] --------
const economicEventRT: ConfigResourceType = {
"name": "economic_event",
// :TODO: finalise
"base_types": [{ "entry_index": 0, "zome_index": 0, "visibility": { "Public": null } }],
"dimensions": [
verifyDimension,
followupDimension,
// payRateDimension,
// hoursWorkedDimension,
],
}
// --------[ COMPUTATION / REDUCTION DEFINITIONS ] --------
const computeTotalVerifications: ConfigMethod = {
"name": "total_verify_method",
"target_resource_type": economicEventRT,
"input_dimensions": [verifyDimension],
"output_dimension": totalVerifications,
"program": { "Sum": null },
"can_compute_live": false,
"must_publish_dataset": false
}
const computeTotalFollowups: ConfigMethod = {
"name": "total_followup_method",
"target_resource_type": economicEventRT,
"input_dimensions": [followupDimension],
"output_dimension": totalFollowupsNeeded,
"program": { "Sum": null },
"can_compute_live": false,
"must_publish_dataset": false
}
// :TODO: revisit when we have more than `ProgramSum | ProgramAverage`
// const computePay: ConfigMethod = {
// "name": "total_payment",
// "target_resource_type": economicEventRT,
// "input_dimensions": [payRateDimension, hoursWorkedDimension],
// "output_dimension": payAmount,
// "program": { "Sum": null },
// "can_compute_live": false,
// "must_publish_dataset": false
// }
// --------[ DATA FILTERS ] --------
const hasValues = (dimension: Dimension): ConfigThreshold => ({
"dimension": dimension,
"kind": { "GreaterThan": null },
"value": { "Integer": 0 }
})
const noValues = (dimension: Dimension): ConfigThreshold => ({
"dimension": dimension,
"kind": { "LessThan": null /*, "Equal": null */ },
"value": { "Integer": 0 }
})
const mostVerifiedWorkContext: ConfigCulturalContext = {
"name": "most_verified_work",
"resource_type": economicEventRT,
"thresholds": [hasValues(verifyDimension)],
"order_by": [[totalVerifications, { "Biggest": null }]]
}
const unverifiedWorkContext: ConfigCulturalContext = {
"name": "unverified_work",
"resource_type": economicEventRT,
"thresholds": [noValues(verifyDimension)],
"order_by": [[totalVerifications, { "Smallest": null }]]
}
const mostFollowupsWorkContext: ConfigCulturalContext = {
"name": "followup_needed",
"resource_type": economicEventRT,
"thresholds": [hasValues(followupDimension)],
"order_by": [[totalFollowupsNeeded, { "Biggest": null }]]
}
const nonFollowupWorkContext: ConfigCulturalContext = {
"name": "no_followup_needed",
"resource_type": economicEventRT,
"thresholds": [noValues(followupDimension)],
"order_by": [[totalFollowupsNeeded, { "Smallest": null }]]
}
// const highestPayingWorkContext: ConfigCulturalContext = {
// "name": "highest_pay",
// "resource_type": economicEventRT,
// // "thresholds": [hasValues(payAmount)],
// "order_by": [[computePay, { "Biggest": null }]]
// }
// create initialisation data for Neighbourhoods Sensemaker
const appletConfig: AppletConfigInput = {
"name": NH_APPLET_ID,
"dimensions": [
verifyDimension, totalVerifications,
followupDimension, totalFollowupsNeeded,
// payRateDimension
],
"resource_types": [economicEventRT],
"methods": [
computeTotalVerifications,
computeTotalFollowups,
// computePay,
],
"cultural_contexts": [
mostVerifiedWorkContext,
unverifiedWorkContext,
mostFollowupsWorkContext,
nonFollowupWorkContext,
// highestPayingWorkContext,
],
}
export default appletConfig