forked from DziugasRam/bs-replays-ai-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
54 lines (41 loc) · 1.79 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from data_processing import get_map_info
from infer_publish import getMapAccForHits, predictHitsForMap, scaleFarmability
from ppCurve.Tech_Calculator.tech_calc import mapCalculation
from setup_flask import app
from setup_flask import cache
@app.after_request
def add_header(response):
response.cache_control.max_age = 60*60
return response
@app.route("/")
def index():
return "hi"
@app.route('/<hash>/<characteristic>/<diff>')
def api_get_ratings(hash, characteristic, diff):
modifiers = [
["SS", "0.85"],
["none", "1"],
["FS", "1.2"],
["SFS", "1.5"],
]
results = {}
for name, timescale in modifiers:
results[name] = get_bl_ratings(hash, characteristic, diff, timescale)
return results
@app.route('/<hash>/<characteristic>/<diff>/<timescale>')
def api_get_rating(hash, characteristic, diff, timescale):
return get_bl_ratings(hash, characteristic, diff, timescale)
@cache.memoize()
def get_bl_ratings(hash, characteristic, diff, timescale):
accs, noteTimes, free_points = predictHitsForMap(hash.lower(), characteristic, int(diff), exclude_dots=False, time_scale=float(timescale))
AIacc = getMapAccForHits(accs, free_points)
adjustedAIacc = scaleFarmability(AIacc, len(accs), (noteTimes[-1] - noteTimes[0])+15)
AIacc = adjustedAIacc
map_info = get_map_info(hash.lower(), characteristic, int(diff))
lack_map_calculation = mapCalculation(map_info["map_json"], map_info["bpm"] * float(timescale), False, False)
# temp = lack_map_calculation['balanced_pass'] ** (timescale / 14 + 1.005) / 1.26
# if temp > lack_map_calculation['balanced_pass']:
# lack_map_calculation['balanced_pass'] = temp
return { "lack_map_calculation": lack_map_calculation, "AIacc": AIacc }
if __name__ == '__main__':
app.run()