Skip to content

Commit 643f0a0

Browse files
committed
refactor type names
1 parent 12b500d commit 643f0a0

File tree

13 files changed

+61
-61
lines changed

13 files changed

+61
-61
lines changed

global.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ interface NeutralItemHistory {
206206
}
207207

208208
// Data to pass to insertMatch from GC
209-
interface GcMatch {
209+
interface GcData {
210210
match_id: number;
211211
cluster: number;
212212
replay_salt: number;
@@ -223,7 +223,7 @@ interface GcPlayer {
223223
account_id?: number;
224224
}
225225

226-
interface ParserMatch {
226+
interface ParsedData {
227227
match_id: number;
228228
// Needed to determine whether to insert pro match data
229229
leagueid: number;
@@ -289,7 +289,7 @@ type GcDataJob = {
289289
pgroup: PGroup;
290290
};
291291

292-
type CountsJob = ApiMatch;
292+
type CountsJob = ApiData;
293293
type ScenariosJob = string;
294294
type CacheJob = string;
295295

@@ -522,7 +522,7 @@ type ParseExtraData = {
522522
origin?: DataOrigin;
523523
pgroup: PGroup;
524524
url: string;
525-
gcMatch: GcMatch;
525+
gcMatch: GcData;
526526
};
527527

528528
type HistoryType = {
@@ -531,8 +531,8 @@ type HistoryType = {
531531
player_slot: number;
532532
};
533533

534-
type ApiMatchResponse = typeof import('./test/data/details_api.json');
535-
type ApiMatch = ApiMatchResponse['result'] & {
534+
type ApiDataResponse = typeof import('./test/data/details_api.json');
535+
type ApiData = ApiDataResponse['result'] & {
536536
picks_bans?: {
537537
hero_id: number;
538538
order: number;
@@ -541,10 +541,10 @@ type ApiMatch = ApiMatchResponse['result'] & {
541541
radiant_team_id?: number;
542542
dire_team_id?: number;
543543
};
544-
type ApiPlayer = ApiMatch['players'][number] & {
544+
type ApiDataPlayer = ApiData['players'][number] & {
545545
ability_upgrades_arr?: number[];
546546
};
547-
type InsertMatchInput = ApiMatch | GcMatch | ParserMatch;
547+
type InsertMatchInput = ApiData | GcData | ParsedData;
548548

549549
type PeersCount = Record<
550550
string,

svc/backfill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ runInLoop(async function backfill() {
5252
// write to blobstore, process the blob using same function as insertMatch
5353
try {
5454
const insertResult = await Promise.all(
55-
resp.map(async (origMatch: ApiMatch) => {
55+
resp.map(async (origMatch: ApiData) => {
5656
const match = transformMatch(origMatch);
5757
const result = await blobArchive.archivePut(
5858
match.match_id + '_api',

svc/fetcher/ApiFetcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { insertMatch } from '../util/insert.ts';
99
import { config } from '../../config.ts';
1010
import db from '../store/db.ts';
1111

12-
export class ApiFetcher extends MatchFetcher<ApiMatch> {
12+
export class ApiFetcher extends MatchFetcher<ApiData> {
1313
useSavedData = Boolean(config.DISABLE_REAPI);
14-
getData = async (matchId: number): Promise<ApiMatch | null> => {
14+
getData = async (matchId: number): Promise<ApiData | null> => {
1515
let data = null;
1616
const archive = await blobArchive.archiveGet(`${matchId}_api`);
17-
data = archive ? (JSON.parse(archive.toString()) as ApiMatch) : null;
17+
data = archive ? (JSON.parse(archive.toString()) as ApiData) : null;
1818
return data;
1919
};
2020
fetchData = async (
@@ -96,7 +96,7 @@ export class ApiFetcher extends MatchFetcher<ApiMatch> {
9696
url,
9797
});
9898
const match = body.result.matches.find(
99-
(m: ApiMatch) => m.match_id === matchId,
99+
(m: ApiData) => m.match_id === matchId,
100100
);
101101
if (!match) {
102102
redisCount('backfill_fail');

svc/fetcher/GcdataFetcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { blobArchive } from '../store/archive.ts';
1010
import { MatchFetcher } from './base.ts';
1111
import config from '../../config.ts';
1212

13-
export class GcdataFetcher extends MatchFetcher<GcMatch> {
13+
export class GcdataFetcher extends MatchFetcher<GcData> {
1414
savedDataMetricName: MetricName = 'regcdata';
1515
useSavedData = Boolean(config.DISABLE_REGCDATA);
16-
getData = async (matchId: number): Promise<GcMatch | null> => {
16+
getData = async (matchId: number): Promise<GcData | null> => {
1717
let data = null;
1818
const archive = await blobArchive.archiveGet(`${matchId}_gcdata`);
19-
data = archive ? (JSON.parse(archive.toString()) as GcMatch) : null;
19+
data = archive ? (JSON.parse(archive.toString()) as GcData) : null;
2020
// Verify data integrity
2121
if (
2222
data?.match_id == null ||
@@ -103,7 +103,7 @@ export class GcdataFetcher extends MatchFetcher<GcMatch> {
103103
).length,
104104
}),
105105
);
106-
const matchToInsert: GcMatch = {
106+
const matchToInsert: GcData = {
107107
match_id: matchId,
108108
players,
109109
series_id: data.match.series_id,

svc/fetcher/ParsedFetcher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import axios from 'axios';
66
import { MatchFetcher } from './base.ts';
77
import config from '../../config.ts';
88

9-
export class ParsedFetcher extends MatchFetcher<ParserMatch> {
9+
export class ParsedFetcher extends MatchFetcher<ParsedData> {
1010
savedDataMetricName: MetricName = 'reparse';
1111
useSavedData = Boolean(config.DISABLE_REPARSE);
12-
getData = async (matchId: number): Promise<ParserMatch | null> => {
12+
getData = async (matchId: number): Promise<ParsedData | null> => {
1313
let data = null;
1414
const archive = await blobArchive.archiveGet(`${matchId}_parsed`);
15-
data = archive ? (JSON.parse(archive.toString()) as ParserMatch) : null;
15+
data = archive ? (JSON.parse(archive.toString()) as ParsedData) : null;
1616
return data;
1717
};
1818
fetchData = async (
@@ -36,11 +36,11 @@ export class ParsedFetcher extends MatchFetcher<ParserMatch> {
3636
// process: 3278ms (node processors/createParsedDataBlob.mjs < output.log)
3737
const parseUrl = await getRandomParserUrl(`/blob?replay_url=${url}`);
3838
console.log('[PARSER]', parseUrl);
39-
const resp = await axios.get<ParserMatch>(parseUrl, { timeout: 150000 });
39+
const resp = await axios.get<ParsedData>(parseUrl, { timeout: 150000 });
4040
if (!resp.data) {
4141
return { data: null, error: 'Parse failed' };
4242
}
43-
const result: ParserMatch = {
43+
const result: ParsedData = {
4444
...resp.data,
4545
match_id: matchId,
4646
leagueid,

svc/fullhistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function processFullHistory(job: FullHistoryJob) {
5858
// const heroArray = config.NODE_ENV === 'test' ? ['0'] : Object.keys(heroes);
5959
// const heroId = '0';
6060
// use steamapi via specific player history and specific hero id (up to 500 games per hero)
61-
const matchesToProcess: Record<string, ApiMatch> = {};
61+
const matchesToProcess: Record<string, ApiData> = {};
6262
let isMatchDataDisabled = null;
6363
// make a request for every possible hero
6464
const url = SteamAPIUrls.api_history({

svc/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ runInLoop(async function scanApi() {
6262
console.log('[API] match_seq_num:%s, matches:%s', seqNum, resp.length);
6363
console.time('insert');
6464
await Promise.all(
65-
resp.map(async (match: ApiMatch) => {
65+
resp.map(async (match: ApiData) => {
6666
// Optionally throttle inserts to prevent overload
6767
if (match.match_id % 100 >= Number(config.SCANNER_PERCENT)) {
6868
return;

svc/util/benchmarksUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const benchmarks: Record<
22
string,
3-
(m: ApiMatch | Match, p: ApiPlayer | Player) => number
3+
(m: ApiData | Match, p: ApiDataPlayer | Player) => number
44
> = {
55
gold_per_min(m, p) {
66
return p.gold_per_min;

svc/util/getMatchBlob.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { redisCount } from './utility.ts';
44
export async function getMatchBlob(
55
matchId: number,
66
fetchers: {
7-
apiFetcher: MatchFetcher<ApiMatch>;
8-
gcFetcher: MatchFetcher<GcMatch>;
9-
parsedFetcher: MatchFetcher<ParserMatch>;
7+
apiFetcher: MatchFetcher<ApiData>;
8+
gcFetcher: MatchFetcher<GcData>;
9+
parsedFetcher: MatchFetcher<ParsedData>;
1010
archivedFetcher: MatchFetcher<ParsedMatch> | null;
1111
},
1212
): Promise<[Match | ParsedMatch | null, GetMatchDataMetadata | null]> {
1313
let { apiFetcher, gcFetcher, parsedFetcher, archivedFetcher } = fetchers;
1414
let [api, gcdata, parsed, archived]: [
15-
ApiMatch | null,
16-
GcMatch | null,
17-
ParserMatch | null,
15+
ApiData | null,
16+
GcData | null,
17+
ParsedData | null,
1818
ParsedMatch | null | undefined,
1919
] = await Promise.all([
2020
apiFetcher.getData(matchId),

svc/util/insert.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export async function insertMatch(
149149
const match = transformMatch(origMatch);
150150
// Use the passed pgroup if gcdata or parsed, otherwise build it
151151
// Do this after removing anonymous account IDs
152-
const pgroup = options.pgroup ?? getPGroup(match as ApiMatch);
152+
const pgroup = options.pgroup ?? getPGroup(match as ApiData);
153153

154154
let isProTier = false;
155155
if ('leagueid' in match && match.leagueid) {
@@ -209,7 +209,7 @@ export async function insertMatch(
209209
// Only if API or parse data
210210
return;
211211
}
212-
if (options.type === 'api' && !isProMatch(match as ApiMatch)) {
212+
if (options.type === 'api' && !isProMatch(match as ApiData)) {
213213
// Check whether we care about this match for pro purposes
214214
// We need the basic match data to run the check, so only do it if type is api
215215
// console.log('[UPSERTMATCHPOSTGRES]: skipping due to check');
@@ -505,14 +505,14 @@ export async function insertMatch(
505505
// Update temporary match counts/hero rankings
506506
if (options.origin === 'scanner' && options.type === 'api') {
507507
await Promise.all([
508-
updateHeroRankings(match as ApiMatch),
509-
upsertMatchSample(match as ApiMatch),
510-
updateRecords(match as ApiMatch),
511-
updateLastPlayed(match as ApiMatch),
512-
updateHeroSearch(match as ApiMatch),
513-
updateHeroCounts(match as ApiMatch, isProTier),
514-
updateMatchCounts(match as ApiMatch),
515-
updateBenchmarks(match as ApiMatch),
508+
updateHeroRankings(match as ApiData),
509+
upsertMatchSample(match as ApiData),
510+
updateRecords(match as ApiData),
511+
updateLastPlayed(match as ApiData),
512+
updateHeroSearch(match as ApiData),
513+
updateHeroCounts(match as ApiData, isProTier),
514+
updateMatchCounts(match as ApiData),
515+
updateBenchmarks(match as ApiData),
516516
]);
517517
}
518518
}
@@ -537,7 +537,7 @@ export async function insertMatch(
537537
}
538538
async function queueMmr(match: InsertMatchInput) {
539539
// Trigger an update for player rank_tier if ranked match
540-
const arr = match.players.filter<ApiPlayer>((p): p is ApiPlayer => {
540+
const arr = match.players.filter<ApiDataPlayer>((p): p is ApiDataPlayer => {
541541
return Boolean(
542542
options.origin === 'scanner' &&
543543
options.type === 'api' &&
@@ -762,7 +762,7 @@ export async function upsertPlayerCaches(
762762
);
763763
}
764764

765-
async function updateHeroRankings(match: ApiMatch) {
765+
async function updateHeroRankings(match: ApiData) {
766766
if (!isSignificant(match)) {
767767
return;
768768
}
@@ -802,7 +802,7 @@ async function updateHeroRankings(match: ApiMatch) {
802802
);
803803
}
804804

805-
async function upsertMatchSample(match: ApiMatch) {
805+
async function upsertMatchSample(match: ApiData) {
806806
if (
807807
isSignificant(match) &&
808808
match.match_id % 100 < Number(config.PUBLIC_SAMPLE_PERCENT)
@@ -829,24 +829,24 @@ async function upsertMatchSample(match: ApiMatch) {
829829
}
830830
}
831831
async function updateRecord(
832-
field: keyof ApiMatch | keyof ApiPlayer,
833-
match: ApiMatch,
834-
player: ApiPlayer,
832+
field: keyof ApiData | keyof ApiDataPlayer,
833+
match: ApiData,
834+
player: ApiDataPlayer,
835835
) {
836836
redis.zadd(
837837
`records:${field}`,
838-
(match[field as keyof ApiMatch] ||
839-
player[field as keyof ApiPlayer]) as number,
838+
(match[field as keyof ApiData] ||
839+
player[field as keyof ApiDataPlayer]) as number,
840840
[match.match_id, match.start_time, player.hero_id].join(':'),
841841
);
842842
// Keep only 100 top scores
843843
redis.zremrangebyrank(`records:${field}`, '0', '-101');
844844
const expire = moment.utc().add(1, 'month').startOf('month').format('X');
845845
redis.expireat(`records:${field}`, expire);
846846
}
847-
async function updateRecords(match: ApiMatch) {
847+
async function updateRecords(match: ApiData) {
848848
if (isSignificant(match) && match.lobby_type === 7) {
849-
updateRecord('duration', match, {} as ApiPlayer);
849+
updateRecord('duration', match, {} as ApiDataPlayer);
850850
match.players.forEach((player) => {
851851
updateRecord('kills', match, player);
852852
updateRecord('deaths', match, player);
@@ -861,7 +861,7 @@ async function updateRecords(match: ApiMatch) {
861861
});
862862
}
863863
}
864-
async function updateLastPlayed(match: ApiMatch) {
864+
async function updateLastPlayed(match: ApiData) {
865865
const filteredPlayers = match.players.filter(
866866
(player) =>
867867
player.account_id && player.account_id !== getAnonymousAccountId(),
@@ -902,7 +902,7 @@ async function updateLastPlayed(match: ApiMatch) {
902902
/**
903903
* Update table storing heroes played in a game for lookup of games by heroes played
904904
* */
905-
async function updateHeroSearch(match: ApiMatch) {
905+
async function updateHeroSearch(match: ApiData) {
906906
const radiant = [];
907907
const dire = [];
908908
for (let i = 0; i < match.players.length; i += 1) {
@@ -934,7 +934,7 @@ async function updateHeroSearch(match: ApiMatch) {
934934
);
935935
}
936936

937-
async function updateHeroCounts(match: ApiMatch, isProTier: boolean) {
937+
async function updateHeroCounts(match: ApiData, isProTier: boolean) {
938938
// If match has leagueid, update pro picks and wins
939939
// If turbo, update picks and wins
940940
// Otherwise, update pub picks and wins if significant
@@ -996,13 +996,13 @@ async function updateHeroCounts(match: ApiMatch, isProTier: boolean) {
996996
}
997997
}
998998

999-
async function updateMatchCounts(match: ApiMatch) {
999+
async function updateMatchCounts(match: ApiData) {
10001000
await redisCount(`${match.game_mode}_game_mode` as MetricName);
10011001
await redisCount(`${match.lobby_type}_lobby_type` as MetricName);
10021002
await redisCount(`${match.cluster}_cluster` as MetricName);
10031003
}
10041004

1005-
async function updateBenchmarks(match: ApiMatch) {
1005+
async function updateBenchmarks(match: ApiData) {
10061006
if (
10071007
match.match_id % 100 < Number(config.BENCHMARKS_SAMPLE_PERCENT) &&
10081008
isSignificant(match)

0 commit comments

Comments
 (0)