|
6 | 6 |
|
7 | 7 | router = APIRouter() |
8 | 8 |
|
| 9 | + |
9 | 10 | @router.get( |
10 | 11 | "/surftimer/point_calc_finishedStages", |
11 | 12 | name="Count Player Finished Stages", |
@@ -88,3 +89,70 @@ def point_calc_finishedMaps( |
88 | 89 | set_cache(cache_key, xquery) |
89 | 90 |
|
90 | 91 | return xquery |
| 92 | + |
| 93 | + |
| 94 | +@router.get( |
| 95 | + "/surftimer/recalculatePoints", |
| 96 | + name="Points Recalculation", |
| 97 | + tags=["Refactored", "Points Calculation"], |
| 98 | +) |
| 99 | +def recalculatePoints( |
| 100 | + request: Request, |
| 101 | + response: Response, |
| 102 | + steamid32: str, |
| 103 | + style: int, |
| 104 | +): |
| 105 | + """Combines all the queries for point calculation into 1 endpoint""" |
| 106 | + tic = time.perf_counter() |
| 107 | + |
| 108 | + # Player Name for the selected Style |
| 109 | + player_name_query = selectQuery( |
| 110 | + surftimer.queries.sql_stray_point_calc_playerRankName.format(steamid32, style) |
| 111 | + ) |
| 112 | + if len(player_name_query) <= 0: |
| 113 | + response.status_code = status.HTTP_204_NO_CONTENT |
| 114 | + return response |
| 115 | + else: |
| 116 | + player_name_query = player_name_query.pop() |
| 117 | + # name = str(player_name_query[0]) |
| 118 | + |
| 119 | + ## Bonuses |
| 120 | + finished_bonuses_query = selectQuery( |
| 121 | + surftimer.queries.sql_stray_point_calc_countFinishedBonus.format( |
| 122 | + style, style, steamid32, style |
| 123 | + ) |
| 124 | + ) |
| 125 | + if len(finished_bonuses_query) <= 0: |
| 126 | + response.status_code = status.HTTP_204_NO_CONTENT |
| 127 | + return response |
| 128 | + |
| 129 | + ## Stages |
| 130 | + finished_stages_query = selectQuery( |
| 131 | + surftimer.queries.sql_stray_point_calc_finishedStages.format(steamid32, style) |
| 132 | + ) |
| 133 | + if len(finished_stages_query) <= 0: |
| 134 | + response.status_code = status.HTTP_204_NO_CONTENT |
| 135 | + return response |
| 136 | + |
| 137 | + ## Maps |
| 138 | + finished_maps_query = selectQuery( |
| 139 | + surftimer.queries.sql_stray_point_calc_finishedMaps.format( |
| 140 | + style, style, steamid32, style |
| 141 | + ) |
| 142 | + ) |
| 143 | + if len(finished_maps_query) <= 0: |
| 144 | + response.status_code = status.HTTP_204_NO_CONTENT |
| 145 | + return response |
| 146 | + |
| 147 | + # Create the JSON output |
| 148 | + output = { |
| 149 | + **player_name_query, # Replace with your desired name |
| 150 | + "maps": finished_maps_query, |
| 151 | + "stages": finished_stages_query, |
| 152 | + "bonuses": finished_bonuses_query, |
| 153 | + } |
| 154 | + |
| 155 | + toc = time.perf_counter() |
| 156 | + print(f"Execution time {toc - tic:0.4f}") |
| 157 | + |
| 158 | + return output |
0 commit comments