Ron Au commited on
Commit
2d467fb
1 Parent(s): 2ef32c5

feat(stats): Improve usability of stats and logs

Browse files
Files changed (2) hide show
  1. app.py +11 -4
  2. static/js/index.js +3 -1
app.py CHANGED
@@ -14,6 +14,10 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
14
 
15
  card_logs = []
16
 
 
 
 
 
17
 
18
  @app.head('/')
19
  @app.get('/')
@@ -22,8 +26,11 @@ def index() -> FileResponse:
22
 
23
 
24
  @app.get('/new_card')
25
- def new_card() -> Dict[str, Union[Details, str]]:
26
- card_logs.append(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()))
 
 
 
27
 
28
  details: Details = rand_details()
29
 
@@ -33,11 +40,11 @@ def new_card() -> Dict[str, Union[Details, str]]:
33
  }
34
 
35
 
36
- @app.get('/stats')
37
  def stats() -> Dict[str, Union[int, object]]:
38
  return {**get_stats(), **{"cards_served": len(card_logs)}}
39
 
40
 
41
- @app.get('/logs')
42
  def logs() -> List[str]:
43
  return card_logs
 
14
 
15
  card_logs = []
16
 
17
+ # card_logs = [
18
+ # {pulls: 1, datetime: time()}
19
+ # ]
20
+
21
 
22
  @app.head('/')
23
  @app.get('/')
 
26
 
27
 
28
  @app.get('/new_card')
29
+ def new_card(pull: int) -> Dict[str, Union[Details, str]]:
30
+ card_logs.append({
31
+ "pull": pull,
32
+ "datetime": strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())
33
+ })
34
 
35
  details: Details = rand_details()
36
 
 
40
  }
41
 
42
 
43
+ @app.get('/stats.json')
44
  def stats() -> Dict[str, Union[int, object]]:
45
  return {**get_stats(), **{"cards_served": len(card_logs)}}
46
 
47
 
48
+ @app.get('/logs.json')
49
  def logs() -> List[str]:
50
  return card_logs
static/js/index.js CHANGED
@@ -9,6 +9,7 @@ let trainerName;
9
  let useTrainerName = true;
10
  let generating = false;
11
  let mousemoveHandlerForPreviousCard;
 
12
 
13
  const generate = async () => {
14
  if (generating) {
@@ -36,7 +37,8 @@ const generate = async () => {
36
 
37
  await new Promise((resolve) => setTimeout(resolve, 5_000));
38
 
39
- const resolvedCardUrl = new URL('new_card', document.location.origin + document.location.pathname).href;
 
40
  const cardResponse = await fetch(resolvedCardUrl);
41
  const card = await cardResponse.json();
42
 
 
9
  let useTrainerName = true;
10
  let generating = false;
11
  let mousemoveHandlerForPreviousCard;
12
+ let pulls = 0;
13
 
14
  const generate = async () => {
15
  if (generating) {
 
37
 
38
  await new Promise((resolve) => setTimeout(resolve, 5_000));
39
 
40
+ pulls += 1;
41
+ const resolvedCardUrl = new URL(`new_card?pull=${pulls}`, document.location.origin + document.location.pathname).href;
42
  const cardResponse = await fetch(resolvedCardUrl);
43
  const card = await cardResponse.json();
44