Created
July 6, 2011 16:57
-
-
Save troygoode/1067763 to your computer and use it in GitHub Desktop.
Generic Buy Signal
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
function(contact, activities, config){ | |
var sortByActivityDateDescending = function(activity1, activity2){ | |
if (activity1.activityDate > activity2.activityDate) return -1; | |
if (activity1.activityDate < activity2.activityDate) return 1; | |
return 0; | |
}; | |
if(config.timeframe) | |
var earliestDateToProcess = new Date().setDate(newDate().getDate() - config.timeframe); | |
var sortedActivities = activities.sort(sortByActivityDateDescending); | |
var valueToReturn = 1; | |
var threshold = config.count ? config.count : 1; | |
var count = 0; | |
var mostRecentActivityDate; | |
for(var i = 0; i < sortedActivities.length && (!earliestDateToProcess || sortedActivities[i].date > earliestDateToProcess); i++){ | |
var activity = sortedActivities[i]; | |
if(activity.type === config.activityType){ | |
count++; | |
if(!mostRecentActivityDate) | |
mostRecentActivityDate = activity.date; | |
} | |
if(count >= threshold) | |
return { | |
score: valueToReturn, | |
date: mostRecentActivityDate | |
}; | |
} | |
return {score: 0, date: null}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment