Skip to content

Commit

Permalink
Merge pull request #8391 from Vitalis95/inventory_missing
Browse files Browse the repository at this point in the history
Improvements to Inventory dialog
  • Loading branch information
lloyddewit committed Jun 23, 2023
2 parents 980819d + 428b244 commit f552aaa
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
39 changes: 28 additions & 11 deletions instat/dlgInventoryPlot.vb
Expand Up @@ -23,8 +23,9 @@ Public Class dlgInventoryPlot
Private clsClimaticDetails As New RFunction
Private clsAddKeyFunction As New RFunction
Private clsNewCAddKeyFunction As New RFunction

Private clsCumulativeInventoryFunction As New RFunction
Private clsDummyFunction As New RFunction
Private clsDataFrameFunction As New RFunction
Private bResetSubdialog As Boolean = True

Private Sub dlgInventoryPlot_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Expand Down Expand Up @@ -109,9 +110,7 @@ Public Class dlgInventoryPlot
ucrSaveDetails.SetSaveTypeAsDataFrame()
ucrSaveDetails.SetDataFrameSelector(ucrInventoryPlotSelector.ucrAvailableDataFrames)
ucrSaveDetails.SetIsComboBox()
' ucrSaveDetails.SetAssignToIfUncheckedValue("last_details")

' ucrChkHour.SetParameter(New RParameter("", ))
ucrChkHour.SetText("Hour") ' this currently has no parameter associated with it
' ucrChkHour.SetRDefault("FALSE")

Expand Down Expand Up @@ -170,7 +169,6 @@ Public Class dlgInventoryPlot
ucrPnlOptions.AddParameterValuesCondition(rdoMissing, "checked", "missing")
ucrPnlOptions.AddParameterValuesCondition(rdoGraph, "checked", "graph")


