Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsilen committed Nov 23, 2017
1 parent a36d961 commit 82ff4a8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions groupanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def stop(self):
# Read data from file
inputfiles = []

<<<<<<< HEAD
timeseries = True

=======
>>>>>>> parent of 040a575... removed timeseries_plt.py and updated plotting to groupanalysis.py
if len(sys.argv) < 2:
sys.argv.append('example.csv')

Expand All @@ -73,6 +76,7 @@ def stop(self):
timeseries_medians = pd.DataFrame()
timeseries_results = pd.DataFrame()

<<<<<<< HEAD


df_timeseries
Expand All @@ -84,15 +88,23 @@ def stop(self):
# Loop through all files
for j, element in enumerate(inputfiles):
progress_bar = ProgressBar()
=======
# Loop through all files
for j, element in enumerate(inputfiles):
>>>>>>> parent of 040a575... removed timeseries_plt.py and updated plotting to groupanalysis.py
try:
input = element

print("\nReading: "+str(input))
<<<<<<< HEAD

if timeseries==False:
df = pd.read_csv(input)
else:
df = df_timeseries
=======
df = pd.read_csv(input)
>>>>>>> parent of 040a575... removed timeseries_plt.py and updated plotting to groupanalysis.py

if input.endswith('.csv'):
input = input[:-4]
Expand All @@ -117,6 +129,10 @@ def stop(self):
else:
print ('Groups are NOT equal size: '+str(a))

<<<<<<< HEAD
=======
progress_bar = ProgressBar()
>>>>>>> parent of 040a575... removed timeseries_plt.py and updated plotting to groupanalysis.py
progress_bar.start()

# Prepare to capture results
Expand Down Expand Up @@ -227,12 +243,21 @@ def stop(self):

except:
progress_bar.stop()
<<<<<<< HEAD

print "\nUnexpected error:", sys.exc_info()[0]

timeseries_results = pd.concat([timeseries_medians, timeseries_values], axis=1)
timeseries_results = pd.concat([timeseries_results.loc[['Group'],:], timeseries_results.drop('Group', axis=0)], axis=0)

=======
progress_bar.join()
print "\nUnexpected error:", sys.exc_info()[0]

timeseries_results = pd.concat([timeseries_medians, timeseries_values], axis=1)
timeseries_results = pd.concat([timeseries_results.loc[['Group'],:], timeseries_results.drop('Group', axis=0)], axis=0)

>>>>>>> parent of 040a575... removed timeseries_plt.py and updated plotting to groupanalysis.py
output = 'medians'+time.strftime("-%d-%m-%Y")+".csv"
print "\nWriting summary of median values: "+str(output)+"\n"
timeseries_results.to_csv(output)
39 changes: 39 additions & 0 deletions timeseries_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
import pandas as pd
import matplotlib.pyplot as plt

# load all input files into array of dataframes
data = []
for j, element in enumerate(sys.argv[1:]):
data.append(pd.read_csv(element))
data[j].set_index('Person',inplace=True)
input = element
if input.endswith('.csv'):
input = input[:-4]
data[j] = data[j].T
data[j].insert(loc=1, column='TimeSeries', value=input)

# merge dataframes, change cells to numeric, not objects
df = pd.concat(data, axis=0, join='inner')
df = pd.concat([df.ix[:,:2], df.ix[:,2:].apply(pd.to_numeric)], axis=1)
df['Group'] = df['Group'].astype(int)

# move groups and timeseries to first columns
cols = list(df)
cols.insert(0, cols.pop(cols.index('Group')))
cols.insert(0, cols.pop(cols.index('TimeSeries')))
df = df.ix[:, cols]

# plotting
for column in df.ix[:,2:]:
fig, ax = plt.subplots()
labels = []
for key, grp in df.groupby(['TimeSeries', 'Group'])[[column]].median().groupby(['TimeSeries']):
ax = grp.reset_index().plot(ax=ax, x='Group', y=column, xticks=grp.reset_index()['Group'], kind='line', title=column)
labels.append(key)
lines, _ = ax.get_legend_handles_labels()
ax.legend(lines, labels, loc='best')
plt.savefig('fig/'+column+'.png')
plt.clf()

df.to_csv('test.csv')

0 comments on commit 82ff4a8

Please sign in to comment.