Skip to content

Commit

Permalink
Bugfixes on reading numeric values for things that should be strings
Browse files Browse the repository at this point in the history
- When reading in numeric values for attributes, or attributes/states,
  etc. with a number as a name, the input routines no longer crash.
- Resolved an issue with datatypes of Compound.SVG, .PNG, and .PDF
  caused by the presence (or absence) of a required package.
  • Loading branch information
jvkerckh committed Feb 18, 2019
1 parent 8d6bde0 commit 67a4ee4
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 76 deletions.
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ Polynomials
SimJulia 0.5
ResumableFunctions
XLSX
Cairo
Fontconfig
2 changes: 1 addition & 1 deletion src/Functions/recruitment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ function readRecruitmentScheme( sheet::XLSX.Worksheet,
sheet[ XLSX.CellRef( 7, dataColNr ) ] )
recState = sheet[ XLSX.CellRef( 8, dataColNr ) ]
recState = isa( recState, Missings.Missing ) ||
lowercase( recState ) == "active" ? "" : recState
lowercase( string( recState ) ) == "active" ? "" : string( recState )
setRecruitState( recScheme, recState )
isAdaptive = sheet[ XLSX.CellRef( 11, dataColNr ) ] == "YES"
isRandom = sheet[ XLSX.CellRef( 12, dataColNr ) ] == "YES"
Expand Down
41 changes: 28 additions & 13 deletions src/Functions/simulationPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function showPlotsFromFile( mpSim::ManpowerSimulation, fName::String )::Void
end # if nPlots == 0

plotStates = plotSheet[ XLSX.CellRange( 13, 1, nPlots + 12, 1 ) ]
isMissing = isa.( plotStates, Missings.Missing )
plotStates[ .!isMissing ] = string.( plotStates[ .!isMissing ] )
plotList = Dict{Tuple{Float64, Bool},
Vector{Tuple{String, Vector{Bool}}}}()

Expand Down Expand Up @@ -107,6 +109,22 @@ function showPlotsFromFile( mpSim::ManpowerSimulation, fName::String )::Void
toShow = [ "personnel", "flux in", "flux out", "net flux" ]

if showPlots || savePlots
if savePlots
popPlotName = mpSim.parFileName[ 1:(end - 5) ]
popPlotName = joinpath( popPlotName, "population plot" )
inBreakdownName = replace( popPlotName, "population plot",
"in flux breakdown" )
outBreakdownName = replace( popPlotName, "population plot",
"out flux breakdown" )

# Wipe and create the necessary folders.
for dName in [ popPlotName, inBreakdownName,
outBreakdownName ]
rm( dName, force = true, recursive = true )
mkdir( dName )
end # for dName in dirname.( ...
end # if isSave

