Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/respec/BASINS
Browse files Browse the repository at this point in the history
  • Loading branch information
mishranurag committed Jun 15, 2018
2 parents b60bbb7 + c5bfb9f commit 4dcfc25
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 36 deletions.
41 changes: 36 additions & 5 deletions atcTimeseriesWaterQualUS/atcTimeseriesWaterQualUS.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Imports Microsoft.VisualBasic.FileIO.TextFieldParser

Public Class atcTimeseriesWaterQualUS
Inherits atcTimeseriesSource
Private Shared pFilter As String = "WaterQualityData US Files (*.csv)|*.csv;|All Files (*.*)|*.*"
Private Shared pFilter As String = "WaterQualityData US Files (*.csv)|*.csv;|Filtered WaterQualityData US Files (*.csv.filtered)|*.csv.filtered;|All Files (*.*)|*.*"
Private pJulianInterval As Double = 1 'Add one day for daily values to record date at end of interval
Public RawDataGroup As New clsWQDUSLocations() 'Dictionary(Of String, clsWQDUSLocation)()
Public SelectAllLocations As Boolean = False
Expand Down Expand Up @@ -57,6 +57,7 @@ Public Class atcTimeseriesWaterQualUS
Throw New ApplicationException("Station file does not contain timeseries data: " & IO.Path.GetFileName(Specification))
Else
Try
RawDataGroup.FileName = Specification
Dim lTimeStartOpen As Date = Now
Logger.Dbg("OpenStartFor " & Specification)
Dim CurrentRecord() As String
Expand Down Expand Up @@ -108,10 +109,36 @@ Public Class atcTimeseriesWaterQualUS
If lDataColumnsValid Then
SelectedConstituents.Clear()
SelectedLocations.Clear()
Dim lfrm As New frmSelect(RawDataGroup, SelectedLocations, SelectedConstituents)
If lfrm.ShowDialog() = Windows.Forms.DialogResult.OK Then
If SelectedLocations.Count > 0 AndAlso SelectedConstituents.Count > 0 Then
Return BuildTimeseries()

'if filename ends with .csv.filtered, don't show form
If IO.Path.GetFileName(Specification).ToLower.EndsWith(".csv.filtered") Then
Dim lSortedList As New SortedList(Of String, Integer)()
For Each loc As String In RawDataGroup.Keys()
lSortedList.Add(loc, 0)
Next
For Each loc As String In lSortedList.Keys
SelectedLocations.Add(loc)
Next
lSortedList.Clear()
For Each cons As String In RawDataGroup.GetUniqueConstituentList()
If Not lSortedList.ContainsKey(cons) Then
lSortedList.Add(cons, 0)
End If
Next
For Each cons As String In lSortedList.Keys()
SelectedConstituents.Add(cons)
Next
Return BuildTimeseries()
Else
'else show form to select timeseries to include
Dim lfrm As New frmSelect(RawDataGroup, SelectedLocations, SelectedConstituents)
If lfrm.ShowDialog() = Windows.Forms.DialogResult.OK Then
If lfrm.cbxSave.Checked Then
Me.Specification = Me.Specification & ".filtered"
End If
If SelectedLocations.Count > 0 AndAlso SelectedConstituents.Count > 0 Then
Return BuildTimeseries()
End If
End If
End If
Else
Expand Down Expand Up @@ -139,11 +166,15 @@ Public Class atcTimeseriesWaterQualUS
Try
Dim lGroupBuilder As New atcTimeseriesGroupBuilder(Me)
Dim lTSBuilder As atcTimeseriesBuilder
Dim lMaxCount As Integer = RawDataGroup.Values.Count
Dim lCount As Integer = 0
For Each loc As clsWQDUSLocation In RawDataGroup.Values
lCount += 1
If Not SelectAllLocations AndAlso Not SelectedLocations.Contains(loc.Location) Then
Continue For
End If
For Each cons As clsWQDUSConstituent In loc.Constituents.Values
Logger.Progress(lCount, lMaxCount)
For Each lcon_unit As String In cons.RecordGroup.Keys
If Not SelectAllConstituents Then
If Not SelectedConstituents.Contains(cons.Name & "-" & lcon_unit) Then
Expand Down
1 change: 1 addition & 0 deletions atcTimeseriesWaterQualUS/clsWaterQualityDataUS.vb
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ End Class

Public Class clsWQDUSLocations
Public Locations As New Dictionary(Of String, clsWQDUSLocation)()
Public FileName As String
Public ReadOnly Property GetUniqueConstituentList() As List(Of String)
Get
Dim lsortedPreferred As New SortedList(Of String, Integer)()
Expand Down
61 changes: 51 additions & 10 deletions atcTimeseriesWaterQualUS/frmSelect.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 86 additions & 21 deletions atcTimeseriesWaterQualUS/frmSelect.vb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Imports System.Windows.Forms
Imports System.IO
Imports System.Text
Imports atcData

Public Class frmSelect
Private pRawDataGroup As clsWQDUSLocations
Private pSelectedLocations As List(Of String)
Private pSelectedConstituents As List(Of String)
Private pAllLocationsSelected As Boolean = False

