def post(self, q): scores = self.get_argument('scores', None) gamedate = self.get_argument('gamedate', None) if scores is None: self.write('{"status":1, "error":"Please enter some scores"}') return scores = json.loads(scores) if len(scores) != 4 and len(scores) != 5: self.write('{"status":1, "error":"Please enter 4 or 5 scores"}') return total = 0 for score in scores: total += score['score'] if total != len(scores) * 25000: self.write('{"status":1, "error":' + "Scores do not add up to " + len(scores) * 25000 + '}') return with db.getCur() as cur: cur.execute("SELECT GameId FROM Scores WHERE GameId = ?", (q,)) row = cur.fetchone() if len(row) == 0: self.write('{"status":1, "error":"Game not found"}') return gameid = row[0] print(gameid) print(gamedate) for i in range(0, len(scores)): score = scores[i] if score['player'] == "": self.write('{"status":1, "error":"Please enter all player names"}') return cur.execute("DELETE FROM Scores WHERE GameId = ?", (gameid,)) for i in range(0, len(scores)): score = scores[i] cur.execute("SELECT Id FROM Players WHERE Id = ? OR Name = ?", (score['player'], score['player'])) player = cur.fetchone() if player is None or len(player) == 0: cur.execute("INSERT INTO Players(Name) VALUES(?)", (score['player'],)) cur.execute("SELECT Id FROM Players WHERE Name = ?", (score['player'],)) player = cur.fetchone() player = player[0] adjscore = util.getScore(score['newscore'], len(scores), i + 1) cur.execute("INSERT INTO Scores(GameId, PlayerId, Rank, PlayerCount, RawScore, Chombos, Score, Date) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", (gameid, player, i + 1, len(scores), score['score'], score['chombos'], adjscore, gamedate)) self.write('{"status":0}')
def post(self): scores = self.get_argument('scores', None) if scores is None: self.write('{"status":1, "error":"Please enter some scores"}') return scores = json.loads(scores) if len(scores) != 4 and len(scores) != 5: self.write('{"status":1, "error":"Please enter some scores"}') return total = 0 for score in scores: total += score['score'] if total != len(scores) * 25000: self.write('{"status":1, "error":' + "Scores do not add up to " + len(scores) * 25000 + '}') return with db.getCur() as cur: gameid = None for i in range(0, len(scores)): score = scores[i] if gameid == None: cur.execute("SELECT GameId FROM Scores ORDER BY GameId DESC LIMIT 1") row = cur.fetchone() if row is not None: gameid = row[0] + 1 else: gameid = 0 if score['player'] == "": self.write('{"status":1, "error":"Please enter all player names"}') return cur.execute("SELECT Id FROM Players WHERE Id = ? OR Name = ?", (score['player'], score['player'])) player = cur.fetchone() if player is None or len(player) == 0: cur.execute("INSERT INTO Players(Name) VALUES(?)", (score['player'],)) cur.execute("SELECT Id FROM Players WHERE Name = ?", (score['player'],)) player = cur.fetchone() player = player[0] adjscore = util.getScore(score['newscore'], len(scores), i + 1) cur.execute("INSERT INTO Scores(GameId, PlayerId, Rank, PlayerCount, RawScore, Chombos, Score, Date) VALUES(?, ?, ?, ?, ?, ?, ?, date('now', 'localtime'))", (gameid, player, i + 1, len(scores), score['score'], score['chombos'], adjscore)) self.write('{"status":0}')
def stop(): global state state = 'menu' global rec rec.stop() fina = time.time() global begin t = fina - begin print('录音时间为%ds' % t) rec.save("test.wav") for ii in range(10000000): pass coeff = util.getCoeff_all('test.wav', 'test.jpg') dis = [] for j in range(len(ys)): tmp2 = util.getScore(coeff, ys[j][0]) # scores[i, ys[j][1]] = min(tmp1, tmp2) dis.append((tmp2, ys[j][1])) print(sorted(dis))
print("Start recording") rec.start() b = input('请回车停止:') print("Stop recording") rec.stop() fina = time.time() t = fina - begin print('录音时间为%ds' % t) rec.save("test.wav") for ii in range(10000000): pass coeff = util.getCoeff_all('test.wav', 'test.jpg') dis = [] for j in range(len(ys)): tmp2 = util.getScore(coeff, ys[j][0]) # scores[i, ys[j][1]] = min(tmp1, tmp2) dis.append((tmp2, ys[j][1])) print(sorted(dis)) elif a == 2: times = 10 name = input("请输入模板名,然后立即开始录音,共%d次:" % times) try: os.mkdir('All/' + name) except: pass for i in range(times): rec = Recorder() begin = time.time() print("Start recording")