for timeKey in keys( plotList ), plotInfo in plotList[ timeKey ]
stateName, plotFlags = plotInfo
plotSimulationResults( mpSim, timeKey[ 1 ], showPlots,
Expand Down Expand Up @@ -230,6 +248,16 @@ function showFluxPlotsFromFile( mpSim::ManpowerSimulation,

# Make the plots.
if showPlots || savePlots
# Wipe folder if needed
if savePlots
plotDir = mpSim.parFileName[ 1:(end - 5) ]
plotDir = joinpath( plotDir, "flux plot" )

# Wipe and create folder.
rm( plotDir, force = true, recursive = true )
mkdir( plotDir )
end # if savePlots

for timeRes in keys( plotList )
plotFluxResults( mpSim, timeRes, showPlots, savePlots,
plotList[ timeRes ]..., fileName = reportFileName,
Expand Down Expand Up @@ -383,13 +411,6 @@ function plotSimulationResults( mpSim::ManpowerSimulation, timeRes::T1,
"in flux breakdown" )
outBreakdownName = replace( popPlotName, "population plot",
"out flux breakdown" )

# Wipe and create the necessary folders.
for dName in dirname.( [ popPlotName, inBreakdownName,
outBreakdownName ] )
rm( dName, force = true, recursive = true )
mkdir( dName )
end # for dName in dirname.( ...
end # if isSave

# Generate the reports for the requested state.
Expand Down Expand Up @@ -512,11 +533,6 @@ function plotFluxResults( mpSim::ManpowerSimulation, timeRes::T1, isShow::Bool,
if isSave
plotFileName = mpSim.parFileName[ 1:(end - 5) ]
plotFileName = joinpath( plotFileName, "flux plot" )

# Wipe and create folder.
rm( plotFileName, force = true, recursive = true )
mkdir( plotFileName )

plotFileName = joinpath( plotFileName, string( tNames[ ii ], " (",
timeRes / timeFactor, ").html" ) )
savefig( plt, plotFileName )
Expand All @@ -532,7 +548,6 @@ function plotFluxResults( mpSim::ManpowerSimulation, timeRes::T1, isShow::Bool,
if fileName != ""
tmpFileName = endswith( fileName, ".xlsx" ) ? fileName :
fileName * ".xlsx"
tmpFileName = joinpath( mpSim.parFileName[ 1:(end-5) ], tmpFileName )
dumpFluxData( mpSim, fluxData, timeRes, tmpFileName, overWrite,
timeFactor, tElapsed )
end # if fileName != ""
Expand Down
19 changes: 13 additions & 6 deletions src/Functions/simulationReport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,9 @@ the fluxes for each time interval `timeStart < t <= timeEnd`
except for the first row; that one counts the flux occurring at time `t = 0.0`.
"""
function generateFluxReport( mpSim::ManpowerSimulation, timeRes::T,
isInFlux::Bool, stateList::String... )::DataFrame where T <: Real
isInFlux::Bool, stateList::String... )::DataFrames.DataFrame where T <: Real

resultReport = DataFrame( Array{Float64}( 0, 2 ),
resultReport = DataFrames.DataFrame( Array{Float64}( 0, 2 ),
[ :timeStart, :timeEnd ] )

# Issue warning if time resolution is negative.
Expand All @@ -980,8 +980,14 @@ function generateFluxReport( mpSim::ManpowerSimulation, timeRes::T,
stateCat = catXF[ "States" ]
catStateList = stateCat[ XLSX.CellRange( 2, 1, nCatStates + 1,
1 ) ]
includeCatStates( mpSim, stateList..., stateCat,
catStateList )

if length( stateList ) > 1
includeCatStates( mpSim, string.( stateList )..., stateCat,
catStateList )
else
includeCatStates( mpSim, string( stateList ), stateCat,
catStateList )
end # if length( stateList ) > 1
end # if XLSX.hassheet( catXF, "General" ) && ...
end # XLSX.openxlsx( mpSim.catFileName ) do catXF

Expand Down Expand Up @@ -1016,7 +1022,7 @@ function generateFluxReport( mpSim::ManpowerSimulation, timeRes::T,
resultData = hcat( resultData, tmpResult )
end # for ii in eachindex( tmpStateList )

resultReport = DataFrame( resultData, vcat( :timeStart, :timeEnd,
resultReport = DataFrames.DataFrame( resultData, vcat( :timeStart, :timeEnd,
Symbol.( nameList ) ) )

return resultReport
Expand Down Expand Up @@ -1956,7 +1962,7 @@ file is created, otherwise a new sheet is added to the file.
This function returns a `Float6'`, the time (in seconds) it took to write the
Excel report.
"""
function dumpFluxData( mpSim::ManpowerSimulation, fluxData::DataFrame,
function dumpFluxData( mpSim::ManpowerSimulation, fluxData::DataFrames.DataFrame,
timeRes::T1, fileName::String, overWrite::Bool, timeFactor::T2,
reportGenerationTime::Float64 )::Float64 where T1 <: Real where T2 <: Real

Expand Down Expand Up @@ -2049,6 +2055,7 @@ function includeCatStates( mpSim, stateList, stateCat, catStateList )::Void
end



# Include the retrieval functions.
include( joinpath( funcPath, "simulationReportRetrieval.jl" ) )

Expand Down
Loading

0 comments on commit 67a4ee4

Please sign in to comment.