Skip to content

Commit 7d7257d

Browse files
bstablerBlake Rosenthal
authored and
Blake Rosenthal
committed
Set up CI with Azure Pipelines
[skip ci]
1 parent dd7c5d8 commit 7d7257d

File tree

73 files changed

+261
-2404
lines changed

Some content is hidden

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

73 files changed

+261
-2404
lines changed

DaySim.Tests/DaySim.Tests.external/DaySimSummaries_regress/excel_report_files/runtimes.csv

-15
This file was deleted.

DaySim.Tests/DaySim.Tests.external/DaySimSummaries_regress/main.R

+112-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
##This is a temporary main control file with lots of TODOs to move
1+
##This is a temporary main control file with lots of TODOs to move
22
##this whole effort to a package with project specific config and run files
33

44
#Rprof()
@@ -9,16 +9,26 @@ options(error = function() traceback(2))
99
options(warning = function() traceback(2))
1010

1111
#-----------------------
12-
#Load packages
12+
# Load packages
1313
#-----------------------
14-
##TODO consider local R installation, with predownloaded packages in that library
15-
library(foreign)
16-
library(reshape)
17-
library(XLConnect)
18-
library(descr)
19-
library(Hmisc)
20-
library(data.table)
21-
library(plyr)
14+
15+
safeLoadPackage <- function(package_name){
16+
tryCatch({
17+
library(package_name, character.only=TRUE)
18+
}, error = function(err) {
19+
print(paste("Installing", package_name))
20+
install.packages(package_name, repos="https://ftp.osuosl.org/pub/cran")
21+
library(package_name, character.only=TRUE)
22+
})
23+
}
24+
25+
safeLoadPackage("foreign")
26+
safeLoadPackage("reshape")
27+
safeLoadPackage("XLConnect")
28+
safeLoadPackage("descr")
29+
safeLoadPackage("Hmisc")
30+
safeLoadPackage("data.table")
31+
safeLoadPackage("plyr")
2232

2333
getScriptDirectory <- function() {
2434
argv <- commandArgs(trailingOnly = FALSE)
@@ -42,29 +52,6 @@ setScriptDirectory <- function() {
4252
}
4353
}
4454

45-
#this script uses relative paths for sourcing so requires that the current working directory be script directory
46-
setScriptDirectory()
47-
48-
#Tried to use ArgParse but it screwed up the long filename of the config file
49-
args <- commandArgs(trailingOnly=TRUE)
50-
print(paste('# of args=',length(args), 'Args:'))
51-
print(args)
52-
53-
if (length(args) == 0) {
54-
print(paste('no arguments passed so using default configuration file.'))
55-
configuration_file = 'daysim_output_config.R'
56-
} else if (length(args) == 1) {
57-
configuration_file = args[1]
58-
print(paste("configuration_file:", configuration_file))
59-
#remove quotes if needed
60-
configuration_file <- gsub('[\'"]', '', configuration_file)
61-
print(paste("configuration_file:", configuration_file))
62-
} else {
63-
print(paste('Unexpected arguments. Expect only path to configuration file but found # of args=',length(args), 'Args:'))
64-
print(args)
65-
stop()
66-
}
67-
6855
sourceAFileInTryCatch <- function(filename){
6956
if (!file.exists(filename)) {
7057
stop(paste('Expected source file does not exist:', filename))
@@ -80,24 +67,105 @@ sourceAFileInTryCatch <- function(filename){
8067
})
8168
}
8269

70+
getNamedArg <- function(args, arg_name, default) {
71+
named_arg = substring(args[grep(arg_name, args)], nchar(arg_name) + 1)
72+
if ((!is.character(named_arg)) | (length(named_arg) == 0)) {
73+
print(paste("No", arg_name, "specified. Using default value."))
74+
return(default)
75+
} else {
76+
return(named_arg)
77+
}
78+
}
79+
8380

