From fb12f863d11a09c97aa3937d2bf9006369819a32 Mon Sep 17 00:00:00 2001 From: Nickito12 Date: Sun, 11 Jun 2017 23:46:30 -0300 Subject: [PATCH 1/5] Calculate judgements, dp and grade server-side(In case of judge!=4) --- smserver/controllers/legacy/game_over.py | 2 +- .../controllers/legacy/game_start_request.py | 6 ++ .../controllers/legacy/game_status_update.py | 34 +++++++ smserver/models/song_stat.py | 99 +++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) diff --git a/smserver/controllers/legacy/game_over.py b/smserver/controllers/legacy/game_over.py index 59f172a..3df99cf 100644 --- a/smserver/controllers/legacy/game_over.py +++ b/smserver/controllers/legacy/game_over.py @@ -56,7 +56,7 @@ def create_stats(self, user, raw_stats, duration): if raw_stats["data"]: songstat.grade = raw_stats["data"][-1]["grade"] - songstat.score = raw_stats["data"][-1]["score"] + songstat.score = raw_stats["dp"] for stepid in models.SongStat.stepid.values(): setattr(songstat, stepid, 0) diff --git a/smserver/controllers/legacy/game_start_request.py b/smserver/controllers/legacy/game_start_request.py index d8cffc0..b1471c8 100644 --- a/smserver/controllers/legacy/game_start_request.py +++ b/smserver/controllers/legacy/game_start_request.py @@ -38,12 +38,18 @@ def handle(self): "feet": self.packet["first_player_feet"], "difficulty": self.packet["first_player_difficulty"], "options": self.packet["first_player_options"], + "toasties": 0, + "perfect_combo": 0, + "dp": 0, "best_score": song.best_score_value(self.packet["first_player_feet"]) }, 1: {"data": [], "feet": self.packet["second_player_feet"], "difficulty": self.packet["second_player_difficulty"], "options": self.packet["second_player_options"], + "toasties": 0, + "perfect_combo": 0, + "dp": 0, "best_score": song.best_score_value(self.packet["second_player_feet"]) }, "start_at": datetime.datetime.now(), diff --git a/smserver/controllers/legacy/game_status_update.py b/smserver/controllers/legacy/game_status_update.py index d52f529..7084b62 100644 --- a/smserver/controllers/legacy/game_status_update.py +++ b/smserver/controllers/legacy/game_status_update.py @@ -25,12 +25,36 @@ def handle(self): "score": self.packet["score"], "combo": self.packet["combo"], "health": self.packet["health"], + #"note_size": self.packet["note_size"], Requires smpacket update "offset": self.packet["offset"] } with self.conn.mutex: best_score = self.conn.songstats[self.packet["player_id"]]["best_score"] + ''' requires smapcket update + if not stats["note_size"] or stats["note_size"] <= 0: + notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) + else: + notesize = stats["note_size"] + ''' + notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) + offset = float(stats["offset"]) / 2000.0 - 16.384 + if stats["stepid"] > 3 and stats["stepid"] < 9: + stats["stepid"] = models.SongStat.get_stepid(offset) + if stats["stepid"] == 7 or stats["stepid"] == 8: + self.conn.songstats[pid]["perfect_combo"] += notesize + elif stats["stepid"] == 4 or stats["stepid"] == 5 or stats["stepid"] == 6: + self.conn.songstats[pid]["perfect_combo"] = 0 + if stats["stepid"] == 3: + self.conn.songstats[pid]["perfect_combo"] = 0 + if self.conn.songstats[pid]["perfect_combo"] != 0 and self.conn.songstats[pid]["perfect_combo"] % 250 == 0: + self.conn.songstats[pid]["toasties"] += 1 + self.conn.songstats[pid]["dp"] += models.SongStat.calc_dp(stats["stepid"]) + stats["grade"] = models.SongStat.calc_grade_from_ratio( \ + self.conn.songstats[pid]["dp"] / (self.conn.songstats[pid]["taps"]*2), \ + self.conn.songstats[pid]["data"]) + if best_score and stats["score"] > best_score: with self.conn.mutex: self.conn.songstats[self.packet["player_id"]]["best_score"] = None @@ -50,3 +74,13 @@ def beat_best_score(self): ) self.sendroom(self.conn.room, smpacket.SMPacketServerNSCSU(message=message)) + + + def notesize_from_combo(self, combo, data): + if len(data) > 0: + if combo > 0: + return combo - data[-1]["combo"] + else: + return 1 + else: + return 1 diff --git a/smserver/models/song_stat.py b/smserver/models/song_stat.py index e7d390f..038ac18 100644 --- a/smserver/models/song_stat.py +++ b/smserver/models/song_stat.py @@ -200,6 +200,105 @@ def stats(self): def nb_notes(self): return sum(getattr(self, note, 0) for note in self.stepid.values()) + @staticmethod + def calc_grade(score, data): + if score >= 100.00: + for note in data: + if note["stepid"] > 2 and note["stepid"] < 9: + if note != 8: + return 1 + return 0 + elif score >= 93.00: + return 2 + elif score >= 80.00: + return 3 + elif score >= 65.00: + return 4 + elif score >= 45.00: + return 5 + return 6 + + @staticmethod + def calc_dp(stepsid): + if stepsid == 8 or stepsid == 7: + return 2 + elif stepsid == 6: + return 1 + elif stepsid == 5: + return 0 + elif stepsid == 4: + return -4 + elif stepsid == 3: + return -8 + elif stepsid == 10: + return 0 + else: + return 0 + + @staticmethod + def calc_migsp(stepsid): + if stepsid == 8: + return 3 + elif stepsid == 7: + return 2 + elif stepsid == 6: + return 1 + elif stepsid == 5: + return 0 + elif stepsid == 4: + return -4 + elif stepsid == 3: + return -8 + elif stepsid == 10: + return 6 + else: + return 0 + + #wife score aproximation + @staticmethod + def calc_wifep(offset): + avedeviation = 95.0 + maxms = offset*1000.0 + y = 1.0 - float(pow(2, (-1) * maxms*maxms / 9025.0)) + y = pow(y, 2) + return (2 + 8)*(1 - y) - 8 + + @staticmethod + def calc_grade_from_ratio(score, data): + if score >= 1: + for note in data: + if note["stepid"] > 2 and note["stepid"] < 9: + if note != 8: + return 1 + return 0 + elif score >= 0.93: + return 2 + elif score >= 0.80: + return 3 + elif score >= 0.65: + return 4 + elif score >= 0.45: + return 5 + return 6 + + # offset-> stepid + @staticmethod + def get_stepid(offset): + smarv = 0.02259; + sperf = 0.04509; + sgreat = 0.09009; + sgood = 0.13509; + sboo = 0.18909; + if (offset < smarv) and (offset > (smarv * -1.0)): + return 8 + elif (offset < sperf) and (offset > (sperf * -1.0)): + return 7 + elif (offset < sgreat) and (offset > (sgreat * -1.0)): + return 6 + elif (offset < sgood) and (offset > (sgood * -1.0)): + return 5 + else: + return 4 class BinaryStats(SMPacket): _payload = [ From 07e32fd282fdc1ef890433597c730eba26b47716 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 14 Jun 2017 20:59:23 -0300 Subject: [PATCH 2/5] Fix indentation error --- smserver/models/song_stat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smserver/models/song_stat.py b/smserver/models/song_stat.py index 038ac18..50ad31a 100644 --- a/smserver/models/song_stat.py +++ b/smserver/models/song_stat.py @@ -298,7 +298,7 @@ def get_stepid(offset): elif (offset < sgood) and (offset > (sgood * -1.0)): return 5 else: - return 4 + return 4 class BinaryStats(SMPacket): _payload = [ From 92be2670ae32cee1027ff41f087cd9c1096d7e18 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 14 Jun 2017 21:07:26 -0300 Subject: [PATCH 3/5] Fix because I copied this to the wrong place --- .../controllers/legacy/game_status_update.py | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/smserver/controllers/legacy/game_status_update.py b/smserver/controllers/legacy/game_status_update.py index 7084b62..6452652 100644 --- a/smserver/controllers/legacy/game_status_update.py +++ b/smserver/controllers/legacy/game_status_update.py @@ -30,30 +30,31 @@ def handle(self): } with self.conn.mutex: - best_score = self.conn.songstats[self.packet["player_id"]]["best_score"] + pid = self.packet["player_id"] + best_score = self.conn.songstats[pid]["best_score"] - ''' requires smapcket update - if not stats["note_size"] or stats["note_size"] <= 0: + ''' requires smapcket update + if not stats["note_size"] or stats["note_size"] <= 0: + notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) + else: + notesize = stats["note_size"] + ''' notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) - else: - notesize = stats["note_size"] - ''' - notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) - offset = float(stats["offset"]) / 2000.0 - 16.384 - if stats["stepid"] > 3 and stats["stepid"] < 9: - stats["stepid"] = models.SongStat.get_stepid(offset) - if stats["stepid"] == 7 or stats["stepid"] == 8: - self.conn.songstats[pid]["perfect_combo"] += notesize - elif stats["stepid"] == 4 or stats["stepid"] == 5 or stats["stepid"] == 6: - self.conn.songstats[pid]["perfect_combo"] = 0 - if stats["stepid"] == 3: - self.conn.songstats[pid]["perfect_combo"] = 0 - if self.conn.songstats[pid]["perfect_combo"] != 0 and self.conn.songstats[pid]["perfect_combo"] % 250 == 0: - self.conn.songstats[pid]["toasties"] += 1 - self.conn.songstats[pid]["dp"] += models.SongStat.calc_dp(stats["stepid"]) - stats["grade"] = models.SongStat.calc_grade_from_ratio( \ - self.conn.songstats[pid]["dp"] / (self.conn.songstats[pid]["taps"]*2), \ - self.conn.songstats[pid]["data"]) + offset = float(stats["offset"]) / 2000.0 - 16.384 + if stats["stepid"] > 3 and stats["stepid"] < 9: + stats["stepid"] = models.SongStat.get_stepid(offset) + if stats["stepid"] == 7 or stats["stepid"] == 8: + self.conn.songstats[pid]["perfect_combo"] += notesize + elif stats["stepid"] == 4 or stats["stepid"] == 5 or stats["stepid"] == 6: + self.conn.songstats[pid]["perfect_combo"] = 0 + if stats["stepid"] == 3: + self.conn.songstats[pid]["perfect_combo"] = 0 + if self.conn.songstats[pid]["perfect_combo"] != 0 and self.conn.songstats[pid]["perfect_combo"] % 250 == 0: + self.conn.songstats[pid]["toasties"] += 1 + self.conn.songstats[pid]["dp"] += models.SongStat.calc_dp(stats["stepid"]) + stats["grade"] = models.SongStat.calc_grade_from_ratio( \ + self.conn.songstats[pid]["dp"] / (self.conn.songstats[pid]["taps"]*2), \ + self.conn.songstats[pid]["data"]) if best_score and stats["score"] > best_score: with self.conn.mutex: From d99eea5c6e526a1627dfc8e9fc13f4578321a810 Mon Sep 17 00:00:00 2001 From: Nickito12 Date: Wed, 14 Jun 2017 21:53:36 -0300 Subject: [PATCH 4/5] Add the taps counter --- smserver/controllers/legacy/game_start_request.py | 2 ++ smserver/controllers/legacy/game_status_update.py | 1 + 2 files changed, 3 insertions(+) diff --git a/smserver/controllers/legacy/game_start_request.py b/smserver/controllers/legacy/game_start_request.py index b1471c8..8954efc 100644 --- a/smserver/controllers/legacy/game_start_request.py +++ b/smserver/controllers/legacy/game_start_request.py @@ -41,6 +41,7 @@ def handle(self): "toasties": 0, "perfect_combo": 0, "dp": 0, + "taps": 0, "best_score": song.best_score_value(self.packet["first_player_feet"]) }, 1: {"data": [], @@ -50,6 +51,7 @@ def handle(self): "toasties": 0, "perfect_combo": 0, "dp": 0, + "taps": 0, "best_score": song.best_score_value(self.packet["second_player_feet"]) }, "start_at": datetime.datetime.now(), diff --git a/smserver/controllers/legacy/game_status_update.py b/smserver/controllers/legacy/game_status_update.py index 6452652..a987640 100644 --- a/smserver/controllers/legacy/game_status_update.py +++ b/smserver/controllers/legacy/game_status_update.py @@ -42,6 +42,7 @@ def handle(self): notesize = self.notesize_from_combo(stats["combo"], self.conn.songstats[pid]["data"]) offset = float(stats["offset"]) / 2000.0 - 16.384 if stats["stepid"] > 3 and stats["stepid"] < 9: + self.conn.songstats[pid]["taps"] += 1 stats["stepid"] = models.SongStat.get_stepid(offset) if stats["stepid"] == 7 or stats["stepid"] == 8: self.conn.songstats[pid]["perfect_combo"] += notesize From 20bd979f9503117a4f88546c3e66547728734f79 Mon Sep 17 00:00:00 2001 From: Nickito12 Date: Thu, 15 Jun 2017 21:55:02 -0300 Subject: [PATCH 5/5] Fix test --- test/test_functional/test_server.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test_functional/test_server.py b/test/test_functional/test_server.py index dfabe97..be6f464 100644 --- a/test/test_functional/test_server.py +++ b/test/test_functional/test_server.py @@ -288,12 +288,12 @@ def test_client_bin_game_status_update(self): self.test_client_json_game_start_request() packet = smpacket.SMPacketClientNSCGSU( player_id=0, - step_id=4, - grade=3, + step_id=8, + grade=0, score=50000, combo=1, health=50, - offset=20000, + offset=32760, ) self.client_bin.on_data(packet.binary) @@ -301,8 +301,8 @@ def test_client_bin_game_status_update(self): songstats = self.client_bin.songstats self.assertEqual(len(songstats[0]["data"]), 1) - self.assertEqual(songstats[0]["data"][0]["stepid"], 4) - self.assertEqual(songstats[0]["data"][0]["grade"], 3) + self.assertEqual(songstats[0]["data"][0]["stepid"], 8) + self.assertEqual(songstats[0]["data"][0]["grade"], 0) self.assertEqual(songstats[0]["data"][0]["score"], 50000) self.assertEqual(songstats[0]["data"][0]["combo"], 1) self.assertEqual(songstats[0]["data"][0]["health"], 50) @@ -326,8 +326,8 @@ def test_client_bin_game_over(self): songstats = list(self.session.query(models.SongStat).filter_by(user=self.user_bin1)) self.assertEqual(len(songstats), 1) - self.assertEqual(songstats[0].score, 50000) - self.assertEqual(songstats[0].grade, 3) + self.assertEqual(songstats[0].score, 4) + self.assertEqual(songstats[0].grade, 1) self.assertEqual(songstats[0].max_combo, 1) def test_client_bin_disconnect(self):