ucrPnlOptions.AddToLinkedControls({ucrChkDisplayRainDays, ucrChkFlipCoordinates, ucrChkShowNonMissing, ucrPnlPlotType, ucrSaveGraph, ucrInputTitle, ucrInputFacetBy}, {rdoGraph}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrPnlOptions.AddToLinkedControls({ucrChkSummary, ucrChkDetails}, {rdoMissing}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
ucrChkDetails.AddToLinkedControls({ucrChkDay}, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True)
Expand All @@ -194,6 +192,8 @@ Public Class dlgInventoryPlot
clsDummyFunction = New RFunction
clsAddKeyFunction = New RFunction
clsNewCAddKeyFunction = New RFunction
clsCumulativeInventoryFunction = New RFunction
clsDataFrameFunction = New RFunction

ucrInventoryPlotSelector.Reset()
ucrReceiverElements.SetMeAsReceiver()
Expand All @@ -212,7 +212,7 @@ Public Class dlgInventoryPlot

clsClimaticMissing.SetRCommand("climatic_missing")
clsClimaticDetails.SetRCommand("climatic_details")
clsClimaticDetails.SetAssignTo("last_details", strTempDataframe:=ucrInventoryPlotSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strDataFrameNames:="last_details")
clsClimaticDetails.SetAssignTo("detail")

clsNewCAddKeyFunction.SetRCommand("c")
clsNewCAddKeyFunction.AddParameter("from", Chr(34) & "From" & Chr(34), bIncludeArgumentName:=False, iPosition:=1)
Expand All @@ -224,8 +224,17 @@ Public Class dlgInventoryPlot
clsAddKeyFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_key")
clsAddKeyFunction.AddParameter("col_names", "key_cols", iPosition:=1)

clsCumulativeInventoryFunction.SetRCommand("cumulative_inventory")
clsCumulativeInventoryFunction.AddParameter("from", Chr(34) & "From" & Chr(34), iPosition:=1)
clsCumulativeInventoryFunction.AddParameter("to", Chr(34) & "To" & Chr(34), iPosition:=2)

clsDataFrameFunction.SetRCommand("data.frame")
clsDataFrameFunction.AddParameter("x", clsRFunctionParameter:=clsCumulativeInventoryFunction, bIncludeArgumentName:=False, iPosition:=0)
clsDataFrameFunction.SetAssignTo("last_details", strTempDataframe:=ucrInventoryPlotSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strDataFrameNames:="last_details")

ucrBase.clsRsyntax.ClearCodes()
ucrBase.clsRsyntax.AddToBeforeCodes(clsInventoryPlot, iPosition:=0)

clsInventoryPlot.iCallType = 3
clsInventoryPlot.bExcludeAssignedFunctionOutput = False

Expand Down Expand Up @@ -257,7 +266,7 @@ Public Class dlgInventoryPlot
ucrChkYear.SetRCode(clsClimaticDetails, bReset)
ucrChkMonth.SetRCode(clsClimaticDetails, bReset)
ucrChkDay.SetRCode(clsClimaticDetails, bReset)
ucrSaveDetails.SetRCode(clsClimaticDetails, bReset)
ucrSaveDetails.SetRCode(clsDataFrameFunction, bReset)
ucrChkOmitStart.SetRCode(clsClimaticMissing, bReset)
ucrChkOmitEnd.SetRCode(clsClimaticMissing, bReset)
ucrPnlOrder.SetRCode(clsClimaticDetails, bReset)
Expand Down Expand Up @@ -332,8 +341,8 @@ Public Class dlgInventoryPlot

Private Sub AddOrRemoveKeyFunctions()
If ucrSaveDetails.ucrChkSave.Checked AndAlso Not ucrReceiverStation.IsEmpty Then
ucrBase.clsRsyntax.AddToAfterCodes(clsNewCAddKeyFunction, iPosition:=3)
ucrBase.clsRsyntax.AddToAfterCodes(clsAddKeyFunction, iPosition:=4)
ucrBase.clsRsyntax.AddToAfterCodes(clsNewCAddKeyFunction, iPosition:=4)
ucrBase.clsRsyntax.AddToAfterCodes(clsAddKeyFunction, iPosition:=5)
Else
ucrBase.clsRsyntax.RemoveFromAfterCodes(clsAddKeyFunction)
ucrBase.clsRsyntax.RemoveFromAfterCodes(clsNewCAddKeyFunction)
Expand All @@ -353,11 +362,13 @@ Public Class dlgInventoryPlot

Private Sub ucrChkDetails_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkDetails.ControlValueChanged
If ucrChkDetails.Checked Then
ucrBase.clsRsyntax.ClearCodes()
ucrBase.clsRsyntax.AddToAfterCodes(clsClimaticDetails, iPosition:=2)
ucrBase.clsRsyntax.AddToAfterCodes(clsDataFrameFunction, iPosition:=3)
clsCumulativeInventoryFunction.AddParameter("data", clsRFunctionParameter:=clsClimaticDetails, iPosition:=0)
clsClimaticDetails.iCallType = 2
Else
ucrBase.clsRsyntax.RemoveFromAfterCodes(clsClimaticDetails)
ucrBase.clsRsyntax.RemoveFromAfterCodes(clsDataFrameFunction)
End If

End Sub
Expand All @@ -378,7 +389,6 @@ Public Class dlgInventoryPlot

Private Sub AllControls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrSaveGraph.ControlContentsChanged, ucrSaveDetails.ControlContentsChanged, ucrReceiverElements.ControlContentsChanged, ucrReceiverDate.ControlContentsChanged, ucrChkSummary.ControlContentsChanged, ucrChkDetails.ControlContentsChanged, ucrChkYear.ControlContentsChanged, ucrChkMonth.ControlContentsChanged, ucrChkDay.ControlContentsChanged, ucrChkHour.ControlContentsChanged, ucrChkMinute.ControlContentsChanged, ucrChkSecond.ControlContentsChanged, ucrPnlOptions.ControlContentsChanged
TestOkEnabled()

End Sub

Private Sub ucrReceiverStation_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverStation.ControlValueChanged
Expand All @@ -392,6 +402,13 @@ Public Class dlgInventoryPlot
Else
clsAddKeyFunction.RemoveParameterByName("data_name")
End If

If ucrSaveDetails.ucrChkSave.Checked Then
clsDataFrameFunction.SetAssignTo(ucrSaveDetails.GetText())
clsDataFrameFunction.iCallType = 0
Else
clsDataFrameFunction.RemoveAssignTo()
clsDataFrameFunction.iCallType = 2
End If
End Sub

End Class
29 changes: 29 additions & 0 deletions instat/static/InstatObject/R/stand_alone_functions.R
Expand Up @@ -2902,6 +2902,35 @@ get_vignette <- function (package = NULL, lib.loc = NULL, all = TRUE)
else return(sprintf("file://%s", file))
}

# for issue 8342 - adding in a count of the number of elements that have missing values by period (and station)
cumulative_inventory <- function(data, station = NULL, from, to){
if (is.null(station)){
data <- data %>%
dplyr::group_by(.data[[from]], .data[[to]]) %>%
dplyr::mutate(cum=dplyr::n())
data <- data %>%
dplyr::group_by(.data[[from]]) %>%
dplyr::mutate(cum1 = dplyr::n()) %>%
dplyr::mutate(cum1 = ifelse(cum == cum1, # are they all in the same period?
yes = cum,
no = ifelse(cum == max(cum),
cum,
max(cum) + 0.5)))
} else {
data <- data %>%
dplyr::group_by(.data[[station]], .data[[from]], .data[[to]]) %>%
dplyr::mutate(cum=dplyr::n())
data <- data %>%
dplyr::group_by(.data[[station]], .data[[from]]) %>%
dplyr::mutate(cum1 = dplyr::n()) %>%
dplyr::mutate(cum1 = ifelse(cum == cum1, # are they all in the same period?
yes = cum,
no = ifelse(cum == max(cum),
cum,
max(cum) + 0.5)))
}
return(data)
}



0 comments on commit f552aaa

Please sign in to comment.