Skip to content

Commit

Permalink
i1027: requested updates per PR review, including:
Browse files Browse the repository at this point in the history
- use concrete data types rather than "any".
- remove debug statements.
- use "const" instead of "let" in variable declarations where
applicable.
  • Loading branch information
clevengr committed Feb 20, 2025
1 parent 89e3952 commit 012426e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 48 deletions.
51 changes: 7 additions & 44 deletions projects/WTI-UI/src/app/modules/core/services/contest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ContestProblem } from '../models/contest-problem';
import { ContestClock } from '../models/contest-clock';
import { ContestTimerService } from './contestTimer.service' ;
import { Clarification } from '../models/clarification';
import { DEBUG_MODE } from 'src/constants';
import { RESYNC_INTERVAL_IN_MINUTES } from 'src/constants';

/**
Expand Down Expand Up @@ -41,10 +40,6 @@ export class ContestService extends IContestService {
constructor(private _httpClient: HttpClient) {
super();

if (DEBUG_MODE) {
console.log ("Executing ContestService constructor; instance ID = ", this.uniqueId) ;
}

this.standingsAreCurrent = false;

//set a timer to auto-refresh the contest clock displays, at a rate defined in src/constants
Expand All @@ -53,9 +48,6 @@ export class ContestService extends IContestService {
setInterval(
//execute this function at the following-specified interval:
() => {
if (DEBUG_MODE) {
console.log("ContestService: resyncing clocks with PC2 Server");
}
this.updateLocalContestClockFromServer();
},
RESYNC_INTERVAL_IN_MINUTES * 60 * 1000 // timer interval in msec: minutes * (secs-per-min) * (msec-per-sec)
Expand All @@ -79,9 +71,6 @@ export class ContestService extends IContestService {
}

getIsContestRunning(): Observable<boolean> {
if (DEBUG_MODE) {
console.log ("ContestService.getIsContestRunning(): invoking HTTP get(.../contest.isRunning) WTI-API endpoint") ;
}
return this._httpClient.get<boolean>(`${environment.baseUrl}/contest/isRunning`);
}

Expand All @@ -93,20 +82,10 @@ export class ContestService extends IContestService {
}

getStandings(): Observable<String> {
if (DEBUG_MODE) {
console.log("ContestService.getStandings():")
}
if (!this.standingsAreCurrent) {
if (DEBUG_MODE) {
console.log ("Standings are out of date; fetching new standings");
}
this.cachedStandings = this._httpClient.get<String>(`${environment.baseUrl}/contest/scoreboard`);
this.standingsAreCurrent = true ;
} else {
if (DEBUG_MODE) {
console.log("Returning cached standings");
}
}
}
return this.cachedStandings ;
}

Expand All @@ -126,20 +105,14 @@ export class ContestService extends IContestService {
updateLocalContestClockFromServer () {

//get the actual contest clock info from the PC2 server via the Contest Service (which gets it via the WTI Server and its PC2 API)
if (DEBUG_MODE) {
console.log(" Invoking ContestService.getContestClock(), subscribing for HTTP callback result")
}
this.getContestClock()
.subscribe(
(data: ContestClock) => {
if (!data) {
(contestClock: ContestClock) => {
if (!contestClock) {
console.error ("ContestService.updateLocalContestClockFromServer() getContestClock() subscription callback: unable to get ContestClock from PC2 API via ContestService!");
} else {
if (DEBUG_MODE) {
console.log("ContestService.updateLocalContestClockFromServer(): got callback from getContestClock() subscription.");
}
//install the received contest clock data into the ContestService's ContestClock
this.installNewContestClock(data);
this.installNewContestClock(contestClock);
}
},
(error: unknown) => {
Expand All @@ -155,20 +128,16 @@ export class ContestService extends IContestService {
* if the received data indicates the clock should be running it starts the ContestTimer (which then genrates a "clock tick"
* once per second to update the clock displays).
*/
installNewContestClock(data: any) {
installNewContestClock(data: ContestClock) {

//copy the data fields (received from the PC2 Server via the WTI-API) into a new ContestService ContestClock object
let newContestClock = new ContestClock();
newContestClock.isRunning = data.running ;
newContestClock.contestLengthSecs = data.contestLengthInSecs ;
newContestClock.isRunning = data.isRunning ;
newContestClock.contestLengthSecs = data.contestLengthSecs ;
newContestClock.elapsedSecs = data.elapsedSecs ;
newContestClock.wallClockStartTime = data.wallClockStartTime ;

//save the new clock
if (DEBUG_MODE) {
console.log("ContestService (id", this.uniqueId, ").installNewContestClock(): replacing Contest Clock with:");
console.log(newContestClock);
}
this.contestClock = newContestClock;

//pull the values out of the updated clock
Expand All @@ -179,9 +148,6 @@ export class ContestService extends IContestService {

//shut off timer if it is running (otherwise we can't update the elapsed/remaining time values)
if (this.contestTimer.isTimerRunning) {
if (DEBUG_MODE) {
console.log("ContestService (id", this.uniqueId, ").installNewContestClock(): stopping timer");
}
this.contestTimer.stopTimer();
}

Expand All @@ -191,9 +157,6 @@ export class ContestService extends IContestService {

//restart the timer if the new contest clock values indicate it should be running
if (timerShouldBeStarted) {
if (DEBUG_MODE) {
console.log("ContestService (id", this.uniqueId, ").installNewContestClock(): starting timer");
}
this.contestTimer.startTimer();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class AppHeaderComponent {
/* Return a string containing the "team id" -- that is, the PC2 team account number with
the leading "team" removed */
get teamId(): string {
let acctId = this._authService.username;
let teamId = acctId.substr(4);
const acctId = this._authService.username;
const teamId = acctId.substr(4);
return teamId;
}

Expand All @@ -44,12 +44,12 @@ export class AppHeaderComponent {


getElapsedSecs(): number {
let secs = this._contestService.getElapsedSecs() ;
const secs = this._contestService.getElapsedSecs() ;
return secs;
}

getRemainingSecs(): number {
let secs = this._contestService.getRemainingSecs() ;
const secs = this._contestService.getRemainingSecs() ;
return secs;
}
}

0 comments on commit 012426e

Please sign in to comment.