speedcontrol / nodecg-speedcontrol

NodeCG bundle to help facilitate the running of speedrunning marathons, including overlays.
MIT License
44 stars 34 forks source link

Updating Oengus schedule #105

Open gaeldemarseille opened 3 years ago

gaeldemarseille commented 3 years ago

New listener updateOengusSchedule Updating Oengus scheduleListener that will receive data with the marathon name and an Oengus schedule with runs that will be updated on Oengus. Only the runs included will be modified (matching on id) and you cannot add nor delete runs

The updating logic should be done on a marathon bundle.

example of implementation to edit the schedule, changing the estimate of the current run to its finished time and the setup time to make so the next run is set to start now

  function updateSchedule() {
    var runFinishTimes = nodecg.readReplicant('runFinishTimes', speedcontrolBundle);
    var runDataActiveRun = nodecg.readReplicant('runDataActiveRun', speedcontrolBundle);

    if (!runDataActiveRun) {
      return Promise.reject('no active run');
    }
    if (!runDataActiveRun.externalID) {
      return Promise.reject('no externalID');
    }

    if (!runDataActiveRun.scheduledS) {
      return Promise.reject('no scheduledS');
    }

    if (!runFinishTimes[runDataActiveRun.id]) {
      return Promise.reject('run not finished');
    }

    var activeRunFinishedTimeInSeconds = Math.floor(runFinishTimes[runDataActiveRun.id].milliseconds / 1000);
    var finish = Math.floor(Date.now() / 1000);

    if (runDataActiveRun.scheduledS > finish) {
      return Promise.reject('start>finish');
    }
    var activeRunSetupTimeInSeconds = finish - runDataActiveRun.scheduledS - activeRunFinishedTimeInSeconds;
    if (activeRunSetupTimeInSeconds < 0) {
      return Promise.reject('setupTimeInSeconds<0');
    }

    var data = {
      marathonName: marathonName,
      schedule: {
        id: 0,
        lines: [
          {
            id: parseInt(runDataActiveRun.externalID),
            estimate: 'PT' + activeRunFinishedTimeInSeconds + 'S',
            setupTime: 'PT' + activeRunSetupTimeInSeconds + 'S',
          }
        ]
      }
    }

    const speedcontrol = nodecg.extensions[speedcontrolBundle];
    return speedcontrol.sendMessage('updateOengusSchedule', data)
  }
}
zoton2 commented 3 years ago

Did you end up using this for an event and did it work well?

Also, I've done some restructuring to this bundle recently that will show some conflicts on this PR. I will happily fix them myself though as I knew something like that was going to happen.

gaeldemarseille commented 2 years ago

Did you end up using this for an event and did it work well?

Also, I've done some restructuring to this bundle recently that will show some conflicts on this PR. I will happily fix them myself though as I knew something like that was going to happen.

Sorry for the very late reply, we didn't end up using it for GTAM21 as we needed to import from horaro for the customData. For GTAM22 we plan on using it since now Oengus support customData.

I also did some cleanups in the code, one thing I'm not sure on is adding exporting schemas/reused/ScheduleImportStatus.json even though horaro doesn't have export feature built in that PR or if I should use different schema for oengus and horaro

gaeldemarseille commented 2 years ago

This was used succesfully during GTAMarathon 2022 (https://oengus.io/en-GB/marathon/gtam2022/schedule).