Bergrebell / CyberCoach

1 stars 1 forks source link

create achievments(mvc) #10

Closed Bergrebell closed 9 years ago

Bergrebell commented 9 years ago

achievement has_many credits title points category

svetakrasikova commented 9 years ago

Do you agree that the category should reference the kind of sport and be connected to the sports resource?

lexruee commented 9 years ago

In a first step keep it simple. Just create a table with sports categories that is referenced by the achievement table. In a later step this table will be replaced by a 'virtual table' which maps the sports catgegory resource on the cyber coach sever.

svetakrasikova commented 9 years ago

Right, that's what I thought I should do. Thanks!

I keep thinking about how we should manage earning achievements (and later challenges) ( I mean the 'validating' story). Let us discuss this at some point. Maybe tomorrow night or some time during the weekend?

9 Oct 2014, в 17:08, Alexander Rüedlinger notifications@github.com написал(а):

In a first step keep it simple. Just create a table with sports categories that is referenced by the achievement table. In later step this table will be replaced by a 'virtual table' which maps the sports catgegory resource on the cyber coach sever.

— Reply to this email directly or view it on GitHub.

lexruee commented 9 years ago

Well, here are my thoughts.

1) The main challenge in implementing achievements and the corresponding validation is that we're trying to push logic into the database, because we want to have our achievement model.

This is the result of developing some kind of "game" using a web framework.

As we already discovered, this forces us to put either ruby code for validation into the db or we need some intelligent way to encode the validation conditions as json message that is saved in the db and a validator method which "understands" this encoded validation condtion.

I don't like these two approaches. I suggest we discard the approach 1).

2) In a pure object oriented way we have something like a game controller (not in the spirit of a controller in the rails framework!!!!) which continuously checks if some game rules or game actions can be applied depending on the state of the player (user).

You can imagine this is like a store. A player is always asking the storekeeper what can I buy with my points or in our case with 10km in 60 minutes. Maybe in our case 10 km in 60 minutes corresponds to 600 kmm points. And with these 600 kmm points you can buy an achievement. So as soon as our system detects that (user enters his data) the user gets the corresponding achievement.

So what do we need?

Classes: Game (GameController), GameRule, Achievement, GameStore (or models that have no tables)

The Game class has maybe a method called check() which takes a user as argument. This method checks if any of the game rules / game actions can be applied. If such a game rule can applied it activates the rule and buys based on the points an achievement (we create a credit entry).

Code example:

achievement = Achievement:new id: 1, title: '10km in 60 minutes' (here the id used later for saving the id in the database) rule_1 = GameRule.new params: { km: 10, minutes: 60}, achievement: achievement rule: ->(user, params) { some code for validation}

GameController.new rules: [rule_1]

Conclusion: We should keep the game logic in the object world and we should only save the history of achievements in a database using a id that identifies an achievement.

I hope its clear what I'm trying to explain.

svetakrasikova commented 9 years ago

This makes sense to me. The explanation is very clear, thank you. I too came to the conclusion that method 1) is not adequate; but I did not get as far as you, of course:)

9 Oct 2014, в 22:09, Alexander Rüedlinger notifications@github.com написал(а):

Well, here are my thoughts.

1) The main challenge in implementing achievements and the corresponding validation is that we're trying to push logic into the database, because we want to have our achievement model.

This is the result of developing some kind of "game" using a web framework.

As we already discovered, this forces us to put either ruby code for validation into the db or we need some intelligent way to encode the validation conditions as json message that is saved in the db and a validator method which "understands" this encoded validation condtion.

I don't like these two approaches. I suggest we discard the approach 1).

2) In a pure object oriented way we have something like a game controller (not in the spirit of a controller in the rails framework!!!!) which continuously checks if some game rules or game actions can be applied depending on the state of the player (user).

You can imagine this is like a store. A player is always asking the storekeeper what can I buy with my points or in our case with 10km in 60 minutes. Maybe in our case 10 km in 60 minutes corresponds to 600 kmm points. And with these 600 kmm points you can buy an achievement. So as soon as our system detects that (user enters his data) the user gets the corresponding achievement.

So what do we need?

Classes: Game (GameController), GameRule, Achievement, GameStore (or models that have no tables)

The Game class has maybe a method called check() which takes a user as argument. This method checks if any of the game rules / game actions can be applied. If such a game rule can applied it activates the rule and buys based on the points an achievement (we create a credit entry).

Code example:

achievement = Achievement:new id: 1, title: '10km in 60 minutes' (here the id used later for saving the id in the database) rule_1 = GameRule.new params: { km: 10, minutes: 60}, achievement: achievement rule: ->(user, params) { some code for validation}

GameController.new rules: [rule_1]

Conclusion: We should keep the game logic in the object world and we should only save the history of achievements in a database using a id that identifies an achievement.

I hope its clear what I'm trying to explain.

— Reply to this email directly or view it on GitHub.

lexruee commented 9 years ago

We need to model it first in terms of objects. Afterwards we should try to identify the necessary tables. Are you guys around after the web-eng lecture?

Am Donnerstag, 9. Oktober 2014 schrieb Sveta Krasikova :

This makes sense to me. The explanation is very clear, thank you. I too came to the conclusion that method 1) is not adequate; but I did not get as far as you, of course:)

9 Oct 2014, в 22:09, Alexander Rüedlinger <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> написал(а):

Well, here are my thoughts.

1) The main challenge in implementing achievements and the corresponding validation is that we're trying to push logic into the database, because we want to have our achievement model.

This is the result of developing some kind of "game" using a web framework.

As we already discovered, this forces us to put either ruby code for validation into the db or we need some intelligent way to encode the validation conditions as json message that is saved in the db and a validator method which "understands" this encoded validation condtion.

I don't like these two approaches. I suggest we discard the approach 1).

2) In a pure object oriented way we have something like a game controller (not in the spirit of a controller in the rails framework!!!!) which continuously checks if some game rules or game actions can be applied depending on the state of the player (user).

You can imagine this is like a store. A player is always asking the storekeeper what can I buy with my points or in our case with 10km in 60 minutes. Maybe in our case 10 km in 60 minutes corresponds to 600 kmm points. And with these 600 kmm points you can buy an achievement. So as soon as our system detects that (user enters his data) the user gets the corresponding achievement.

So what do we need?

Classes: Game (GameController), GameRule, Achievement, GameStore (or models that have no tables)

The Game class has maybe a method called check() which takes a user as argument. This method checks if any of the game rules / game actions can be applied. If such a game rule can applied it activates the rule and buys based on the points an achievement (we create a credit entry).

Code example:

achievement = Achievement:new id: 1, title: '10km in 60 minutes' (here the id used later for saving the id in the database) rule_1 = GameRule.new params: { km: 10, minutes: 60}, achievement: achievement rule: ->(user, params) { some code for validation}

GameController.new rules: [rule_1]

Conclusion: We should keep the game logic in the object world and we should only save the history of achievements in a database using a id that identifies an achievement.

I hope its clear what I'm trying to explain.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/Bergrebell/CyberCoach/issues/10#issuecomment-58573878 .

wanze commented 9 years ago

Good morning :) Nice discussion! :+1:

Here's a simple model that could also work: Assuming that the conditions to get an achievement are always measured based on the sport attributes. We could introduce 3 operators:

Based on these three operators, an achievment can be evaluated against the data of sport session.

Example: Run more than 10 km under 1 hour km >= 10 && duration <= 1

To store this rule, we could use a JSON string, as alex suggests, but I would also store the operator. For the above example this would be an array with two JSON objects each holding 3 key/value pairs:

[
  { attribute : 'km',
    operator : '>=',
    value : 10 },
  { attribute : 'duration',
    operator : '<=',
    value : 1 }
]

In this model, the achievment object looks something like this:

If a user has finished a sport event, we loop through the available achievments (not yet obtained) and check the rules against our data. If true, the user gets the achievment which is stored in an additional table as "History".

I think this would be a very "simple" model, however it works only nice if the achievments depend on the sports data

lexruee commented 9 years ago

@wanze That's actually a nice way how user defined challenges could be implemented. However, I still want to have a simple UML diagram which illustrates how the different objects / components are interacting with each other :-).

lexruee commented 9 years ago

@wanze I hope you like the condition parser :-) See unit tests: https://github.com/Bergrebell/CyberCoach/blob/dev/test/units/lib/condtion_parser_test.rb

wanze commented 9 years ago

@lexruee This is f#@!?ing awesome :D

lexruee commented 9 years ago

@wanze @svetakrasikova I did some prototyping to see how I would implement achievements and a kind of game controller (aka game rule engine). This should demonstrate what I had in mind. Honestly, I don't like it :-), but at least I found out some problems that may arise in the future and what does work and what doesn't.

Some notes:

The notes * / \ remembered me of routing/dispatching/request handlers in the context of http requests.

You can see this kind of prototype in this unit test: https://github.com/Bergrebell/CyberCoach/blob/prototype-achievements/test/units/lib/achievement_prototype_test.rb

svetakrasikova commented 9 years ago

Hi, I feel exhausted today, will try to catch up with you early tomorrow morning and start pestering you with questions again:)

Good night Sveta

Отправлено с iPhone

11 окт. 2014 г., в 20:28, Alexander Rüedlinger notifications@github.com написал(а):

@wanze @svetakrasikova I did some prototyping to see how I would implement achievements and kind of game controller (aka game rule engine). This should demonstrate what I had in mind. Honestly, I don't like it :-), but at least I found out some problems that may arise in the future and what does work and what doesn't.

Some notes:

How would you implement an achievement that depends on another achievement? If somebody got the achievement '10km in 60 under minutes', he or she should also get the achievement '5km in under 30 minutes'? Plays the order how the rules are applied a role? You can see this kind of 'oo' prototype in this unit test: https://github.com/Bergrebell/CyberCoach/blob/prototype-achievements/test/units/lib/achievement_prototype_test.rb

— Reply to this email directly or view it on GitHub.

svetakrasikova commented 9 years ago

I haven't studied Alex's prototype yet. I have a comment on the game rule engine (as sketched by Stefan). Why use JSON for the conditions (this is not a typical use of JSON, isn't it?) and not put them in a separate table Validation Conditions and then the Rule Definition would refer to Validation Conditions.

wanze commented 9 years ago

Hi Sveta JSON is often used to encode data if there is no fixed schema given. Every rule has other data to check, so using JSON in this case is simpler in my opinion. If going for separate tables, every Rule needs another table to store the specific data.

svetakrasikova commented 9 years ago

Hi Stefan,

The JSON strings follow the pattern:

Operator Value Attribute

for attribute rules. I was thinking about having a separate table with these three fields where you store different rule conditions (not to have to parse JSON strings). But maybe the problem is that this scheme does not cover all kinds of rules, in particular non-attribute rules would need other kind of conditions. Right?

Îòïðàâëåíî ñ iPad

12 îêò. 2014 ã., â 14:36, Stefan Wanzenried notifications@github.com íàïèñàë(à):

Hi Sveta JSON is often used to encode data if there is no fixed schema given. Every rule has other data to check, so using JSON in this case is simpler in my opinion. If going for separate tables, every Rule needs another table to store the specific data.

— Reply to this email directly or view it on GitHub.

svetakrasikova commented 9 years ago

Regarding monotonicity(10 in 60 entails 5 in 30?): This sounds too difficult, this need not hold. Maybe better not to make achievements depend on each other.

wanze commented 9 years ago

@svetakrasikova Yep that was my thinking. Parsing JSON to arrays/lists is implemented in (I'd say) every programming language. The condition parser of Alex is already much more advanced, I was thinking of 3 operators to implement (<,>,=) :)

Some thoughts on the questions of Alex:

How would you implement an achievement that depends on another achievement?

I don't think we need this :)

If somebody got the achievement '10km in 60 under minutes', he or she should also get the achievement '5km in under 30 minutes'?

I'm with Sveta on this one, let's leave it out. This would assume that we could evaluate the data after 5 km, but we only have one snapshot. However, if the person runs 5.1 km in 29 minutes, then it's true

Plays the order how the rules are applied a role?

I'd suggest to introduce a difficulty level for achievments, then we can apply the checks according this metric.

Can a user obtain an achievement multiple times? (For each sport event achievements can be earned?)

No, just once

A new entered sport event (running, boxing) can trigger multiple game rules

Each achievment has a rule that evaluates the data. We have to loop the achievments of a sport and check if a rule evaluates to true -> Therfore multiple achievments could be earned with one sport event

How can we decide if a rule should be applied on the incoming sport event

The achievment has to know which rule (or rules) do the checks. Each achievment not yet earned has to be checked.

Should an achievement register itself to a game rule? If so, can multiple achievements register to the same game rule? If the game rule can be applied then all registered achievements are awarded to the user?

In my sketeched model each achievment has a rule definition that is checked by a rule. Let's discuss tomorrow.

lexruee commented 9 years ago

@wanze Thanks for the remarks. Related to the application of the game rules. Interesting, I would have done it in the reverse order :-), looping over the game rules, check which rule can be applied on the data, then award the user with all the achievements that are associated with the rule. As short remark. I did this prototyoe only to find out how I would do it and to get a feeling of the problems we might encounter.

However, I'm for the json approach to implement challenges and achievements. With a nice 'condition' parser this is a really powerful design. A user can define pretty complex challenges like: (Running: 5 km under 20 minutes and weather: rainy) or (Running: 30km under 3*60 minutes)