Skip to content

Instantly share code, notes, and snippets.

@RedBlaze42
Last active March 6, 2020 21:45
Show Gist options
  • Save RedBlaze42/3f4b86086f3c2bfd2b694cb4dea71001 to your computer and use it in GitHub Desktop.
Save RedBlaze42/3f4b86086f3c2bfd2b694cb4dea71001 to your computer and use it in GitHub Desktop.
Python tools
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
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