Created
January 23, 2018 12:35
-
-
Save furushchev/df5f37f40e10fb55c9892435fe635209 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Author: furushchev <[email protected]> | |
import matplotlib | |
import pandas as pd | |
import pylab | |
import matplotlib.pyplot as plt | |
import sys | |
import os | |
import pathlib2 | |
import numpy as np | |
def load(fpath): | |
if not os.path.exists(fpath): | |
raise OSError("%s not found" % fpath) | |
df = pd.read_csv(fpath) | |
names = sorted(set(df.Name)) | |
rdf = None | |
for name in names: | |
sdf = df[df.Name==name][['Date','FullCapacity']] | |
sdf = sdf.rename(columns={'FullCapacity': name}) | |
if rdf is None: | |
rdf = sdf | |
else: | |
rdf = pd.merge(rdf, sdf, on='Date') | |
return rdf | |
def plot(df): | |
df['Date'] = pd.to_datetime(df['Date'], unit='s') | |
size = 20 | |
df.plot(x='Date', rot=45, grid=True, figsize=(size, size * 1080.0 / 1920.0)) | |
plt.tight_layout(pad=2) | |
plt.ylim(0, 7000) | |
plt.xlabel('Date') | |
plt.ylabel('Full Capacity') | |
plt.savefig("battery_plot.pdf", format="pdf", dpi=300) | |
plt.show() | |
p = pathlib2.Path(sys.argv[1]) | |
df = None | |
for f in p.iterdir(): | |
if f.suffix != '.csv': | |
continue | |
pdf = load(str(f.absolute())) | |
if df is None: | |
df = pdf | |
else: | |
df = pd.concat([df, pdf]) | |
print df | |
df = df.replace(-1.0, np.nan).replace(0.0, np.nan) | |
plot(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment