MCPcopy
hub / github.com/slowlydev/f1-dash / findYellowSectors

Function findYellowSectors

dashboard/src/lib/map.ts:72–105  ·  view source on GitHub ↗
(messages: Message[] | undefined)

Source from the content-addressed store, hash-verified

70};
71
72export const findYellowSectors = (messages: Message[] | undefined): Set<number> => {
73 const msgs = messages?.sort(sortUtc).filter((msg) => {
74 return msg.Flag === "YELLOW" || msg.Flag === "DOUBLE YELLOW" || msg.Flag === "CLEAR";
75 });
76
77 if (!msgs) {
78 return new Set();
79 }
80
81 const done: Set<number> = new Set();
82 const sectors: Set<number> = new Set();
83 for (let i = 0; i < msgs.length; i++) {
84 const msg = msgs[i];
85 if (msg.Scope === "Track" && msg.Flag !== "CLEAR") {
86 // Spam with sectors so all sectors are yellow no matter what
87 // number of sectors there really are
88 for (let j = 0; j < 100; j++) {
89 sectors.add(j);
90 }
91 return sectors;
92 }
93 if (msg.Scope === "Sector") {
94 if (!msg.Sector || done.has(msg.Sector)) {
95 continue;
96 }
97 if (msg.Flag === "CLEAR") {
98 done.add(msg.Sector);
99 } else {
100 sectors.add(msg.Sector);
101 }
102 }
103 }
104 return sectors;
105};
106
107type RenderedSector = {
108 number: number;

Callers 1

MapFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected