Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Analytics Coverage for Python Operations #11208

Merged
merged 13 commits into from
Oct 29, 2020
11 changes: 9 additions & 2 deletions src/Libraries/DSCPython/CPythonEvaluator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Autodesk.DesignScript.Runtime;
Expand Down Expand Up @@ -262,7 +261,7 @@ private static void InstallPython()
}

/// <summary>
/// Creates and initializaes the global Python scope.
/// Creates and initializes the global Python scope.
/// </summary>
private static PyScope CreateGlobalScope()
{
Expand Down Expand Up @@ -553,6 +552,10 @@ private static void OnEvaluationBegin(PyScope scope,
if (EvaluationBegin != null)
{
EvaluationBegin(EvaluationState.Begin, scope, code, bindingValues);
Analytics.TrackEvent(
Dynamo.Logging.Actions.Start,
Dynamo.Logging.Categories.PythonOperations,
"CPythonEvaluation");
}
}

Expand All @@ -572,6 +575,10 @@ private static void OnEvaluationEnd(bool isSuccessful,
{
EvaluationEnd(isSuccessful ? EvaluationState.Success : EvaluationState.Failed,
scope, code, bindingValues);
Analytics.TrackEvent(
Dynamo.Logging.Actions.End,
Dynamo.Logging.Categories.PythonOperations,
"CPythonEvaluation");
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/Libraries/DSIronPython/IronPythonEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ private static void OnEvaluationBegin( ScriptEngine engine,
if (EvaluationBegin != null)
{
EvaluationBegin(EvaluationState.Begin, engine, scope, code, bindingValues);
Analytics.TrackEvent(
Dynamo.Logging.Actions.End,
Dynamo.Logging.Categories.PythonOperations,
"IronPythonEvaluation");
}
}

Expand All @@ -315,6 +319,10 @@ private static void OnEvaluationEnd( bool isSuccessful,
{
EvaluationEnd( isSuccessful ? EvaluationState.Success : EvaluationState.Failed,
engine, scope, code, bindingValues);
Analytics.TrackEvent(
Dynamo.Logging.Actions.End,
Dynamo.Logging.Categories.PythonOperations,
"IronPythonEvaluation");
}
}

Expand Down
22 changes: 21 additions & 1 deletion src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ private void OnSaveClicked(object sender, RoutedEventArgs e)
originalScript = editText.Text;
nodeModel.Engine = CachedEngine;
UpdateScript(editText.Text);
Analytics.TrackEvent(
Dynamo.Logging.Actions.Save,
Dynamo.Logging.Categories.PythonOperations);
}

private void OnRevertClicked(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -191,6 +194,9 @@ private void OnRunClicked(object sender, RoutedEventArgs e)
{
dynamoViewModel.HomeSpace.Run();
}
Analytics.TrackEvent(
Dynamo.Logging.Actions.Run,
Dynamo.Logging.Categories.PythonOperations);
}

private void OnMigrationAssistantClicked(object sender, RoutedEventArgs e)
Expand All @@ -199,6 +205,9 @@ private void OnMigrationAssistantClicked(object sender, RoutedEventArgs e)
throw new NullReferenceException(nameof(nodeModel));

UpdateScript(editText.Text);
Analytics.TrackEvent(
Dynamo.Logging.Actions.Migration,
Dynamo.Logging.Categories.PythonOperations);
nodeModel.RequestCodeMigration(e);
}

Expand All @@ -209,14 +218,25 @@ private void OnMoreInfoClicked(object sender, RoutedEventArgs e)

private void OnEngineChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (CachedEngine != nodeModel.Engine || originalScript != editText.Text) { nodeWasModified = true; }
if (CachedEngine != nodeModel.Engine)
{
Copy link
Member

Choose a reason for hiding this comment

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

👍

nodeWasModified = true;
// Cover what switch did user make. Only track when the new engine option is different with the previous one.
Analytics.TrackEvent(
Dynamo.Logging.Actions.Switch,
Dynamo.Logging.Categories.PythonOperations,
CachedEngine.ToString());
}
editText.Options.ConvertTabsToSpaces = CachedEngine != PythonEngineVersion.IronPython2;
}

private void OnScriptEditorWindowClosed(object sender, EventArgs e)
{
nodeModel.CodeMigrated -= OnNodeModelCodeMigrated;
this.Closed -= OnScriptEditorWindowClosed;
Analytics.TrackEvent(
Dynamo.Logging.Actions.Close,
Dynamo.Logging.Categories.PythonOperations);
}

