Skip to content

Commit

Permalink
add rand || songinfo || selfinfo || best
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Aug 18, 2023
1 parent cc89339 commit fbb1dac
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 10 deletions.
104 changes: 102 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- [x] /api/phi/bests

**Get Users Best, support Overflow songs, you can delete this limit.**

> args: Session | overflow (max:20)
```
Expand Down Expand Up @@ -55,8 +57,106 @@
```

- [ ] /api/phi/re8
- [ ] /api/phi/songs
- [x] /api/phi/best

**Check User's best Songs.**

> args: songid | Session | diff: Optional(Default "IN")
- tips: songid just like "DESTRUCTION321.Normal1zervsBrokenNerdz" || diff just like "EZ" "AT"

```
{
"status": true,
"content": {
"record": {
"score": 999383,
"acc": 99.93145751953125,
"level": "IN",
"fc": true,
"songId": "DESTRUCTION321.Normal1zervsBrokenNerdz",
"songname": "DESTRUCTION 3,2,1",
"difficulty": 15.9,
"rks": 15.851600202364502
},
"PlayerID": "压压鸭ya",
"ChallengeModeRank": 445,
"RankingScore": 15.800082206726074
}
}
```

- [x] /api/phi/info

**User's Status, no others**

> args: session
```
{
"status": true,
"Content": {
"PlayerID": "MoeMagicMango",
"ChallengeModeRank": 245,
"RankingScore": 13.175806999206543
}
}
```

- [x] /api/phi/rand

> no args
```
{
"status": true,
"content": {
"songid": "BetterGraphicAnimation.ルゼ",
"songname": "Better Graphic Animation",
"composer": "ルゼ",
"level": "HD",
"rating": 11.7
}
}
```

- [x] /api/phi/song

> args: songid
```
{
"status": true,
"content": {
"songid": "BetterGraphicAnimation.ルゼ",
"info": {
"songname": "Better Graphic Animation",
"composer": "ルゼ",
"illustrator": "A-Zero Project",
"chartDetail": {
"EZ": {
"rating": 6.5,
"charter": "NerSAN"
},
"HD": {
"rating": 11.7,
"charter": "NerSAN"
},
"In": {
"rating": 15.3,
"charter": "縱連打の信者☆無極"
},
"level_list": [
6.5,
11.7,
15.3
]
}
}
}
}
```

...

Expand Down
149 changes: 148 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import json

from flask import Flask, jsonify, request, make_response
from method import BestsRender
from method import (
BestsRender,
difficulty,
info,
info_by,
levels,
info_illustrator,
info_hd_designer,
info_at_designer,
info_ez_desinger,
info_in_desingner,
)
import random as rand


app = Flask(__name__)
# init

BestsRender.read_difficulty("difficulty.csv")
BestsRender.read_playerInfo("info.csv")
listDiff = list(difficulty.items())
getLength = len(difficulty)


@app.route("/", methods=["GET"])
Expand Down Expand Up @@ -41,5 +56,137 @@ def get_bests():
return data


@app.route("/api/phi/best", methods=["GET"])
def get_songs():
session = request.args.get("session")
songs = request.args.get("songid")
diff = request.args.get("diff")
if session is None:
return jsonify({"message": "session is required."})
if songs is None:
return jsonify({"message": "songid is required."})
if diff is None:
diff = "IN"
try:
Contents = BestsRender.get_songs_stats(session, songs, diff)
if Contents is None:
data = {"status": False, "message": "SongID or Diff Not found"}
else:
get_formatData = BestsRender.get_formatData(session)
Contents = {"record": Contents}
Content = {**Contents, **get_formatData}
data = {
"status": True,
"content": Content,
}
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
data.headers["Content-Type"] = "application/json; charset=utf-8"
except Exception as e:
return jsonify({"status": False, "message": str(e)})
return data


@app.route("/api/phi/rand", methods=["GET"])
def get_rand():
try:
getRandSongIDNum = rand.randrange(0, getLength)
result = listDiff[getRandSongIDNum - 1]
result_info_name = info[result[0]]
result_info_by = info_by[result[0]]
result_get_diff_list = result[1]
getLength_result_range = rand.randrange(0, len(result_get_diff_list))
getLevel = levels[getLength_result_range]
getRating = result_get_diff_list[getLength_result_range]
Content = {
"songid": result[0],
"songname": result_info_name,
"composer": result_info_by,
"level": getLevel,
"rating": getRating,
}
data = {
"status": True,
"content": Content,
}
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
data.headers["Content-Type"] = "application/json; charset=utf-8"
except Exception as e:
return jsonify({"status": False, "message": str(e)})
return data


@app.route("/api/phi/info", methods=["GET"])
def get_info():
session = request.args.get("session")
if session is None:
return jsonify({"message": "session is required."})
try:
get_formatData = BestsRender.get_formatData(session)
except Exception as e:
return jsonify({"status": False, "message": str(e)})
data = {"status": True, "Content": get_formatData}
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
data.headers["Content-Type"] = "application/json; charset=utf-8"
return data


@app.route("/api/phi/song", methods=["GET"])
def get_song_info():
songid = request.args.get("songid")
if songid is None:
return jsonify({"message": "songid is required."})
try:
result_info_name = info[songid]
result_info_by = info_by[songid]
result_get_diff_list: list = difficulty[songid] # list
result_get_ins_by = info_illustrator[songid]
result_get_ez_designer = info_ez_desinger[songid]
result_get_hd_desinger = info_hd_designer[songid]
result_get_in_desinger = info_in_desingner[songid]
result_get_at_desinger = info_at_designer[songid]
showEZDetailed = {
"EZ": {"rating": result_get_diff_list[0], "charter": result_get_ez_designer}
}
showHDDetailed = {
"HD": {"rating": result_get_diff_list[1], "charter": result_get_hd_desinger}
}
showInDetailed = {
"In": {"rating": result_get_diff_list[2], "charter": result_get_in_desinger}
}
if len(result_get_diff_list) >= 4:
showAtDetailed = {
"In": {
"rating": result_get_diff_list[3],
"charter": result_get_at_desinger,
}
}
else:
showAtDetailed = {}
getChartDetailedInfo = {
**showEZDetailed,
**showHDDetailed,
**showInDetailed,
**showAtDetailed,
"level_list": result_get_diff_list,
}
infos = {
"songname": result_info_name,
"composer": result_info_by,
"illustrator": result_get_ins_by,
"chartDetail": getChartDetailedInfo,
}
content = {"songid": songid, "info": infos}
data = {"status": True, "content": content}
except Exception as e:
return jsonify({"status": False, "message": str(e)})
data = json.dumps(data, ensure_ascii=False).encode("utf-8")
data = make_response(data)
data.headers["Content-Type"] = "application/json; charset=utf-8"
return data


if __name__ == "__main__":
app.run(debug=True)
Loading

0 comments on commit fbb1dac

Please sign in to comment.