Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Oengus schedule #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gaeldemarseille
Copy link
Contributor

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
Copy link
Contributor

zoton2 commented Jun 17, 2021

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
Copy link
Contributor Author

gaeldemarseille commented Mar 24, 2022

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

Listener that will receive data with an Oengus schedule with lines that will be updated on Oengus.
Only the runs included will be modified (matching on id) and you cannot add nor delete runs nor nullify fields
@gaeldemarseille gaeldemarseille force-pushed the feature/oengus-update branch from efa9c32 to 259704d Compare May 7, 2022 13:20
@gaeldemarseille
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants