private void Initialize(DateTime startDate, DateTime endDate, ActivityDescriptor activityDescriptor) { this.StartDate = startDate; this.EndDate = endDate; this.ActivityDescriptor = activityDescriptor; this.Hypothetical = false; }
// confirms that it is valid to create a new activity with the given name and parent private string ValidateCandidateNewInheritance(Inheritance inheritance) { ActivityDescriptor childDescriptor = inheritance.ChildDescriptor; if (childDescriptor == null) { return("Child name is required"); } Activity existingChild = this.ResolveDescriptor(childDescriptor); if (existingChild != null) { return("Child " + existingChild.Name + " already exists"); } ActivityDescriptor parentDescriptor = inheritance.ParentDescriptor; if (parentDescriptor == null) { return("Parent name is required: try \"Activity\""); } Activity parent = this.ResolveDescriptor(parentDescriptor); if (parent == null) { return("Parent " + parentDescriptor.ActivityName + " does not exist"); } if (parent is ToDo) { return("Parent " + parentDescriptor.ActivityName + " is a ToDo which cannot have child activities"); } return(""); }
// makes an ActivityDescriptor that describes this Activity public override ActivityDescriptor MakeDescriptor() { ActivityDescriptor descriptor = new ActivityDescriptor(); descriptor.ActivityName = this.Name; descriptor.Suggestible = this.Suggestible; return(descriptor); }
public AbsoluteRating(double score, DateTime date, ActivityDescriptor activityDescriptor, RatingSource source) { this.Score = score; this.Date = date; this.ActivityDescriptor = activityDescriptor; this.Source = source; this.Initialize(); }
} // If true, the user entered this rating. If false, this was inferred by the engine public override double GetScoreForDescriptor(ActivityDescriptor descriptor) { if (descriptor == this.ActivityDescriptor) { return(this.Score); } throw new ArgumentException("cannot ask an absolute rating for the score of a different activity"); }
public Activity GetActivityOrCreateCategory(ActivityDescriptor descriptor) { Activity existing = this.ResolveDescriptor(descriptor); if (existing == null) { return(this.CreateCategory(descriptor)); } return(existing); }
public Problem GetOrCreateProblem(ActivityDescriptor descriptor) { Problem existing = this.ResolveProblem(descriptor); if (existing == null) { return(this.CreateProblem(descriptor)); } return(existing); }
public ToDo GetOrCreateTodo(ActivityDescriptor descriptor) { ToDo existing = this.ResolveTodo(descriptor); if (existing == null) { return(this.CreateToDo(descriptor)); } return(existing); }
public bool CanMatch(ActivityDescriptor activityDescriptor) { foreach (ActivitySuggestion ours in this.Children) { if (ours.ActivityDescriptor.CanMatch(activityDescriptor)) { return(true); } } return(false); }
// tells whether the given descriptor can match the given activity public bool Matches(ActivityDescriptor descriptor, Activity activity) { if (this.MatchQuality(descriptor, activity) > 0) { return(true); } else { return(false); } }
public override double GetScoreForDescriptor(ActivityDescriptor descriptor) { if (descriptor == this.BetterRating.ActivityDescriptor) { return(this.BetterRating.Score); } if (descriptor == this.WorseRating.ActivityDescriptor) { return(this.WorseRating.Score); } throw new ArgumentException("cannot ask for the score for an activity not known to the RelativeRating"); }
// constructs an Activity from the given ActivityDescriptor public Category CreateCategory(ActivityDescriptor sourceDescriptor) { Activity existing = this.ResolveDescriptor(sourceDescriptor); if (existing != null) { throw new ArgumentException("Activity " + sourceDescriptor.ActivityName + " already exists"); } Category result = new Category(sourceDescriptor.ActivityName, this.happinessSummarizer, this.efficiencySummarizer); this.AddActivity(result); return(result); }
public void DemandNextParticipationBe(ActivityDescriptor activityDescriptor, Metric metric) { if (activityDescriptor != null) { this.SetActivityName(activityDescriptor.ActivityName); } this.demanded_nextParticipationActivity = activityDescriptor; this.metricChooser.DemandMetric(metric); // If there was not previously a demanded participation and metric, then the metric chooser may have allowed the user to enter no metric // Now that we're demanding a specific metric, it's possible that a metric has appeared in the metric chooser, and we might need to // suddenly ask the user if they completed this metric this.updateMetricSelectorVisibility(); }
public ToDo CreateToDo(ActivityDescriptor sourceDescriptor) { Activity existing = this.ResolveDescriptor(sourceDescriptor); if (existing != null) { throw new ArgumentException("Activity " + sourceDescriptor.ActivityName + " already exists"); } ToDo result = new ToDo(sourceDescriptor.ActivityName, this.happinessSummarizer, this.efficiencySummarizer); result.AddParent(this.todoCategory); this.AddActivity(result); return(result); }
public Problem CreateProblem(ActivityDescriptor sourceDescriptor) { Activity existing = this.ResolveDescriptor(sourceDescriptor); if (existing != null) { throw new ArgumentException("Activity " + sourceDescriptor.ActivityName + " already exists"); } Problem result = new Problem(sourceDescriptor.ActivityName, this.happinessSummarizer, this.efficiencySummarizer); this.AddActivity(result); this.hasProblem = true; return(result); }
public ActivitySuggestion GetSuggestion(ActivityDescriptor activityDescriptor, DateTime skipCreationDate) { List <ActivitySuggestion> candidates; if (!this.skipsByDate.TryGetValue(skipCreationDate, out candidates)) { return(null); } foreach (ActivitySuggestion skip in candidates) { if (activityDescriptor.CanMatch(skip.ActivityDescriptor)) { return(skip); } } return(null); }
private bool get_wasSuggested(ActivityDescriptor activity) { foreach (ActivitiesSuggestion suggestion in this.ExternalSuggestions) { foreach (ActivitySuggestion child in suggestion.Children) { if (activity.CanMatch(child.ActivityDescriptor)) { return(true); } } } if (activity.ActivityName == this.suggestedActivityName) { return(true); } return(false); }
// finds the Activity indicated by the ActivityDescriptor public Activity ResolveDescriptor(ActivityDescriptor descriptor) { IEnumerable <Activity> candidates = this.GetCandidateMatches(descriptor); Activity result = null; double bestMatchScore = 0; // figure out which activity matches best foreach (Activity activity in candidates) { double matchScore = this.MatchQuality(descriptor, activity); if (matchScore > bestMatchScore) { result = activity; bestMatchScore = matchScore; } } // now we've found the activity that is indicated by that descriptor return(result); }
private void OkButton_Clicked(object sender, EventArgs e) { this.engine.EnsureRatingsAreAssociated(); IProgression xAxisProgression = this.XAxisProgression; ActivityDescriptor yAxisDescriptor = this.YAxisActivityDescriptor; Activity yAxisActivity = null; if (yAxisDescriptor != null) { yAxisActivity = this.engine.ActivityDatabase.ResolveDescriptor(yAxisDescriptor); } if (yAxisActivity != null) { yAxisActivity.ApplyPendingData(); ActivityVisualizationView visualizationView = new ActivityVisualizationView(xAxisProgression, yAxisActivity, this.engine.RatingSummarizer, this.engine.EfficiencySummarizer, this.layoutStack); this.layoutStack.AddLayout(visualizationView, "Graph"); } }
// returns a string other than "" in case of error public string CreateCategory(Inheritance inheritance) { string err = this.ValidateCandidateNewInheritance(inheritance); if (err != "") { return(err); } Activity parent = this.ResolveDescriptor(inheritance.ParentDescriptor); if (parent == this.todoCategory || parent == this.problemCategory) { return("You can't assign an Activity of type Category as a child of the Category named " + parent.Name); } ActivityDescriptor childDescriptor = inheritance.ChildDescriptor; Activity child = this.CreateCategory(inheritance.ChildDescriptor); return(this.AddParent(inheritance)); }
// Returns a list of Activity that might be considered to match <descriptor> private IEnumerable <Activity> GetCandidateMatches(ActivityDescriptor descriptor) { if (descriptor == null) { return(new List <Activity>(0)); } IEnumerable <Activity> activities = null; if (descriptor.RequiresPerfectMatch) { // requiring a perfect match means that we can do a sorted lookup to find the activity by name activities = this.activitiesByName.CombineBetweenKeys(descriptor.ActivityName, true, descriptor.ActivityName, true); } else { // if we allow approximate string matches, then we have to check all activities activities = this.activitiesByName.CombineAll(); } return(activities); }
// Find the top few matching activities public List <Activity> FindBestMatches(ActivityDescriptor descriptor, int count) { if (count < 1) { return(new List <Activity>(0)); } if (count == 1) { Activity best = this.ResolveDescriptor(descriptor); if (best != null) { return new List <Activity>() { best } } ; return(new List <Activity>() { }); } IEnumerable <Activity> activities = this.GetCandidateMatches(descriptor); StatList <double, Activity> sortedItems = new StatList <double, Activity>(new ReverseDoubleComparer(), new NoopCombiner <Activity>()); foreach (Activity activity in activities) { double quality = this.MatchQuality(descriptor, activity); if (quality > 0) { sortedItems.Add(quality, activity); } } count = Math.Min(count, sortedItems.NumItems); List <Activity> top = new List <Activity>(count); for (int i = 0; i < count; i++) { top.Add(sortedItems.GetValueAtIndex(i).Value); } return(top); }
private void OkButton_Clicked(object sender, EventArgs e) { ActivityDescriptor childDescriptor = this.childNameBox.ActivityDescriptor; ActivityDescriptor parentDescriptor = this.parentNameBox.ActivityDescriptor; Inheritance inheritance = new Inheritance(parentDescriptor, childDescriptor); inheritance.DiscoveryDate = DateTime.Now; string error = this.activityDatabase.AddParent(inheritance); if (error == "") { this.childNameBox.Clear(); this.parentNameBox.Clear(); this.feedbackLayout.setText(childDescriptor.ActivityName + " now inherits from " + parentDescriptor.ActivityName); } else { this.feedbackLayout.setText(error); } }
private void OkButton_Clicked(object sender, EventArgs e) { ActivityDescriptor childDescriptor = this.childNameBox.ActivityDescriptor; ActivityDescriptor parentDescriptor = this.parentNameBox.ActivityDescriptor; Inheritance inheritance = new Inheritance(parentDescriptor, childDescriptor); inheritance.DiscoveryDate = DateTime.Now; string error; if (this.SelectedActivityTypeIsCategory || this.SelectedActivityTypeIsSolution) { error = this.activityDatabase.CreateCategory(inheritance); } else { if (this.SelectedActivityTypeIsToDo) { error = this.activityDatabase.CreateToDo(inheritance); } else { error = this.activityDatabase.CreateProblem(inheritance); } } if (error == "") { this.childNameBox.Clear(); this.parentNameBox.Clear(); this.showMessage("Created " + childDescriptor.ActivityName); if (this.GoBackAfterCreation) { this.layoutStack.GoBack(); } } else { this.showError(error); } }
public bool PreferAvoidCompletedToDos = false; // if true, we prefer to avoid completed ToDos public bool CanMatch(ActivityDescriptor other) { if (other == null) { return(false); } if (this.ActivityName != null && other.ActivityName != null) { if (!this.ActivityName.Equals(other.ActivityName)) { return(false); } } if (this.Suggestible != null && other.Suggestible != null) { if (this.Suggestible.Value != other.Suggestible.Value) { return(false); } } return(true); }
public ToDo ResolveTodo(ActivityDescriptor descriptor) { return((ToDo)this.ResolveDescriptor(descriptor)); }
public bool HasActivity(ActivityDescriptor descriptor) { return(this.ResolveDescriptor(descriptor) != null); }
public Category ResolveToCategory(ActivityDescriptor descriptor) { return((Category)this.ResolveDescriptor(descriptor)); }
// If there is a discrepancy, returns 0 // Otherwise, returns a number that gets larger if it's more likely that the user meant to match <activity> public double MatchQuality(ActivityDescriptor descriptor, Activity activity) { if (descriptor.RequiresPerfectMatch) { // make sure the name matches if (descriptor.ActivityName != null && !descriptor.ActivityName.Equals(activity.Name)) { return(0); } return(1); } int stringScore = 0; // points based on string similarity string desiredName = descriptor.ActivityName; if (desiredName.Length < 2 * activity.Name.Length) { stringScore = this.stringScore(activity.Name, desiredName); } else { // if the user enters a string that it ridiculously long, then we don't bother comparing it stringScore = 0; } if (desiredName.Length > 0 && stringScore <= 0) { // name has nothing in common return(0); } // now that we've verified that this activity is allowed to be a match, we calculate its score // extra points for a fully matching name, because it must be possible to select an activity by name directly double exactNameScore = 0; if (descriptor.ActivityName.ToLower().Equals(activity.Name.ToLower())) { exactNameScore += 1; } if (descriptor.ActivityName.Equals(activity.Name)) { exactNameScore += 1; } // more points if the 'Suggestible' property matches double suggestibleScore = 0; if (descriptor.Suggestible != null) { if (descriptor.Suggestible.Value) { // If we're looking for a suggestible activity, then we give more points to activities that are willing to be suggested if (activity.Suggestible) { suggestibleScore += 1; } // If we're looking for a suggestible activity, then we give more points to activities that have no children // (activities having child categories are generally less interesting than their children) if (!activity.HasChildCategory) { suggestibleScore++; } } else { // If we're looking for a non-suggestible activity, then we give more points to an activity that's not willing to be suggested if (!activity.Suggestible) { suggestibleScore += 1; } } } double participationScore = 0; // more points based on the likelihood that the user did this activity if (descriptor.PreferMorePopular) { // Give better scores to activities that the user has logged more often participationScore += (1.0 - 1.0 / ((double)activity.NumParticipations + 1.0)); } // fewer points for completed Todos double completedTodoScore = 1; ToDo t = activity as ToDo; if (t != null) { if (t.IsCompleted()) { completedTodoScore = 0; } } double isACompletedToDoScore = 1; if (descriptor.PreferAvoidCompletedToDos) { ToDo toDo = activity as ToDo; if (toDo != null) { if (toDo.IsCompleted()) { isACompletedToDoScore = 0; } } } // Now we add up the score // We give lower priority to the factors at the top of this calculation and higher priority to the lower factors double finalScore = 0; // points for non-name properties finalScore += participationScore; finalScore += suggestibleScore; finalScore += completedTodoScore; finalScore += isACompletedToDoScore; finalScore /= 4; // more points for a more closely matching name finalScore += stringScore; return(finalScore); }
public Problem ResolveProblem(ActivityDescriptor descriptor) { return((Problem)this.ResolveDescriptor(descriptor)); }