8481
#------------------------------------
85-
#Source functions and config settings
82+
# Source functions and config settings
8683
#------------------------------------
87-
#TODO function in package to create template config file in a specified location
88-
sourceAFileInTryCatch(configuration_file)
84+
# this script uses relative paths for sourcing so requires that the current working directory be script directory
85+
setScriptDirectory()
86+
87+
args <- commandArgs(trailingOnly=TRUE)
88+
print(paste('# of args=',length(args), 'Args:'))
89+
print(args)
90+
91+
# Override defaults if specified in commandArgs
92+
DAYSIM_REFERENCE_OUTPUTS = getNamedArg(args, "--reference_dir=", "reference/regress_outputs")
93+
DAYSIM_NEW_OUTPUTS = getNamedArg(args, "--outputs_dir=", "new/regress_outputs")
94+
DAYSIM_REPORT_DIRECTORY = getNamedArg(args, "--reports_dir=", "excel_report_files")
95+
96+
print(paste("DAYSIM_REFERENCE_OUTPUTS:", DAYSIM_REFERENCE_OUTPUTS))
97+
print(paste("DAYSIM_NEW_OUTPUTS:", DAYSIM_NEW_OUTPUTS))
98+
print(paste("DAYSIM_REPORT_DIRECTORY:", DAYSIM_REPORT_DIRECTORY))
99+
100+
# DaySim Version - DelPhi or C#
101+
dsVersion = "C#"
102+
103+
# daysim outputs
104+
dshhfile = paste(DAYSIM_NEW_OUTPUTS, "/_household.tsv", sep="")
105+
dsperfile = paste(DAYSIM_NEW_OUTPUTS, "/_person.tsv", sep="")
106+
dspdayfile = paste(DAYSIM_NEW_OUTPUTS, "/_person_day.tsv", sep="")
107+
dstourfile = paste(DAYSIM_NEW_OUTPUTS, "/_tour.tsv", sep="")
108+
dstripfile = paste(DAYSIM_NEW_OUTPUTS, "/_trip.tsv", sep="")
109+
110+
# reference/survey
111+
surveyhhfile = paste(DAYSIM_REFERENCE_OUTPUTS, "/_household.tsv", sep="")
112+
surveyperfile = paste(DAYSIM_REFERENCE_OUTPUTS, "/_person.tsv", sep="")
113+
surveypdayfile = paste(DAYSIM_REFERENCE_OUTPUTS, "/_person_day.tsv", sep="")
114+
surveytourfile = paste(DAYSIM_REFERENCE_OUTPUTS, "/_tour.tsv", sep="")
115+
surveytripfile = paste(DAYSIM_REFERENCE_OUTPUTS, "/_trip.tsv", sep="")
116+
117+
wrklocmodelfile = "./model_csv_files/WrkLocation.csv"
118+
schlocmodelfile = "./model_csv_files/SchLocation.csv"
119+
vehavmodelfile = "./model_csv_files/VehAvailability.csv"
120+
daypatmodelfile1 = "./model_csv_files/DayPattern_pday.csv"
121+
daypatmodelfile2 = "./model_csv_files/DayPattern_tour.csv"
122+
daypatmodelfile3 = "./model_csv_files/DayPattern_trip.csv"
123+
tourdestmodelfile = "./model_csv_files/TourDestination.csv"
124+
tourdestwkbmodelfile = "./model_csv_files/TourDestination_wkbased.csv"
125+
tripdestmodelfile = "./model_csv_files/TripDestination.csv"
126+
tourmodemodelfile = "./model_csv_files/TourMode.csv"
127+
tourtodmodelfile = "./model_csv_files/TourTOD.csv"
128+
tripmodemodelfile = "./model_csv_files/TripMode.csv"
129+
triptodmodelfile = "./model_csv_files/TripTOD.csv"
130+
131+
wrklocmodelout = "WrkLocation.xlsm"
132+
schlocmodelout = "SchLocation.xlsm"
133+
vehavmodelout = "VehAvailability.xlsm"
134+
daypatmodelout = "DayPattern.xlsm"
135+
tourdestmodelout = c("TourDestination_Escort.xlsm","TourDestination_PerBus.xlsm","TourDestination_Shop.xlsm",
136+
"TourDestination_Meal.xlsm","TourDestination_SocRec.xlsm")
137+
tourdestwkbmodelout = "TourDestination_WrkBased.xlsm"
138+
tourmodemodelout = "TourMode.xlsm"
139+
tourtodmodelout = "TourTOD.xlsm"
140+
tripmodemodelout = "TripMode.xlsm"
141+
triptodmodelout = "TripTOD.xlsm"
142+
143+
outputsDir = paste(DAYSIM_REPORT_DIRECTORY, "", sep="")
144+
validationDir = ""
145+
146+
prepSurvey = TRUE
147+
prepDaySim = TRUE
148+
149+
runWrkSchLocationChoice = TRUE
150+
runVehAvailability = TRUE
151+
runDayPattern = TRUE
152+
runTourDestination = TRUE
153+
runTourMode = TRUE
154+
runTourTOD = TRUE
155+
runTripMode = TRUE
156+
runTripTOD = TRUE
89157

