Skip to content

Commit ba89816

Browse files
colinsheppardwrashid
authored andcommitted
merging 496 back to master (#689)
* merging 496 back to master * turn into proper code blocks * Update beam.conf reset beam config * get failing tests back up * touch to get new build * flaky test * touch to rebuild * make await short * ignore single mode spec as on master * analysis scripts * cleaning up sf-light data * change await to 60 sec * updating PhyssimCalcLinkStats * restart maybe flakey test
1 parent 6c34ac1 commit ba89816

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1323
-283
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ scalafmt {
259259
// configFilePath = ".scalafmt.conf" // .scalafmt.conf in the project root is default value, provide only if other location is needed
260260
}
261261

262-
compileScala.dependsOn(scalafmtAll)
262+
//compileScala.dependsOn(scalafmtAll)
263263

264264
// Task to run scala tests, as Scala tests not picked up by Gradle by default.
265265
task spec(dependsOn: ['testClasses'], type: JavaExec) {
@@ -570,3 +570,4 @@ task execute(type:JavaExec) {
570570
}
571571
}
572572
}
573+

docs/developers.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,37 +112,37 @@ Production versus test data. Any branch beginning with "production" or "applicat
112112

113113
However, sometimes troubleshooting / debugging / development happens on a production branch. The cleanest way to get changes to source code or other non-production files back into master is the following.
114114

115-
Checkout your production branch:
115+
Checkout your production branch::
116116

117117
git checkout production-branch
118118

119-
Bring branch even with master
119+
Bring branch even with master::
120120

121121
git merge master
122122

123123
Resolve conflicts if needed
124124

125-
Capture the files that are different now between production and master:
125+
Capture the files that are different now between production and master::
126126

127127
git diff --name-only HEAD master > diff-with-master.txt
128128

129129
You have created a file "diff-with-master.txt" containing a listing of every file that is different.
130130

