yaz/commit

sync scoring

authorMichiel Hildebrand
Sat Feb 5 23:55:06 2011 +0100
committerMichiel Hildebrand
Sat Feb 5 23:55:06 2011 +0100
commit13a2c95ccb46994f8930e5ea0bd89b1fc47edf28
tree2b5e2e9bbf99e2b304adf7e4823482342162cd5e
parentb2d6e4ef9a7db77954abfabfda0da9bc94252eab
Diff style: patch stat
diff --git a/applications/yaz_game.pl b/applications/yaz_game.pl
index 51b9579..b352adf 100644
--- a/applications/yaz_game.pl
+++ b/applications/yaz_game.pl
@@ -1,5 +1,6 @@
 :- module(yaz_game,
 	  [ http_yaz_game/1,
+	    match_score/5,
 	    update_tag_score/4
 	  ]).
 
@@ -506,7 +507,7 @@ http_game_add_tag(Request) :-
 			]),
 	setting(match_interval, Interval),
  	add_tag(Game, User, Tag, Playhead, Id),
-	match_existing_tags(Game, User, Id, Tag, Playhead, Interval, Matches),
+	matching_tags(Game, User, Id, Tag, Playhead, Interval, Matches),
 	length(Matches, C),
 	rdf_transaction(update_scores(Matches, 0, C, Game)),
  	reply_json(json([id=Id])).
@@ -518,7 +519,7 @@ http_game_add_tag(Request) :-
 %	Returns all matches with tag within Interval of Playhead.
 %	Matches are sorted by time.
 
-match_existing_tags(Game, User, Id, Tag, Playhead, Interval, Matches) :-
+matching_tags(Game, User, Id, Tag, Playhead, Interval, Matches) :-
 	findall(Time-match(Entry, Player, Type),
 		matching_tag(Game, User, Tag, Playhead, Interval, Entry, Player, Type, Time),
 		Matches0),
@@ -546,10 +547,8 @@ tag_match(Tag, Game, Annotation, exact) :-
 update_scores([], _, _, _).
 update_scores([match(Id,Player,Match)|Ms], N, Count, Game) :-
 	N1 is N + 1,
-	match_points(Match, MPoints),
-	order_count_multiplier(N1, Count, Multiplier),
-	Points is MPoints*Multiplier,
- 	update_tag_score(Id, Game, Points, Multiplier),
+	match_score(Match, N1, Count, Points, Multiplier),
+  	update_tag_score(Id, Game, Points, Multiplier),
 	update_player_score(Game, Player, Points),
 	update_scores(Ms, N1, Count, Game).
 
@@ -559,7 +558,12 @@ update_player_score(Game, Player, Points) :-
 	NewScore is OldScore+Points,
 	assert(player_score(Game, Player, NewScore)).
 
-match_points(exact, 50).
+match_score(Match, N1, Count, Points, Multiplier) :-
+	match_type_points(Match, MPoints),
+	order_count_multiplier(N1, Count, Multiplier),
+	Points is MPoints*Multiplier.
+
+match_type_points(exact, 50).
 
 order_count_multiplier(Order, Count, X) :-
 	X is 4/(Order*2) + ((Count-2)/2).
diff --git a/applications/yaz_sgarden.pl b/applications/yaz_sgarden.pl
index 4c02b1d..ffed800 100644
--- a/applications/yaz_sgarden.pl
+++ b/applications/yaz_sgarden.pl
@@ -190,7 +190,7 @@ http_yaz_api_edit_tag(Request) :-
 			 score=Score
  			])).
 
-tag_matches(Tagentry, Tag, Interval, Score) :-
+tag_matches(Tagentry, Tag, Interval, Points) :-
 	rdf(Tagentry, pprime:videoPlayhead, literal(Time0), Game:_),
  	rdf(Tagentry, pprime:creator, User),
 	literal_to_number(Time0, Time),
@@ -198,12 +198,12 @@ tag_matches(Tagentry, Tag, Interval, Score) :-
 	End is Time+Interval,
 	findall(E, tagentry_in_interval(Tag, Game, User, Start, End, E), Es),
 	(   Es = []
-	->  Score = 0
+	->  Points = 0
 	;   length(Es, N),
-	    N1 is N+1,
-	    Score is max(25, 100-((N-1)*25)),
-	    current_user_process(Process),
-	    assert_match(Tagentry, Process, exact, Score, N1)
+	    Total is N+1,
+	    match_score(exact, Total, Total, Points, Multiplier),
+ 	    current_user_process(Process),
+	    update_tag_score(Tagentry, Process, Points, Multiplier)
 	).
 
 tagentry_in_interval(Tag, Game, User, Start, End, E) :-