#!/usr/bin/env python3

import os
import cv2
import glob
from matplotlib import pyplot as plt
import numpy as np

def collage():  
    myFiles = glob.glob('*.txt')
    a=0
    for i in range(len(myFiles)):
        image1=cv2.imread(f'arrival_results_{myFiles[a][:9]}.csv_ipd.plot.png')
        image2=cv2.imread(f'arrival_results_{myFiles[a][:9]}.csv_cdf.plot.png')
        image3=cv2.imread(f'departure_results_{myFiles[a][:9]}.csv_ipd.plot.png')
        image4=cv2.imread(f'departure_results_{myFiles[a][:9]}.csv_cdf.plot.png')
        Horizontal1=np.hstack([image1,image3])
        Horizontal2=np.hstack([image2,image4])
        Vertical_attachment=np.vstack([Horizontal1,Horizontal2])
        cv2.imwrite(f"plots_{myFiles[a][:9]}.csv.png",Vertical_attachment)
        cv2.waitKey(1)
        cv2.destroyAllWindows()
        a+=1
os.chdir('convShaper2_cerberus')
p=os.listdir(os.getcwd())
c=0
for i in range(len(p)):
    try:
        os.chdir(p[c])
        c=c+1
        collage()
    except NotADirectoryError:
        pass
    except FileNotFoundError:
        pass
    os.chdir('..')

os.chdir('..')
os.chdir('convShaper2_convSrc3')
p=os.listdir(os.getcwd())
d=0
for i in range(len(p)):
    try:
        os.chdir(p[d])
        d+=1
        collage()
    except NotADirectoryError:
        pass
    except FileNotFoundError:
        pass
    os.chdir('..')

os.chdir('..')
os.chdir('convSrc3_cerberus')

p=os.listdir(os.getcwd())
e=0
for i in range(len(p)):
    try:
        os.chdir(p[e])
        e+=1
        collage()
    except NotADirectoryError:
        pass
    except FileNotFoundError:
        pass
    os.chdir('..')
print("INFO: Done with the graphs, check them in the respective directories\n")
