Last active
March 6, 2020 21:45
-
-
Save RedBlaze42/3f4b86086f3c2bfd2b694cb4dea71001 to your computer and use it in GitHub Desktop.
Python tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time,os | |
import matplotlib.pyplot as plt | |
import matplotlib.ticker as ticker | |
import matplotlib.dates as mdates | |
from datetime import datetime | |
import matplotlib | |
import locale | |
def plotter(x,y,path,y_text,title,unit): | |
locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")#Édite la locale vers le français pour avoir des jours de la semaines français | |
fig, ax = plt.subplots()#Crée le graphique | |
format = mdates.DateFormatter('%a %H:%M')#Indique le format de date à utiliser | |
for i,timestamp in enumerate(x):#Remplace les timestamp par des objets datetime | |
x[i]=datetime.fromtimestamp(timestamp) | |
plt.plot_date(x, y,linestyle='solid',ms=1)#Plot les données | |
plt.xlabel('Temps') | |
plt.ylabel(y_text) | |
plt.title(title) | |
maxDATA=indexMax(x,y)#Annotations min/max | |
minDATA=indexMin(x,y) | |
plt.annotate('Max: '+str(indexMax(x,y)[1])+unit,maxDATA,xytext=(10,10),textcoords='offset pixels',annotation_clip=True) | |
plt.annotate('Min: '+str(indexMin(x,y)[1])+unit,minDATA,xytext=(10,10),textcoords='offset pixels',annotation_clip=True) | |
plt.gcf().autofmt_xdate()#Arrange les données selon un axe x constitué de datetimes | |
ax.xaxis.set_major_formatter(format)#Indique à l'axe X quel format de grille utiliser | |
plt.savefig(path) | |
plt.clf() | |
def indexMax(index,values): | |
maxValue,maxIndex=0,0 | |
for i in range(len(values)): | |
if(values[i]>=maxValue): | |
maxValue,maxIndex=values[i],index[i] | |
return maxIndex,maxValue | |
def indexMin(index,values): | |
minValue,minIndex=indexMax(index,values)[1],0 | |
for i in range(len(values)): | |
if(values[i]<=minValue): | |
minValue,minIndex=values[i],index[i] | |
return minIndex,minValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import listdir,getcwd | |
from os.path import isfile, join | |
import os | |
def cmdFile(cmd): | |
os.system(str(cmd)+">tmp 2>&1") | |
with open('tmp',"r") as file: | |
data=file.read().split("\n") | |
os.system("rm tmp") | |
return data | |
path="./" | |
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))] | |
def digit(input,nb): | |
output=str(input) | |
while(len(output)<nb): | |
output="0"+output | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment