<<<<<<< HEAD
import polars as pl
from matplotlib import pyplot as plt
import numpy as np
import survey
import tkinter as tk
from tkinter import filedialog

# function to open file as df
def make_df(file):
    try:
        print("Trying to create dataframe from csv...")
        df = pl.read_csv(file)
        print("Dataframe created from csv.")
        return df
    except:
        print("Failed to create dataframe from csv.")
        return 0

def make_timeseries_plot(df,time,time_series_input):
    num_plots = len(time_series_input)
    fig = plt.subplots(1,num_plots)
    for i in range(num_plots):
        plt.subplot(i)
        plt.plot(new_df[time]-new_df[time][0],new_df[time_series_input][i])
        plt.xlabel(time_units)
        plt.ylabel(time_series_input_units[i])
        plt.title(time_series_input[i])
    
    plt.show()

# casts a polars df into floats
def cast_df_to_float(df):
    new_df = df.with_columns([pl.col(col).cast(pl.Float64) for col in df.columns])
    return new_df

root = tk.Tk()
root.withdraw()  # hide the root window

file_path = filedialog.askopenfilename(initialdir="/", title="Select a File", filetypes=(("CSV's", "*.csv"), ("All files", "*.*")))

print(file_path)

# filename = input("Enter file path: ")
df = make_df(file_path)

time = "INS1_UNIX_TIME_SECONDS"

while True:
    # time_series_input = input("Enter timeseries variable: ")

    opt = df.columns
    indexes = list(survey.routines.basket("Please choose an option or type a keyword: ",options=opt))
    time_series_input = []
    for item in indexes:
        time_series_input.append(opt[item])
    print(f"You selected: {time_series_input}")

    newdf_cols = time_series_input[:]
    newdf_cols.append(time)

    new_df = df[newdf_cols]
    time_units = new_df[time][0]
    time_series_input_units = new_df[time_series_input][0]

    # new_filename = "output" + time_series_input + ".png"

    try:
        new_df = cast_df_to_float(new_df)
        make_timeseries_plot(df,time,time_series_input)
    except:
        new_df = new_df.shift(-1)
        try:
            new_df = cast_df_to_float(new_df)
        except:
            print("Something went wrong...try a different variable?")
=======
import polars as pl
import os
from matplotlib import pyplot as plt
import numpy as np
import survey
import tkinter as tk
from tkinter import filedialog

# function to open file as df
def make_df(file):
    try:
        print("Trying to create dataframe from csv...")
        df = pl.read_csv(file)
        print("Dataframe created from csv.")
        return df
    except:
        print("Failed to create dataframe from csv.")
        return 0

root = tk.Tk()
root.withdraw()  # hide the root window

file_path = filedialog.askopenfilename(initialdir="/", title="Select a File", filetypes=(("CSV's", "*.csv"), ("All files", "*.*")))

print(file_path)

# filename = input("Enter file path: ")
df = make_df(file_path)

time = "INS1_UNIX_TIME_SECONDS"

while True:
    # time_series_input = input("Enter timeseries variable: ")

    opt = df.columns
    index = survey.routines.select("Please choose an option or type a keyword: ",options=opt)
    time_series_input = opt[index]
    print(f"You selected: {time_series_input}")

    new_df = df[time,time_series_input]
    time_units = new_df[time][0]
    time_series_input_units = new_df[time_series_input][0]

    # new_filename = "output" + time_series_input + ".png"

    try:
        new_df = new_df.with_columns([pl.col(col).cast(pl.Float64) for col in new_df.columns])
    except:
        new_df = new_df.shift(-1)
        try:
            new_df = new_df.with_columns([pl.col(col).cast(pl.Float64) for col in new_df.columns])
            plt.plot(new_df[time]-new_df[time][0],new_df[time_series_input])
            plt.xlabel(time_units)
            plt.ylabel(time_series_input_units)
            plt.title(time_series_input)
            plt.show()
        except:
            print("Something went wrong...try a different variable?")


print("Script finished. Press Enter to exit...")
input()
>>>>>>> ebac091896f9d9fd44ed5b44ad3c4b4ae5a38f21
