PittAPI icon indicating copy to clipboard operation
PittAPI copied to clipboard

Find out the state number for "Out of Service" in `lab.py`

Open tianyizheng02 opened this issue 1 year ago • 1 comments

In lab.py, the comments state that there are 4 possible states for lab computers: "off", "available", "in use", and "out of service". We know that the first three states correspond to 0, 1, and 2 in the JSON API data, but we don't know the number corresponding to "out of service", at least not for certain. Currently, the code looks like https://github.com/pittcsc/PittAPI/blob/684d056d362dbb1bb55b1176ee95b095d21bc597/pittapi/lab.py#L105-L113 and ideally we should have

for computer_info in lab_data["state"].values():
    if computer_info["up"] == 0:
        off_computers += 1
    elif computer_info["up"] == 1:
        available_computers += 1
    elif computer_info["up"] == 2:
        in_use_computers += 1
    elif computer_info["up"] == UNKNOWN:
        out_of_service_computers += 1
    else:
        # Raise some kind of error

We should figure out this number somehow. By documenting it, we can handle the "out of service" case correctly and also test the case.

tianyizheng02 avatar Aug 11 '24 05:08 tianyizheng02

It's 3. From the keyserve client JS:

O = [
  {
    off: 'free used gone',
    on: 'down',
    order: '1'
  },
  {
    off: 'down used gone',
    on: 'free',
    order: '0'
  },
  {
    off: 'down free gone',
    on: 'used',
    order: '2'
  },
  {
    off: 'down free used',
    on: 'gone',
    order: '3'
  }
]

var C = O[P.up] || O[3]

up in the status dict is the index into O, so 3 is "gone", aka out of service.

winterqt avatar Sep 02 '24 03:09 winterqt