-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pandas as pd | ||
|
||
# Define the files we want to load | ||
travel_time_file = "Travel Time - train dataset - Raw.csv" | ||
tmc_file = "Dorchester Road and Huron Church Road_tmc_data_train.csv" | ||
|
||
# Load the TMC data into a dataframe | ||
tmc_df = pd.read_csv(tmc_file, parse_dates=["dt_bin"]) | ||
tt_df = pd.read_csv(travel_time_file, parse_dates=["Start time", "End time"]) | ||
|
||
# Some code to prepare and aggreagte the travel time data | ||
|
||
tt_agg_df = tt_df.groupby( | ||
[ | ||
pd.Grouper(key="Start time", freq="15Min"), # You can adjust the frequency here | ||
"Source name", | ||
"Source ID", | ||
"Destination name", | ||
"Destination ID", | ||
] | ||
).agg(["mean", "median", "count"]) | ||
|
||
# Reset the index to make joining simpler | ||
tt_agg_df.reset_index() | ||
|
||
# And let's flatten the column hiearchy | ||
tt_agg_df.columns = [" ".join(col).strip() for col in tt_agg_df.columns.values] | ||
|
||
# We can also aggregate the TMC data | ||
tmc_agg_df = tmc_df.groupby(["Intersection Name", "Intersection ID", "dt_bin"]).sum() | ||
tmc_agg_df = tmc_agg_df.reset_index() | ||
|
||
# Here's how you can join the datasets together | ||
|
||
merged_df = pd.merge( | ||
tmc_agg_df, | ||
tt_agg_df, | ||
how="left", | ||
left_on=["dt_bin", "Intersection ID"], | ||
right_on=["Start time", "Source ID"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
from basic_tests import dorchester_arr | ||
|
||
testing = pd.read_csv("Miovision Data/Dorchester Road and Huron Church Road_tmc_data_test.csv")[["dt_bin", "Direction", "Movement Type", | ||
"Vehicle Classification", | ||
"Number of Vehicles"]] | ||
print(dorchester_arr[0]) | ||
|
||
|
||
vehicles_aggregate = testing[["Vehicle Classification", "Number of Vehicles"]] | ||
|
||
vehicles = testing["Vehicle Classification"] | ||
unique_vehicles = [] | ||
for vehicle in vehicles: | ||
if vehicle not in unique_vehicles: | ||
unique_vehicles.append(vehicle) | ||
|
||
#print(vehicles_aggregate) | ||
|
||
totals = {unique_vehicles[i]: 0 for i in range(0, len(unique_vehicles))} | ||
|
||
for i in range(0, len(vehicles_aggregate)): | ||
totals[vehicles_aggregate["Vehicle Classification"][i]] += vehicles_aggregate["Number of Vehicles"][i] | ||
|
||
|
||
#print(totals) |