90-
#stop("Finished test")
158+
excludeChildren5 = TRUE
91159

92160
sourceAFileInTryCatch("utilfunc.R")
93161

94162
progressStart("run DaySim summaries",14)
95163

96164
#-----------------------
97-
#Load data
165+
# Load data
98166
#-----------------------
99167

100-
#Load DaySim outputs into Rdata files
168+
# Load DaySim outputs into Rdata files
101169
if(runWrkSchLocationChoice | runVehAvailability | runDayPattern | runTourDestination | runTourMode)
102170
{
103171
progressNextStep("reading hh data")
@@ -147,7 +215,7 @@ if(runDayPattern | runTripMode | runTripTOD)
147215
gc()
148216

149217
#-----------------------
150-
#Run tabulations
218+
# Run tabulations
151219
#-----------------------
152220
##TODO split between preparing tables in an R object and then putting them somewhere
153221
##TODO e.g. in a spreadsheet, in a pdf report, etc.
@@ -181,17 +249,17 @@ if(runTourDestination)
181249
}
182250
if(runTourMode)
183251
{
184-
progressNextStep("summarizing Tour Mode Choice")
252+
progressNextStep("summarizing Tour Mode Choice")
185253
sourceAFileInTryCatch("tourmode.R")
186254
}
187255
if(runTourTOD)
188256
{
189-
progressNextStep("summarizing Tour Time of Day Choice")
257+
progressNextStep("summarizing Tour Time of Day Choice")
190258
sourceAFileInTryCatch("tourtod.R")
191259
}
192260
if(runTripMode)
193261
{
194-
progressNextStep("summarizing Trip Mode Choice")
262+
progressNextStep("summarizing Trip Mode Choice")
195263
sourceAFileInTryCatch("tripmode.R")
196264
}
197265
if(runTripTOD)
@@ -203,4 +271,4 @@ if(runTripTOD)
203271
progressEnd(outputsDir)
204272

205273
# Rprof(NULL)
206-
# memprof <- summaryRprof()
274+
# memprof <- summaryRprof()

DaySim.Tests/DaySim.Tests.external/compare_output_directories/compare_output_directories.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
def remove_irrelevant_files(listOfFiles):
1717
return [file for file in listOfFiles if not ( file.endswith('.log')
1818
or file.endswith('.RData')
19-
or file.endswith('.Rdata'))]
19+
or file.endswith('.Rdata')
20+
or file.startswith('.git'))]
2021

