Changeset 24dd246 in flowtimer


Ignore:
Timestamp:
08/24/24 00:22:09 (9 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
guix
Children:
5f4ef8e
Parents:
0ec1bff
Message:

to_json added

Signed-off-by: Enrico Schwass <ennoausberlin@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • flowtimer/Schedule.py

    r0ec1bff r24dd246  
    7171
    7272    def to_json(self):
    73         return json.dumps(self.__dict__)
     73        def serialize_block(block):
     74            if not block.is_sequence:
     75                return {"type": "Phase", "title": block.title, "initial_ticks": block.initial_ticks}
     76            if block.is_sequence:
     77                return {
     78                    "type": "Sequence",
     79                    "title": block.title,
     80                    "sequence": [serialize_block(phase) for phase in block.sequence],
     81                    "initial_repetitions": block.initial_repetitions
     82                }
     83            raise TypeError(f"Unknown block type: {type(block)}")
     84
     85        return json.dumps({
     86            "title": self.title,
     87            "blocks": [serialize_block(block) for block in self.blocks]
     88        })
    7489
    7590    def start(self):
     
    108123                self.current_block = self.upcoming_blocks()[0]
    109124            return
    110 
    111         print("Jump to next block")
    112125        index = self.blocks.index(self.current_block)
    113126        self.current_block = self.blocks[index+1]
Note: See TracChangeset for help on using the changeset viewer.