Skip to content

Commit

Permalink
Added Card.score_as_fail, Card.score_as_pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
omo committed Nov 19, 2011
1 parent 2927a77 commit cf215f2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
8 changes: 5 additions & 3 deletions MEMO.txt
Expand Up @@ -28,12 +28,14 @@ TODO:
> Exercise mode
+ Add "Level" model - which is embeded into User model.
+ Add Card.next_round, Card.maturity, Card.pass_count, Card.fail_count
- Add scoring logic (pass/fail)
+ Add scoring logic (pass/fail)
- Add a Get for exercise list.
- Think Simple UI
- Add simplest per-card UI
- Add Card.judge or something like that.
- More UI...?


> A bit serious about UI
> Be a bit serious about UI
- Extract hard-coded CSS to a separate less file.

> A simple CRUD for the Card model
Expand Down
15 changes: 14 additions & 1 deletion app/coffee/blbr.coffee
Expand Up @@ -9,7 +9,7 @@ class JsonRestStorage extends Batman.RestStorage
class Blbr.Card extends Batman.Model
@storageKey: 'r/me/card'
@persist JsonRestStorage
@encode 'owner', 'face', 'back', 'next_round', 'pass_count', 'fail_count'
@encode 'owner', 'face', 'back', 'next_round', 'pass_count', 'fail_count', 'succession'
face: ''
back: ''

Expand All @@ -23,6 +23,19 @@ class Blbr.Card extends Batman.Model
save: ->
super =>
@set 'editing', false
score_as_pass: ->
@set('pass_count', @get('pass_count') + 1)
@set('succession', @get('succession') + 1)
@set('next_round', @get('last_round') + @get('succession'))
pass: ->
@score_as_pass()
@save()
score_as_fail: ->
@set('fail_count', @get('fail_count') + 1)
@set('succession', 0)
fail: ->
@score_as_fail()
@save()

class Blbr.Level extends Batman.Model
@storageKey: 'r/me/level'
Expand Down
21 changes: 21 additions & 0 deletions app/coffee/test.coffee
Expand Up @@ -26,3 +26,24 @@ asyncTest "Instantiate Card model", ->
faking.respond(200, { "r/me/cards": ["id": "foo"] })
equal(ret.reduce().get("id"), "foo")
start()

make_fixture_card = ->
card = new Blbr.Card(next_round: 10, pass_count: 1, fail_count: 2, succession: 3)
card.set('last_round', 20)
card

test "Card.score_as_pass", ->
card = make_fixture_card()
card.score_as_pass()
equal(card.get("next_round"), 24)
equal(card.get("pass_count"), 2)
equal(card.get("fail_count"), 2)
equal(card.get("succession"), 4)

test "Card.score_as_fail", ->
card = make_fixture_card()
card.score_as_fail()
equal(card.get("next_round"), 10)
equal(card.get("pass_count"), 1)
equal(card.get("fail_count"), 3)
equal(card.get("succession"), 0)
1 change: 1 addition & 0 deletions app/py/blbr/card.py
Expand Up @@ -24,6 +24,7 @@ class Card(restics.Model):
next_round = db.IntegerProperty(default=1, required=True)
pass_count = db.IntegerProperty(default=0, required=True)
fail_count = db.IntegerProperty(default=0, required=True)
succession = db.IntegerProperty(default=0, required=True)

wild_property_names = ['face', 'back', 'next_round', 'pass_count', 'fail_count']

Expand Down
5 changes: 5 additions & 0 deletions app/template/dashboard.html
Expand Up @@ -65,6 +65,11 @@ <h3><a href="#">Blank Bracket</a></h3>
<input type="button" data-event-click="card.cancel" value="Cancel">
<input type="button" data-event-click="card.destroy" data-confirm="Delete the card?" value="Delete">
</div>
<div>
pass: <span class="card-fail-count" data-bind="card.pass_count"></span>
fail: <span class="card-pass-count" data-bind="card.fail_count"></span>
succ: <span class="card-succession" data-bind="card.succession"></span>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit cf215f2

Please sign in to comment.