Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4544efa
commit 632bc3f
Showing
9 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"zone.bytes.gardening" = "Digital Gardening for Omnifocus"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"label" = "Pick Something"; | ||
"shortLabel" = "Pick"; | ||
"mediumLabel" = "Pick Something"; | ||
"longLabel" = "Pick Something"; | ||
"paletteLabel" = "Pick"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"use strict"; | ||
(() => { | ||
let creds = new Credentials(); | ||
var getWeights = function () { | ||
const now = new Date(); | ||
const hour = now.getHours(); | ||
const day = now.getDay(); | ||
if (hour >= 8 && hour <= 17 && day != 0 && day != 6) { | ||
return { work: 0.8, personal: 0.2 }; | ||
} | ||
else { | ||
return { work: 0.8, personal: 0.2 }; | ||
return { work: 0.0, personal: 1.0 }; | ||
} | ||
}; | ||
var categorizeTask = function (task) { | ||
var todo = task.tags; | ||
while (todo.length != 0) { | ||
let tag = todo.pop(); | ||
if (tag.name == "work") { | ||
return "work"; | ||
} | ||
else if (tag.name == "personal") { | ||
return "personal"; | ||
} | ||
else if (tag.parent) { | ||
todo.push(tag.parent); | ||
} | ||
} | ||
return null; | ||
}; | ||
var daysBetween = function (a, b) { | ||
let millis = Math.abs(a.getTime() - b.getTime()); | ||
return millis / 1000 / 60 / 60 / 24; | ||
}; | ||
var weightedRandom = function (pairs) { | ||
var total = 0; | ||
for (let pair of pairs) { | ||
total += pair[1]; | ||
} | ||
let target = Math.random() * total; | ||
for (let pair of pairs) { | ||
target -= pair[1]; | ||
if (target <= 0) { | ||
return pair[0]; | ||
} | ||
} | ||
return null; | ||
}; | ||
var chooseATask = function () { | ||
let weights = getWeights(); | ||
let now = new Date(); | ||
let possibleTasks = flattenedProjects | ||
.filter((p) => p.status == Project.Status.Active) | ||
.flatMap((p) => p.flattenedTasks.filter((t) => t.taskStatus == Task.Status.Available || | ||
t.taskStatus == Task.Status.DueSoon || | ||
t.taskStatus == Task.Status.Next || | ||
t.taskStatus == Task.Status.Overdue)); | ||
let weightedTasks = []; | ||
for (let task of possibleTasks) { | ||
// weight some categories higher than others | ||
let categoryWeight = 0; | ||
let category = categorizeTask(task); | ||
if (category) { | ||
categoryWeight = weights[category]; | ||
} | ||
// weight stale-er tasks higher, up to 7 days | ||
let ageWeight = Math.min(7, daysBetween(now, task.modified)) / 7; | ||
// weight due-er tasks higher, up to 100 points | ||
let dueWeight = 0; | ||
if (task.effectiveDueDate) { | ||
dueWeight = 100 - daysBetween(now, task.effectiveDueDate); | ||
} | ||
weightedTasks.push([task, ageWeight + dueWeight + categoryWeight]); | ||
} | ||
return weightedRandom(weightedTasks); | ||
}; | ||
var action = new PlugIn.Action(async () => { | ||
try { | ||
console.log(`task: ${chooseATask()}`); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
}); | ||
return action; | ||
})(); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
(() => { | ||
let creds = new Credentials(); | ||
|
||
var getWeights = function (): { work: number; personal: number } { | ||
const now = new Date(); | ||
const hour = now.getHours(); | ||
const day = now.getDay(); | ||
|
||
if (hour >= 8 && hour <= 17 && day != 0 && day != 6) { | ||
return { work: 0.8, personal: 0.2 }; | ||
} else { | ||
return { work: 0.8, personal: 0.2 }; | ||
return { work: 0.0, personal: 1.0 }; | ||
} | ||
}; | ||
|
||
var categorizeTask = function (task: Task): "work" | "personal" | null { | ||
var todo = task.tags; | ||
while (todo.length != 0) { | ||
let tag = todo.pop(); | ||
|
||
if (tag.name == "work") { | ||
return "work"; | ||
} else if (tag.name == "personal") { | ||
return "personal"; | ||
} else if (tag.parent) { | ||
todo.push(tag.parent); | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
var daysBetween = function (a: Date, b: Date): number { | ||
let millis = Math.abs(a.getTime() - b.getTime()); | ||
return millis / 1000 / 60 / 60 / 24; | ||
}; | ||
|
||
var weightedRandom = function <Type>(pairs: [Type, number][]): Type | null { | ||
var total = 0; | ||
for (let pair of pairs) { | ||
total += pair[1]; | ||
} | ||
|
||
let target = Math.random() * total; | ||
for (let pair of pairs) { | ||
target -= pair[1]; | ||
|
||
if (target <= 0) { | ||
return pair[0]; | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
var chooseATask = function (): Task | null { | ||
let weights = getWeights(); | ||
let now = new Date(); | ||
|
||
let possibleTasks = flattenedProjects | ||
.filter((p) => p.status == Project.Status.Active) | ||
.flatMap((p) => | ||
p.flattenedTasks.filter( | ||
(t: Task) => | ||
t.taskStatus == Task.Status.Available || | ||
t.taskStatus == Task.Status.DueSoon || | ||
t.taskStatus == Task.Status.Next || | ||
t.taskStatus == Task.Status.Overdue | ||
) | ||
); | ||
|
||
let weightedTasks: [Task, number][] = []; | ||
|
||
for (let task of possibleTasks) { | ||
// weight some categories higher than others | ||
let categoryWeight = 0; | ||
let category = categorizeTask(task); | ||
if (category) { | ||
categoryWeight = weights[category]; | ||
} | ||
|
||
// weight stale-er tasks higher, up to 7 days | ||
let ageWeight = Math.min(7, daysBetween(now, task.modified)) / 7; | ||
|
||
// weight due-er tasks higher, up to 100 points | ||
let dueWeight = 0; | ||
if (task.effectiveDueDate) { | ||
dueWeight = 100 - daysBetween(now, task.effectiveDueDate); | ||
} | ||
|
||
weightedTasks.push([task, ageWeight + dueWeight + categoryWeight]); | ||
} | ||
|
||
return weightedRandom(weightedTasks); | ||
}; | ||
|
||
var action = new PlugIn.Action(async () => { | ||
try { | ||
console.log(`task: ${chooseATask()}`); | ||
} catch (err) { | ||
console.error(err); | ||
throw err; | ||
} | ||
}); | ||
|
||
return action; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"author": "Brian Hicks", | ||
"identifier": "zone.bytes.gardening", | ||
"defaultLocale": "en", | ||
"version": "1.0", | ||
"description": "Digital Gardening in OmniFocus", | ||
"actions": [ | ||
{ | ||
"identifier": "pick", | ||
"image": "pick.png" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters