Permalink
Browse files

stuff

  • Loading branch information...
1 parent 115978f commit 3767686f93fe916f1ea1c1a1daad8779f28bb260 Roger Braun committed Sep 1, 2010
Showing with 89 additions and 12 deletions.
  1. BIN .app.rb.swo
  2. +3 −0 Gemfile
  3. +18 −12 app.rb
  4. +3 −0 config.ru
  5. BIN db/dev.db
  6. +65 −0 models/Kana.rb
View
Binary file not shown.
View
@@ -1,3 +1,6 @@
source "http://gemcutter.org"
gem 'sinatra'
gem "haml"
+gem "dm-core"
+gem "dm-postgres-adapter"
+gem "sinbook"
View
@@ -1,25 +1,31 @@
require "rubygems"
+require "sinbook"
require "sinatra"
require "haml"
+require "datamapper"
-class Supermemo2
-# see http://www.supermemo.com/english/ol/sm2.htm
+require "models/Kana.rb"
- def interval(n, ef)
- return 1 if n == 1
- return 6 if n == 2
- return (interval(n-1) * ef).round
- end
+DataMapper.setup(:default, ENV["DATABASE_URL"] || "sqlite:db/dev.db")
- def ef(oldef,q)
- ef = ef+(0.1-(5-q)*(0.08+(4-q)*0.02))
- [ef,1.3].max
- end
+DataMapper.auto_upgrade!
-end
+facebook do
+ api_key "095013a6174927028e52bc5c6652be1e"
+ secret "6c06a0379eb2af215a66e76d95a75c4e"
+ app_id "115027275218758"
+ url "http://kanaweb.heroku.com/"
+ callback "http://kanaweb.heroku.com/"
+end
get "/" do
haml :index
end
+
+get "/facebook" do
+ fb.require_login!
+ "Hi <fb:name uid=#{fb[:user]} useyou=false />!"
+end
+
View
@@ -0,0 +1,3 @@
+require "app.rb"
+
+run Sinatra::Application
View
Binary file not shown.
View
@@ -0,0 +1,65 @@
+class Kana
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :utf8, String
+ property :url, String
+
+ belongs_to :flipcard, :required => false
+end
+
+class Flipcard
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :last_learned_on, Date
+ property :repetition, Integer, :default => 0
+ property :easiness, Decimal, :default => 2.5
+
+ def interval(n, ef)
+ return 1 if n == 1
+ return 6 if n == 2
+ return (interval(n-1) * ef).round
+ end
+
+ def ef(oldef,q)
+ ef = ef+(0.1-(5-q)*(0.08+(4-q)*0.02))
+ [ef,1.3].max
+ end
+
+ def learn_today?
+ interval(repetition) < (Date.now - last_learned_on)
+ end
+
+ def learn(q)
+ easiness = ef(easiness,q)
+ last_learned_on = Date.today
+ q < 3 ? repetition = 0 : repetition +=1
+ save
+ end
+
+ has 1, :kana
+ belongs_to :user
+end
+
+class User
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :openid, String
+ property :email, String
+ property :pwhash, String
+
+ has n, :flipcards
+
+ def reset
+ flipcards.each(&:destroy)
+ Kana.all.each do |kana|
+ flipcard = Flipcard.new
+ flipcard.kana = kana
+ flipcards << flipcard
+ end
+ save
+ end
+
+end

0 comments on commit 3767686

Please sign in to comment.