Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Point Rules Outside of Controllers #24

Closed
MarkBorcherding opened this issue Aug 2, 2012 · 11 comments
Closed

Creating Point Rules Outside of Controllers #24

MarkBorcherding opened this issue Aug 2, 2012 · 11 comments

Comments

@MarkBorcherding
Copy link
Contributor

Is there any interest from anyone else in creating point rules that are observable on the model rather than on controller actions"? We have a large use for creating points off events other than controller actions, such as cron jobs, Twitter streams, etc.

I was thinking of adding model callbacks to the points DSL and using observables to assign the points. Something like this:

point 25, :on => Tweet => :retweet, :to => :retweeted

Then notify_observers :retweet in the Tweet model.

Just spitballing some ideas with exactly what the DSL would be. I'm not sure if there is any interest in this, or if our case is unique.

@tute
Copy link
Member

tute commented Aug 2, 2012

As points are just an integer, what I do is define an observer which updates de points field directly. I don't see a reason to define an API for that, as we are not saving history on that field yet; Merit treats it as a simple integer change.

When we need more logic than the provided "visited this action", we change that value inside controller actions.

Would this fit your needs?

@MarkBorcherding
Copy link
Contributor Author

Updating points directly was my alternative. It does spread the point logic out from a place where it's held nice and tidy tight now.

The history is another feature we are considering adding. We typically show our points history as a spark line, and are considering some type of point snapshot every time points change along with some daily aggregation and sparse data population.

Another feature we're needing is recording points in specific skills (e.g. strength, dexterity, charisma, etc).

We were planning on building our own pointing and badging, but found Merit and loved it's simplicity. I don't know if bloating Merit with our additions is desirable. We may end up with our own anyway, but Merit looks great.

@tute
Copy link
Member

tute commented Aug 2, 2012

Interesting. Saving the history for points granting is definitely desirable. And agree that spreading the reputation logic out is not best.

Points right now are the greenest part of Merit: only one attribute, no history, kind of too simple. I don't think it would be bad to add some logic to it.

Right now I'm merging a little fix for allowing different point rules on same controller actions. I have a project which would benefit from having split points (as "normal" user and as other type of users), so I'm open to suggestions. Thanks for your feedback!

@MarkBorcherding
Copy link
Contributor Author

Great! We'll look at adding them to Merit first.

@MarkBorcherding
Copy link
Contributor Author

Our first thought was a polymorphic Point model that would be would be an

@tute tute reopened this Aug 2, 2012
@tute
Copy link
Member

tute commented Aug 2, 2012

Yes, makes sense. So, a User has_many Points (or better name).

And we would need a PointsLog model for logging these kinds of changes. We'll also need a method for adding points to a meritable resource ("User").

@MarkBorcherding
Copy link
Contributor Author

Woops. Prematurely hit send there.

Yea. A user has many points/score/award. Each point can have a value, timestamp, category (e.g. strength, charisma), a target maybe (e.g. the post that earned the points) and maybe an action (e.g. edited, approved). That was our thought, but, as usual, I don't know if we're overcomplicating things.

@tute
Copy link
Member

tute commented Aug 2, 2012

Scores is a good model name, and inside of scores we have category, points (the final computed value) and sash_id ("target", no need of polymorphism thanks to that intermediary object).

The Score#points attribute builds from PointsLog, which holds score_id, points and description string (have to define a nice way of logging yet, so we get the action, source, etc).

I'm also thinking out loud, but this should serve as a rather good foundation.

@tute
Copy link
Member

tute commented Oct 13, 2012

@MarkBorcherding, just reviewed all your commits. I just cherry-picked a nice refactoring. What I saw is that through AwardedPoint (which I'll call Score) you were able to handle different categories, but not history.

My sketch adds the PointsLog for logging everything related to that attribute, pretty important for recomputing rules if they are adjusted, and monitoring changes and how do points move in the system.

So I'll start this changeset in the opposite direction: will get running both new models, focus on the PointLog functionality, ignore for now Score#category string attribute, and then make categories work.

Are you using your fork/branch in an app, so we can test? My goal is to do some plumbing but not change the API whenever possible. Thanks!

@MarkBorcherding
Copy link
Contributor Author

Unfortunately, the project we were planning to use Merit on got stalled, and still hasn't picked up. I wouldn't worry about perserving any API I created. We aren't using it anywhere and once we pick back up on it, we can just adapt what we have then.

@tute
Copy link
Member

tute commented Oct 26, 2012

Just released merit version 1.0.0.

  • About points on models, with callbacks it will work, check the new add_points and substract_points methods.
  • Points history is done. From a meritable resource, check it's scores, and inside of it the point entries, that's the history from where we compute user#points, which is now an SQL SUM instead of an attribute. More info in https://github.com/tute/merit/wiki.
  • Recording points in specific skills will come out almost automatically from scores indirection, not yet done though. As this issue is becoming a little cluttered, I'll close it; we may open a new one with Merit::Score#category testing and implementation if you need it.

Thanks for your feedback and help!

@tute tute closed this as completed Oct 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants