-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (35 loc) · 1.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
import numpy as np
import os
import plotly.express as px
global DIR
DIR = os.getcwd()
def get_fs(df, unit = 'milliseconds'):
# Converting to UNIX time for better calculations
time = (pd.to_datetime(df.TIME) - pd.Timestamp("1970-01-01")) // pd.Timedelta(1, unit)
if unit == 'milliseconds':
k = 10**3
else:
raise ValueError(f"Unit: {unit}, must be miliseconds for now")
return 1/np.mean(np.diff(time)/k)
def single_file():
file = input("Entre o nome do arquivo\n")
if file in os.listdir(DIR):
if file.endswith(".csv"):
df = pd.read_csv(os.path.join(DIR,file))
# Add new column with only time
df['time'] = pd.to_datetime(df.TIME).dt.strftime('%H:%M:%S')
print(df['time'])
elementos = list(df.columns)
grafico = input(f"\n\n{elementos}\n\n\tEscolha dentre as possibilidades acima\n")
if grafico not in elementos:
raise ValueError("Valor escolhido nao existente!")
fig = px.line(df, x='time', y=grafico,
title = f"<b>{grafico}</b><br><sup>Freq. Amostragem = {get_fs(df):.3f}</sup>")
fig.show()
else:
raise NameError(f'Arquivo {file} nao existe')
def main():
single_file()
if __name__ == "__main__":
main()