Skip to content

Commit

Permalink
Work issue #21: Split out PE and OBS export into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
lbross committed Apr 13, 2016
1 parent 05f04bc commit b2fe869
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/BAGIS_ClassLibrary/enumerations/PublicPath.vb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ Public Enum PublicPath
<Description("\map_parameters.txt")> MapParameters
<Description("\task_log.xml")> EBagisTaskLog
<Description("/FeatureServer/0")> FeatureServiceUrl
<Description("\BAGIS\bagis-h-settings.json")> BagisHSettings
End Enum
32 changes: 24 additions & 8 deletions src/BAGIS_P/Forms/FrmExportParametersEwsf.vb
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,10 @@ Public Class FrmExportParametersEwsf
If nmonthsTable IsNot Nothing Then
Dim paramNamesToUpdate As IList(Of String) = New List(Of String)
paramNamesToUpdate.Add(BA_Aoi_Parameter_jh_coef)
If CkPeAndSrObs.Checked Then
paramNamesToUpdate.Add(BA_Aoi_Parameter_PE_Obs)
paramNamesToUpdate.Add(BA_Aoi_Parameter_SR_Obs)
End If
'If CkPeAndSrObs.Checked Then
' paramNamesToUpdate.Add(BA_Aoi_Parameter_PE_Obs)
' paramNamesToUpdate.Add(BA_Aoi_Parameter_SR_Obs)
'End If
nmonthsTable = BA_UpdateParametersInNmonthsTable(nmonthsTable, m_aoiParamTable, paramNamesToUpdate)
m_tablesTable(NMONTHS) = nmonthsTable
End If
Expand Down Expand Up @@ -586,6 +586,18 @@ Public Class FrmExportParametersEwsf
retVal = BA_ConvertGDBToShapefile(hruGdbName, vName, zipFolder, targetFile)
'Copy the parameter file into the tempBagisFolder
File.Copy(TxtOutputFolder.Text, zipFolder & "\" & BA_GetBareName(TxtOutputFolder.Text), True)
'Create the pe and Obs file into the zipfolder (If desired)
Dim peAndObsExportPath As String = zipFolder & BA_EnumDescription(PublicPath.PeAndObsExportCsv)
If File.Exists(peAndObsExportPath) Then File.Delete(peAndObsExportPath)
If CkPeAndSrObs.Checked Then
Dim peParam As AoiParameter = Nothing
Dim srParam As AoiParameter = Nothing
If m_hasPeObs Then peParam = m_aoiParamTable(BA_Aoi_Parameter_PE_Obs)
If m_hasSrObs Then srParam = m_aoiParamTable(BA_Aoi_Parameter_SR_Obs)
retVal = BA_ExportPeAndSrFile(peAndObsExportPath, m_aoi.Name, peParam, srParam, _
missingData)
End If

m_exportMessage = "Converting HRU zones to ASCII .........."
LblStatus.Text = m_exportMessage
Dim hruClipPath As String = AddZonesToZipFolder(zipFolder, hruGdbName, targetFile)
Expand Down Expand Up @@ -620,14 +632,18 @@ Public Class FrmExportParametersEwsf
retVal = BA_ZipFolder(zipFolder, zipFileName)
End If

If success = True And retVal = BA_ReturnCode.Success Then
If retVal = BA_ReturnCode.Success Then
BA_Remove_Folder(zipFolder)
TimerStatus.Enabled = False
m_exportMessage = ""
LblStatus.Text = m_exportMessage
MessageBox.Show("Parameter file export complete !", _
"File export", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("An error occurred while trying to export the parameter file !", _
"File export", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
'Do this if we are successful or not
TimerStatus.Enabled = False
m_exportMessage = ""
LblStatus.Text = m_exportMessage
Else
TimerStatus.Enabled = False
m_exportMessage = ""
Expand Down
66 changes: 63 additions & 3 deletions src/BAGIS_P/ParameterModule.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,8 @@ Module ParameterModule
End Function

Public Function BA_ExportPeAndSrFile(ByVal outputFile As String, ByVal aoiName As String, _
ByVal pe_param As AoiParameter, ByVal sr_param As AoiParameter) As BA_ReturnCode
ByVal pe_param As AoiParameter, ByVal sr_param As AoiParameter, _
ByVal missingValue As String) As BA_ReturnCode
Dim sb As StringBuilder = New StringBuilder
Try
Using sw = New StreamWriter(outputFile)
Expand All @@ -1778,7 +1779,7 @@ Module ParameterModule
sb.Remove(0, sb.Length)
sb.Append(LEN_KEY)
sb.Append(",")
sb.Append(pe_param.ValuesList.Count)
sb.Append(NUM_MONTHS)
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
sb.Append(CREATED_AT)
Expand Down Expand Up @@ -1807,7 +1808,66 @@ Module ParameterModule
sb.Append(aoiName)
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)

sb.Append("unit_for_PE")
sb.Append(",")
sb.Append("inch/day")
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
sb.Append("unit_for_SR")
sb.Append(",")
sb.Append("langleys/day or calories/sq cm/day")
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
sb.Append(HEADER_FLAG)
sb.Append(",")
sb.Append("date")
sb.Append(",")
sb.Append(BA_Aoi_Parameter_PE_Obs)
sb.Append(",")
sb.Append(BA_Aoi_Parameter_SR_Obs)
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
sb.Append("Type")
sb.Append(",")
sb.Append("Date")
sb.Append(",")
sb.Append("Real")
sb.Append(",")
sb.Append("Real")
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
'Prepare to write table of values
Dim peValues As IList(Of String) = New List(Of String)
Dim srValues As IList(Of String) = New List(Of String)
If pe_param IsNot Nothing Then
peValues = pe_param.ValuesList
End If
If sr_param IsNot Nothing Then
srValues = sr_param.ValuesList
End If
'Write out table
For i As Short = 1 To NUM_MONTHS
sb.Append(",")
sb.Append(i)
sb.Append(",")
Dim nextPe As String = missingValue
If peValues.Count >= i - 1 Then
If peValues.Item(i - 1) IsNot Nothing Then
nextPe = peValues.Item(i - 1)
End If
End If
sb.Append(nextPe)
sb.Append(",")
Dim nextSr As String = missingValue
If srValues.Count >= i - 1 Then
If srValues.Item(i - 1) IsNot Nothing Then
nextSr = srValues.Item(i - 1)
End If
End If
sb.Append(nextSr)
sw.WriteLine(sb.ToString)
sb.Remove(0, sb.Length)
Next
End Using
Return BA_ReturnCode.Success
Catch ex As Exception
Expand Down

0 comments on commit b2fe869

Please sign in to comment.