#endregion
Expand Down
24 changes: 22 additions & 2 deletions src/NodeServices/IAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public enum Categories
/// Events Category related to DesignScript VM
/// </summary>
Engine,

/// <summary>
/// Events Category related to Python operations
/// </summary>
PythonOperations,
}

/// <summary>
Expand Down Expand Up @@ -99,7 +104,7 @@ public enum Actions
Open,

/// <summary>
/// Close Event, such as Close workspace
/// Close Event, such as Close workspace, Close Python Editor
/// </summary>
Close,

Expand All @@ -114,7 +119,7 @@ public enum Actions
Write,

/// <summary>
/// Save Event, such as Save workspace
/// Save Event, such as Save workspace and save Python code
/// </summary>
Save,

Expand Down Expand Up @@ -152,6 +157,21 @@ public enum Actions
/// Update Installed event
/// </summary>
Installed,

/// <summary>
/// Migration event, such as Python migration or DYN migration
/// </summary>
Migration,

/// <summary>
/// Switch event, such as Python engine switch, dropdown node switch
/// </summary>
Switch,

/// <summary>
/// Run event, such as Python node run clicked, Graph run Clicked
/// </summary>
Run,
}

/// <summary>
Expand Down
15 changes: 14 additions & 1 deletion src/PythonMigrationViewExtension/Controls/BaseDiffViewer.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Dynamo.PythonMigration.MigrationAssistant;
using Dynamo.Logging;
using Dynamo.PythonMigration.MigrationAssistant;
using System;
using System.Windows;

namespace Dynamo.PythonMigration.Controls
Expand Down Expand Up @@ -52,11 +54,22 @@ private void OnAcceptButtonClicked(object sender, RoutedEventArgs e)
{
ViewModel.ChangeCode();
this.Close();
// Record if changes are accepted and if there are proposed changes
Analytics.TrackEvent(
Dynamo.Logging.Actions.Migration,
Dynamo.Logging.Categories.PythonOperations,
"Accept",
Convert.ToInt32(ViewModel.CurrentViewModel.HasChanges));
}

private void OnRejectButtonClicked(object sender, RoutedEventArgs e)
{
this.Close();
Analytics.TrackEvent(
Dynamo.Logging.Actions.Migration,
Dynamo.Logging.Categories.PythonOperations,
"Reject",
Convert.ToInt32(ViewModel.CurrentViewModel.HasChanges));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IDiffViewViewModel
{
ViewMode ViewMode { get; }
State DiffState { get; set; }
bool HasChanges { get; }
}

public enum ViewMode
Expand Down
2 changes: 1 addition & 1 deletion src/PythonMigrationViewExtension/Differ/InLineViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class InLineViewModel : IDiffViewViewModel
{
public ViewMode ViewMode { get; set; }
public DiffPaneModel DiffModel { get; set; }
private bool HasChanges { get { return DiffModel.HasDifferences; } }
public bool HasChanges { get { return DiffModel.HasDifferences; } }

private State diffState;
public State DiffState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SideBySideViewModel : IDiffViewViewModel
public SideBySideDiffModel DiffModel { get; set; }
public DiffPaneModel AfterPane { get { return DiffModel.NewText; } }
public DiffPaneModel BeforePane { get { return DiffModel.OldText; } }
private bool HasChanges { get { return DiffModel.NewText.HasDifferences | DiffModel.OldText.HasDifferences; } }
public bool HasChanges { get { return DiffModel.NewText.HasDifferences | DiffModel.OldText.HasDifferences; } }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mmisol @aparajit-pratap @mjkkirschner I dont recall why we specifically made this property private, but I would like to expose it on interface level and add analytics coverage so we know not only user clicked accept or Reject but also if there are any real code changes.


private State diffState;
public State DiffState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<ProjectReference Include="..\NodeServices\DynamoServices.csproj">
Copy link
Member

Choose a reason for hiding this comment

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

whats added from this project?

Copy link
Contributor Author

@QilongTang QilongTang Oct 27, 2020

Choose a reason for hiding this comment

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

Analytics is only available from logging, so in the future, everytime we want to track on extension layer (at least the OOTB ones developed by us), this will be a dependency in that case seems. We could expose APIs but unless we expose dashboards as well, APIs wont be useful I think

<Project>{ef879a10-041d-4c68-83e7-3192685f1bae}</Project>
<Name>DynamoServices</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
7 changes: 1 addition & 6 deletions test/DynamoCoreTests/Models/UndoRedoCommandTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework;
using static Dynamo.Models.DynamoModel;

namespace Dynamo.Tests.ModelsTest
Expand Down