Skip to content

Conversation

@jesusalvino
Copy link
Contributor

Purpose

Implement the improvement https://jira.autodesk.com/browse/DYN-4469

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@zeusongit

FYIs

@RobertGlobant20 @filipeotero

@jesusalvino
Copy link
Contributor Author

numberformat_improvement

}
}

private bool IsDoubleRealNumber(string valueToTest)
Copy link
Contributor

@QilongTang QilongTang Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this function? Since this is only a one line if check, maybe we can just fold it to the function above?

if (double.TryParse(valueToTest, out double d) && !Double.IsNaN(d) && !Double.IsInfinity(d))
{
       return Convert.ToDouble(numberValue).ToString(nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat);
}
else
{
       return numberValue;
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this function? Since this is only a one line if check, maybe we can just fold it to the function above?

if (double.TryParse(valueToTest, out double d) && !Double.IsNaN(d) && !Double.IsInfinity(d))
{
       return Convert.ToDouble(numberValue).ToString(nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat);
}
else
{
       return numberValue;
 }

just wanted to keep separate it, probably it would be part of a helper class or similar so we can move latter, like ADSK.Dynamo.Helpers.IsDoubleRealNumber (maybe we already have a similar) or you approach to keep it simple is totally valid, please your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, in that case, I am fine with keeping it, but we should then probably move this function to one of DynamoUtilites file, like https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/Utilities/PreferencesPanelUtilities.cs. Also maybe pick a name easier to understand, like IsValidDoubleNumber?

Copy link
Contributor

@QilongTang QilongTang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with two comments

@aparajit-pratap
Copy link
Contributor

aparajit-pratap commented Feb 14, 2023

@jesusalvino I think there was some work done on this before and this issue is not isolated to only String from Object node. Here is the PR that tries to fix this issue more holistically. There was some work left on the UI side to add a default format preference that would not impose any digits: https://jira.autodesk.com/browse/DYN-5101. FYI @Amoursol .

I feel we should consider that previous work before merging this fix that is specific to just one node. ⚠️

@jesusalvino
Copy link
Contributor Author

@aparajit-pratap I have picked up your previous work and refactored the mine based on your suggestion in my last commit 584cbcb , your thoughts please.

Comment on lines 235 to 239
if (Data is double)
{
return (Data as IFormattable).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
}
else
Copy link
Contributor

@aparajit-pratap aparajit-pratap Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would comment out this code for the time being and leave a TODO comment here saying "uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete".

default:
if (double.TryParse(obj.ToString(), out double d))
{
return Convert.ToDouble(obj).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be ProtoCore.Mirror.MirrorData.PrecisionFormat.

return ObjectToLabelString(obj);
case TypeCode.Double:
return ((double)obj).ToString(numberFormat, CultureInfo.InvariantCulture);
return ((double)obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
Copy link
Contributor

@aparajit-pratap aparajit-pratap Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I would comment out this change for the time being until https://jira.autodesk.com/browse/DYN-5101 is done. Add a TODO.

IsCollection = label == WatchViewModel.LIST || label == WatchViewModel.DICTIONARY;
}

internal static string PrecisionFormat { get; set; } = "f3";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to add this property.

nodeViewModel.NodeModel.OutPorts.Select(p => p.Name).Where(n => !string.IsNullOrEmpty(n));
}

WatchViewModel.PrecisionFormat = nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file can be reverted entirely.

@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be reverted entirely.

@QilongTang QilongTang added this to the 2.18.0 milestone Feb 17, 2023
@QilongTang
Copy link
Contributor

Reported regression is sporadic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants