Skip to content

Commit

Permalink
log_event.php failing should not break the game
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Oct 3, 2024
1 parent f7a77b0 commit a3fd705
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
customize number of pitchers in rotation https://discord.com/channels/290013534023057409/944392892905037885/1291306004495204363
- use this to set the max pFatigue value in play.ts
- use in UI for how many starting pitchers are shown in depth chart
- use in getStartingPitcher
- use in auto sorting pitcher depth chart

best teams option in legends mode
- iterate over teams, compute ovr, drop ones who don't make the top 30 - is this too slow?

Expand Down
20 changes: 20 additions & 0 deletions src/common/analyticsEventLocal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ACCOUNT_API_URL } from "./constants";
import fetchWrapper from "./fetchWrapper";

export const analyticsEventLocal = async (
type: "new_league" | "completed_season",
) => {
try {
await fetchWrapper({
url: `${ACCOUNT_API_URL}/log_event.php`,
method: "POST",
data: {
sport: process.env.SPORT,
type,
},
credentials: "include",
});
} catch (error) {
console.error(error);
}
};
13 changes: 2 additions & 11 deletions src/ui/views/NewLeague/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
WEBSITE_ROOT,
unwrapGameAttribute,
LEAGUE_DATABASE_VERSION,
ACCOUNT_API_URL,
fetchWrapper,
} from "../../../common";
import {
ActionButton,
Expand Down Expand Up @@ -54,6 +52,7 @@ import type { Settings } from "../../../worker/views/settings";
import type { BasicInfo } from "../../../worker/api/leagueFileUpload";
import { SelectSeasonRange } from "./SelectSeasonRange";
import { orderBy } from "../../../common/utils";
import { analyticsEventLocal } from "../../../common/analyticsEventLocal";

const animationVariants = {
visible: {
Expand Down Expand Up @@ -888,15 +887,7 @@ const NewLeague = (props: View<"newLeague">) => {
league_id: lid,
});
if (window.enableLogging) {
fetchWrapper({
url: `${ACCOUNT_API_URL}/log_event.php`,
method: "POST",
data: {
sport: process.env.SPORT,
type: "new_league",
},
credentials: "include",
});
analyticsEventLocal("new_league");
}

realtimeUpdate([], `/l/${lid}`);
Expand Down
35 changes: 14 additions & 21 deletions src/worker/core/phase/newPhaseBeforeDraft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ACCOUNT_API_URL, PLAYER, fetchWrapper } from "../../../common";
import { PLAYER } from "../../../common";
import { draft, player, season, team, league } from "..";
import { idb } from "../../db";
import {
Expand All @@ -25,6 +25,7 @@ import type {
import setGameAttributes from "../league/setGameAttributes";
import { doExpand, doRelocate } from "./relocateExpand";
import addAward from "../player/addAward";
import { analyticsEventLocal } from "../../../common/analyticsEventLocal";

const INFLATION_GAME_ATTRIBUTES = [
"salaryCap",
Expand Down Expand Up @@ -559,27 +560,19 @@ const newPhaseBeforeDraft = async (
riggedLottery: undefined,
});

toUI(
"analyticsEvent",
[
"completed_season",
{
season: g.get("season"),
league_id: g.get("lid"),
},
],
conditions,
);
if (env.enableLogging) {
fetchWrapper({
url: `${ACCOUNT_API_URL}/log_event.php`,
method: "POST",
data: {
sport: process.env.SPORT,
type: "completed_season",
},
credentials: "include",
});
toUI(
"analyticsEvent",
[
"completed_season",
{
season: g.get("season"),
league_id: g.get("lid"),
},
],
conditions,
);
analyticsEventLocal("completed_season");
}

return {
Expand Down

0 comments on commit a3fd705

Please sign in to comment.