Public Sub New(ByVal aRawDataGroup As clsWQDUSLocations,
ByRef aSelectedLocations As List(Of String),
Expand Down Expand Up @@ -72,29 +76,31 @@ Public Class frmSelect
End If
End Sub
Private Sub lstLocations_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles lstLocations.ItemCheck
txtMsgCons.Text = ""
If e.NewValue = CheckState.Checked Then
If Not pSelectedLocations.Contains(lstLocations.SelectedItem.ToString()) Then
pSelectedLocations.Add(lstLocations.SelectedItem.ToString())
End If
Dim loc As clsWQDUSLocation = pRawDataGroup.Item(lstLocations.SelectedItem)
Dim cons As List(Of String) = loc.DataKeys()
Dim lnalist As New List(Of String)()
For Each Item As String In lstConstituents.CheckedItems
If Not cons.Contains(Item) Then
lnalist.Add(Item)
If Not pAllLocationsSelected Then
txtMsgCons.Text = ""
If e.NewValue = CheckState.Checked Then
If Not pSelectedLocations.Contains(lstLocations.SelectedItem.ToString()) Then
pSelectedLocations.Add(lstLocations.SelectedItem.ToString())
End If
Next
Dim lmsg As String = loc.Location & " has none of the following:" & vbCrLf
If lnalist.Count > 0 Then
For Each itm As String In lnalist
lmsg &= itm & vbCrLf
Dim loc As clsWQDUSLocation = pRawDataGroup.Item(lstLocations.SelectedItem)
Dim cons As List(Of String) = loc.DataKeys()
Dim lnalist As New List(Of String)()
For Each Item As String In lstConstituents.CheckedItems
If Not cons.Contains(Item) Then
lnalist.Add(Item)
End If
Next
txtMsgCons.Text = lmsg
End If
Else
If pSelectedLocations.Contains(lstLocations.SelectedItem.ToString()) Then
pSelectedLocations.Remove(lstLocations.SelectedItem.ToString())
Dim lmsg As String = loc.Location & " has none of the following:" & vbCrLf
If lnalist.Count > 0 Then
For Each itm As String In lnalist
lmsg &= itm & vbCrLf
Next
txtMsgCons.Text = lmsg
End If
Else
If pSelectedLocations.Contains(lstLocations.SelectedItem.ToString()) Then
pSelectedLocations.Remove(lstLocations.SelectedItem.ToString())
End If
End If
End If
End Sub
Expand All @@ -109,8 +115,67 @@ Public Class frmSelect
End Sub

Private Sub btnDoTser_Click(sender As Object, e As EventArgs) Handles btnDoTser.Click
If cbxSave.Checked Then
SaveSelected()
End If
Me.DialogResult = DialogResult.OK
Close()
End Sub

Private Sub btnSelectAllCons_Click(sender As Object, e As EventArgs) Handles btnSelectAllCons.Click
For ind As Integer = 0 To lstConstituents.Items.Count - 1
lstConstituents.SelectedItem = lstConstituents.Items(ind)
pSelectedConstituents.Add(lstConstituents.Items(ind))
lstConstituents.SetItemChecked(ind, True)
Next
End Sub

Private Sub btnSelectAllLoc_Click(sender As Object, e As EventArgs) Handles btnSelectAllLoc.Click
pAllLocationsSelected = True
For ind As Integer = 0 To lstLocations.Items.Count - 1
lstLocations.SelectedItem = lstLocations.Items(ind)
pSelectedLocations.Add(lstLocations.Items(ind))
lstLocations.SetItemChecked(ind, True)
Next
pAllLocationsSelected = False
End Sub

Private Sub SaveSelected()
'open the original file
Dim lSB As New StringBuilder
Dim lStreamReader As New StreamReader(pRawDataGroup.FileName)
Dim lCurrentRecord As String
lCurrentRecord = lStreamReader.ReadLine 'first line is header
lSB.AppendLine(lCurrentRecord)
Do
lCurrentRecord = lStreamReader.ReadLine
If lCurrentRecord Is Nothing Then
Exit Do
Else
Dim lAppend As Boolean = False
For Each lLoc As String In pSelectedLocations
If lCurrentRecord.Contains(lLoc) Then
For Each lCon As String In pSelectedConstituents
Dim lConShort As String = lCon.Remove(lCon.IndexOf("-"))
If lCurrentRecord.Contains(lConShort) Then
lAppend = True
Exit For
End If
Next
End If
Next
If lAppend Then
lSB.AppendLine(lCurrentRecord)
End If
End If
Loop
atcUtility.SaveFileString(pRawDataGroup.FileName & ".filtered", lSB.ToString)

''rename file in project
'Dim lDataSource As atcTimeseriesWaterQualUS = Nothing
'lDataSource = atcDataManager.DataSourceBySpecification(pRawDataGroup.FileName)
'If lDataSource IsNot Nothing Then
' lDataSource.Specification = pRawDataGroup.FileName & ".filtered"
'End If
End Sub
End Class

0 comments on commit 4dcfc25

Please sign in to comment.