Skip to content

Commit

Permalink
created plot_any fnc
Browse files Browse the repository at this point in the history
  • Loading branch information
Aphexis committed Mar 29, 2020
1 parent 941c881 commit 3b5e71d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
7 changes: 5 additions & 2 deletions basic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ def split_df(df): # returns an array where each element is one traffic type of t
start = 0
end = 5670
while (end < 40344):
split_arr.append(df.iloc[start:end].copy())
convert_to_int(split_arr[-1])
new_df = df.iloc[start:end].copy()
convert_to_int(new_df)
new_df['Start Time'] = pd.to_datetime(new_df['Start Time'])
new_df.set_index(['Start Time'], inplace=True)
split_arr.append(new_df)
start += 5764
end = start + 5760
return split_arr
Expand Down
57 changes: 45 additions & 12 deletions day_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,60 @@
import matplotlib.pyplot as plt
from basic_tests import dorchester_arr, malden_arr, totten_arr

plt.close('all')

def plot_data(df): # plot data for one direction of traffic at an intersection
ax1 = df['Thru'].plot(label="Through")
ax2 = df['Right'].plot(label="Right")
ax3 = df['Left'].plot(label="Left")
ax4 = df['U-Turn'].plot(label="U-Turn")
df.plot()
plt.legend(loc="upper right")

# arr = array of dfs
# d = direction (N = 0, E = 1, S = 2, W = 3)
# i = index of arr with the df you want to graph
def plot_any(arr, d, i):
d_dict = {0: 'Southbound', 1: 'Westbound', 2: 'Northbound', 3: 'Eastbound'}
i_dict = {0: 'General Traffic', 1: 'Single-Unit Trucks', 2: 'Articulated Trucks', 3: 'Buses',
4: 'Work Vans', 5: 'Bicycles', 6: 'Pedestrians'}
graph_title= d_dict[d] + " " + i_dict[i]
if (d==0):
df = arr[i].iloc[:, :6]
else:
df = arr[i].iloc[:, np.r_[0, d*6+1:d*6+6]]
df_grouped = df.groupby([df.index.hour, df.index.minute]).mean()
ax = df_grouped.plot(title=graph_title)
ax.set_xlabel("Time of day (hour, minute)")
ax.set_ylabel("# of vehicles")
plt.legend(loc="upper right")
plt.show()

plot_any(dorchester_arr,3, 5)
plt.show()

##### MOST OF BELOW CAN NOW BE COMPLETED WITH PLOT_ANY #####
### Setup
d_lights_n = dorchester_arr[0]
d_lights_n['Start Time'] = pd.to_datetime(d_lights_n['Start Time'])
d_lights_n.set_index(['Start Time'], inplace=True)
# d_lights_n = dorchester_arr[0].iloc[:, :6]
# d_lights_n['Start Time'] = pd.to_datetime(d_lights_n['Start Time'])
# d_lights_n.set_index(['Start Time'], inplace=True)

# d_sut_n = dorchester_arr[1].iloc[:,0:6]
# print(d_sut_n)
# d_lights_e = dorchester_arr[0].iloc[:, np.r_[0, 7:12]]
# d_sut_n['Start Time'] = pd.to_datetime(d_sut_n['Start Time'])
# d_sut_n.set_index(['Start Time'], inplace=True)

## Filter by day (monday = 0)
d_lights_n_monday = d_lights_n[d_lights_n.index.weekday == 0]
# d_lights_n_monday = d_lights_n[d_lights_n.index.weekday == 0]

## Resample: split data at different intervals (ex. every day or every 30 min instead of 15min)
# dlnr = d_lights_n_monday.resample('D').mean()

## Group by day (view average data for one day)
# dlnr = d_lights_n.groupby(lambda x: x.hour+x.minute, axis=0).mean() # doesn't work
dlnr = d_lights_n.groupby([d_lights_n.index.hour, d_lights_n.index.minute]).mean()
print(dlnr)
plot_data(dlnr)
# dlnr = d_sut_n.groupby([d_sut_n.index.hour, d_sut_n.index.minute]).mean()
#
# print(dlnr)
# plot_data(dlnr)
# plt.show()

# dler = d_lights_e.groupby([d_lights_e.index.hour, d_lights_e.index.minute]).mean()
# print(dler.info)
# plot_data(dler)
# plt.show()
3 changes: 2 additions & 1 deletion plotting_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import matplotlib.pyplot as plt
from basic_tests import dorchester_arr, malden_arr, totten_arr

# Plots right, left &
## Testing data plotting
# Plots right, left, through, u-turn
d_lights_n = dorchester_arr[0].iloc[:, :6]
plt.ylabel('Amount of Traffic')
plt.xlabel('Date/Time')
Expand Down

0 comments on commit 3b5e71d

Please sign in to comment.