131131
IMPORTANT!!!! -- Edit the file diff-with-master.txt and remove all production-related data (this typically will be all files underneath "production" sub-directory.
132132

133-
Checkout master
133+
Checkout master::
134134

135135
git checkout master
136136

137-
Create a new branch off of master, this is where you will stage the files to then merge back into master:
137+
Create a new branch off of master, this is where you will stage the files to then merge back into master::
138138

139139
git checkout -b new-branch-with-changes-4ci
140140

141-
Do a file by file checkout of all differing files from production branch onto master:
141+
Do a file by file checkout of all differing files from production branch onto master::
142142

143143
cat diff-with-master.txt | xargs git checkout production-branch --
144144

145-
Note, if any of our diffs include the deletion of a file on your production branch, then you will need to remove (i.e. with "git remove" these before you do the above "checkout" step and you should also remove them from the diff-with-master.txt". If you don't do this, you will see an error message ("did not match any file(s) known to git.") and the checkout command will not be completed.
145+
Note, if any of our diffs include the deletion of a file on your production branch, then you will need to remove (i.e. with "git remove" these before you do the above "checkout" step and you should also remove them from the diff-with-master.txt"). If you don't do this, you will see an error message ("did not match any file(s) known to git.") and the checkout command will not be completed.
146146

147147
Finally, commit the files that were checked out of the production branch, push, and go create your pull request!
148148

src/main/R/beam-utilities.R

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ load.libraries(c('GEOquery','XML'))
33

44
clean.and.relabel <- function(ev,factor.to.scale.personal.back,factor.to.scale.transit.back,val.of.time=16.9){
55
# Clean and relabel
6-
ev[vehicle_type=="bus",vehicle_type:="Bus"]
7-
ev[vehicle_type=="CAR" | substr(vehicle,1,5)=="rideH",vehicle_type:="TNC"]
8-
ev[vehicle_type=="subway",vehicle_type:="BART"]
6+
ev[vehicle_type=="bus",vehicle_type:="BUS-DEFAULT"]
7+
ev[vehicle_type=="CAR",vehicle_type:="Car"]
8+
ev[substr(vehicle,1,5)=="rideH",mode:="ride_hail"]
9+
ev[vehicle_type=="subway",vehicle_type:="SUBWAY-DEFAULT"]
910
ev[vehicle_type=="SUV",vehicle_type:="Car"]
10-
ev[vehicle_type=="cable_car",vehicle_type:="Cable_Car"]
11-
ev[vehicle_type=="tram",vehicle_type:="Muni"]
12-
ev[vehicle_type=="rail",vehicle_type:="Rail"]
13-
ev[vehicle_type=="ferry",vehicle_type:="Ferry"]
11+
ev[vehicle_type=="cable_car",vehicle_type:="CABLE_CAR-DEFAULT"]
12+
ev[vehicle_type=="tram",vehicle_type:="TRAM-DEFAULT"]
13+
ev[vehicle_type=="rail",vehicle_type:="RAIL-DEFAULT"]
14+
ev[vehicle_type=="ferry",vehicle_type:="FERRY-DEFAULT"]
15+
transit.types <- c('BUS-DEFAULT','FERRY-DEFAULT','TRAM-DEFAULT','RAIL-DEFAULT','CABLE_CAR-DEFAULT','SUBWAY-DEFAULT')
1416
ev[,tripmode:=ifelse(mode%in%c('subway','bus','rail','tram','walk_transit','drive_transit','cable_car','ferry'),'transit',as.character(mode))]
1517
ev[,hour:=time/3600]
1618
ev[,hr:=round(hour)]
@@ -25,9 +27,9 @@ clean.and.relabel <- function(ev,factor.to.scale.personal.back,factor.to.scale.t
2527
if(is.factor(ev$fuel[1]))ev[,fuel:=as.numeric(as.character(fuel))]
2628
ev[start.y<=0.003 | end.y <=0.003,':='(start.x=NA,start.y=NA,end.x=NA,end.y=NA)]
2729
ev[length==Inf,length:=NA]
28-
ev[vehicle_type%in%c('BART','Ferry','Muni','Rail','Cable_Car') & !is.na(start.x) & !is.na(start.y) & !is.na(end.y) & !is.na(end.y),length:=dist.from.latlon(start.y,start.x,end.y,end.x)]
29-
ev[vehicle_type%in%c('BART','Bus','Cable_Car','Muni','Rail'),num_passengers:=round(num_passengers*factor.to.scale.personal.back)]
30-
ev[vehicle_type%in%c('BART','Bus','Cable_Car','Muni','Rail'),capacity:=round(capacity*factor.to.scale.transit.back)]
30+
ev[vehicle_type%in%transit.types & !is.na(start.x) & !is.na(start.y) & !is.na(end.y) & !is.na(end.y),length:=dist.from.latlon(start.y,start.x,end.y,end.x)]
31+
ev[vehicle_type%in%transit.types,num_passengers:=round(num_passengers*factor.to.scale.personal.back)]
32+
ev[vehicle_type%in%transit.types,capacity:=round(capacity*factor.to.scale.transit.back)]
3133
ev[num_passengers > capacity,num_passengers:=capacity]
3234
ev[,pmt:=num_passengers*length/1609]
3335
ev[is.na(pmt),pmt:=0]
@@ -41,8 +43,8 @@ clean.and.relabel <- function(ev,factor.to.scale.personal.back,factor.to.scale.t
4143
ev
4244
}
4345

44-
pretty.titles <- c('TNC Number'='ridehail_num',
45-
'TNC Price'='ridehail_price',
46+
pretty.titles <- c('Ride Hail Number'='ridehail_num',
47+
'Ride Hail Price'='ridehail_price',
4648
'Transit Capacity'='transit_capacity',
4749
'Transit Price'='transit_price',
4850
'Toll Price'='toll_price',
@@ -57,8 +59,8 @@ to.title <- function(abbrev){
5759
}
5860
}
5961
pretty.modes <- function(ugly){
60-
pretty.list <- c('TNC'='ride_hail',
61-
'TNC'='ride_hail',
62+
pretty.list <- c('Ride Hail'='ride_hail',
63+
'Ride Hail - Transit'='ride_hail_transit',
6264
'Cable Car'='cable_car',
6365
'Car'='car',
6466
'Walk'='walk',
@@ -89,7 +91,7 @@ parse.link.stats <- function(link.stats.file,net.file=NA){
8991
}
9092

9193
my.colors <- c(blue='#377eb8',green='#227222',orange='#C66200',purple='#470467',red='#B30C0C',yellow='#C6A600',light.green='#C0E0C0',magenta='#D0339D',dark.blue='#23128F',brown='#542D06',grey='#8A8A8A',dark.grey='#2D2D2D',light.yellow='#FFE664',light.purple='#9C50C0',light.orange='#FFB164',black='#000000')
92-
mode.colors <- c(TNC='red',Car='grey',Walk='green',Transit='blue')
94+
mode.colors <- c('Ride Hail'='red',Car='grey',Walk='green',Transit='blue','Ride Hail - Transit'='purple')
9395
mode.colors <- data.frame(key=names(mode.colors),color=mode.colors,color.hex=my.colors[mode.colors])
9496

9597
download.from.nersc <- function(experiment.dir,include.pattern='*'){

src/main/R/bin/csv2Rdata.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ option_list <- list(
1515
)
1616
if(interactive()){
1717
#setwd('~/downs/')
18-
args<-'/Users/critter/Downloads/2014-Clipper.csv'
19-
args<-'/Users/critter/Downloads/output 3/application-sfbay/base__2018-06-18_16-21-35/ITERS/it.1/1.events.csv'
18+
args<-'/Users/critter/Downloads/output 2/application-sfbay/RH2Transit_Plus10__2018-09-26_04-55-53/ITERS/it.10/10.events.csv'
2019
args <- parse_args(OptionParser(option_list = option_list,usage = "csv2Rdata.R [file-to-convert]"),positional_arguments=T,args=args)
2120
}else{
2221
args <- parse_args(OptionParser(option_list = option_list,usage = "csv2Rdata.R [file-to-convert]"),positional_arguments=T)

src/main/R/bin/exp2plots.R

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ option_list <- list(
1717
)
1818
if(interactive()){
1919
#setwd('~/downs/')
20-
args<-'/Users/critter/Documents/beam/beam-output/experiments/2018-04/surge-pricing/'
21-
args<-'/Users/critter/Documents/beam/beam-output/experiments/2018-04/ridehail-price/'
20+
args<-'/Users/critter/Downloads/RH2Transit-2Iter/RH2Transit'
21+
args<-'/Users/critter/Downloads/cost-sensitivities/cost-sensitivity/'
22+
#args<-'/Users/critter/Downloads/diffusion-5iter/diffusion/'
2223
args <- parse_args(OptionParser(option_list = option_list,usage = "exp2plots.R [experiment-directory]"),positional_arguments=T,args=args)
2324
}else{
2425
args <- parse_args(OptionParser(option_list = option_list,usage = "exp2plots.R [experiment-directory]"),positional_arguments=T)
2526
}
2627
######################################################################################################
2728

28-
factor.to.scale.personal.back <- 35
29-
factor.to.scale.transit.back <- 2
29+
# TODO make these come from conf file
30+
factor.to.scale.personal.back <- 20
31+
factor.to.scale.transit.back <- 1/.22 # inverse of param: beam.agentsim.tuning.transitCapacity
3032
plot.congestion <- F
33+
plot.modality.styles <- F
3134

3235
######################################################################################################
3336
# Load the exp config
@@ -72,21 +75,25 @@ for(run.i in 1:nrow(exp)){
7275
}
7376
links[[length(links)+1]] <- link
7477
}
75-
last.iter.minus.5 <- ifelse(last.iter>4,last.iter - 4,1)
76-
for(the.iter in last.iter.minus.5:last.iter){
77-
pop.csv <- pp(run.dir,output.dir,'/ITERS/it.',the.iter,'/',the.iter,'.population.csv.gz')
78-
if(file.exists(pop.csv)){
79-
pop <- csv2rdata(pop.csv)
80-
pop[,iter:=the.iter]
81-
streval(pp('pop[,',fact,':="',the.level,'"]'))
82-
pops[[length(pops)+1]] <- pop
78+
if(plot.modality.styles){
79+
last.iter.minus.5 <- ifelse(last.iter>4,last.iter - 4,1)
80+
for(the.iter in last.iter.minus.5:last.iter){
81+
pop.csv <- pp(run.dir,output.dir,'/ITERS/it.',the.iter,'/',the.iter,'.population.csv.gz')
82+
if(file.exists(pop.csv)){
83+
pop <- csv2rdata(pop.csv)
84+
pop[,iter:=the.iter]
85+
streval(pp('pop[,',fact,':="',the.level,'"]'))
86+
pops[[length(pops)+1]] <- pop
87+
}
8388
}
8489
}
8590
}
8691
ev <- rbindlist(evs,use.names=T,fill=T)
8792
rm('evs')
88-
pop <- rbindlist(pops,use.names=T,fill=T)
89-
rm('pops')
93+
if(plot.modality.styles){
94+
pop <- rbindlist(pops,use.names=T,fill=T)
95+
rm('pops')
96+
}
9097
if(plot.congestion){
9198
link <- rbindlist(links,use.names=T,fill=T)
9299
rm('links')
@@ -97,12 +104,12 @@ ev <- clean.and.relabel(ev,factor.to.scale.personal.back,factor.to.scale.transit
97104
setkey(ev,type)
98105

99106
## Prep data needed to do quick version of energy calc
100-
en <- data.table(read.csv('~/Dropbox/ucb/vto/beam-all/beam/test/input/sf-light/energy/energy-consumption.csv'))
101-
setkey(en,vehicleType)
107+
en <- data.table(read.csv('~/Dropbox/ucb/vto/beam-all/beam/production/application-sfbay/samples/vehicleTypes.csv'))
108+
setkey(en,vehicleTypeId)
102109
en <- u(en)
103110
## Energy Density in MJ/liter or MJ/kWh
104111
# https://en.wikipedia.org/wiki/Gasoline_gallon_equivalent
105-
en.density <- data.table(fuelType=c('gasoline','diesel','electricity'),density=c(31.81905,36.14286,3.6))
112+
#en.density <- data.table(fuelType=c('gasoline','diesel','electricity','biodiesel'),density=c(31.81905,36.14286,3.6,33.2))
106113
ev[tripmode%in%c('car') & vehicle_type=='Car',':='(num_passengers=1)]
107114
ev[,pmt:=num_passengers*length/1609]
108115
ev[is.na(pmt),pmt:=0]
@@ -132,8 +139,9 @@ for(fact in factors){
132139
toplot[,frac:=num/tot]
133140
toplot[,tripmode:=pretty.modes(tripmode)]
134141
setkey(toplot,the.factor,tripmode)
135-
p <- ggplot(toplot,aes(x=the.factor,y=frac*100,fill=tripmode))+geom_bar(stat='identity',position='stack')+labs(x="Scenario",y="% of Trips",title=pp('Factor: ',fact),fill="Trip Mode")+
136-
scale_fill_manual(values=as.character(mode.colors$color.hex[match(sort(u(toplot$tripmode)),mode.colors$key)]))
142+
p <- ggplot(toplot,aes(x=the.factor,y=frac*100,fill=tripmode))+geom_bar(stat='identity',position='stack')+
143+
labs(x="Scenario",y="% of Trips",title=pp('Factor: ',fact),fill="Trip Mode")+
144+
scale_fill_manual(values=as.character(mode.colors$color.hex[match(sort(u(toplot$tripmode)),mode.colors$key)]))
137145
pdf.scale <- .6
138146
ggsave(pp(plots.dir,'mode-split-by-',fact,'.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
139147
write.csv(toplot,file=pp(plots.dir,'mode-split-by-',fact,'.csv'))
@@ -150,7 +158,7 @@ for(fact in factors){
150158
ggsave(pp(plots.dir,'mode-split-by-hour-by-',fact,'.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
151159
write.csv(toplot,file=pp(plots.dir,'mode-split-by-hour-',fact,'.csv'))
152160

153-
target <- data.frame(tripmode=rep(c('Car','Walk','Transit','TNC'),length(u(toplot$the.factor))),
161+
target <- data.frame(tripmode=rep(c('Car','Walk','Transit','Ride Hail'),length(u(toplot$the.factor))),
154162
perc=rep(c(79,4,13,5),length(u(toplot$the.factor))),
155163
the.factor=rep(u(toplot$the.factor),each=4))
156164
p <- ggplot(toplot,aes(x=tripmode,y=frac*100))+geom_bar(stat='identity')+facet_wrap(~the.factor)+geom_point(data=target,aes(y=perc),colour='red')
@@ -188,24 +196,23 @@ for(fact in factors){
188196
toplot <- pt[,.(fuel=sum(fuel),numVehicles=as.double(length(fuel)),numberOfPassengers=as.double(sum(num_passengers)),pmt=sum(pmt),vmt=sum(length)/1609,mpg=sum(length)/1609/sum(fuel/3.78)),by=c('the.factor','vehicle_type','tripmode')]
189197
toplot <- toplot[vehicle_type!='Human' & tripmode!="walk"]
190198
if(nrow(en)>30){
191-
toplot <- join.on(toplot,en[vehicle%in%c('SUBWAY-DEFAULT','BUS-DEFAULT','CABLE_CAR-DEFAULT','CAR','FERRY-DEFAULT','TRAM-DEFAULT','RAIL-DEFAULT')|vehicleType=='TNC'],'vehicle_type','vehicleType','fuelType')
199+
toplot <- join.on(toplot,en[vehicleTypeId%in%c('SUBWAY-DEFAULT','BUS-DEFAULT','CABLE_CAR-DEFAULT','Car','FERRY-DEFAULT','TRAM-DEFAULT','RAIL-DEFAULT') | substr(vehicleTypeId,0,3)=='BEV'],'vehicle_type','vehicleTypeId','primaryFuelType')
192200
}else{
193-
toplot <- join.on(toplot,en,'vehicle_type','vehicleType','fuelType')
201+
toplot <- join.on(toplot,en,'vehicle_type','vehicleTypeId','primaryFuelType')
194202
}
195-
toplot <- join.on(toplot,en.density,'fuelType','fuelType')
196-
toplot[,energy:=fuel*density]
197-
toplot[vehicle_type=='TNC',tripmode:='TNC']
198-
toplot[vehicle_type%in%c('Car','TNC'),energy:=energy*factor.to.scale.personal.back*10]
199-
toplot[vehicle_type%in%c('Car','TNC'),numVehicles:=numVehicles*factor.to.scale.personal.back]
200-
toplot[vehicle_type%in%c('Car','TNC'),pmt:=pmt*factor.to.scale.personal.back]
201-
toplot[vehicle_type%in%c('Car','TNC'),numberOfPassengers:=numVehicles]
203+
toplot[,energy:=fuel] # fuel is now in units of J so no need to convert from L to J
204+
toplot[tripmode%in%c('car','ride_hail'),energy:=energy*factor.to.scale.personal.back]
205+
toplot[tripmode%in%c('car','ride_hail'),numVehicles:=numVehicles*factor.to.scale.personal.back]
206+
toplot[tripmode%in%c('car','ride_hail'),pmt:=pmt*factor.to.scale.personal.back]
207+
toplot[tripmode%in%c('car','ride_hail'),numberOfPassengers:=numVehicles]
202208
toplot[,ag.mode:=tripmode]
203209
toplot[tolower(ag.mode)%in%c('bart','bus','cable_car','muni','rail','tram','transit'),ag.mode:='Transit']
204210
toplot[ag.mode=='car',ag.mode:='Car']
211+
toplot[ag.mode=='ride_hail',ag.mode:='Ride Hail']
205212
toplot.ag <- toplot[,.(energy=sum(energy),pmt=sum(pmt)),by=c('the.factor','ag.mode')]
206213
pdf.scale <- .6
207214
setkey(toplot.ag,the.factor,ag.mode)
208-
p <- ggplot(toplot.ag,aes(x=the.factor,y=energy/1e6,fill=ag.mode))+geom_bar(stat='identity',position='stack')+labs(x="Scenario",y="Energy Consumption (TJ)",title=to.title(fact),fill="Trip Mode")+
215+
p <- ggplot(toplot.ag,aes(x=the.factor,y=energy/1e12,fill=ag.mode))+geom_bar(stat='identity',position='stack')+labs(x="Scenario",y="Energy Consumption (TJ)",title=to.title(fact),fill="Trip Mode")+
209216
scale_fill_manual(values=as.character(mode.colors$color.hex[match(sort(u(toplot.ag$ag.mode)),mode.colors$key)]))
210217
ggsave(pp(plots.dir,'energy-by-mode-',fact,'.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
211218
write.csv(toplot.ag,file=pp(plots.dir,'energy-by-mode-',fact,'.csv'))
@@ -219,11 +226,11 @@ for(fact in factors){
219226
ggsave(pp(plots.dir,'energy-per-pmt-by-vehicle-type-',fact,'.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
220227

221228
# Deadheading
222-
toplot <- pt[vehicle_type=='TNC',.(dead=num_passengers==0,miles=length/1609,hr,the.factor)]
229+
toplot <- pt[tripmode=='ride_hail',.(dead=num_passengers==0,miles=length/1609,hr,the.factor)]
223230
setkey(toplot,hr,dead)
224231
dead.frac <- toplot[,.(dead.frac=pp(roundC(100*sum(miles[dead==T])/sum(miles),1),"% Empty")),by=c('the.factor')]
225232
toplot <- toplot[,.(miles=sum(miles)),by=c('dead','hr','the.factor')]
226-
p <- ggplot(toplot,aes(x=hr,y=miles,fill=dead))+geom_bar(stat='identity')+labs(x="Hour",y="Vehicle Miles Traveled",fill="Empty",title=pp("TNC Deadheading"))+geom_text(data=dead.frac,hjust=1,aes(x=24,y=max(toplot$miles),label=dead.frac,fill=NA))+facet_wrap(~the.factor)
233+
p <- ggplot(toplot,aes(x=hr,y=miles,fill=dead))+geom_bar(stat='identity')+labs(x="Hour",y="Vehicle Miles Traveled",fill="Empty",title=pp("Ride Hail Deadheading"))+geom_text(data=dead.frac,hjust=1,aes(x=24,y=max(toplot$miles),label=dead.frac,fill=NA))+facet_wrap(~the.factor)
227234
pdf.scale <- .6
228235
ggsave(pp(plots.dir,'dead-heading.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
229236
}
@@ -244,32 +251,34 @@ if(plot.congestion){
244251
}
245252
}
246253

247-
if('customAttributes' %in% names(pop)){
248-
for(fact in factors){
249-
streval(pp('pop[,the.factor:=',fact,']'))
250-
if(all(c('low','base','high') %in% u(pop$the.factor))){
251-
pop[,the.factor:=factor(the.factor,levels=c('low','base','high'))]
252-
}else if(all(c('Low','Base','High') %in% u(pop$the.factor))){
253-
pop[,the.factor:=factor(the.factor,levels=c('Low','Base','High'))]
254-
}else{
255-
streval(pp('pop[,the.factor:=factor(the.factor,levels=exp$',fact,')]'))
256-
}
257-
pop[,style:=customAttributes]
258-
pop <- pop[style!='']
259-
if(any(u(pop$style)=='class1')){
260-
new.names <- c(class1='Multimodals',class2='Empty nesters',class3='Transit takers',class4='Inveterate drivers',class5='Moms in cars',class6='Car commuters')
261-
pop[,style:=new.names[as.character(style)]]
262-
}
263-
toplot <- pop[,.(n=length(type)),by=c('style','the.factor','iter')]
264-
toplot <- toplot[,.(n=mean(n)),by=c('style','the.factor')]
265-
setkey(toplot,style,the.factor)
254+
if(plot.modality.styles){
255+
if('customAttributes' %in% names(pop)){
256+
for(fact in factors){
257+
streval(pp('pop[,the.factor:=',fact,']'))
258+
if(all(c('low','base','high') %in% u(pop$the.factor))){
259+
pop[,the.factor:=factor(the.factor,levels=c('low','base','high'))]
260+
}else if(all(c('Low','Base','High') %in% u(pop$the.factor))){
261+
pop[,the.factor:=factor(the.factor,levels=c('Low','Base','High'))]
262+
}else{
263+
streval(pp('pop[,the.factor:=factor(the.factor,levels=exp$',fact,')]'))
264+
}
265+
pop[,style:=customAttributes]
266+
pop <- pop[style!='']
267+
if(any(u(pop$style)=='class1')){
268+
new.names <- c(class1='Multimodals',class2='Empty nesters',class3='Transit takers',class4='Inveterate drivers',class5='Moms in cars',class6='Car commuters')
269+
pop[,style:=new.names[as.character(style)]]
270+
}
271+
toplot <- pop[,.(n=length(type)),by=c('style','the.factor','iter')]
272+
toplot <- toplot[,.(n=mean(n)),by=c('style','the.factor')]
273+
setkey(toplot,style,the.factor)
266274

267-
pdf.scale <- .8
268-
p<-ggplot(toplot,aes(x=the.factor,y=n,fill=style))+geom_bar(stat='identity',position='stack')+labs(x='Trip #',y='# Agents',title='Modality Style Distributions')
269-
ggsave(pp(plots.dir,'modality-styles.pdf'),p,width=10*pdf.scale,height=8*pdf.scale,units='in')
275+
pdf.scale <- .8
276+
p<-ggplot(toplot,aes(x=the.factor,y=n,fill=style))+geom_bar(stat='identity',position='stack')+labs(x='Trip #',y='# Agents',title='Modality Style Distributions')
277+
ggsave(pp(plots.dir,'modality-styles.pdf'),p,width=10*pdf.scale,height=8*pdf.scale,units='in')
270278

271-
p<-ggplot(toplot,aes(x=style,y=n,fill=the.factor))+geom_bar(stat='identity',position='dodge')+labs(x='',y='# Agents',fill=fact,title='Modality Style Distributions')
272-
ggsave(pp(plots.dir,'modality-styles-dodged.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
279+
p<-ggplot(toplot,aes(x=style,y=n,fill=the.factor))+geom_bar(stat='identity',position='dodge')+labs(x='',y='# Agents',fill=fact,title='Modality Style Distributions')
280+
ggsave(pp(plots.dir,'modality-styles-dodged.pdf'),p,width=10*pdf.scale,height=6*pdf.scale,units='in')
281+
}
273282
}
274283
}
275284

0 commit comments

Comments
 (0)