# Path: grohoviz/publisher.py
# class Publisher:
#     def __init__(self, datadir: pathlib.Path, plotting_file: pathlib.Path):
#         self.datadir = datadir
#         self.plotting_file = plotting_file
#         self.datadir_last_changed = 0
#         self.plotting_file_last_changed = 0
# 
#         self.atlas = plotlib.Atlas(self.plotting_file)
#         self._animator = None
#         self.poll()
# 
#     def run(self):
#         self._animator = animation.FuncAnimation(
#             self.atlas.fig, self.poll, interval=10, blit=False, cache_frame_data=False
#         )
#         plt.show()
# 
#     def poll(self, frameNum=None):
#         datadir_last_changed = (self.datadir / manifest_file).stat().st_mtime
#         plotting_file_last_changed = self.plotting_file.stat().st_mtime
# 
#         should_reload_data = datadir_last_changed > self.datadir_last_changed
#         should_reload_plotfile = (
#             plotting_file_last_changed > self.plotting_file_last_changed
#         )
#         should_replot = False
# 
#         if should_reload_data:
#             self.reload_data()
#             self.datadir_last_changed = datadir_last_changed
#             should_replot = True
# 
#         if should_reload_plotfile:
#             self.atlas.update_description(
#                 yaml.load(open(self.plotting_file, "r"), Loader=Loader)
#             )
#             self.plotting_file_last_changed = plotting_file_last_changed
#             should_replot = True
# 
#         if should_replot:
#             self.replot()
# 
#     def reload_data(self):
#         lock = FileLock(self.datadir / lock_file)
#         with lock:
#             self.atlas.update_data(
#                 trajectories=datalib.load_data(self.datadir),
#                 bodies=yaml.load(
#                     (self.datadir / manifest_file).open("r"), Loader=Loader
#                 ),
#             )
#             ts = from_ts(self.atlas.bodies.get("time"))
#             sys.stderr.write(f"Reloaded sim: {ts}\n")
# 
#     def replot(self):
#         self.atlas.replot()
#         sys.stderr.write("Replotting\n")


import time
import argparse
import pathlib
import matplotlib.pyplot as plt
from grohoviz.publisher import Publisher




def main():
    parser = argparse.ArgumentParser(description="Plot simulation data")
    parser.add_argument("datadir", help="Directory with simulation data")

# Path: grohoviz/publisher.py
# class Publisher:
#     def __init__(self, datadir: pathlib.Path, plotting_file: pathlib.Path):
#         self.datadir = datadir
#         self.plotting_file = plotting_file
#         self.datadir_last_changed = 0
#         self.plotting_file_last_changed = 0
# 
#         self.atlas = plotlib.Atlas(self.plotting_file)
#         self._animator = None
#         self.poll()
# 
#     def run(self):
#         self._animator = animation.FuncAnimation(
#             self.atlas.fig, self.poll, interval=10, blit=False, cache_frame_data=False
#         )
#         plt.show()
# 
#     def poll(self, frameNum=None):
#         datadir_last_changed = (self.datadir / manifest_file).stat().st_mtime
#         plotting_file_last_changed = self.plotting_file.stat().st_mtime
# 
#         should_reload_data = datadir_last_changed > self.datadir_last_changed
#         should_reload_plotfile = (
#             plotting_file_last_changed > self.plotting_file_last_changed
#         )
#         should_replot = False
# 
#         if should_reload_data:
#             self.reload_data()
#             self.datadir_last_changed = datadir_last_changed
#             should_replot = True
# 
#         if should_reload_plotfile:
#             self.atlas.update_description(
#                 yaml.load(open(self.plotting_file, "r"), Loader=Loader)
#             )
#             self.plotting_file_last_changed = plotting_file_last_changed
#             should_replot = True
# 
#         if should_replot:
#             self.replot()
# 
#     def reload_data(self):
#         lock = FileLock(self.datadir / lock_file)
#         with lock:
#             self.atlas.update_data(
#                 trajectories=datalib.load_data(self.datadir),
#                 bodies=yaml.load(
#                     (self.datadir / manifest_file).open("r"), Loader=Loader
#                 ),
#             )
#             ts = from_ts(self.atlas.bodies.get("time"))
#             sys.stderr.write(f"Reloaded sim: {ts}\n")
# 
#     def replot(self):
#         self.atlas.replot()
#         sys.stderr.write("Replotting\n")


# Path: grohoviz/main.py
import time
import argparse
import pathlib
import matplotlib.pyplot as plt
from grohoviz.publisher import Publisher





def main():
    parser = argparse.ArgumentParser(description="Plot simulation data")
    parser.add_argument("datadir", help="Directory with simulation data")

    parser.add_argument("plotfile", help="File with plotting instructions")