2122
#modifies the passed in dcmp object recursively to remove all files we don't care about
2223
def remove_irrelevant_files_from_dcmp(dcmp, filter_function=remove_irrelevant_files):
@@ -27,19 +28,19 @@ def remove_irrelevant_files_from_dcmp(dcmp, filter_function=remove_irrelevant_fi
2728
dcmp.right_only = filter_function(dcmp.right_only)
2829
dcmp.diff_files = filter_function(dcmp.diff_files)
2930
dcmp.funny_files = filter_function(dcmp.funny_files)
30-
dcmp.common_files = filter_function(dcmp.common_files)
31+
dcmp.common_files = filter_function(dcmp.common_files)
3132
dcmp.common_funny = filter_function(dcmp.common_funny)
3233

3334
for sub_dcmp in dcmp.subdirs.values():
3435
remove_irrelevant_files_from_dcmp(sub_dcmp)
35-
36+
3637
def are_all_files_common_func(dcmp):
3738
"""This will return true if the dcmp object passed in shows
3839
that both directories had the same files and subfolders (recursively)"""
3940
if len(dcmp.left_only) > 0:
40-
return False
41+
return False
4142
if len(dcmp.right_only) > 0:
42-
return False
43+
return False
4344

4445
for sub_dcmp in dcmp.subdirs.values():
4546
return are_all_files_common_func(sub_dcmp)
@@ -97,8 +98,8 @@ def are_outputs_equal(parameters):
9798
elif not os.path.isdir(args.outputs_new):
9899
raise Exception('outputs_reference "' + args.outputs_reference + '" exists but not outputs_new "' + args.outputs_new + '"')
99100

100-
print('python ' + os.path.realpath(__file__) + ' --outputs_reference "' + os.path.realpath(args.outputs_reference) + '" --outputs_new "' + os.path.realpath(args.outputs_new) + '"')
101-
dcmp = filecmp.dircmp(args.outputs_reference, args.outputs_new)
101+
print('python ' + os.path.realpath(__file__) + ' --outputs_reference "' + os.path.realpath(args.outputs_reference) + '" --outputs_new "' + os.path.realpath(args.outputs_new) + '"')
102+
dcmp = filecmp.dircmp(args.outputs_reference, args.outputs_new)
102103
remove_irrelevant_files_from_dcmp(dcmp)
103104

104105
are_all_files_common = are_all_files_common_func(dcmp)
@@ -129,7 +130,7 @@ def are_outputs_equal(parameters):
129130
#quickest and least memory method is to sum the hash of each line and then compare
130131
hash_sum_reference = get_hash_sum_of_lines(reference_file)
131132
hash_sum_new_file = get_hash_sum_of_lines(new_file)
132-
133+
133134
filesAreDifferent = hash_sum_reference != hash_sum_new_file
134135
if not filesAreDifferent:
135136
logging.debug('File "' + different_file + '" has identical content just in different order.')
@@ -172,7 +173,7 @@ def are_outputs_equal(parameters):
172173

173174
missing_from_new.sort(key=lambda line_count_tuple : line_count_tuple[0])
174175
missing_from_new = missing_from_new[:args.max_different_lines_to_show]
175-
176+
176177
print('hdr: ' + reference_header.strip('\n'))
177178
for missing_line_index in range(0, min(len(missing_from_reference), len(missing_from_new))):
178179
print('ref: ' + missing_from_reference[missing_line_index][0].strip('\n') + '\tmissing count: ' + str(abs(missing_from_reference[missing_line_index][1])))
@@ -182,14 +183,14 @@ def are_outputs_equal(parameters):
182183
actuallyDifferentFiles.append(different_file)
183184
result = result and not filesAreDifferent
184185
#print('Is "' + different_file + '" actually different?: ' + str(filesAreDifferent) + '. Is regression still passing?: ' + str(result))
185-
186+
186187
print('There were ' + str(len(all_common_different_files)) + ' that were binary different. Of those, ' + str(len(actuallyDifferentFiles)) + ' files differed in ways that mattered: ' + str(actuallyDifferentFiles))
187188
if result:
188189
print('PASSED! :-)')
189190
else:
190191
print('FAILED! :-(')
191192
return result
192-
193+
193194
if __name__ == "__main__":
194195
try:
195196
outputs_are_equal = are_outputs_equal(sys.argv[1:])

DaySim.Tests/DaySim.Tests.external/compare_output_directories/compare_output_directories.pyproj

-51
This file was deleted.

0 commit comments

Comments
 (0)